Example usage for java.util Locale getLanguage

List of usage examples for java.util Locale getLanguage

Introduction

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

Prototype

public String getLanguage() 

Source Link

Document

Returns the language code of this Locale.

Usage

From source file:com.anrisoftware.sscontrol.httpd.fudforum.core.LocaleRenderer.java

private String toString(Locale locale, String formatString) {
    if (StringUtils.equals(formatString, LANGUAGE_KEY)) {
        return locale.getLanguage();
    }/*from  w w  w .ja v a 2  s  . c o  m*/
    return locale.toString();
}

From source file:arena.translation.TranslationSetSelectorBean.java

public TranslationSet getTranslationSet(Locale locale) {
    String language = locale.getLanguage();
    synchronized (this.translationSets) {
        TranslationSet translationSet = (TranslationSet) this.translationSets.get(language.toLowerCase());
        if (translationSet == null) {
            Object translationSheet = null;
            if (this.translationSheets != null) {
                translationSheet = this.translationSheets.get(language);
            }/*from w  w w. j a va2  s  .c om*/
            if (translationSheet == null) {
                translationSheet = this.defaultBasePath + language + ".xml";
            }
            if (this.servletContext != null) {
                translationSheet = servletContext.getRealPath(translationSheet.toString());
            }
            File file = new File(translationSheet.toString());
            if (!file.isFile()) {
                log.warn("Translation file not found: " + translationSheet);
            }
            Document doc = XMLUtils.parseFileToXML(file);
            NodeList items = doc.getDocumentElement().getChildNodes();
            Map<String, String> translations = new Hashtable<String, String>();
            for (int n = 0; n < items.getLength(); n++) {
                Node node = items.item(n);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    String key = XMLUtils.getAttributeByName(node, "key");
                    String text = XMLUtils.extractStringFromElement(node);
                    if ((key != null) && (text != null)) {
                        translations.put(key, text);
                    }
                }
            }
            log.info("Loaded " + translations.size() + " translations for " + language + " from "
                    + translationSheet);
            translationSet = new FixedTranslationSet(translations);
            this.translationSets.put(language.toLowerCase(), translationSet);
        }
        return translationSet;
    }
}

From source file:com.welshare.web.InfoController.java

private String getLocaleSpecificPage(String viewNamePrefix, Locale locale) {
    try {/*from   w  w w . j  av  a2s  .c  o  m*/
        String viewName = viewNamePrefix + locale.getLanguage().toLowerCase();
        if (ctx.getResource("/WEB-INF/jsp/" + viewName + ".jsp") != null) {
            return viewName;
        }
    } catch (MalformedURLException ex) {
        logger.error("Unable to show info page" + viewNamePrefix + " for locale " + locale, ex);
    }

    return viewNamePrefix + "en";
}

From source file:com.sample.application.email.srv.EmailTemplateRepositoryImp.java

@Override
public String getContentType(String template, Locale locale) {
    // "text/html"
    String templateName = template + ((locale == null ? "" : "-" + locale.getLanguage()));
    return emailTemplates.getTemplateMap().get(templateName).getContentType();
}

From source file:cn.remex.core.util.StringUtils.java

/**
 *  HTTP  RFC 3306??/*from  w w w.j ava  2 s . c  o  m*/
 * Determine the RFC 3066 compliant language tag,
 * as used for the HTTP "Accept-Language" header.
 * @param locale the Locale to transform to a language tag 
 * @return the RFC 3066 compliant language tag as String  RFC 3306??
 */
public static String toLanguageTag(final Locale locale) {
    return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : "");
}

From source file:org.opendatakit.utilities.LocalizationUtilsTest.java

@Test
public void testHackedName() {
    Locale defaultLocale = Locale.getDefault();
    String full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    assertEquals("aname", LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale,
            NameUtil.normalizeDisplayName(NameUtil.constructSimpleDisplayName("aname"))));
    assertEquals("a name", LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale,
            NameUtil.normalizeDisplayName(NameUtil.constructSimpleDisplayName("a_name"))));
    assertEquals("_ an am e", LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale,
            NameUtil.normalizeDisplayName(NameUtil.constructSimpleDisplayName("_an_am_e"))));
    assertEquals("an ame _", LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale,
            NameUtil.normalizeDisplayName(NameUtil.constructSimpleDisplayName("an_ame_"))));
}

