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.globalsight.machineTranslation.domt.DoMTProxy.java

private String getDoMtXliff(HashMap<Integer, String> segmentsNoTag, Locale sourceLocale, Locale targetLocale) {
    String sourceLang = DoMTUtil.checkLang(sourceLocale.getLanguage(), sourceLocale.getCountry());
    String targetLang = DoMTUtil.checkLang(targetLocale.getLanguage(), targetLocale.getCountry());
    String engineName = (String) getMtParameterMap().get(MTProfileConstants.MT_DOMT_ENGINE_NAME);

    // "translate-xliff" is a default engine on DoMT server, it is using
    // "nl" and "en" as source/target language name.
    if (DEFAULT_ENGINE_NAME.equals(engineName)) {
        sourceLang = "nl";
        targetLang = "en";
    }/*from w  w  w . j a  va 2s . c o  m*/

    StringBuffer xlf = new StringBuffer();
    xlf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
    xlf.append("<xliff version=\"1.2\">\r\n");
    xlf.append("<file original=\"None\" source-language=\"").append(sourceLang).append("\" target-language=\"")
            .append(targetLang).append("\" datatype=\"multi-format\">\r\n");
    xlf.append("<header>\r\n");
    xlf.append("  <note from=\"PTTOOLS\">\r\n");
    xlf.append("    <graphname>").append(engineName).append("</graphname>\r\n");
    xlf.append("  </note>\r\n");
    xlf.append("</header>\r\n");
    xlf.append("<body>\r\n");
    Iterator<Entry<Integer, String>> it = segmentsNoTag.entrySet().iterator();
    while (it.hasNext()) {
        Entry<Integer, String> entry = (Entry<Integer, String>) it.next();
        int id = entry.getKey();
        String source = entry.getValue();
        xlf.append("<trans-unit id=\"" + id + "\" translate=\"yes\">\r\n");
        xlf.append("<source>").append(source).append("</source>\r\n");
        xlf.append("</trans-unit>\r\n");
    }
    xlf.append("</body>\r\n");
    xlf.append("</file>\r\n");
    xlf.append("</xliff>\r\n");

    return xlf.toString();
}

From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java

@Test
public void testCacheFile() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);

    final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
    treeWalkerConfig.addChild(checkConfig);

    final DefaultConfiguration checkerConfig = new DefaultConfiguration("checkstyleConfig");
    checkerConfig.addAttribute("charset", "UTF-8");
    checkerConfig.addChild(treeWalkerConfig);
    checkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath());

    final Checker checker = new Checker();
    final Locale locale = Locale.ROOT;
    checker.setLocaleCountry(locale.getCountry());
    checker.setLocaleLanguage(locale.getLanguage());
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.configure(checkerConfig);/* w  ww.j av  a2s  .co m*/
    checker.addListener(new BriefUtLogger(stream));

    final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
    final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;

    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
    // one more time to reuse cache
    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
}

From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java

@Test
public void testClearNonexistentCache() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);

    final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
    treeWalkerConfig.addChild(checkConfig);

    final DefaultConfiguration checkerConfig = new DefaultConfiguration("simpleConfig");
    checkerConfig.addAttribute("charset", "UTF-8");
    checkerConfig.addChild(treeWalkerConfig);

    final Checker checker = new Checker();
    final Locale locale = Locale.ROOT;
    checker.setLocaleCountry(locale.getCountry());
    checker.setLocaleLanguage(locale.getLanguage());
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.configure(checkerConfig);/*  ww  w . j ava2s . c o m*/
    checker.addListener(new BriefUtLogger(stream));

    final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
    final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;

    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
    checker.clearCache();
    // one more time, but cache does not exist
    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
}

From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java

@Test
public void testClearExistingCache() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);

    final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
    treeWalkerConfig.addChild(checkConfig);

    final DefaultConfiguration checkerConfig = new DefaultConfiguration("myConfig");
    checkerConfig.addAttribute("charset", "UTF-8");
    checkerConfig.addChild(treeWalkerConfig);
    checkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath());

    final Checker checker = new Checker();
    final Locale locale = Locale.ROOT;
    checker.setLocaleCountry(locale.getCountry());
    checker.setLocaleLanguage(locale.getLanguage());
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.configure(checkerConfig);//from w  w  w. ja v a2 s.  c om
    checker.addListener(new BriefUtLogger(stream));

    final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
    final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;

    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
    checker.clearCache();
    // one more time, but file that should be audited is not in cache
    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
}

