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

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

本文整理了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

@Override
  public final String convert(final Locale o) {
    final StringBuilder value = new StringBuilder(o.getLanguage());
    if (!o.getCountry().isEmpty() || !o.getVariant().isEmpty()) {
      value.append("-").append(o.getCountry());
    }
    if (!o.getVariant().isEmpty()) {
      value.append("-").append(o.getVariant());
    }
    return value.toString(); //JDK7+: return o.toLanguageTag();
  }
};

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

/**
 * <p>Obtains the list of languages supported for a given country.</p>
 *
 * <p>This method takes a country code and searches to find the
 * languages available for that country. Variant locales are removed.</p>
 *
 * @param countryCode  the 2 letter country code, null returns empty
 * @return an unmodifiable List of Locale objects, not null
 */
public static List<Locale> languagesByCountry(final String countryCode) {
  if (countryCode == null) {
    return Collections.emptyList();
  }
  List<Locale> langs = cLanguagesByCountry.get(countryCode);
  if (langs == null) {
    langs = new ArrayList<>();
    final List<Locale> locales = availableLocaleList();
    for (final Locale locale : locales) {
      if (countryCode.equals(locale.getCountry()) &&
        locale.getVariant().isEmpty()) {
        langs.add(locale);
      }
    }
    langs = Collections.unmodifiableList(langs);
    cLanguagesByCountry.putIfAbsent(countryCode, langs);
    langs = cLanguagesByCountry.get(countryCode);
  }
  return langs;
}

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

public void setCountry(String country)
{
  // Grab the old locale
  Locale oldLocale = getLocale();
  // Create a new one
  Locale newLocale = new Locale(oldLocale.getLanguage(), country, oldLocale.getVariant());
  setLocale(newLocale);
}

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

/**
 * Resolves locale code from locale.
 */
public static String resolveLocaleCode(Locale locale) {
  return resolveLocaleCode(locale.getLanguage(), locale.getCountry(), locale.getVariant());
}

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

/**
 * <p>Obtains the list of languages supported for a given country.</p>
 *
 * <p>This method takes a country code and searches to find the
 * languages available for that country. Variant locales are removed.</p>
 *
 * @param countryCode  the 2 letter country code, null returns empty
 * @return an unmodifiable List of Locale objects, never null
 */
public static List languagesByCountry(String countryCode) {
  List langs = (List) cLanguagesByCountry.get(countryCode);  //syncd
  if (langs == null) {
    if (countryCode != null) {
      langs = new ArrayList();
      List locales = availableLocaleList();
      for (int i = 0; i < locales.size(); i++) {
        Locale locale = (Locale) locales.get(i);
        if (countryCode.equals(locale.getCountry()) &&
            locale.getVariant().length() == 0) {
          langs.add(locale);
        }
      }
      langs = Collections.unmodifiableList(langs);
    } else {
      langs = Collections.EMPTY_LIST;
    }
    cLanguagesByCountry.put(countryCode, langs);  //syncd
  }
  return langs;
}

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

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

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

/**
 * Returns the {@code Currency} instance for this {@code Locale}'s country.
 * @throws IllegalArgumentException
 *             if the locale's country is not a supported ISO 3166 country.
 */
public static Currency getInstance(Locale locale) {
  synchronized (localesToCurrencies) {
    Currency currency = localesToCurrencies.get(locale);
    if (currency != null) {
      return currency;
    }
    String country = locale.getCountry();
    String variant = locale.getVariant();
    if (!variant.isEmpty() && (variant.equals("EURO") || variant.equals("HK") ||
        variant.equals("PREEURO"))) {
      country = country + "_" + variant;
    }
    String currencyCode = ICU.getCurrencyCode(country);
    if (currencyCode == null) {
      throw new IllegalArgumentException("Unsupported ISO 3166 country: " + locale);
    } else if (currencyCode.equals("XXX")) {
      return null;
    }
    Currency result = getInstance(currencyCode);
    localesToCurrencies.put(locale, result);
    return result;
  }
}

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

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

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

