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

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

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

Locale.getVariant介绍

[英]Returns the variant code for this Locale or an empty String if no variant was set.
[中]返回此区域设置的变量代码,如果未设置变量,则返回空字符串。

代码示例

代码示例来源:origin: aws/aws-sdk-java

  1. @Override
  2. public final String convert(final Locale o) {
  3. final StringBuilder value = new StringBuilder(o.getLanguage());
  4. if (!o.getCountry().isEmpty() || !o.getVariant().isEmpty()) {
  5. value.append("-").append(o.getCountry());
  6. }
  7. if (!o.getVariant().isEmpty()) {
  8. value.append("-").append(o.getVariant());
  9. }
  10. return value.toString(); //JDK7+: return o.toLanguageTag();
  11. }
  12. };

代码示例来源:origin: org.apache.commons/commons-lang3

  1. /**
  2. * <p>Obtains the list of languages supported for a given country.</p>
  3. *
  4. * <p>This method takes a country code and searches to find the
  5. * languages available for that country. Variant locales are removed.</p>
  6. *
  7. * @param countryCode the 2 letter country code, null returns empty
  8. * @return an unmodifiable List of Locale objects, not null
  9. */
  10. public static List<Locale> languagesByCountry(final String countryCode) {
  11. if (countryCode == null) {
  12. return Collections.emptyList();
  13. }
  14. List<Locale> langs = cLanguagesByCountry.get(countryCode);
  15. if (langs == null) {
  16. langs = new ArrayList<>();
  17. final List<Locale> locales = availableLocaleList();
  18. for (final Locale locale : locales) {
  19. if (countryCode.equals(locale.getCountry()) &&
  20. locale.getVariant().isEmpty()) {
  21. langs.add(locale);
  22. }
  23. }
  24. langs = Collections.unmodifiableList(langs);
  25. cLanguagesByCountry.putIfAbsent(countryCode, langs);
  26. langs = cLanguagesByCountry.get(countryCode);
  27. }
  28. return langs;
  29. }

代码示例来源:origin: com.atlassian.jira/jira-api

  1. public void setCountry(String country)
  2. {
  3. // Grab the old locale
  4. Locale oldLocale = getLocale();
  5. // Create a new one
  6. Locale newLocale = new Locale(oldLocale.getLanguage(), country, oldLocale.getVariant());
  7. setLocale(newLocale);
  8. }

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

  1. /**
  2. * Resolves locale code from locale.
  3. */
  4. public static String resolveLocaleCode(Locale locale) {
  5. return resolveLocaleCode(locale.getLanguage(), locale.getCountry(), locale.getVariant());
  6. }

代码示例来源:origin: commons-lang/commons-lang

  1. /**
  2. * <p>Obtains the list of languages supported for a given country.</p>
  3. *
  4. * <p>This method takes a country code and searches to find the
  5. * languages available for that country. Variant locales are removed.</p>
  6. *
  7. * @param countryCode the 2 letter country code, null returns empty
  8. * @return an unmodifiable List of Locale objects, never null
  9. */
  10. public static List languagesByCountry(String countryCode) {
  11. List langs = (List) cLanguagesByCountry.get(countryCode); //syncd
  12. if (langs == null) {
  13. if (countryCode != null) {
  14. langs = new ArrayList();
  15. List locales = availableLocaleList();
  16. for (int i = 0; i < locales.size(); i++) {
  17. Locale locale = (Locale) locales.get(i);
  18. if (countryCode.equals(locale.getCountry()) &&
  19. locale.getVariant().length() == 0) {
  20. langs.add(locale);
  21. }
  22. }
  23. langs = Collections.unmodifiableList(langs);
  24. } else {
  25. langs = Collections.EMPTY_LIST;
  26. }
  27. cLanguagesByCountry.put(countryCode, langs); //syncd
  28. }
  29. return langs;
  30. }

代码示例来源:origin: spring-projects/spring-framework

  1. String language = locale.getLanguage();
  2. String country = locale.getCountry();
  3. String variant = locale.getVariant();
  4. StringBuilder temp = new StringBuilder(basename);

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

  1. /**
  2. * Returns the {@code Currency} instance for this {@code Locale}'s country.
  3. * @throws IllegalArgumentException
  4. * if the locale's country is not a supported ISO 3166 country.
  5. */
  6. public static Currency getInstance(Locale locale) {
  7. synchronized (localesToCurrencies) {
  8. Currency currency = localesToCurrencies.get(locale);
  9. if (currency != null) {
  10. return currency;
  11. }
  12. String country = locale.getCountry();
  13. String variant = locale.getVariant();
  14. if (!variant.isEmpty() && (variant.equals("EURO") || variant.equals("HK") ||
  15. variant.equals("PREEURO"))) {
  16. country = country + "_" + variant;
  17. }
  18. String currencyCode = ICU.getCurrencyCode(country);
  19. if (currencyCode == null) {
  20. throw new IllegalArgumentException("Unsupported ISO 3166 country: " + locale);
  21. } else if (currencyCode.equals("XXX")) {
  22. return null;
  23. }
  24. Currency result = getInstance(currencyCode);
  25. localesToCurrencies.put(locale, result);
  26. return result;
  27. }
  28. }

代码示例来源:origin: spring-projects/spring-framework

  1. String lang = locale.getLanguage();
  2. String country = locale.getCountry();
  3. String variant = locale.getVariant();

