本文整理匯總了Java中java.util.Locale.getVariant方法的典型用法代碼示例。如果您正苦於以下問題:Java Locale.getVariant方法的具體用法?Java Locale.getVariant怎麽用?Java Locale.getVariant使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Locale
的用法示例。
在下文中一共展示了Locale.getVariant方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLocaleStringIso639
import java.util.Locale; //導入方法依賴的package包/類
public static String getLocaleStringIso639() {
Locale locale = getInstance().getSystemDefaultLocale();
if (locale == null) {
return "en";
}
String languageCode = locale.getLanguage();
String countryCode = locale.getCountry();
String variantCode = locale.getVariant();
if (languageCode.length() == 0 && countryCode.length() == 0) {
return "en";
}
StringBuilder result = new StringBuilder(11);
result.append(languageCode);
if (countryCode.length() > 0 || variantCode.length() > 0) {
result.append('-');
}
result.append(countryCode);
if (variantCode.length() > 0) {
result.append('_');
}
result.append(variantCode);
return result.toString();
}
示例2: fallback
import java.util.Locale; //導入方法依賴的package包/類
/**
* Fallback from the given locale name by removing the rightmost _-delimited
* element. If there is none, return the root locale ("", "", ""). If this
* is the root locale, return null. NOTE: The string "root" is not
* recognized; do not use it.
*
* @return a new Locale that is a fallback from the given locale, or null.
*/
public static Locale fallback(Locale loc) {
// Split the locale into parts and remove the rightmost part
String[] parts = new String[]
{ loc.getLanguage(), loc.getCountry(), loc.getVariant() };
int i;
for (i=2; i>=0; --i) {
if (parts[i].length() != 0) {
parts[i] = "";
break;
}
}
if (i<0) {
return null; // All parts were empty
}
return new Locale(parts[0], parts[1], parts[2]);
}
示例3: main
import java.util.Locale; //導入方法依賴的package包/類
public static void main(String[] args) {
String thisFile = "" +
new java.io.File(System.getProperty("test.src", "."),
"VerifyLocale.java");
for (Locale loc : Locale.getAvailableLocales()) {
language = loc.getLanguage();
country = loc.getCountry();
variant = loc.getVariant();
if (!language.equals("")) {
String[] command_line = {
// jumble the options in some weird order
"-doclet", "VerifyLocale",
"-locale", language + (country.equals("") ? "" : ("_" + country + (variant.equals("") ? "" : "_" + variant))),
"-docletpath", System.getProperty("test.classes", "."),
thisFile
};
if (jdk.javadoc.internal.tool.Main.execute(command_line) != 0)
throw new Error("Javadoc encountered warnings or errors.");
}
}
}
示例4: getLocaleString
import java.util.Locale; //導入方法依賴的package包/類
private String getLocaleString(Locale locale) {
if (locale == null) {
return "fa";
}
String languageCode = locale.getLanguage();
String countryCode = locale.getCountry();
String variantCode = locale.getVariant();
if (languageCode.length() == 0 && countryCode.length() == 0) {
return "fa";
}
StringBuilder result = new StringBuilder(11);
result.append(languageCode);
if (countryCode.length() > 0 || variantCode.length() > 0) {
//result.append('-');
result.append('_');
}
result.append(countryCode);
if (variantCode.length() > 0) {
result.append('_');
}
result.append(variantCode);
return result.toString();
}
示例5: isSupportedCalendarLocale
import java.util.Locale; //導入方法依賴的package包/類
private static boolean isSupportedCalendarLocale(Locale locale) {
Locale base = locale;
if (base.hasExtensions() || base.getVariant() != "") {
base = new Locale.Builder()
.setLocale(locale)
.clearExtensions()
.build();
}
if (!supportedLocaleSet.contains(base)) {
return false;
}
String requestedCalType = locale.getUnicodeLocaleType("ca");
String nativeCalType =
getCalendarID(base.toLanguageTag()).replaceFirst("gregorian", "gregory");
if (requestedCalType == null) {
return Calendar.getAvailableCalendarTypes().contains(nativeCalType);
} else {
return requestedCalType.equals(nativeCalType);
}
}
示例6: getLocaleParts
import java.util.Locale; //導入方法依賴的package包/類
private String[] getLocaleParts(
final Locale locale) {
if (locale == null) {
return new String[0];
}
if (!locale.getLanguage().equals("")) {
if (!locale.getCountry().equals("")) {
if (!locale.getVariant().equals("")) {
return new String[] {
locale.getLanguage(),
locale.getCountry(),
locale.getVariant()
};
}
return new String[] {
locale.getLanguage(),
locale.getCountry()
};
}
return new String[] {
locale.getLanguage()
};
}
return new String[0];
}
示例7: RefCapablePropertyResourceBundle
import java.util.Locale; //導入方法依賴的package包/類
private RefCapablePropertyResourceBundle(String baseName,
PropertyResourceBundle wrappedBundle, ClassLoader loader) {
this.baseName = baseName;
this.wrappedBundle = wrappedBundle;
Locale locale = wrappedBundle.getLocale();
this.loader = loader;
language = locale.getLanguage();
country = locale.getCountry();
variant = locale.getVariant();
if (language.length() < 1) language = null;
if (country.length() < 1) country = null;
if (variant.length() < 1) variant = null;
}
示例8: handleLangs
import java.util.Locale; //導入方法依賴的package包/類
/**
* Processes languages. Retrieves language labels with default locale, then
* sets them into the specified data model.
*
* @param dataModel
* the specified data model
*/
private void handleLangs(final Map<String, Object> dataModel) {
final Locale locale = Latkes.getLocale();
final String language = locale.getLanguage();
final String country = locale.getCountry();
final String variant = locale.getVariant();
final StringBuilder keyBuilder = new StringBuilder(language);
if (!StringUtils.isBlank(country)) {
keyBuilder.append("_").append(country);
}
if (!StringUtils.isBlank(variant)) {
keyBuilder.append("_").append(variant);
}
final String localKey = keyBuilder.toString();
final Properties props = langs.get(localKey);
if (null == props) {
return;
}
final Set<Object> keySet = props.keySet();
for (final Object key : keySet) {
dataModel.put((String) key, props.getProperty((String) key));
}
}
示例9: main
import java.util.Locale; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String language = "en";
String country = "US";
String variant = "socal";
Locale aLocale = new Locale(language, country, variant);
String localeVariant = aLocale.getVariant();
if (localeVariant.equals(variant)) {
System.out.println("passed");
} else {
System.out.println("failed");
throw new Exception("Bug4210525 test failed.");
}
}
示例10: calculateFilenamesForLocale
import java.util.Locale; //導入方法依賴的package包/類
/**
* Calculate the filenames for the given bundle basename and Locale,
* appending language code, country code, and variant code.
* E.g.: basename "messages", Locale "de_AT_oo" -> "messages_de_AT_OO",
* "messages_de_AT", "messages_de".
* <p>Follows the rules defined by {@link java.util.Locale#toString()}.
*
* @param basename the basename of the bundle
* @param locale the locale
* @return the List of filenames to check
*/
protected List<String> calculateFilenamesForLocale(String basename, Locale locale) {
List<String> result = new ArrayList<String>(3);
String language = locale.getLanguage();
String country = locale.getCountry();
String variant = locale.getVariant();
StringBuilder temp = new StringBuilder(basename);
temp.append('_');
if (language.length() > 0) {
temp.append(language);
result.add(0, temp.toString());
}
temp.append('_');
if (country.length() > 0) {
temp.append(country);
result.add(0, temp.toString());
}
if (variant.length() > 0 && (language.length() > 0 || country.length() > 0)) {
temp.append('_').append(variant);
result.add(0, temp.toString());
}
return result;
}
示例11: main
import java.util.Locale; //導入方法依賴的package包/類
public static void main(String[] args) {
if (args.length != 1) {
throw new RuntimeException("expected locale needs to be specified");
}
Locale locale = Locale.getDefault();
// don't use Locale.toString - it's bogus
String language = locale.getLanguage();
String country = locale.getCountry();
String variant = locale.getVariant();
String localeID = null;
if (variant.length() > 0) {
localeID = language + "_" + country + "_" + variant;
} else if (country.length() > 0) {
localeID = language + "_" + country;
} else {
localeID = language;
}
if (localeID.equals(args[0])) {
System.out.println("Correctly set from command line: " + localeID);
} else {
throw new RuntimeException("expected default locale: " + args[0]
+ ", actual default locale: " + localeID);
}
}
示例12: createLocalePath
import java.util.Locale; //導入方法依賴的package包/類
private String createLocalePath(Locale locale) {
String language = locale.getLanguage();
String country = locale.getCountry();
String variant = locale.getVariant();
String localePath = null;
if (!variant.equals("")) {
localePath = "_" + language + "/_" + country + "/_" + variant;
} else if (!country.equals("")) {
localePath = "_" + language + "/_" + country;
} else {
localePath = "_" + language;
}
return localePath;
}
示例13: toHtmlLang
import java.util.Locale; //導入方法依賴的package包/類
@SuppressWarnings("nls")
public static String toHtmlLang(Locale locale)
{
String lang = locale.getLanguage();
String country = locale.getCountry();
String variant = locale.getVariant();
return lang + (!Check.isEmpty(country) ? '-' + country : "") + (!Check.isEmpty(variant) ? '-' + variant : "");
}
示例14: LocaleData
import java.util.Locale; //導入方法依賴的package包/類
public LocaleData(Locale locale, boolean rightToLeft)
{
this.locale = locale;
this.rightToLeft = rightToLeft;
language = locale.getLanguage();
country = locale.getCountry();
variant = locale.getVariant();
}
示例15: stripVariantAndExtensions
import java.util.Locale; //導入方法依賴的package包/類
private static Locale stripVariantAndExtensions(Locale locale) {
if (locale.hasExtensions() || locale.getVariant() != "") {
// strip off extensions and variant.
locale = new Locale.Builder()
.setLocale(locale)
.clearExtensions()
.build();
}
return locale;
}