From source file:com.easyjf.core.i18n.I18nInteceptor.java

private Object createI18nClass(String oldClazzName) throws ClassNotFoundException {
    Locale local = LocalManager.getCurrentLocal();
    String localName = local.getLanguage().toUpperCase();

    String realClassName = oldClazzName + localName;
    Object newObj = com.easyjf.beans.BeanUtils.instantiateClass(Class.forName(realClassName));
    return newObj;
}

From source file:de.micromata.genome.gwiki.wicket.GWikiLocalizer.java

protected String getI18NFromGWiki(String key, Component component, IModel<?> model) {
    GWikiWeb wikiWeb = GWikiWeb.getWiki();
    Locale loc = component.getLocale();
    String lang = loc.getLanguage();
    if (StringUtils.isEmpty(lang) == true) {
        lang = "en";
    }/*from ww w .  j a  v a2  s.c o  m*/

    for (String mod : modules) {
        GWikiI18nElement el = (GWikiI18nElement) wikiWeb.getElement(mod);
        String v = el.getMessage(lang, key);
        if (v != null) {
            return v;
        }
    }
    return null;
}

From source file:com.doculibre.constellio.wicket.pages.BaseSearchPage.java

public BaseSearchPage(SimpleSearch simpleSearch, PageParameters params) {
    super(new Model(simpleSearch));

    if (params != null) {
        WebRequest webRequest = getWebRequestCycle().getWebRequest();
        String displayLang = webRequest.getHttpServletRequest().getParameter(DISPLAY_LANG_PARAM);
        if (StringUtils.isNotBlank(displayLang)) {
            for (Locale supportedLocale : ConstellioSpringUtils.getSupportedLocales()) {
                if (supportedLocale.getLanguage().equals(displayLang)) {
                    this.locale = supportedLocale;
                    break;
                }//ww  w  .  j a va2s .  c  om
            }
        }
    }

    VisibleCollectionsModel visibleCollectionsModel = new VisibleCollectionsModel();
    if (StringUtils.isEmpty(simpleSearch.getCollectionName())) {
        List<RecordCollection> visibleCollections = visibleCollectionsModel.getObject(null, null);
        if (!visibleCollections.isEmpty()) {
            simpleSearch.setCollectionName(visibleCollections.get(0).getName());
        }
    }
}

From source file:com.cyclopsgroup.tornado.ui.view.user.UserProfile.java

/**
 * Override method execute in class UserProfile
 *
 * @see com.cyclopsgroup.waterview.Module#execute(com.cyclopsgroup.waterview.RuntimeData, com.cyclopsgroup.waterview.Context)
 *//*  ww  w. j a  va2s .c om*/
public void execute(RuntimeData data, Context context) throws Exception {
    RuntimeUser user = RuntimeUser.getInstance(data);
    PersistenceManager persist = (PersistenceManager) lookup(PersistenceManager.ROLE);
    User u = (User) persist.load(User.class, user.getId());
    context.put("userObject", u);

    TreeMap languages = new TreeMap();
    TreeMap countries = new TreeMap();
    Locale[] availableLocales = Locale.getAvailableLocales();
    for (int i = 0; i < availableLocales.length; i++) {
        Locale locale = availableLocales[i];
        DefaultSelectOption lang = new DefaultSelectOption(locale.getLanguage(),
                locale.getDisplayLanguage(data.getLocale()) + '(' + locale.getLanguage() + ')');
        languages.put(locale.getLanguage(), lang);

        if (StringUtils.isNotEmpty(locale.getCountry())) {
            DefaultSelectOption cout = new DefaultSelectOption(locale.getCountry(),
                    locale.getDisplayCountry(data.getLocale()) + '(' + locale.getCountry() + ')');
            countries.put(locale.getCountry(), cout);
        }
    }
    context.put("countries", countries.values());
    context.put("languages", languages.values());
}