代码示例来源:origin: com.atlassian.jira/jira-api

  1. public void setLanguage(String language)
  2. {
  3. // Grab the old locale
  4. Locale oldLocale = getLocale();
  5. // Create a new one
  6. Locale newLocale = new Locale(language, oldLocale.getCountry(), oldLocale.getVariant());
  7. setLocale(newLocale);
  8. }

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

  1. /**
  2. * Returns a locale that's one less specific, or {@code null} if there's no less specific locale.
  3. */
  4. public static Locale getLessSpecificLocale(Locale locale) {
  5. String country = locale.getCountry();
  6. if (locale.getVariant().length() != 0) {
  7. String language = locale.getLanguage();
  8. return country != null ? new Locale(language, country) : new Locale(language);
  9. }
  10. if (country.length() != 0) {
  11. return new Locale(locale.getLanguage());
  12. }
  13. return null;
  14. }

代码示例来源:origin: org.apache.commons/commons-lang3

  1. if (locale != null) {
  2. list.add(locale);
  3. if (!locale.getVariant().isEmpty()) {
  4. list.add(new Locale(locale.getLanguage(), locale.getCountry()));
  5. if (!locale.getCountry().isEmpty()) {
  6. list.add(new Locale(locale.getLanguage(), StringUtils.EMPTY));

代码示例来源:origin: org.apache.commons/commons-lang3

  1. /**
  2. * <p>Obtains the list of countries supported for a given language.</p>
  3. *
  4. * <p>This method takes a language code and searches to find the
  5. * countries available for that language. Variant locales are removed.</p>
  6. *
  7. * @param languageCode the 2 letter language code, null returns empty
  8. * @return an unmodifiable List of Locale objects, not null
  9. */
  10. public static List<Locale> countriesByLanguage(final String languageCode) {
  11. if (languageCode == null) {
  12. return Collections.emptyList();
  13. }
  14. List<Locale> countries = cCountriesByLanguage.get(languageCode);
  15. if (countries == null) {
  16. countries = new ArrayList<>();
  17. final List<Locale> locales = availableLocaleList();
  18. for (final Locale locale : locales) {
  19. if (languageCode.equals(locale.getLanguage()) &&
  20. !locale.getCountry().isEmpty() &&
  21. locale.getVariant().isEmpty()) {
  22. countries.add(locale);
  23. }
  24. }
  25. countries = Collections.unmodifiableList(countries);
  26. cCountriesByLanguage.putIfAbsent(languageCode, countries);
  27. countries = cCountriesByLanguage.get(languageCode);
  28. }
  29. return countries;
  30. }

代码示例来源:origin: commons-lang/commons-lang

  1. if (locale != null) {
  2. list.add(locale);
  3. if (locale.getVariant().length() > 0) {
  4. list.add(new Locale(locale.getLanguage(), locale.getCountry()));
  5. if (locale.getCountry().length() > 0) {
  6. list.add(new Locale(locale.getLanguage(), ""));

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

  1. /**
  2. * Returns a locale with the most-specific field removed, or null if this
  3. * locale had an empty language, country and variant.
  4. */
  5. private static Locale strip(Locale locale) {
  6. String language = locale.getLanguage();
  7. String country = locale.getCountry();
  8. String variant = locale.getVariant();
  9. if (!variant.isEmpty()) {
  10. variant = "";
  11. } else if (!country.isEmpty()) {
  12. country = "";
  13. } else if (!language.isEmpty()) {
  14. language = "";
  15. } else {
  16. return null;
  17. }
  18. return new Locale(language, country, variant);
  19. }

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

  1. /**
  2. * Return the resource file suffic for the indicated locale
  3. * For most locales, this will be based the language code. However
  4. * for Chinese, we do distinguish between Taiwan and PRC
  5. *
  6. * @param locale the locale
  7. * @return an String suffix which canbe appended to a resource name
  8. */
  9. private static final String getResourceSuffix(Locale locale)
  10. {
  11. String lang = locale.getLanguage();
  12. String country = locale.getCountry();
  13. String variant = locale.getVariant();
  14. String suffix = "_" + locale.getLanguage();
  15. if (lang.equals("zh"))
  16. suffix += "_" + country;
  17. if (country.equals("JP"))
  18. suffix += "_" + country + "_" + variant;
  19. return suffix;
  20. }

代码示例来源:origin: commons-lang/commons-lang

  1. for (int i = 0; i < locales.size(); i++) {
  2. Locale locale = (Locale) locales.get(i);
  3. if (languageCode.equals(locale.getLanguage()) &&
  4. locale.getCountry().length() != 0 &&
  5. locale.getVariant().length() == 0) {
  6. countries.add(locale);

代码示例来源:origin: org.springframework/spring-context

  1. String language = locale.getLanguage();
  2. String country = locale.getCountry();
  3. String variant = locale.getVariant();
  4. StringBuilder temp = new StringBuilder(basename);

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

  1. String language = locale.getLanguage();
  2. String country = locale.getCountry();
  3. String variant = locale.getVariant();

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

  1. String language = locale.getLanguage();
  2. String country = locale.getCountry();
  3. String variant = locale.getVariant();

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

  1. private static Calendar createCalendar(TimeZone zone, Locale aLocale) {
  2. // If the specified locale is a Thai locale, returns a BuddhistCalendar
  3. // instance.
  4. if ("th".equals(aLocale.getLanguage())
  5. && ("TH".equals(aLocale.getCountry()))) {
  6. return new sun.util.BuddhistCalendar(zone, aLocale);
  7. } else if ("JP".equals(aLocale.getVariant())
  8. && "JP".equals(aLocale.getCountry())
  9. && "ja".equals(aLocale.getLanguage())) {
  10. return new JapaneseImperialCalendar(zone, aLocale);
  11. }
  12. // else create the default calendar
  13. return new GregorianCalendar(zone, aLocale);
  14. }

相关文章