From source file:org.opencommercesearch.CloudSearchServer.java

public synchronized void initSolrServer() throws MalformedURLException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    if (maxConnections > 0) {
        params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections);
    }//from w w  w  .ja va  2 s  .c o  m
    if (maxConnectionsPerHost > 0) {
        params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost);
    }
    if (connectTimeout > 0) {
        params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectTimeout);
    }
    if (socketTimeout > 0) {
        params.set(HttpClientUtil.PROP_SO_TIMEOUT, socketTimeout);
    }
    HttpClient httpClient = HttpClientUtil.createClient(params);
    LBHttpSolrServer newLbServer = new LBHttpSolrServer(httpClient);

    for (Locale locale : SUPPORTED_LOCALES) {
        CloudSolrServer catalogSolrServer = getSolrServer(getCatalogCollection(), locale);
        String languagePrefix = "_" + locale.getLanguage();

        if (catalogSolrServer != null) {
            catalogSolrServer.shutdown();
        }

        catalogSolrServer = new CloudSolrServer(getHost(), newLbServer);
        catalogSolrServer.setDefaultCollection(getCatalogCollection() + languagePrefix);
        catalogSolrServer.setZkConnectTimeout(getZkConnectTimeout());
        catalogSolrServer.setZkClientTimeout(getZkClientTimeout());
        setCatalogSolrServer(catalogSolrServer, locale);

        CloudSolrServer rulesSolrServer = getSolrServer(getRulesCollection(), locale);

        if (rulesSolrServer != null) {
            rulesSolrServer.shutdown();
        }
        rulesSolrServer = new CloudSolrServer(getHost(), newLbServer);
        rulesSolrServer.setDefaultCollection(getRulesCollection() + languagePrefix);
        rulesSolrServer.setZkConnectTimeout(getZkConnectTimeout());
        rulesSolrServer.setZkClientTimeout(getZkClientTimeout());
        setRulesSolrServer(rulesSolrServer, locale);

        CloudSolrServer autocompleteSolrServer = getSolrServer(getAutocompleteCollection(), locale);

        if (autocompleteSolrServer != null) {
            autocompleteSolrServer.shutdown();
        }
        autocompleteSolrServer = new CloudSolrServer(getHost(), newLbServer);
        //TODO gsegura: we may need to add the language prefix here
        autocompleteSolrServer.setDefaultCollection(getAutocompleteCollection());
        autocompleteSolrServer.setZkConnectTimeout(getZkConnectTimeout());
        autocompleteSolrServer.setZkClientTimeout(getZkClientTimeout());
        setAutocompleteSolrServers(autocompleteSolrServer, locale);
    }

    if (lbServer != null) {
        lbServer.shutdown();
    }
    lbServer = newLbServer;
}

From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java

@Test
public void testCacheFileChangeInConfig() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);

    final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
    treeWalkerConfig.addChild(checkConfig);

    final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration");
    checkerConfig.addAttribute("charset", "UTF-8");
    checkerConfig.addChild(treeWalkerConfig);
    checkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath());

    final Checker checker = new Checker();
    final Locale locale = Locale.ROOT;
    checker.setLocaleCountry(locale.getCountry());
    checker.setLocaleLanguage(locale.getLanguage());
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.configure(checkerConfig);//from   w w w  . ja  v  a2s .  c o m
    checker.addListener(new BriefUtLogger(stream));

    final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
    final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;

    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);

    // update Checker config
    checker.destroy();
    checker.configure(checkerConfig);

    final Checker otherChecker = new Checker();
    otherChecker.setLocaleCountry(locale.getCountry());
    otherChecker.setLocaleLanguage(locale.getLanguage());
    otherChecker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    otherChecker.configure(checkerConfig);
    otherChecker.addListener(new BriefUtLogger(stream));
    // here is diff with previous checker
    checkerConfig.addAttribute("fileExtensions", "java,javax");

    // one more time on updated config
    verify(otherChecker, pathToEmptyFile, pathToEmptyFile, expected);
}

