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; }
/** * Returns a normalized RFC 639-2/T code for {@code language}. * * @param language A case-insensitive ISO 639 alpha-2 or alpha-3 language code. * @return The all-lowercase normalized code, or null if the input was null, or {@code * language.toLowerCase()} if the language could not be normalized. */ public static @Nullable String normalizeLanguageCode(@Nullable String language) { try { return language == null ? null : new Locale(language).getISO3Language(); } catch (MissingResourceException e) { return toLowerInvariant(language); } }
public LanguagesListerGlosbe() { final String [] languages ={"eng", "deu", "jpn", "fra", "spa", "pol", "ita", "rus", "ces", "zho", "nld", "por", "swe", "hrv", "hin", "hun", "vie", "ara", "tur"}; // Java Locale uses ISO 639-2 rather than 639-3 so we currently only support the subset of // the languages on Glosbe which are in ISO 639-2. "Chinese Mandarin" ("cmn") for example // is not supported, but "Chinese" ("zho") is. for (String l : languages) { Locale locale = new Locale(l); addLanguage(locale.getDisplayLanguage(), locale.getISO3Language()); } }
protected void extractLanguage(List<Document> ttmls) { String firstLang = null; for (Document ttml : ttmls) { String lang = getLanguage(ttml); if (firstLang == null) { firstLang = lang; trackMetaData.setLanguage(Locale.forLanguageTag(lang).getISO3Language()); } else if (!firstLang.equals(lang)) { throw new RuntimeException("Within one Track all sample documents need to have the same language"); } } }
/** * Convert from 3 letter ISO 639-2 language code to ISO 639-1 * @param req 3 letter language code * @return 2 letter language code */ public static String requestToResponseLangCode(String req) { if (locale_map == null) { String[] languages = Locale.getISOLanguages(); locale_map = new HashMap<>(languages.length); for (String language : languages) { Locale locale = new Locale(language); locale_map.put(locale.getISO3Language(), locale); } } return locale_map.get(req).getLanguage(); } }
@Signature public Memory getISO3Language(Environment env, Memory... args) { return StringMemory.valueOf(locale.getISO3Language()); }
for (int i = 0; i < availableTtsLocales.size(); i++) { dialogItems.add(availableTtsLocales.get(i).getDisplayName()); dialogIds.add(availableTtsLocales.get(i).getISO3Language());
public WebVttTrack(InputStream is, String trackName, Locale locale) throws IOException { super(trackName); trackMetaData.setTimescale(1000); trackMetaData.setLanguage(locale.getISO3Language()); long mediaTimestampUs = 0;
@Override public void handle(Request request, Response response) throws Exception { Date timestamp = request.paramAsDateTime(TS_PARAM); if (timestamp != null && timestamp.after(server.getStartedAt())) { response.stream().setStatus(HTTP_NOT_MODIFIED).output().close(); return; } String localeParam = request.mandatoryParam(LOCALE_PARAM); Locale locale = Locale.forLanguageTag(localeParam); checkArgument(!locale.getISO3Language().isEmpty(), "'%s' cannot be parsed as a BCP47 language tag", localeParam); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); json.prop("effectiveLocale", i18n.getEffectiveLocale(locale).toLanguageTag()); json.name("messages"); json.beginObject(); i18n.getPropertyKeys().forEach(messageKey -> json.prop(messageKey, i18n.message(locale, messageKey, messageKey))); json.endObject(); json.endObject(); } } }
protected static String getLanguageIso3() { try { return Locale.getDefault().getISO3Language().toLowerCase(Locale.US); } catch (MissingResourceException e) { return LANGUAGE_DEFAULT_ISO3; } }
String[] languages = Locale.getISOLanguages(); Map<String, Locale> localeMap = new HashMap<String, Locale>(languages.length); for (String language : languages) { Locale locale = new Locale(language); localeMap.put(locale.getISO3Language(), locale); }
/** * Checks if specified locale object is valid * * @param locale * object for validation * @return true if locale is available */ public static boolean isValid(Locale locale) { try { return locale.getISO3Language() != null && locale.getISO3Country() != null; } catch (MissingResourceException e) { return false; } }
public void setResources(String locale) { // validate locale Locale lo = parseLocale(locale); if (isValid(lo)) { System.out.println(lo.getDisplayCountry()); } else { System.out.println("invalid: " + locale); } } private Locale parseLocale(String locale) { String[] parts = locale.split("_"); switch (parts.length) { case 3: return new Locale(parts[0], parts[1], parts[2]); case 2: return new Locale(parts[0], parts[1]); case 1: return new Locale(parts[0]); default: throw new IllegalArgumentException("Invalid locale: " + locale); } } private boolean isValid(Locale locale) { try { return locale.getISO3Language() != null && locale.getISO3Country() != null; } catch (MissingResourceException e) { return false; } }
locale.getISO3Language(); } catch (MissingResourceException e) { throw new IllegalArgumentException("Unknown language: " + parts[0], e);
@Override public void afterPropertiesSet() throws Exception { lang3to2 = new HashMap<String, String>(); for (Locale locale : Locale.getAvailableLocales()) { try { lang3to2.put(locale.getISO3Language(), locale.getLanguage()); } catch (MissingResourceException e) { continue; } } }
for (Locale locale : Locale.getAvailableLocales()) { System.out.println("" + locale + "; display: " + locale.getDisplayLanguage() + "; name: " + locale.getDisplayName() + "; lang: " + locale.getLanguage() + "; iso3: " + locale.getISO3Language()); }
/** * Initialize PubmedLanguageMetadatumContributor and create the iso3toiso2 mapping used in the transforming of * language codes */ public PubmedLanguageMetadatumContributor() { iso3toIso2 = new HashMap<>(); // Populate the languageMap with the mapping between iso3 and iso2 language codes for (Locale locale : Locale.getAvailableLocales()) { iso3toIso2.put(locale.getISO3Language(), locale.getLanguage()); } }
public String toISO3(String name) { for (Locale locale : Locale.getAvailableLocales()) { if (name.equals(locale.getDisplayLanguage()) { return locale.getISO3Language(); } } throw new IllegalArgumentException("No language found: " + name); }
public String getLangString() { String country = this.lang.getISO3Country(); String language = this.lang.getISO3Language(); StringBuilder sb = new StringBuilder(language); if (!country.isEmpty()) { sb.append("-").append(country); } return sb.toString(); }
@Override public void onLocaleChange(Locale locale, int localeResId, Context context, LocaleChangeListenable listenable) { switch (locale.getISO3Language().toLowerCase()) { case "rus": listenable.setText(context.getResources().getString(R.string.custom_text)); break; case "eng": listenable.setText(context.getResources().getString(R.string.custom_text)); break; } } });