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