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:de.gesundkrank.wikipedia.hadoop.io.WikiDumpLoader.java

/**
 * Return last change of the latest online dump of the given language
 *
 * @param locale Language of wikidump/*from   www  .j av  a2s .co m*/
 * @return
 */
private long checkNewDump(Locale locale) throws IOException {
    try {
        String localeDumpUrl = String.format(DUMP_URL, locale.getLanguage(), locale.getLanguage());
        URLConnection connection = new URL(localeDumpUrl).openConnection();
        String lastModified = connection.getHeaderField("Last-Modified");
        return new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH).parse(lastModified).getTime();
    } catch (ParseException e) {
        throw new IOException(e);
    }
}

From source file:com.github.mrstampy.gameboot.locale.processor.LocaleProcessorTest.java

/**
 * Test process./*from   ww w.  j ava  2  s.  c om*/
 *
 * @throws Exception
 *           the exception
 */
@Test
public void testProcess() throws Exception {
    assertEquals(0, registry.size());

    testCurrent(Locale.getDefault());

    LocaleMessage msg = new LocaleMessage();
    msg.setSystemId(SYSTEM_ID_KEY);
    msg.setLanguageCode(FRENCH_CODE);

    Response r = processor.process(msg);

    assertNotNull(r);
    assertEquals(ResponseCode.SUCCESS, r.getResponseCode());
    assertEquals(1, registry.size());

    Locale fr = new Locale(FRENCH_CODE);
    testCurrent(fr);

    Locale locale = registry.get(SYSTEM_ID_KEY);
    assertNotNull(locale);
    assertEquals(FRENCH_CODE, locale.getLanguage());
}

From source file:be.fedict.trust.service.bean.ConfigurationServiceBean.java

/**
 * {@inheritDoc}//w  w w . jav a2  s.c o  m
 */
public void saveText(String key, Locale locale, String text) {

    LOG.debug("save text for key=" + key + " language=" + locale.getLanguage());
    LocalizationKeyEntity localizationKey = this.localizationDAO.findLocalization(key);
    for (LocalizationTextEntity localizationText : localizationKey.getTexts()) {
        if (localizationText.getLanguage().equals(locale.getLanguage())) {
            localizationText.setText(text);
        }
    }
}

From source file:nz.co.senanque.localemanagement.XMLMessageSource.java

@Override
protected MessageFormat resolveCode(String code, Locale locale) {
    String ret = null;//  w  ww  . j  a v a 2 s. co  m
    String country = locale.getCountry();
    String language = locale.getLanguage();
    String variant = locale.getVariant();
    logger.debug("Code {} Initial locale {}", code, locale.toString());
    Locale thisLocale = null;
    if (!StringUtils.isEmpty(variant)) {
        thisLocale = new Locale(language, country, variant);
        Map<String, String> m = m_map.get(thisLocale);
        if (m != null) {
            ret = m.get(code);
        }
        logger.debug("tried locale {} result: {}", thisLocale.toString(), ret);

    }
    if (ret == null) {
        if (!StringUtils.isEmpty(country)) {
            thisLocale = new Locale(language, country);
            Map<String, String> m = m_map.get(thisLocale);
            if (m != null) {
                ret = m.get(code);
            }
            logger.debug("tried locale {} result: {}", thisLocale.toString(), ret);
        }
    }
    if (ret == null) {
        if (!StringUtils.isEmpty(language)) {
            thisLocale = new Locale(language);
            Map<String, String> m = m_map.get(thisLocale);
            if (m != null) {
                ret = m.get(code);
            }
            logger.debug("tried locale {} result: {}", thisLocale.toString(), ret);
        }
    }
    if (ret == null) {
        thisLocale = Locale.getDefault();
        Map<String, String> m = m_map.get(thisLocale);
        if (m != null) {
            ret = m.get(code);
        }
        logger.debug("tried locale {} result: {}", thisLocale.toString(), ret);
    }
    if (ret == null) {
        return null;
    }
    return new MessageFormat(ret, locale);
}

From source file:com.enonic.cms.business.localization.resource.LocalizationResourceBundleServiceImpl.java

private LocalizationResourceBundle createResourceBundle(Locale locale,
        ResourceKey defaultLocalizationResourceKey) {
    Properties props = new Properties();

    String lang = locale.getLanguage();
    String country = locale.getCountry();
    String variant = locale.getVariant();

    props.putAll(loadBundle(defaultLocalizationResourceKey, ""));

    if (StringUtils.isNotEmpty(lang)) {
        lang = lang.toLowerCase();/* ww  w . j a  va 2 s  . c om*/
        props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang));
    }

    if (StringUtils.isNotEmpty(country)) {
        country = country.toLowerCase();
        props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang + "_" + country));
    }

    if (StringUtils.isNotEmpty(variant)) {
        variant = variant.toLowerCase();
        props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang + "_" + country + "_" + variant));
    }

    return new LocalizationResourceBundle(props);
}

From source file:net.sourceforge.ganttproject.gui.options.InterfaceOptionPageProvider.java