public void setLanguage(String language)
{
  // Grab the old locale
  Locale oldLocale = getLocale();
  // Create a new one
  Locale newLocale = new Locale(language, oldLocale.getCountry(), oldLocale.getVariant());
  setLocale(newLocale);
}

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

/**
 * Returns a locale that's one less specific, or {@code null} if there's no less specific locale.
 */
public static Locale getLessSpecificLocale(Locale locale) {
  String country = locale.getCountry();
  if (locale.getVariant().length() != 0) {
    String language = locale.getLanguage();
    return country != null ? new Locale(language, country) : new Locale(language);
  }
  if (country.length() != 0) {
    return new Locale(locale.getLanguage());
  }
  return null;
}

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

if (locale != null) {
  list.add(locale);
  if (!locale.getVariant().isEmpty()) {
    list.add(new Locale(locale.getLanguage(), locale.getCountry()));
  if (!locale.getCountry().isEmpty()) {
    list.add(new Locale(locale.getLanguage(), StringUtils.EMPTY));

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

/**
 * <p>Obtains the list of countries supported for a given language.</p>
 *
 * <p>This method takes a language code and searches to find the
 * countries available for that language. Variant locales are removed.</p>
 *
 * @param languageCode  the 2 letter language code, null returns empty
 * @return an unmodifiable List of Locale objects, not null
 */
public static List<Locale> countriesByLanguage(final String languageCode) {
  if (languageCode == null) {
    return Collections.emptyList();
  }
  List<Locale> countries = cCountriesByLanguage.get(languageCode);
  if (countries == null) {
    countries = new ArrayList<>();
    final List<Locale> locales = availableLocaleList();
    for (final Locale locale : locales) {
      if (languageCode.equals(locale.getLanguage()) &&
          !locale.getCountry().isEmpty() &&
        locale.getVariant().isEmpty()) {
        countries.add(locale);
      }
    }
    countries = Collections.unmodifiableList(countries);
    cCountriesByLanguage.putIfAbsent(languageCode, countries);
    countries = cCountriesByLanguage.get(languageCode);
  }
  return countries;
}

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

if (locale != null) {
  list.add(locale);
  if (locale.getVariant().length() > 0) {
    list.add(new Locale(locale.getLanguage(), locale.getCountry()));
  if (locale.getCountry().length() > 0) {
    list.add(new Locale(locale.getLanguage(), ""));

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

/**
 * Returns a locale with the most-specific field removed, or null if this
 * locale had an empty language, country and variant.
 */
private static Locale strip(Locale locale) {
  String language = locale.getLanguage();
  String country = locale.getCountry();
  String variant = locale.getVariant();
  if (!variant.isEmpty()) {
    variant = "";
  } else if (!country.isEmpty()) {
    country = "";
  } else if (!language.isEmpty()) {
    language = "";
  } else {
    return null;
  }
  return new Locale(language, country, variant);
}

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

/**
 * Return the resource file suffic for the indicated locale
 * For most locales, this will be based the language code.  However
 * for Chinese, we do distinguish between Taiwan and PRC
 *
 * @param locale the locale
 * @return an String suffix which canbe appended to a resource name
 */
private static final String getResourceSuffix(Locale locale)
{
 String lang = locale.getLanguage();
 String country = locale.getCountry();
 String variant = locale.getVariant();
 String suffix = "_" + locale.getLanguage();
 if (lang.equals("zh"))
  suffix += "_" + country;
 if (country.equals("JP"))
  suffix += "_" + country + "_" + variant;
 return suffix;
}

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

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

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

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

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

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

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

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

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

private static Calendar createCalendar(TimeZone zone, Locale aLocale) {
  // If the specified locale is a Thai locale, returns a BuddhistCalendar
  // instance.
  if ("th".equals(aLocale.getLanguage())
    && ("TH".equals(aLocale.getCountry()))) {
    return new sun.util.BuddhistCalendar(zone, aLocale);
  } else if ("JP".equals(aLocale.getVariant())
    && "JP".equals(aLocale.getCountry())
    && "ja".equals(aLocale.getLanguage())) {
    return new JapaneseImperialCalendar(zone, aLocale);
  }       

  // else create the default calendar
  return new GregorianCalendar(zone, aLocale);    
}

相关文章