Java Code Examples for java.util.Locale.getDisplayName()

The following are Jave code examples for showing how to use getDisplayName() of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: airgram   File: LocaleController.java   View Source Code Vote up 6 votes
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");
            }
        }
    }
}
 
Example 2
Project: tomcat7   File: Util.java   View Source Code Vote up 6 votes
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();
    }
}
 
Example 3
Project: Equella   File: I18nTextField.java   View Source Code Vote up 6 votes
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();
}
 
Example 4
Project: PlusGram   File: LocaleController.java   View Source Code Vote up 6 votes
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");
            }
        }
    }
}
 
Example 5
Project: apache-tomcat-7.0.73-with-comment   File: Util.java   View Source Code Vote up 6 votes
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();
    }
}
 
Example 6
Project: lazycat   File: Util.java   View Source Code Vote up 6 votes
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();
	}
}
 
Example 7
Project: CountryCurrencyPicker   File: Country.java   View Source Code Vote up 6 votes
@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;
    }
}
 
Example 8
Project: Equella   File: RootLanguageSection.java   View Source Code Vote up 5 votes
@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)));
}
 
Example 9
Project: Equella   File: I18nTextField.java   View Source Code Vote up 5 votes
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);
}
 
Example 10
Project: OpenJSharp   File: InputMethodPopupMenu.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 11
Project: jdk8u-jdk   File: InputMethodPopupMenu.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 12
Project: CountryCurrencyPicker   File: Country.java   View Source Code Vote up 5 votes
@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;
    }
}
 
Example 13
Project: scoold   File: TranslateController.java   View Source Code Vote up 5 votes
@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";
}
 
Example 14
Project: openjdk-jdk10   File: InputMethodPopupMenu.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 15
Project: firefox-tv   File: LocaleListPreference.java   View Source Code Vote up 5 votes
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;
}
 
Example 16
Project: AOSP-Kayboard-7.1.2   File: UserDictionarySettingsUtils.java   View Source Code Vote up 5 votes
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);
}
 
Example 17
Project: Equella   File: MultiEditBoxRenderer.java   View Source Code Vote up 4 votes
@Override
public String convertToString(Locale locale)
{
	return locale.getDisplayName();
}
 
Example 18
Project: Equella   File: MultiEditBox.java   View Source Code Vote up 4 votes
@Override
public String convertToString(Locale locale)
{
	return locale.getDisplayName();
}
 
Example 19
Project: openjdk-jdk10   File: LocaleTest.java   View Source Code Vote up 4 votes
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);
        }
    }
}
 
Example 20
Project: openrouteservice   File: LocalizationManager.java   View Source Code Vote up 4 votes
private void loadLocalizations() throws Exception
{
	File classFile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getFile());
	String classPath = classFile.getAbsolutePath();
	String classesPath = classPath.substring(0, classPath.indexOf("classes") + "classes".length());
	Path localesPath = Paths.get(classesPath, "resources", "locales");

	String filePattern = "ors_(.*?).resources";
	Pattern pattern = Pattern.compile(filePattern);

	File[] files = new File(localesPath.toString()).listFiles();

	if (files == null)
		throw new Exception("Resources can not be found.");

	for (File file : files) {
		try
		{
			if (file.isFile()) {
				if (file.getName().matches(filePattern))
				{
					Matcher matcher = pattern.matcher(file.getName());
					if (matcher.find())
					{
						String langCode = matcher.group(1).toLowerCase();
						String[] langCountry = langCode.split("-");
						Locale locale = new Locale(langCountry[0], langCountry.length == 2 ? langCountry[1] : "");
						Language lang = new Language(langCode, locale.getDisplayLanguage(), locale.getDisplayName());
						LanguageResources langResources = new LanguageResources(lang);

						Config allConfig = ConfigFactory.parseFile(file);

						allConfig.entrySet().forEach(entry -> {
							langResources.addLocalString(entry.getKey(), StringUtility.trim(entry.getValue().render(), '\"'));
						});

						_langResources.put(langCode, langResources);
					}
				}
			}
		}
		catch(Exception ex)
		{
			LOGGER.error("Unable to load resources from file " + file.getAbsolutePath());				
		}
	}
}