List of usage examples for java.util Locale getISO3Language
public String getISO3Language() throws MissingResourceException
From source file:com.amsterdam.marktbureau.makkelijkemarkt.AboutFragment.java
/** * Inflate the about_fragment layout containing the about text from strings resource * @param inflater LayoutInflater//from w w w .java 2 s . c om * @param container ViewGroup * @param savedInstanceState Bundle * @return View */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // get the about fragment View view = inflater.inflate(R.layout.about_fragment, container, false); // bind the elements to the view ButterKnife.bind(this, view); // load the about text from the assets depending on the locale String about_html = "about-nl.html"; Locale current = getResources().getConfiguration().locale; if (current.getISO3Language().equals("eng")) { about_html = "about-en.html"; } mAboutWebView.loadUrl("file:///android_asset/" + about_html); return view; }
From source file:Deet.java
private boolean testDeet(Locale l) { // getISO3Language() may throw a MissingResourceException out.format("Locale = %s, ISO Language Code = %s%n", l.getDisplayName(), l.getISO3Language()); return true;/*from w w w.ja v a2s . co m*/ }
From source file:org.entrystore.repository.impl.converters.OAI_DC2RDFGraphConverter.java
private String getISO2Language(String iso3Language) { if (localeMap == null) { String[] languages = Locale.getISOLanguages(); localeMap = new HashMap<String, Locale>(languages.length); for (String language : languages) { Locale locale = new Locale(language); localeMap.put(locale.getISO3Language(), locale); }/*from w w w . jav a 2s.c om*/ } Locale locale = localeMap.get(iso3Language); if (locale != null) { return locale.getLanguage(); } return null; }
From source file:com.michellemay.mappings.ISO639Alpha3Mapping.java
/** * Instantiates a new ISO 639 alpha 3 mapping. */// w w w.j av a 2 s. c o m public ISO639Alpha3Mapping() { super(NAME); // Build reverse map HashMap<String, Locale> map = new HashMap<String, Locale>(); for (Locale loc : LocaleUtils.availableLocaleList()) { String isoCode = loc.getLanguage(); if (isoCode.length() > 0) { String displayValue = loc.getISO3Language().toLowerCase(); if (!map.containsKey(displayValue)) { map.put(displayValue, LocaleUtils.toLocale(isoCode)); } } } this.withMapping(map).withCaseSensitive(false); }
From source file:net.felsing.client_cert.GetCountries.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final Locale defaultLanguage = Locale.ENGLISH; String bestLanguage = null;/*ww w .jav a 2 s . c o m*/ resp.setContentType("application/json; charset=UTF-8"); resp.setCharacterEncoding("UTF-8"); final String acceptLanguage = StringEscapeUtils.escapeJava(req.getHeader("Accept-Language")); List<Locale.LanguageRange> languageRanges = Locale.LanguageRange.parse(acceptLanguage); for (Locale.LanguageRange l : languageRanges) { try { if (bestLanguage == null) { Locale locale = new Locale(l.getRange().split("-")[0]); bestLanguage = locale.getISO3Language(); logger.debug("bestLanguage: " + bestLanguage); usedLocale = locale; } } catch (Exception e) { // do nothing } } if (bestLanguage == null) { logger.debug("No sufficient language found for " + acceptLanguage); bestLanguage = defaultLanguage.getISO3Language(); usedLocale = Locale.ENGLISH; } logger.debug("usedLocale: " + usedLocale.getISO3Language()); PrintWriter pw = resp.getWriter(); loadFromJson(context); List<Country> countriesList = new ArrayList<>(); for (JsonElement jsonElement : countries) { String cca2 = jsonElement.getAsJsonObject().get("cca2").toString().replaceAll("\\\"", ""); cca2 = cca2.replaceAll("\\\\", ""); Country countryItem = new Country(); try { countryItem.name = jsonElement.getAsJsonObject().get("name").getAsJsonObject().get(bestLanguage) .getAsJsonObject().get("common").getAsString(); } catch (NullPointerException e) { countryItem.name = jsonElement.getAsJsonObject().get("name_").getAsString(); } countryItem.cca2 = cca2; countriesList.add(countryItem); } Collator coll = Collator.getInstance(usedLocale); coll.setStrength(Collator.PRIMARY); Collections.sort(countriesList); pw.print(new Gson().toJson(countriesList)); pw.flush(); }
From source file:org.sonar.core.i18n.DefaultI18n.java
public Locale getEffectiveLocale(Locale locale) { Locale bundleLocale = ResourceBundle .getBundle(BUNDLE_PACKAGE + "core", locale, this.classloader, this.control).getLocale(); locale.getISO3Language(); return bundleLocale.getLanguage().isEmpty() ? Locale.ENGLISH : bundleLocale; }
From source file:org.mili.core.resource.MissingResourceLogger.java
void save(Locale l) throws IOException { Properties p = new Properties(); String filenameProp = System.getProperty(ResourceUtil.PROP_MISSINGRESOURCELOGGERFILENAME); File file = null;/* w w w . j av a 2 s . co m*/ if (StringUtils.isEmpty(filenameProp)) { file = new File(new File(System.getProperty("java.io.tmpdir")), "missing-properties-" + l.getISO3Language() + ".properties"); } else { file = new File(filenameProp.replace("%0", l.getISO3Language())); } if (file.exists()) { InputStream is = new FileInputStream(file); p.load(is); is.close(); } Map<String, String> m = this.model.get(l); for (Iterator<String> i = m.keySet().iterator(); i.hasNext();) { String k = i.next(); p.put(k, ""); } OutputStream os = new FileOutputStream(file); p.store(os, "missing properties found by core.resource.MissingResourceLogger"); os.close(); return; }
From source file:org.mili.core.resource.ResourceUtilImpl.java
private String getInfo(Locale l, String baseName, String key) { final String pattern = "[locale=%1-%2, baseName=%3, key=%4]"; return pattern.replace("%1", l.getISO3Country()).replace("%2", l.getISO3Language()).replace("%3", baseName) .replace("%4", key); }
From source file:eu.inmite.apps.smsjizdenka.service.UpdateService.java
@Override protected void onHandleIntent(Intent intent) { if (intent == null) { return;/* w ww . j av a2 s . com*/ } final boolean force = intent.getBooleanExtra("force", false); try { Locale loc = Locale.getDefault(); String lang = loc.getISO3Language(); // http://www.loc.gov/standards/iso639-2/php/code_list.php; T-values if present both T and B if (lang == null || lang.length() == 0) { lang = ""; } int serverVersion = intent.getIntExtra("serverVersion", -1); boolean fromPush = serverVersion != -1; JSONObject versionJson = null; if (!fromPush) { versionJson = getVersion(true); serverVersion = versionJson.getInt("version"); } int localVersion = Preferences.getInt(c, Preferences.DATA_VERSION, -1); final String localLanguage = Preferences.getString(c, Preferences.DATA_LANGUAGE, ""); if (serverVersion <= localVersion && !force && lang.equals(localLanguage) && !LOCAL_DEFINITION_TESTING) { // don't update DebugLog.i("Nothing new, not updating"); return; } // update but don't notify about it. boolean firstLaunchNoUpdate = ((localVersion == -1 && getVersion(false).getInt("version") == serverVersion) || !lang.equals(localLanguage)); if (!firstLaunchNoUpdate) { DebugLog.i("There are new definitions available!"); } handleAuthorMessage(versionJson, lang, intent, fromPush); InputStream is = getIS(URL_TICKETS_ID); try { String json = readResult(is); JSONObject o = new JSONObject(json); JSONArray array = o.getJSONArray("tickets"); final SQLiteDatabase db = DatabaseHelper.get(this).getWritableDatabase(); for (int i = 0; i < array.length(); i++) { final JSONObject city = array.getJSONObject(i); try { final ContentValues cv = new ContentValues(); cv.put(Cities._ID, city.getInt("id")); cv.put(Cities.CITY, getStringLocValue(city, lang, "city")); if (city.has("city_pubtran")) { cv.put(Cities.CITY_PUBTRAN, city.getString("city_pubtran")); } cv.put(Cities.COUNTRY, city.getString("country")); cv.put(Cities.CURRENCY, city.getString("currency")); cv.put(Cities.DATE_FORMAT, city.getString("dateFormat")); cv.put(Cities.IDENTIFICATION, city.getString("identification")); cv.put(Cities.LAT, city.getDouble("lat")); cv.put(Cities.LON, city.getDouble("lon")); cv.put(Cities.NOTE, getStringLocValue(city, lang, "note")); cv.put(Cities.NUMBER, city.getString("number")); cv.put(Cities.P_DATE_FROM, city.getString("pDateFrom")); cv.put(Cities.P_DATE_TO, city.getString("pDateTo")); cv.put(Cities.P_HASH, city.getString("pHash")); cv.put(Cities.PRICE, city.getString("price")); cv.put(Cities.PRICE_NOTE, getStringLocValue(city, lang, "priceNote")); cv.put(Cities.REQUEST, city.getString("request")); cv.put(Cities.VALIDITY, city.getInt("validity")); if (city.has("confirmReq")) { cv.put(Cities.CONFIRM_REQ, city.getString("confirmReq")); } if (city.has("confirm")) { cv.put(Cities.CONFIRM, city.getString("confirm")); } final JSONArray additionalNumbers = city.getJSONArray("additionalNumbers"); for (int j = 0; j < additionalNumbers.length() && j < 3; j++) { cv.put("ADDITIONAL_NUMBER_" + (j + 1), additionalNumbers.getString(j)); } db.beginTransaction(); int count = db.update(DatabaseHelper.CITY_TABLE_NAME, cv, Cities._ID + " = " + cv.getAsInteger(Cities._ID), null); if (count == 0) { db.insert(DatabaseHelper.CITY_TABLE_NAME, null, cv); } db.setTransactionSuccessful(); getContentResolver().notifyChange(Cities.CONTENT_URI, null); } finally { if (db.inTransaction()) { db.endTransaction(); } } } Preferences.set(c, Preferences.DATA_VERSION, serverVersion); Preferences.set(c, Preferences.DATA_LANGUAGE, lang); if (!firstLaunchNoUpdate && !fromPush) { final int finalServerVersion = serverVersion; mHandler.post(new Runnable() { @Override public void run() { Toast.makeText(UpdateService.this, getString(R.string.cities_update_completed, finalServerVersion), Toast.LENGTH_LONG).show(); } }); } if (LOCAL_DEFINITION_TESTING) { DebugLog.w( "Local definition testing - data updated from assets - must be removed in production!"); } } finally { is.close(); } } catch (IOException e) { DebugLog.e("IOException when calling update: " + e.getMessage(), e); } catch (JSONException e) { DebugLog.e("JSONException when calling update: " + e.getMessage(), e); } }
From source file:com.github.olga_yakovleva.rhvoice.android.RHVoiceService.java
@Override protected String[] onGetLanguage() { String[] result = { "rus", "RUS", "" }; AndroidVoiceInfo voice = currentVoice; if (voice == null) { Tts tts = ttsManager.get();/*www. j a va 2s. co m*/ if (tts != null) { Locale locale = Locale.getDefault(); Candidate bestMatch = findBestVoice(tts, locale.getISO3Language(), locale.getISO3Country(), "", "", getLanguageSettings(tts)); if (bestMatch.voice != null) voice = bestMatch.voice; } } if (voice == null) return result; result[0] = voice.getLanguage(); result[1] = voice.getCountry(); return result; }