Example usage for java.util Locale getDisplayName

List of usage examples for java.util Locale getDisplayName

Introduction

In this page you can find the example usage for java.util Locale getDisplayName.

Prototype

public String getDisplayName(Locale inLocale) 

Source Link

Document

Returns a name for the locale that is appropriate for display to the user.

Usage

From source file:com.norconex.commons.wicket.markup.html.i18n.LocaleDropDownChoice.java

public LocaleDropDownChoice(String id, IModel<Locale> model, List<Locale> supportedLocales,
        final Locale displayLocale) {
    super(id, model, new ListModel<Locale>(supportedLocales), new IChoiceRenderer<Locale>() {
        private static final long serialVersionUID = 7765914025904608599L;

        @Override//from   w  w w  . ja va 2  s .  c  o m
        public Object getDisplayValue(Locale locale) {
            Locale textLocale = displayLocale;
            if (textLocale == null) {
                textLocale = locale;
            }
            return StringUtils.capitalize(locale.getDisplayName(locale));
        }

        @Override
        public String getIdValue(Locale locale, int index) {
            return locale.toString();
        }
    });
}

From source file:info.magnolia.module.admininterface.dialogs.LanguageSelect.java

/**
 * @see info.magnolia.cms.gui.dialog.DialogSelect#init(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, info.magnolia.cms.core.Content, info.magnolia.cms.core.Content)
 *//*from   w w w  . java2s  . c om*/
public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode,
        Content configNode) throws RepositoryException {
    super.init(request, response, websiteNode, configNode);

    List options = new ArrayList();

    Collection col = MessagesManager.getAvailableLocales();

    for (Iterator iter = col.iterator(); iter.hasNext();) {
        Locale locale = (Locale) iter.next();
        String code = locale.getLanguage();
        if (StringUtils.isNotEmpty(locale.getCountry())) {
            code += "_" + locale.getCountry(); //$NON-NLS-1$
        }
        String name = locale.getDisplayName(MgnlContext.getLocale());
        SelectOption option = new SelectOption(name, code);
        options.add(option);
    }

    // sort them
    Collections.sort(options, new Comparator() {

        public int compare(Object arg0, Object arg1) {
            try {
                String name0 = ((SelectOption) arg0).getLabel();
                String name1 = ((SelectOption) arg1).getLabel();
                return name0.compareTo(name1);
            } catch (Exception e) {
                return 0;
            }
        }
    });

    this.setOptions(options);
}

From source file:org.sipfoundry.sipxconfig.site.common.JarMessagesSource.java

public String resolveLocaleName(Locale locale) {
    Properties languagesForLocale = loadMessagesFromJar(LANGUAGE_NAME_RESOURCE, locale);
    if (languagesForLocale == null || languagesForLocale.getProperty(LOCALE_PROPERTY) == null) {
        return locale.getDisplayName(locale);
    }//www . j a v  a 2 s  .  c o m
    return languagesForLocale.getProperty(LOCALE_PROPERTY);
}

From source file:org.webguitoolkit.ui.controls.util.TextService.java

public void loadLocalesInt(ISelect lcSelect) {
    Locale[] locs = Locale.getAvailableLocales();
    Map<String, String> loclist = new TreeMap<String, String>();

    for (int i = 0; i < locs.length; i++) {
        Locale l = locs[i];
        String displayName = l.getDisplayName(getLocale());
        if (StringUtils.isNotBlank(displayName) && !loclist.containsValue(displayName)) {
            loclist.put(l.toString(), displayName);
        }//w ww  . jav a 2  s .  com
    }
    lcSelect.setModel(new SelectKVModel().loadList(loclist));
    lcSelect.loadList();
    lcSelect.setValue(getLocale().toString());
}

From source file:org.opencms.workplace.tools.content.CmsElementChangeLocaleDialog.java

