本文整理了Java中java.util.Locale.getCountry()
方法的一些代码示例,展示了Locale.getCountry()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.getCountry()
方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:getCountry
[英]Returns the country code for this locale, or "" if this locale doesn't correspond to a specific country.
[中]返回此区域设置的国家/地区代码,如果此区域设置与特定国家/地区不对应,则返回“”。
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine the RFC 3066 compliant language tag,
* as used for the HTTP "Accept-Language" header.
* @param locale the Locale to transform to a language tag
* @return the RFC 3066 compliant language tag as {@code String}
* @deprecated as of 5.0.4, in favor of {@link Locale#toLanguageTag()}
*/
@Deprecated
public static String toLanguageTag(Locale locale) {
return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : "");
}
代码示例来源:origin: redisson/redisson
/**
* Resolves locale code from locale.
*/
public static String resolveLocaleCode(Locale locale) {
return resolveLocaleCode(locale.getLanguage(), locale.getCountry(), locale.getVariant());
}
代码示例来源: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: stackoverflow.com
// may contain simple syntax error, i dont have java rite now to test..
// but this is a bigger picture for ur algo...
public String localeToString(Locale l) {
return l.getLanguage() + "," + l.getCountry();
}
public Locale stringToLocale(String s) {
StringTokenizer tempStringTokenizer = new StringTokenizer(s,",");
if(tempStringTokenizer.hasMoreTokens())
String l = tempStringTokenizer.nextElement();
if(tempStringTokenizer.hasMoreTokens())
String c = tempStringTokenizer.nextElement();
return new Locale(l,c);
}
代码示例来源:origin: stackoverflow.com
String[] locales = Locale.getISOCountries();
for (String countryCode : locales) {
Locale obj = new Locale("", countryCode);
System.out.println("Country Code = " + obj.getCountry()
+ ", Country Name = " + obj.getDisplayCountry());
}
代码示例来源: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: 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.springframework/spring-core
/**
* Determine the RFC 3066 compliant language tag,
* as used for the HTTP "Accept-Language" header.
* @param locale the Locale to transform to a language tag
* @return the RFC 3066 compliant language tag as {@code String}
* @deprecated as of 5.0.4, in favor of {@link Locale#toLanguageTag()}
*/
@Deprecated
public static String toLanguageTag(Locale locale) {
return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : "");
}
代码示例来源: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: lets-blade/blade
public static Tuple2<String,Locale> toLocaleModel(String baseName,Locale locale) {
if (StringKit.isBlank(baseName)) {
return new Tuple2<>("i18n_"+locale.getLanguage()+"_"+locale.getCountry(),locale);
}else {
String[] baseNames = pattern.split(baseName);
if (baseNames != null && baseNames.length == 3) {
return new Tuple2<>(baseName,new Locale(baseNames[1],baseNames[2]));
}
throw new IllegalArgumentException("baseName illegal,name format is :i18n_{language}_{country}.properties," +
"for example:i18n_zh_CN.properties");
}
}
代码示例来源:origin: robovm/robovm
m_locale = new Locale(langValue.toLowerCase(),
Locale.getDefault().getCountry());
代码示例来源: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: 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: jfinal/jfinal
public static String toLocale(Locale locale) {
return locale.getLanguage() + "_" + locale.getCountry();
}
}
代码示例来源:origin: spring-projects/spring-framework
String language = locale.getLanguage();
String country = locale.getCountry();
String variant = locale.getVariant();
StringBuilder temp = new StringBuilder(basename);
代码示例来源:origin: lets-blade/blade
public static Tuple2<String,Locale> toLocaleModel(String baseName,Locale locale) {
if (StringKit.isBlank(baseName)) {
return new Tuple2<>("i18n_"+locale.getLanguage()+"_"+locale.getCountry(),locale);
}else {
String[] baseNames = pattern.split(baseName);
if (baseNames != null && baseNames.length == 3) {
return new Tuple2<>(baseName,new Locale(baseNames[1],baseNames[2]));
}
throw new IllegalArgumentException("baseName illegal,name format is :i18n_{language}_{country}.properties," +
"for example:i18n_zh_CN.properties");
}
}
代码示例来源:origin: xalan/xalan
m_locale = new Locale(langValue.toLowerCase(),
Locale.getDefault().getCountry());
代码示例来源: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: 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: jwtk/jjwt
/**
* Determine the RFC 3066 compliant language tag,
* as used for the HTTP "Accept-Language" header.
* @param locale the Locale to transform to a language tag
* @return the RFC 3066 compliant language tag as String
*/
public static String toLanguageTag(Locale locale) {
return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : "");
}
内容来源于网络,如有侵权,请联系作者删除!