@Override
public void init(IGanttProject project, final UIFacade uiFacade) {
    super.init(project, uiFacade);
    uiFacade.getLanguageOption().addChangeValueListener(new ChangeValueListener() {
        @Override//from   w w w .  ja v  a2 s. c o m
        public void changeValue(ChangeValueEvent event) {
            Locale selectedLocale = uiFacade.getLanguageOption().getSelectedValue();
            if (selectedLocale != null && "gl".equals(selectedLocale.getLanguage().toLowerCase())
                    && myLabel != null) {
                Pair<Boolean, File> localeTest = checkLocale(selectedLocale);
                if (!localeTest.first() && localeTest.second() != null) {
                    GanttLanguage i18n = GanttLanguage.getInstance();
                    myLabel.setVisible(true);
                    myLabel.setText(i18n.formatText("optionPage.ui.general.localeInstallText",
                            i18n.getText("optionPage.ui.general.localeInstallUrl"),
                            localeTest.second().getAbsolutePath()));
                }
            } else if (myLabel != null && myLabel.isVisible()) {
                myLabel.setVisible(false);
            }
        }
    });
}

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

@Test
public void testNormalizeDisplayName() throws JsonProcessingException {
    Map<String, Object> langMap = new TreeMap<String, Object>();
    langMap.put("en_US", "This is a test");
    langMap.put("en_GB", "Test is This");
    langMap.put("en", "Huh Test");
    langMap.put("fr", "Je suis");
    langMap.put("default", "No way!");
    Map<String, Object> topMap = new TreeMap<String, Object>();
    topMap.put("text", langMap);
    String value = ODKFileUtils.mapper.writeValueAsString(topMap);

    Locale defaultLocale;
    String full_locale;//from  w ww.  j  a v a  2  s  .  co  m
    String match;

    Locale.setDefault(Locale.US);
    defaultLocale = Locale.getDefault();
    full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value);
    assertEquals("This is a test", match);

    Locale.setDefault(Locale.UK);
    defaultLocale = Locale.getDefault();
    full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value);
    assertEquals("Test is This", match);

    Locale.setDefault(Locale.CANADA);
    defaultLocale = Locale.getDefault();
    full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value);
    assertEquals("Huh Test", match);

    Locale.setDefault(Locale.CANADA_FRENCH);
    defaultLocale = Locale.getDefault();
    full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value);
    assertEquals("Je suis", match);

    Locale.setDefault(Locale.GERMANY);
    defaultLocale = Locale.getDefault();
    full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value);
    assertEquals("No way!", match);

    Locale.setDefault(Locale.US);
}

From source file:de.matzefratze123.heavyspleef.core.i18n.YMLControl.java

@Override
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
    List<Locale> candidates = Lists.newArrayList();

    candidates.add(locale);/*w w  w .  j  a  v  a  2s.  co  m*/

    if (!locale.getLanguage().isEmpty() && !locale.getCountry().isEmpty() && !locale.getVariant().isEmpty()) {
        candidates.add(new Locale(locale.getLanguage(), locale.getCountry()));
        candidates.add(new Locale(locale.getLanguage()));
    } else if (!locale.getLanguage().isEmpty() && !locale.getCountry().isEmpty()) {
        candidates.add(new Locale(locale.getLanguage()));
    }

    candidates.add(Locale.US);
    candidates.add(Locale.ROOT);
    return candidates;
}

From source file:com.enonic.cms.core.localization.LocalizationResourceBundleServiceImpl.java

private LocalizationResourceBundle createResourceBundle(final Locale locale,
        final ResourceKey defaultLocalizationResourceKey) {
    Properties props = new Properties();

    String lang = locale.getLanguage();
    String country = locale.getCountry();
    String variant = locale.getVariant();

    props.putAll(loadBundle(defaultLocalizationResourceKey, ""));

    if (StringUtils.isNotEmpty(lang)) {
        lang = lang.toLowerCase();/*www. j a v a  2s  . c  o  m*/
        props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang));
    }

    if (StringUtils.isNotEmpty(country)) {
        country = country.toLowerCase();
        props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang + "_" + country));
    }

    if (StringUtils.isNotEmpty(variant)) {
        variant = variant.toLowerCase();
        props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang + "_" + country + "_" + variant));
    }

    return new LocalizationResourceBundle(props);
}

From source file:fi.helsinki.opintoni.integration.leiki.LeikiRestClient.java

@Override
public List<LeikiSearchHit> search(String searchTerm, Locale locale) {
    URI uri = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/focus/api").queryParam("method", "searchc")
            .query("sourceallmatch").query("instancesearch").queryParam("lang", locale.getLanguage())
            .queryParam("query", searchTerm).queryParam("format", "json")
            .queryParam("t_type", LeikiTType.getByLocale(locale).getValue()).queryParam("max", maxSearchResults)
            .queryParam("fulltext", "true").queryParam("partialsearchpriority", "ontology").build().encode()
            .toUri();//from www .  j av  a  2s  . c  om

    return getLeikiItemsData(uri, new ParameterizedTypeReference<LeikiResponse<LeikiSearchHit>>() {
    });
}