本文整理汇总了Java中java.util.spi.LocaleNameProvider.getAvailableLocales方法的典型用法代码示例。如果您正苦于以下问题:Java LocaleNameProvider.getAvailableLocales方法的具体用法?Java LocaleNameProvider.getAvailableLocales怎么用?Java LocaleNameProvider.getAvailableLocales使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.spi.LocaleNameProvider
的用法示例。
在下文中一共展示了LocaleNameProvider.getAvailableLocales方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: 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));
}
示例3: 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));
}
示例4: 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));
}
示例5: 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));
}
示例6: 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));
}
示例7: addImpl
import java.util.spi.LocaleNameProvider; //导入方法依赖的package包/类
@Override
public void addImpl(LocaleNameProvider impl) {
for (Locale l : impl.getAvailableLocales()) {
map.putIfAbsent(l, impl);
}
}