当前位置: 首页>>代码示例>>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;未经允许,请勿转载。