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


Java Locale.getCountry方法代碼示例

本文整理匯總了Java中java.util.Locale.getCountry方法的典型用法代碼示例。如果您正苦於以下問題:Java Locale.getCountry方法的具體用法?Java Locale.getCountry怎麽用?Java Locale.getCountry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Locale的用法示例。


在下文中一共展示了Locale.getCountry方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setLocale

import java.util.Locale; //導入方法依賴的package包/類
/**
 * Called explicitely by user to set the Content-Language and
 * the default encoding
 */
public void setLocale(Locale locale) {

    if (locale == null) {
        return;  // throw an exception?
    }

    // Save the locale for use by getLocale()
    this.locale = locale;

    // Set the contentLanguage for header output
    contentLanguage = locale.getLanguage();
    if ((contentLanguage != null) && (contentLanguage.length() > 0)) {
        String country = locale.getCountry();
        StringBuffer value = new StringBuffer(contentLanguage);
        if ((country != null) && (country.length() > 0)) {
            value.append('-');
            value.append(country);
        }
        contentLanguage = value.toString();
    }

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:Response.java

示例2: getLocaleFileNames

import java.util.Locale; //導入方法依賴的package包/類
/**
 * Gets a list containing the names of all possible message files
 * for a locale.
 *
 * @param prefix The file name prefix.
 * @param suffix The file name suffix.
 * @param locale The {@code Locale} to generate file names for.
 * @return A list of candidate file names.
 */
public static List<String> getLocaleFileNames(String prefix,
                                              String suffix,
                                              Locale locale) {
    String language = locale.getLanguage();
    String country = locale.getCountry();
    String variant = locale.getVariant();

    List<String> result = new ArrayList<>(4);

    if (!language.isEmpty()) language = "_" + language;
    if (!country.isEmpty()) country = "_" + country;
    if (!variant.isEmpty()) variant = "_" + variant;

    result.add(prefix + suffix);
    String filename = prefix + language + suffix;
    if (!result.contains(filename)) result.add(filename);
    filename = prefix + language + country + suffix;
    if (!result.contains(filename)) result.add(filename);
    filename = prefix + language + country + variant + suffix;
    if (!result.contains(filename)) result.add(filename);
    return result;
}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:32,代碼來源:FreeColDirectories.java

示例3: getLocale

import java.util.Locale; //導入方法依賴的package包/類
/**
 * @return the string for the given locale, translating
 * Android deprecated language codes into the modern ones
 * used by Chromium.
 */
public static String getLocale(Locale locale) {
    String language = locale.getLanguage();
    String country = locale.getCountry();

    // Android uses deprecated lanuages codes for Hebrew and Indonesian but Chromium uses the
    // updated codes. Also, Android uses "tl" while Chromium uses "fil" for Tagalog/Filipino.
    // So apply a mapping.
    // See http://developer.android.com/reference/java/util/Locale.html
    if ("iw".equals(language)) {
        language = "he";
    } else if ("in".equals(language)) {
        language = "id";
    } else if ("tl".equals(language)) {
        language = "fil";
    }
    return country.isEmpty() ? language : language + "-" + country;
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:23,代碼來源:LocaleUtils.java

示例4: getLocalisedFloat

import java.util.Locale; //導入方法依賴的package包/類
/**
    * Convert a string back into a Float. Assumes string was formatted using formatLocalisedNumber originally. Should
    * ensure that it is using the same locale/number format as when it was formatted. If no locale is suppied, it will
    * use the server's locale
    *
    * Need to strip out any spaces as spaces are valid group separators in some European locales (e.g. Polish) but they
    * seem to come back from Firefox as a plain space rather than the special separating space.
    */
   public static Float getLocalisedFloat(String inputStr, Locale locale) {
String numberStr = inputStr;
if (numberStr != null) {
    numberStr = numberStr.replace(" ", "");
}
if ((numberStr != null) && (numberStr.length() > 0)) {
    Locale useLocale = locale != null ? locale : NumberUtil.getServerLocale();
    NumberFormat format = NumberFormat.getInstance(useLocale);
    ParsePosition pp = new ParsePosition(0);
    Number num = format.parse(numberStr, pp);
    if ((num != null) && (pp.getIndex() == numberStr.length())) {
	return num.floatValue();
    }
}
throw new NumberFormatException("Unable to convert number " + numberStr + "to float using locale "
	+ locale.getCountry() + " " + locale.getLanguage());
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:NumberUtil.java

示例5: getLocaleStringIso639

import java.util.Locale; //導入方法依賴的package包/類
public static String getLocaleStringIso639() {
    Locale locale = getInstance().getSystemDefaultLocale();
    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(countryCode);
    if (variantCode.length() > 0) {
        result.append('_');
    }
    result.append(variantCode);
    return result.toString();
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:24,代碼來源:LocaleController.java

示例6: 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:SunburstApps,項目名稱:OpenJSharp,代碼行數:16,代碼來源:ExecutableInputMethodManager.java

示例7: getDefaultLanguageCode

import java.util.Locale; //導入方法依賴的package包/類
private String getDefaultLanguageCode() {
    final Locale locale = Locale.getDefault();
    final StringBuilder language = new StringBuilder(locale.getLanguage());
    final String country = locale.getCountry();
    if (!TextUtils.isEmpty(country)) {
        language.append("-");
        language.append(country);
    }
    return language.toString();
}
 
開發者ID:hypeapps,項目名稱:black-mirror,代碼行數:11,代碼來源:SpeechService.java

示例8: prepareModel

import java.util.Locale; //導入方法依賴的package包/類
@Override
protected void prepareModel(RenderContext info)
{
	super.prepareModel(info);
	final MultiEditBoxState state = getState(info);
	Map<String, HtmlValueState> map = new LinkedHashMap<String, HtmlValueState>();

	TreeSet<Locale> languages = new TreeSet<Locale>(localeComparator);
	languages.addAll(getContributeLocales());
	languages.addAll(getBundleLocales(info));

	for( Locale locale : languages )
	{
		String id = locale.toString();
		HtmlValueState valState = langMap.getValueState(info, id);

		// Build format into: Language [(country)] where country
		String displayString = Constants.BLANK;

		String displayLanguage = locale.getDisplayLanguage();
		String displayCountry = locale.getCountry();
		displayString = !Check.isEmpty(displayCountry) ? MessageFormat.format(
			"{0} ({1})", displayLanguage, displayCountry) : displayLanguage; //$NON-NLS-1$

		valState.setLabel(new TextLabel(displayString));
		map.put(id, valState);
	}
	state.setSize(size);
	state.setLocaleMap(map);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:31,代碼來源:MultiEditBox.java

示例9: toBundleName

import java.util.Locale; //導入方法依賴的package包/類
@Override
protected String toBundleName(String baseName, Locale locale) {
    StringBuilder sb = new StringBuilder(baseName);
    String lang = locale.getLanguage();
    if (!lang.isEmpty()) {
        sb.append('_').append(lang);
        String country = locale.getCountry();
        if (!country.isEmpty()) {
            sb.append('_').append(country);
        }
    }
    return sb.toString();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:MyResourcesProvider.java

示例10: getCodePage

import java.util.Locale; //導入方法依賴的package包/類
static String getCodePage() {

        if (defaultCodePage != null) {
            return defaultCodePage;
        }

        if (FontUtilities.isWindows) {
            defaultCodePage =
                (String)java.security.AccessController.doPrivileged(
                   new sun.security.action.GetPropertyAction("file.encoding"));
        } else {
            if (languages.length != codePages.length) {
                throw new InternalError("wrong code pages array length");
            }
            Locale locale = sun.awt.SunToolkit.getStartupLocale();

            String language = locale.getLanguage();
            if (language != null) {
                if (language.equals("zh")) {
                    String country = locale.getCountry();
                    if (country != null) {
                        language = language + "_" + country;
                    }
                }
                for (int i=0; i<languages.length;i++) {
                    for (int l=0;l<languages[i].length; l++) {
                        if (language.equals(languages[i][l])) {
                            defaultCodePage = codePages[i];
                            return defaultCodePage;
                        }
                    }
                }
            }
        }
        if (defaultCodePage == null) {
            defaultCodePage = "";
        }
        return defaultCodePage;
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:40,代碼來源:TrueTypeFont.java

示例11: prependToAcceptLanguagesIfNecessary

import java.util.Locale; //導入方法依賴的package包/類
/**
 * Get the language code for the default locales and prepend it to the Accept-Language string
 * if it isn't already present. The logic should match PrependToAcceptLanguagesIfNecessary in
 * chrome/browser/android/preferences/pref_service_bridge.cc
 * @param locales A comma separated string that represents a list of default locales.
 * @param acceptLanguages The default language list for the language of the user's locales.
 * @return An updated language list.
 */
@VisibleForTesting
static String prependToAcceptLanguagesIfNecessary(String locales, String acceptLanguages) {
    String localeStrings = locales + "," + acceptLanguages;
    String[] localeList = localeStrings.split(",");

    ArrayList<Locale> uniqueList = new ArrayList<>();
    for (String localeString : localeList) {
        Locale locale = LocaleUtils.forLanguageTag(localeString);
        if (uniqueList.contains(locale) || locale.getLanguage().isEmpty()) {
            continue;
        }
        uniqueList.add(locale);
    }

    // If language is not in the accept languages list, also add language code.
    // A language code should only be inserted after the last languageTag that
    // contains that language.
    // This will work with the IDS_ACCEPT_LANGUAGE localized strings bundled
    // with Chrome but may fail on arbitrary lists of language tags due to
    // differences in case and whitespace.
    HashSet<String> seenLanguages = new HashSet<>();
    ArrayList<String> outputList = new ArrayList<>();
    for (int i = uniqueList.size() - 1; i >= 0; i--) {
        Locale localeAdd = uniqueList.get(i);
        String languageAdd = localeAdd.getLanguage();
        String countryAdd = localeAdd.getCountry();

        if (!seenLanguages.contains(languageAdd)) {
            seenLanguages.add(languageAdd);
            outputList.add(languageAdd);
        }
        if (!countryAdd.isEmpty()) {
            outputList.add(LocaleUtils.toLanguageTag(localeAdd));
        }
    }
    Collections.reverse(outputList);
    return TextUtils.join(",", outputList);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:47,代碼來源:PwsClientImpl.java

示例12: 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:parabuild-ci,項目名稱:parabuild-ci,代碼行數:14,代碼來源:RefCapablePropertyResourceBundle.java

示例13: compareResources

import java.util.Locale; //導入方法依賴的package包/類
static void compareResources(Locale loc) {
    String mapKeyHourFormat = HMT, mapKeyGmtFormat = GMT;
    ResourceBundle compatBundle, cldrBundle;
    compatBundle = LocaleProviderAdapter.forJRE().getLocaleResources(loc)
            .getJavaTimeFormatData();
    cldrBundle = LocaleProviderAdapter.forType(Type.CLDR)
            .getLocaleResources(loc).getJavaTimeFormatData();
    if (loc.getCountry() == "FR" || loc.getCountry() == "FI") {
        mapKeyHourFormat = loc.getCountry() + HMT;
        mapKeyGmtFormat = loc.getCountry() + GMT;
    }

    if (!(expectedResourcesMap.get(mapKeyGmtFormat)
            .equals(compatBundle.getString(GMT_RESOURCE_KEY))
            && expectedResourcesMap.get(mapKeyHourFormat)
            .equals(compatBundle.getString(HMT_RESOURCE_KEY))
            && expectedResourcesMap.get(mapKeyGmtFormat)
            .equals(cldrBundle.getString(GMT_RESOURCE_KEY))
            && expectedResourcesMap.get(mapKeyHourFormat)
            .equals(cldrBundle.getString(HMT_RESOURCE_KEY)))) {

        throw new RuntimeException("Retrieved resource does not match with "
                + "  expected string for Locale " + compatBundle.getLocale());

    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:Bug8154797.java

示例14: _getBundleName

import java.util.Locale; //導入方法依賴的package包/類
private String _getBundleName(Locale locale)
{
  int index = _bundleName.lastIndexOf(".");
  String bundleName = _bundleName.substring(index + 1);

  if (locale.getLanguage().length() == 0)
    return bundleName;

  bundleName +=   "_" +  locale.getLanguage();

  if (locale.getCountry().length() != 0)
    bundleName = bundleName  + "_" + locale.getCountry();
  return bundleName;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:15,代碼來源:MessageBundleTest.java

示例15: getLocaleString

import java.util.Locale; //導入方法依賴的package包/類
public static String getLocaleString() {
    Locale locale = Locale.getDefault();
    return locale.getLanguage() + "-" + locale.getCountry();
}
 
開發者ID:TaRGroup,項目名稱:EveryCoolPic,代碼行數:5,代碼來源:Utils.java


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