java.util.Locale.getISO3Language()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(206)

本文整理了Java中java.util.Locale.getISO3Language()方法的一些代码示例,展示了Locale.getISO3Language()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.getISO3Language()方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:getISO3Language

Locale.getISO3Language介绍

[英]Returns the three-letter ISO 639-2/T language code which corresponds to the language code for this Locale.
[中]返回与此区域设置的语言代码相对应的三字母ISO 639-2/T语言代码。

代码示例

代码示例来源:origin: SonarSource/sonarqube

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;
}

代码示例来源:origin: google/ExoPlayer

/**
 * 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);
 }
}

代码示例来源:origin: ankidroid/Anki-Android

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());
  }
}

代码示例来源:origin: sannies/mp4parser

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");
    }
  }
}

代码示例来源:origin: ankidroid/Anki-Android

/**
   * 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();
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory getISO3Language(Environment env, Memory... args) {
  return StringMemory.valueOf(locale.getISO3Language());
}

代码示例来源:origin: ankidroid/Anki-Android

for (int i = 0; i < availableTtsLocales.size(); i++) {
  dialogItems.add(availableTtsLocales.get(i).getDisplayName());
  dialogIds.add(availableTtsLocales.get(i).getISO3Language());

代码示例来源:origin: sannies/mp4parser

public WebVttTrack(InputStream is, String trackName, Locale locale) throws IOException {
  super(trackName);
  trackMetaData.setTimescale(1000);
  trackMetaData.setLanguage(locale.getISO3Language());
  long mediaTimestampUs = 0;

代码示例来源:origin: SonarSource/sonarqube

@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();
  }
 }
}

代码示例来源:origin: delight-im/Android-AdvancedWebView

protected static String getLanguageIso3() {
  try {
    return Locale.getDefault().getISO3Language().toLowerCase(Locale.US);
  }
  catch (MissingResourceException e) {
    return LANGUAGE_DEFAULT_ISO3;
  }
}

代码示例来源:origin: stackoverflow.com

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);
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * 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;
  }
}

代码示例来源:origin: stackoverflow.com

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;
 }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

locale.getISO3Language();
} catch (MissingResourceException e) {
  throw new IllegalArgumentException("Unknown language: " + parts[0], e);

代码示例来源:origin: DSpace/DSpace

@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;
    }
  }
}

代码示例来源:origin: stackoverflow.com

for (Locale locale : Locale.getAvailableLocales()) {
   System.out.println("" + locale
       + "; display: " + locale.getDisplayLanguage()
       + "; name: " + locale.getDisplayName()
       + "; lang: " + locale.getLanguage()
       + "; iso3: " + locale.getISO3Language());
 }

代码示例来源:origin: DSpace/DSpace

/**
 * 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());
  }
}

代码示例来源:origin: stackoverflow.com

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);
}

代码示例来源:origin: org.n52.janmayen/janmayen

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();
}

代码示例来源:origin: metalurgus/LocaleText

@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;
    }
  }
});

相关文章