當前位置: 首頁>>代碼示例>>Java>>正文


Java Locale.getVariant方法代碼示例

本文整理匯總了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();
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:24,代碼來源:LocaleController.java

示例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]);
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:26,代碼來源:LocaleUtility.java

示例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.");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:VerifyLocale.java

示例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();
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:24,代碼來源:LocaleController.java

示例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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:HostLocaleProviderAdapterImpl.java

示例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];
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:NbiProperties.java

示例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;
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:14,代碼來源:RefCapablePropertyResourceBundle.java

示例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));
	}
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:36,代碼來源:AbstractPlugin.java

示例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.");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:Bug4210525.java

示例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" -&gt; "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;
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:38,代碼來源:ConfigMessageSource.java

示例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);
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:29,代碼來源:Bug4152725.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:ExecutableInputMethodManager.java

示例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 : "");
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:9,代碼來源:LocaleUtils.java

示例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();
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:10,代碼來源:LocaleData.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:HostLocaleProviderAdapterImpl.java


注:本文中的java.util.Locale.getVariant方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。