From source file:com.liusoft.dlog4j.velocity.VelocityTool.java

/**
 * //from w ww.ja  v a2s. com
 * @return
 */
public String today() {
    Locale locale = request.getLocale();
    String fmt = null;
    if (locale != null && "zh".equalsIgnoreCase(locale.getLanguage()))
        fmt = "yyyyMd EEEEE";
    else
        fmt = "yyyy/MM/dd EEEEE";
    return new SimpleDateFormat(fmt, locale).format(Calendar.getInstance(locale).getTime());
}

From source file:com.bdaum.zoom.gps.naming.geonaming.internal.GeoNamesService.java

public WaypointArea[] findLocation(String address)
        throws IOException, WebServiceException, SAXException, ParserConfigurationException, HttpException {
    List<WaypointArea> pnts = new ArrayList<WaypointArea>();
    Locale locale = Locale.getDefault();
    String template = "http://api.geonames.org/search?" + getSearchParms() //$NON-NLS-1$
            + "&countryBias={1}&lang={2}&maxRows={3}"; //$NON-NLS-1$
    String query = NLS.bind(template, new Object[] { URLEncoder.encode(address, "UTF-8"), locale.getCountry(), //$NON-NLS-1$
            locale.getLanguage(), GeoCodeParser.MAXRESULTS });
    try (InputStream in = openGeonamesService(query)) {
        new GeoCodeParser(in).parse(pnts);
        return pnts.toArray(new WaypointArea[pnts.size()]);
    }//from   w  ww  .j a v  a2  s .c  o m
}

From source file:com.orange.mmp.i18n.helpers.DefaultInternationalizationManager.java

/**
 * @see com.orange.mmp.i18n.InternationalizationManager#getLocalizationMap(java.lang.String, java.util.Locale)
 *///  w w w. ja v a  2  s  . c o  m
public Map<?, ?> getLocalizationMap(final String messageSource, final Locale locale) {
    final Properties i18nBundle = new Properties();
    final String baseFilePath = i18nFilesPathByMessageSource.get(messageSource);

    //Find name for the i18n file (and verify if file exist)
    File file = null;
    if (locale.getCountry() != null && locale.getCountry().length() > 0) {
        file = new File(baseFilePath + "_" + locale.getLanguage() + "_" + locale.getCountry() + ".properties");
    }
    if (file == null || !file.exists()) {
        file = new File(baseFilePath + "_" + locale.getLanguage() + ".properties");
    }
    if (file == null || !file.exists()) {
        file = new File(baseFilePath + ".properties");
    }

    //Read file (event if file not exist... error is automatically processed via AspectJ and add to log
    final InputStream inStream;
    try {
        inStream = new FileInputStream(file);
        i18nBundle.load(inStream);
    } catch (FileNotFoundException e) {
        //File cannot be opened
        //Add in log via AspectJ
    } catch (IOException e) {
        //Error during read file
        //Add in log via AspectJ
    }

    //Return properties map
    return i18nBundle;
}

From source file:cn.edu.zjnu.acm.judge.contest.ContestController.java

@GetMapping(value = "standing", produces = { TEXT_HTML_VALUE, ALL_VALUE })
public String standingHtml(@PathVariable("contestId") long id, Model model, Locale locale) {
    Contest contest = contestMapper.findOneByIdAndDisabledFalse(id);
    // TODO//from  w  w  w  . ja  va2 s. c  o m
    model.addAttribute("contestId", id);
    model.addAttribute("contest", contest);
    if (contest == null) {
        throw new MessageException("onlinejudge.contest.nosuchcontest", HttpStatus.NOT_FOUND);
    }
    if (!contest.isStarted()) {
        throw new MessageException("Contest not started yet", HttpStatus.OK);
    }
    // TODO user is empty
    List<Problem> problems = contestMapper.getProblems(id, null, locale.getLanguage());
    model.addAttribute("id", id);
    model.addAttribute("problems", problems);
    model.addAttribute("standing", standing(id));
    return "contests/standing";
}