/**
 * Returns the selector widget options to build a Locale selector widget.<p>
 * /*  w  w  w  . j  a v a 2 s.  c o  m*/
 * @return the selector widget options to build a Locale selector widget
 */
public List getLocaleConfigOptions() {

    List result = new ArrayList();

    List locales = OpenCms.getLocaleManager().getAvailableLocales();
    Iterator i = locales.iterator();
    while (i.hasNext()) {
        Locale locale = (Locale) i.next();
        String localeStr = locale.toString();
        String localeDisplayStr = locale.getDisplayName(getLocale());

        result.add(new CmsSelectWidgetOption(localeStr, false, localeDisplayStr));
    }

    return result;
}

From source file:it.cnr.icar.eric.client.ui.thin.UserPreferencesBean.java

/** Returns a Collection of available locales as SelectItems. */
public Collection<SelectItem> getSupportedLocalesSelectItems() {
    if (supportedLocalesSelectItems == null) {
        ArrayList<SelectItem> selectItems = new ArrayList<SelectItem>();
        for (Iterator<Locale> it = getSupportedUiLocales().iterator(); it.hasNext();) {
            Locale loc = it.next();
            SelectItem item = new SelectItem(loc.toString(), loc.getDisplayName(loc));
            selectItems.add(item);/*from  w w w . j a v  a 2s  . com*/
        }
        supportedLocalesSelectItems = selectItems;
    }
    return supportedLocalesSelectItems;
}

From source file:org.olat.core.commons.controllers.impressum.ImpressumAdminController.java

private String getTranslated(String lang) {
    String langName;/*  w  ww .j  a v a  2  s  . co  m*/
    Locale locale = i18nManager.getLocaleOrNull(lang);
    if (locale != null) {
        langName = locale.getDisplayName(getLocale());
    } else {
        langName = lang;
    }
    return langName;
}

From source file:org.jbpm.formbuilder.server.RESTFormService.java

@POST
@Path("/preview/lang/{language}")
public Response getFormPreview(FormPreviewDTO dto, @PathParam("language") String language,
        @Context ServletContext context, @Context HttpServletRequest request) {
    setContext(context);/*from  ww w  .  ja v a 2 s.c  o m*/
    try {
        URL url = createTemplate(language, dto);
        Map<String, Object> inputs = dto.getInputsAsMap();
        Renderer renderer = getRenderer(language);
        inputs.put(Renderer.BASE_CONTEXT_PATH, context.getContextPath());
        Locale locale = request.getLocale();
        inputs.put(Renderer.BASE_LOCALE, locale == null ? "default" : locale.getDisplayName(locale));
        Object html = renderer.render(url, inputs);
        String htmlUrl = createHtmlTemplate(html, language, context);
        return Response.ok(htmlUrl, MediaType.TEXT_PLAIN).build();
    } catch (FormEncodingException e) {
        return error("Problem encoding form preview", e);
    } catch (TranslatorException e) {
        return error("Problem transforming form preview to " + language + " language", e);
    } catch (RendererException e) {
        return error("Problem rendering form preview in " + language + " language", e);
    } catch (IOException e) {
        return error("Problem writing form preview in " + language + " language", e);
    }
}

From source file:it.cnr.icar.eric.client.ui.thin.UserPreferencesBean.java

/** returns the localized supported locales display names */
public Collection<String> getSupportedUiLocalesDisplayNames() {
    String supportedLocales = ProviderProperties.getInstance()
            .getProperty("eric.client.thinbrowser.supportedlocales", "en_US");
    StringTokenizer tkz = new StringTokenizer(supportedLocales, "|");
    ArrayList<String> locales = new ArrayList<String>();
    while (tkz.hasMoreTokens()) {
        Locale locale = parseLocale(tkz.nextToken());
        if (locale != null && this.uiLocale != null) {
            locales.add(locale.getDisplayName(this.uiLocale) + " (" + locale + ")");
        }/*from w ww  .j av a  2 s . co m*/
    }
    return locales;
}

