本文整理汇总了Java中java.util.spi.LocaleNameProvider类的典型用法代码示例。如果您正苦于以下问题:Java LocaleNameProvider类的具体用法?Java LocaleNameProvider怎么用?Java LocaleNameProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocaleNameProvider类属于java.util.spi包,在下文中一共展示了LocaleNameProvider类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDisplayString
import java.util.spi.LocaleNameProvider; //导入依赖的package包/类
private String getDisplayString(String code, Locale inLocale, int type) {
if (code.length() == 0) {
return "";
}
if (inLocale == null) {
throw new NullPointerException();
}
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(LocaleNameProvider.class);
String key = (type == DISPLAY_VARIANT ? "%%"+code : code);
String result = pool.getLocalizedObject(
LocaleNameGetter.INSTANCE,
inLocale, key, type, code);
if (result != null) {
return result;
}
return code;
}
示例2: getObject
import java.util.spi.LocaleNameProvider; //导入依赖的package包/类
@Override
public String getObject(LocaleNameProvider localeNameProvider,
Locale locale,
String key,
Object... params) {
assert params.length == 2;
int type = (Integer)params[0];
String code = (String)params[1];
switch(type) {
case DISPLAY_LANGUAGE:
return localeNameProvider.getDisplayLanguage(code, locale);
case DISPLAY_COUNTRY:
return localeNameProvider.getDisplayCountry(code, locale);
case DISPLAY_VARIANT:
return localeNameProvider.getDisplayVariant(code, locale);
case DISPLAY_SCRIPT:
return localeNameProvider.getDisplayScript(code, locale);
default:
assert false; // shouldn't happen
}
return null;
}
示例3: getLocaleNameProvider
import java.util.spi.LocaleNameProvider; //导入依赖的package包/类
@Override
public LocaleNameProvider getLocaleNameProvider() {
if (localeNameProvider == null) {
LocaleNameProvider provider = AccessController.doPrivileged(
(PrivilegedAction<LocaleNameProvider>) () ->
new LocaleNameProviderImpl(
getAdapterType(),
getLanguageTagSet("LocaleNames")));
synchronized (this) {
if (localeNameProvider == null) {
localeNameProvider = provider;
}
}
}
return localeNameProvider;
}
示例4: getObject
import java.util.spi.LocaleNameProvider; //导入依赖的package包/类
public String getObject(LocaleNameProvider localeNameProvider,
Locale locale,
String key,
Object... params) {
assert params.length == 2;
int type = (Integer)params[0];
String code = (String)params[1];
switch(type) {
case DISPLAY_LANGUAGE:
return localeNameProvider.getDisplayLanguage(code, locale);
case DISPLAY_COUNTRY:
return localeNameProvider.getDisplayCountry(code, locale);
case DISPLAY_VARIANT:
return localeNameProvider.getDisplayVariant(code, locale);
default:
assert false; // shouldn't happen
}
return null;
}
示例5: getObject
import java.util.spi.LocaleNameProvider; //导入依赖的package包/类
public String getObject(LocaleNameProvider localeNameProvider,
Locale locale,
String key,
Object... params) {
assert params.length == 2;
int type = (Integer)params[0];
String code = (String)params[1];
switch(type) {
case DISPLAY_LANGUAGE:
return localeNameProvider.getDisplayLanguage(code, locale);
case DISPLAY_COUNTRY:
return localeNameProvider.getDisplayCountry(code, locale);
case DISPLAY_VARIANT:
return localeNameProvider.getDisplayVariant(code, locale);
case DISPLAY_SCRIPT:
return localeNameProvider.getDisplayScript(code, locale);
default:
assert false; // shouldn't happen
}
return null;
}
示例6: getLocaleNameProvider
import java.util.spi.LocaleNameProvider; //导入依赖的package包/类
@Override
public LocaleNameProvider getLocaleNameProvider() {
if (localeNameProvider == null) {
LocaleNameProvider provider = new LocaleNameProviderImpl(getAdapterType(),
getLanguageTagSet("LocaleNames"));
synchronized (this) {
if (localeNameProvider == null) {
localeNameProvider = provider;
}
}
}
return localeNameProvider;
}
示例7: TestThread
import java.util.spi.LocaleNameProvider; //导入依赖的package包/类
public TestThread() {
int which = count++ % 3;
switch (which) {
case 0 : cls = LocaleNameProvider.class; break;
case 1 : cls = TimeZoneNameProvider.class; break;
case 2 : cls = DateFormatProvider.class; break;
default : throw new AssertionError("Should not reach here");
}
}
示例8: getDisplayLanguage
import java.util.spi.LocaleNameProvider; //导入依赖的package包/类
/**
* <p>
* Gets the name of the language specified by this locale, in a form suitable
* for display to the user. If possible, the display name will be localized
* to the specified locale. For example, if the locale instance is
* <code>Locale.GERMANY</code>, and the specified locale is <code>Locale.UK</code>,
* the result would be 'German'. Using the German locale would instead give
* 'Deutsch'. If the display name can not be localized to the supplied
* locale, it will fall back on other output in the following order:
* </p>
* <ul>
* <li>the display name in the default locale</li>
* <li>the display name in English</li>
* <li>the ISO code</li>
* </ul>
* <p>
* If the language is unspecified by this locale, then the empty string is
* returned.
* </p>
*
* @param inLocale the locale to use for formatting the display string.
* @return the language name of this locale localized to the given locale,
* with the default locale, English and the ISO code as backups.
* @throws NullPointerException if the supplied locale is null.
*/
public String getDisplayLanguage(Locale inLocale)
{
if (language.isEmpty())
return "";
try
{
ResourceBundle res =
ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
inLocale,
ClassLoader.getSystemClassLoader());
return res.getString("languages." + language);
}
catch (MissingResourceException e)
{
/* This means runtime support for the locale
* is not available, so we check providers. */
}
for (LocaleNameProvider p :
ServiceLoader.load(LocaleNameProvider.class))
{
for (Locale loc : p.getAvailableLocales())
{
if (loc.equals(inLocale))
{
String locLang = p.getDisplayLanguage(language,
inLocale);
if (locLang != null)
return locLang;
break;
}
}
}
if (inLocale.equals(Locale.ROOT)) // Base case
return language;
return getDisplayLanguage(LocaleHelper.getFallbackLocale(inLocale));
}
示例9: getDisplayCountry
import java.util.spi.LocaleNameProvider; //导入依赖的package包/类
/**
* <p>
* Gets the name of the country specified by this locale, in a form suitable
* for display to the user. If possible, the display name will be localized
* to the specified locale. For example, if the locale instance is
* <code>Locale.GERMANY</code>, and the specified locale is <code>Locale.UK</code>,
* the result would be 'Germany'. Using the German locale would instead give
* 'Deutschland'. If the display name can not be localized to the supplied
* locale, it will fall back on other output in the following order:
* </p>
* <ul>
* <li>the display name in the default locale</li>
* <li>the display name in English</li>
* <li>the ISO code</li>
* </ul>
* <p>
* If the country is unspecified by this locale, then the empty string is
* returned.
* </p>
*
* @param inLocale the locale to use for formatting the display string.
* @return the country name of this locale localized to the given locale,
* with the default locale, English and the ISO code as backups.
* @throws NullPointerException if the supplied locale is null.
*/
public String getDisplayCountry(Locale inLocale)
{
if (country.isEmpty())
return "";
try
{
ResourceBundle res =
ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
inLocale,
ClassLoader.getSystemClassLoader());
return res.getString("territories." + country);
}
catch (MissingResourceException e)
{
/* This means runtime support for the locale
* is not available, so we check providers. */
}
for (LocaleNameProvider p :
ServiceLoader.load(LocaleNameProvider.class))
{
for (Locale loc : p.getAvailableLocales())
{
if (loc.equals(inLocale))
{
String locCountry = p.getDisplayCountry(country,
inLocale);
if (locCountry != null)
return locCountry;
break;
}
}
}
if (inLocale.equals(Locale.ROOT)) // Base case
return country;
return getDisplayCountry(LocaleHelper.getFallbackLocale(inLocale));
}
示例10: getDisplayVariant
import java.util.spi.LocaleNameProvider; //导入依赖的package包/类
/**
* <p>
* Gets the name of the variant specified by this locale, in a form suitable
* for display to the user. If possible, the display name will be localized
* to the specified locale. For example, if the locale instance is a revised
* variant, and the specified locale is <code>Locale.UK</code>, the result
* would be 'REVISED'. Using the German locale would instead give
* 'Revidiert'. If the display name can not be localized to the supplied
* locale, it will fall back on other output in the following order:
* </p>
* <ul>
* <li>the display name in the default locale</li>
* <li>the display name in English</li>
* <li>the ISO code</li>
* </ul>
* <p>
* If the variant is unspecified by this locale, then the empty string is
* returned.
* </p>
*
* @param inLocale the locale to use for formatting the display string.
* @return the variant name of this locale localized to the given locale,
* with the default locale, English and the ISO code as backups.
* @throws NullPointerException if the supplied locale is null.
*/
public String getDisplayVariant(Locale inLocale)
{
if (variant.isEmpty())
return "";
try
{
ResourceBundle res =
ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
inLocale,
ClassLoader.getSystemClassLoader());
return res.getString("variants." + variant);
}
catch (MissingResourceException e)
{
/* This means runtime support for the locale
* is not available, so we check providers. */
}
for (LocaleNameProvider p :
ServiceLoader.load(LocaleNameProvider.class))
{
for (Locale loc : p.getAvailableLocales())
{
if (loc.equals(inLocale))
{
String locVar = p.getDisplayVariant(variant,
inLocale);
if (locVar != null)
return locVar;
break;
}
}
}
if (inLocale.equals(Locale.ROOT)) // Base case
return country;
return getDisplayVariant(LocaleHelper.getFallbackLocale(inLocale));
}