本文整理汇总了Java中java.util.Locale.getDisplayName方法的典型用法代码示例。如果您正苦于以下问题:Java Locale.getDisplayName方法的具体用法?Java Locale.getDisplayName怎么用?Java Locale.getDisplayName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Locale
的用法示例。
在下文中一共展示了Locale.getDisplayName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDeviceConfigurationChange
import java.util.Locale; //导入方法依赖的package包/类
public void onDeviceConfigurationChange(Configuration newConfig) {
if (changingConfiguration) {
return;
}
is24HourFormat = DateFormat.is24HourFormat(ApplicationLoader.applicationContext);
systemDefaultLocale = newConfig.locale;
if (languageOverride != null) {
LocaleInfo toSet = currentLocaleInfo;
currentLocaleInfo = null;
applyLanguage(toSet, false);
} else {
Locale newLocale = newConfig.locale;
if (newLocale != null) {
String d1 = newLocale.getDisplayName();
String d2 = currentLocale.getDisplayName();
if (d1 != null && d2 != null && !d1.equals(d2)) {
recreateFormatters();
}
currentLocale = newLocale;
currentPluralRules = allRules.get(currentLocale.getLanguage());
if (currentPluralRules == null) {
currentPluralRules = allRules.get("en");
}
}
}
}
示例2: message
import java.util.Locale; //导入方法依赖的package包/类
static String message(ELContext context, String name, Object... props) {
Locale locale = null;
if (context != null) {
locale = context.getLocale();
}
if (locale == null) {
locale = Locale.getDefault();
if (locale == null) {
return "";
}
}
ResourceBundle bundle = ResourceBundle.getBundle(
"javax.el.LocalStrings", locale);
try {
String template = bundle.getString(name);
if (props != null) {
template = MessageFormat.format(template, props);
}
return template;
} catch (MissingResourceException e) {
return "Missing Resource: '" + name + "' for Locale "
+ locale.getDisplayName();
}
}
示例3: I18nTextField
import java.util.Locale; //导入方法依赖的package包/类
public I18nTextField(Set<Locale> defaultLocales)
{
this.defaultLocales = defaultLocales;
Comparator<Locale> localeComparator = new NumberStringComparator<Locale>()
{
private static final long serialVersionUID = 1L;
@Override
public String convertToString(Locale locale)
{
return locale.getDisplayName();
}
};
this.editableLocales = new TreeSet<Locale>(localeComparator);
this.editableLocales.addAll(defaultLocales);
this.textMap = new TreeMap<Locale, String>(localeComparator);
initialise();
}
示例4: onDeviceConfigurationChange
import java.util.Locale; //导入方法依赖的package包/类
public void onDeviceConfigurationChange(Configuration newConfig) {
if (changingConfiguration) {
return;
}
is24HourFormat = DateFormat.is24HourFormat(ApplicationLoader.applicationContext);
systemDefaultLocale = newConfig.locale;
if (languageOverride != null) {
LocaleInfo toSet = currentLocaleInfo;
currentLocaleInfo = null;
applyLanguage(toSet, false);
} else {
Locale newLocale = newConfig.locale;
if (newLocale != null) {
String d1 = newLocale.getDisplayName();
String d2 = currentLocale.getDisplayName();
if (d1 != null && d2 != null && !d1.equals(d2)) {
recreateFormatters();
}
currentLocale = newLocale;
currentPluralRules = allRules.get(currentLocale.getLanguage());
if (currentPluralRules == null) {
currentPluralRules = allRules.get("fa");
}
}
}
}
示例5: message
import java.util.Locale; //导入方法依赖的package包/类
static String message(ELContext context, String name, Object... props) {
Locale locale = null;
if (context != null) {
locale = context.getLocale();
}
if (locale == null) {
locale = Locale.getDefault();
if (locale == null) {
return "";
}
}
ResourceBundle bundle = ResourceBundle.getBundle("javax.el.LocalStrings", locale);
try {
String template = bundle.getString(name);
if (props != null) {
template = MessageFormat.format(template, props);
}
return template;
} catch (MissingResourceException e) {
return "Missing Resource: '" + name + "' for Locale " + locale.getDisplayName();
}
}
示例6: getCountryByName
import java.util.Locale; //导入方法依赖的package包/类
@Nullable
public static Country getCountryByName(final String countryName, Context context) {
try {
Locale locale = Iterables.find(Arrays.asList(Locale.getAvailableLocales()), new Predicate<Locale>() {
@Override
public boolean apply(Locale input) {
return input.getDisplayCountry(Locale.US).equals(countryName);
}
});
return new Country(locale.getCountry(),
locale.getDisplayName(),
Helper.getFlagDrawableId(locale.getCountry(), context));
} catch (NullPointerException e) {
return null;
}
}
示例7: transform
import java.util.Locale; //导入方法依赖的package包/类
@Override
protected void transform(SectionInfo info, SelectionsTableSelection selection, Locale locale,
List<SectionRenderable> actions, int index)
{
final Label name;
// toString() gets the country, lang and variant and sticks them
// together. If none of them are populated it returns a blank string
if( Strings.isNullOrEmpty(locale.toString()) )
{
name = LABEL_LOCALE_DEFAULT_NAME;
}
else
{
name = new TextLabel(locale.getDisplayName());
}
selection.setViewAction(new LabelRenderer(name));
/**
* Export handled as a GET rather than a POST, to avoid errors with
* 'page already being submitted', hence the BookmarkAndModify
* utilisation.
*/
Bookmark bookmarkForGET = new BookmarkAndModify(info,
events.getNamedModifier("exportLocale", locale.toString()));
actions.add(new LinkRenderer(new HtmlLinkState(EXPORT_LABEL, bookmarkForGET)));
actions.add(makeAction(DELETE_LABEL,
new OverrideHandler(deleteLocaleHandler, locale.toString()).addValidator(CONFIRM_REMOVE_LANGPACK)));
}
示例8: PopupPanel
import java.util.Locale; //导入方法依赖的package包/类
public PopupPanel(JPopupMenu popup)
{
this.popup = popup;
this.mapping = new HashMap<Locale, JTextComponent>();
setLayout(new MigLayout("wrap,fill", "[grow]r[]", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
for( Locale locale : editableLocales )
{
String actionCommand = locale.toString();
JTextComponent field = getTextComponent();
JButton button = new JButton(locale.getDisplayName());
button.setActionCommand(actionCommand);
button.addActionListener(this);
field.setText(textMap.get(locale));
mapping.put(locale, field);
add(prepareTextComponent(field), "growx, sizegroup f, hmax 100px"); //$NON-NLS-1$
add(button, "sizegroup b"); //$NON-NLS-1$
}
closeButton = new JLinkButton(CurrentLocale.get("prompts.close")); //$NON-NLS-1$
closeButton.addActionListener(this);
closeButton.setActionCommand(""); //$NON-NLS-1$
closeButton.setIcon(new ArrowIcon(SwingConstants.NORTH));
closeButton.setHorizontalTextPosition(SwingConstants.LEFT);
add(closeButton, "span 2, align right, shrink"); //$NON-NLS-1$
setBorder(BorderFactory.createLineBorder(Color.BLACK));
final int width = Math.max(400, I18nTextField.this.getSize().width);
setPreferredSize(new Dimension(width, getPreferredSize().height));
popup.addPopupMenuListener(this);
}
示例9: getLocaleName
import java.util.Locale; //导入方法依赖的package包/类
/**
* Returns a localized locale name for input methods with the
* given locale. It falls back to Locale.getDisplayName() and
* then to Locale.toString() if no localized locale name is found.
*
* @param locale Locale for which localized locale name is obtained
*/
String getLocaleName(Locale locale) {
String localeString = locale.toString();
String localeName = Toolkit.getProperty("AWT.InputMethodLanguage." + localeString, null);
if (localeName == null) {
localeName = locale.getDisplayName();
if (localeName == null || localeName.length() == 0)
localeName = localeString;
}
return localeName;
}
示例10: getCountry
import java.util.Locale; //导入方法依赖的package包/类
@Nullable
public static Country getCountry(String countryCode, Context context) {
try {
Locale locale = new Locale("", countryCode);
return new Country(countryCode,
locale.getDisplayName(),
Helper.getFlagDrawableId(countryCode, context));
} catch (NullPointerException e) {
return null;
}
}
示例11: translate
import java.util.Locale; //导入方法依赖的package包/类
@GetMapping({"/{locale}", "/{locale}/{index}"})
public String translate(@PathVariable String locale, @PathVariable(required = false) String index,
HttpServletRequest req, Model model) {
Locale showLocale = utils.getLangutils().getProperLocale(locale);
if (showLocale == null || "en".equals(showLocale.getLanguage())) {
// can't translate default language
return "redirect:" + LANGUAGESLINK;
}
int showIndex = -1;
List<Translation> translationslist = Collections.emptyList();
Pager itemcount = utils.getPager("page", req);
if (!StringUtils.isBlank(index)) {
showIndex = getIndex(index, langkeys);
// this is what is currently shown for translation
translationslist = utils.getLangutils().
readAllTranslationsForKey(showLocale.getLanguage(), langkeys.get(showIndex), itemcount);
}
String title = utils.getLang(req).get("translate.title") + " - " + showLocale.getDisplayName(showLocale);
int showLocaleProgress = utils.getLangutils().getTranslationProgressMap().get(showLocale.getLanguage());
model.addAttribute("path", "translate.vm");
model.addAttribute("title", title);
model.addAttribute("showIndex", showIndex);
model.addAttribute("showLocale", showLocale);
model.addAttribute("langkeys", langkeys);
model.addAttribute("deflang", deflang);
model.addAttribute("showLocaleProgress", showLocaleProgress);
model.addAttribute("translationslist", translationslist);
model.addAttribute("itemcount", itemcount);
return "base";
}
示例12: LocaleDescriptor
import java.util.Locale; //导入方法依赖的package包/类
public LocaleDescriptor(Locale locale, String tag) {
this.tag = tag;
final String displayName;
if (languageCodeToNameMap.containsKey(locale.getLanguage())) {
displayName = languageCodeToNameMap.get(locale.getLanguage());
} else {
displayName = locale.getDisplayName(locale);
}
if (TextUtils.isEmpty(displayName)) {
// There's nothing sane we can do.
Log.w(LOG_TAG, "Display name is empty. Using " + locale.toString());
this.nativeName = locale.toString();
return;
}
// For now, uppercase the first character of LTR locale names.
// This is pretty much what Android does. This is a reasonable hack
// for Bug 1014602, but it won't generalize to all locales.
final byte directionality = Character.getDirectionality(displayName.charAt(0));
if (directionality == Character.DIRECTIONALITY_LEFT_TO_RIGHT) {
this.nativeName = displayName.substring(0, 1).toUpperCase(locale) +
displayName.substring(1);
return;
}
this.nativeName = displayName;
}
示例13: getLocaleDisplayName
import java.util.Locale; //导入方法依赖的package包/类
public static String getLocaleDisplayName(Context context, String localeStr) {
if (TextUtils.isEmpty(localeStr)) {
// CAVEAT: localeStr should not be null because a null locale stands for the system
// locale in UserDictionary.Words.addWord.
return context.getResources().getString(R.string.user_dict_settings_all_languages);
}
final Locale locale = LocaleUtils.constructLocaleFromString(localeStr);
final Locale systemLocale = context.getResources().getConfiguration().locale;
return locale.getDisplayName(systemLocale);
}
示例14: convertToString
import java.util.Locale; //导入方法依赖的package包/类
@Override
public String convertToString(Locale locale)
{
return locale.getDisplayName();
}
示例15: doTestDisplayNames
import java.util.Locale; //导入方法依赖的package包/类
private void doTestDisplayNames(Locale inLocale, int compareIndex, boolean defaultIsFrench) {
String language = Locale.getDefault().getLanguage();
if (defaultIsFrench && !language.equals("fr")) {
errln("Default locale should be French, but it's really " + language);
} else if (!defaultIsFrench && !language.equals("en")) {
errln("Default locale should be English, but it's really " + language);
}
for (int i = 0; i <= MAX_LOCALES; i++) {
Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
logln(" Testing " + testLocale + "...");
String testLang;
String testCtry;
String testVar;
String testName;
if (inLocale == null) {
testLang = testLocale.getDisplayLanguage();
testCtry = testLocale.getDisplayCountry();
testVar = testLocale.getDisplayVariant();
testName = testLocale.getDisplayName();
} else {
testLang = testLocale.getDisplayLanguage(inLocale);
testCtry = testLocale.getDisplayCountry(inLocale);
testVar = testLocale.getDisplayVariant(inLocale);
testName = testLocale.getDisplayName(inLocale);
}
String expectedLang;
String expectedCtry;
String expectedVar;
String expectedName;
expectedLang = dataTable[compareIndex][i];
if (expectedLang.equals("") && defaultIsFrench) {
expectedLang = dataTable[DLANG_EN][i];
}
if (expectedLang.equals("")) {
expectedLang = dataTable[DLANG_ROOT][i];
}
expectedCtry = dataTable[compareIndex + 1][i];
if (expectedCtry.equals("") && defaultIsFrench) {
expectedCtry = dataTable[DCTRY_EN][i];
}
if (expectedCtry.equals("")) {
expectedCtry = dataTable[DCTRY_ROOT][i];
}
expectedVar = dataTable[compareIndex + 2][i];
if (expectedVar.equals("") && defaultIsFrench) {
expectedVar = dataTable[DVAR_EN][i];
}
if (expectedVar.equals("")) {
expectedVar = dataTable[DVAR_ROOT][i];
}
expectedName = dataTable[compareIndex + 3][i];
if (expectedName.equals("") && defaultIsFrench) {
expectedName = dataTable[DNAME_EN][i];
}
if (expectedName.equals("")) {
expectedName = dataTable[DNAME_ROOT][i];
}
if (!testLang.equals(expectedLang)) {
errln("Display language mismatch: " + testLang + " versus " + expectedLang);
}
if (!testCtry.equals(expectedCtry)) {
errln("Display country mismatch: " + testCtry + " versus " + expectedCtry);
}
if (!testVar.equals(expectedVar)) {
errln("Display variant mismatch: " + testVar + " versus " + expectedVar);
}
if (!testName.equals(expectedName)) {
errln("Display name mismatch: " + testName + " versus " + expectedName);
}
}
}