From source file:org.jahia.taglibs.uicomponents.i18n.DisplayLanguageSwitchLinkTag.java

public int doStartTag() {
    try {/*from   ww w . jav  a  2s. c o  m*/
        final StringBuilder buff = new StringBuilder();

        final boolean isCurrentBrowsingLanguage = isCurrentBrowsingLanguage(languageCode);
        final boolean isRedirectToHomePageActivated = InitLangBarAttributes.GO_TO_HOME_PAGE
                .equals(onLanguageSwitch);

        if (!isCurrentBrowsingLanguage) {
            if (isRedirectToHomePageActivated) {
                if (redirectCssClassName == null || redirectCssClassName.length() == 0) {
                    redirectCssClassName = InitLangBarAttributes.REDIRECT_DEFAULT_STYLE;
                }
                buff.append("<div class='");
                buff.append(redirectCssClassName);
                buff.append("'>");
            }
            buff.append("<a href='");
            final String link;
            if (onLanguageSwitch == null || onLanguageSwitch.length() == 0
                    || InitLangBarAttributes.STAY_ON_CURRENT_PAGE.equals(onLanguageSwitch)) {
                link = generateCurrentNodeLangSwitchLink(languageCode) + "##requestParameters##";

            } else if (isRedirectToHomePageActivated) {
                link = generateNodeLangSwitchLink(rootPage, languageCode) + "##requestParameters##";

            } else {
                throw new JspTagException("Unknown onLanguageSwitch attribute value " + onLanguageSwitch);
            }

            buff.append(StringEscapeUtils.escapeXml(link));
            if (urlVar != null && urlVar.length() > 0) {
                pageContext.setAttribute(urlVar, link);
            }
            buff.append("' ");
            buff.append("title='");
            if (isRedirectToHomePageActivated) {
                titleKey += "." + onLanguageSwitch;
            }
            buff.append(getMessage(titleKey, title));
            buff.append("'>");
        } else {
            buff.append("<span>");
            if (urlVar != null)
                pageContext.removeAttribute(urlVar, PageContext.PAGE_SCOPE);
        }

        String attributeValue = null;
        if (linkKind == null || linkKind.length() == 0 || LANGUAGE_CODE.equals(linkKind)
                || linkKind.startsWith(FLAG)) {
            attributeValue = languageCode;
            buff.append(languageCode);

        } else if (NAME_CURRENT_LOCALE.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(getRenderContext().getMainResource().getLocale());
            attributeValue = value;
            buff.append(value);

        } else if (NAME_IN_LOCALE.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(locale);
            attributeValue = value;
            buff.append(value);

        } else if (LETTER.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(locale).substring(0, 1).toUpperCase();
            attributeValue = value;
            buff.append(value);

        } else if (DOUBLE_LETTER.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(locale).substring(0, 2).toUpperCase();
            attributeValue = value;
            buff.append(value);

        } else if (ISOLOCALECOUNTRY_CODE.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            StringBuilder value = new StringBuilder(locale.getLanguage().toUpperCase());
            if (locale.getCountry() != null && locale.getCountry().length() != 0) {
                value.append("(").append(locale.getCountry()).append(")");
            }
            attributeValue = value.toString();
            buff.append(value);

        } else {
            throw new JspTagException("Unknown linkKind value '" + linkKind + "'");
        }

        if (getVar() != null) {
            pageContext.setAttribute(getVar(), attributeValue);
        }

        if (!isCurrentBrowsingLanguage) {
            buff.append("</a>");
            if (isRedirectToHomePageActivated)
                buff.append("</div>");
        } else {
            buff.append("</span>");
        }

        if (display) {
            pageContext.getOut().print(buff.toString());
        }

    } catch (final Exception e) {
        logger.error("Error while getting language switch URL", e);
    }
    return SKIP_BODY;
}