List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:com.claude.sharecam.util.CountryMaster.java
/** * Returns the device's locale iso code/*from ww w . j a v a 2s . co m*/ * * @return String */ public String getDefaultCountryIso() { Locale locale = Locale.getDefault(); return locale.getCountry(); }
From source file:fr.cls.atoll.motu.library.converter.jaxb.LocaleAdapter.java
/** * Convert a given uri into a string representation. * /*from w w w. j a va 2 s . c o m*/ * @param locale the locale * * @return the string representation. */ @Override public String marshal(Locale locale) { if (locale == null) { return null; } return locale.getLanguage() + (StringUtils.isNotEmpty(locale.getCountry()) ? "-" + locale.getCountry() : ""); }
From source file:com.github.jrh3k5.plugin.maven.l10n.data.AbstractMessagesPropertiesParserTest.java
/** * Test the determination of supported locale for a messages properties file with only the language specified. * // w ww . j a va2 s.com * @throws Exception * If any errors occur during the test run. */ @Test public void testDetermineSupportedLocale() throws Exception { final File messagesFile = new File("messages_es.properties"); final Locale supportedLocale = parser.determineSupportedLocale(messagesFile); assertThat(supportedLocale.getLanguage()).isEqualTo("es"); assertThat(supportedLocale.getCountry()).isEmpty(); }
From source file:com.github.jrh3k5.plugin.maven.l10n.data.AbstractMessagesPropertiesParserTest.java
/** * Test the determination of locale support with a specified country. * // www.j a v a2s . c o m * @throws Exception * If any errors occur during the test run. */ @Test public void testDetermineSupportedLocaleWithCountry() throws Exception { final File messagesFile = new File("messages_es_MX.properties"); final Locale supportedLocale = parser.determineSupportedLocale(messagesFile); assertThat(supportedLocale.getLanguage()).isEqualTo("es"); assertThat(supportedLocale.getCountry()).isEqualTo("MX"); }
From source file:com.puppycrawl.tools.checkstyle.filters.SuppressionCommentFilterTest.java
@Override protected Checker createChecker(Configuration checkConfig) throws CheckstyleException { final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration"); final DefaultConfiguration checksConfig = createCheckConfig(TreeWalker.class); checksConfig.addChild(createCheckConfig(FileContentsHolder.class)); checksConfig.addChild(createCheckConfig(MemberNameCheck.class)); checksConfig.addChild(createCheckConfig(ConstantNameCheck.class)); checksConfig.addChild(createCheckConfig(IllegalCatchCheck.class)); checkerConfig.addChild(checksConfig); if (checkConfig != null) { checkerConfig.addChild(checkConfig); }// w w w . ja v a2 s .co m 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); checker.addListener(new BriefLogger(stream)); return checker; }
From source file:org.echocat.locela.api.java.messages.StandardMessagesProvider.java
protected boolean isEmpty(@Nullable Locale locale) { final boolean result; if (locale == null) { result = true;/*from w ww . j av a 2s. c o m*/ } else { result = StringUtils.isEmpty(locale.getLanguage()) && StringUtils.isEmpty(locale.getCountry()) && StringUtils.isEmpty(locale.getVariant()); } return result; }
From source file:com.haulmont.chile.core.datatypes.Datatypes.java
private void putFormat(Locale locale, FormatStrings formatStrings) { formatStringsMap.put(locale, formatStrings); if (!StringUtils.isEmpty(locale.getCountry()) || !StringUtils.isEmpty(locale.getVariant())) useLocaleLanguageOnly = false;/* ww w . ja v a2 s . c o m*/ }
From source file:no.sesat.search.http.filters.SiteLocatorFilter.java
/** The method to obtain the correct Site from the request. * It only returns a site with a locale supported by that site. ** @param servletRequest/* w w w .ja va 2 s. c o m*/ * @return the site instance. or null if no such skin has been deployed. */ public static Site getSite(final ServletRequest servletRequest) { // find the current site. Since we are behind a ajp13 connection request.getServerName() won't work! // httpd.conf needs: // 1) "JkEnvVar SERVER_NAME" inside the virtual host directive. // 2) "UseCanonicalName Off" to assign ServerName from client's request. final String vhost = getServerName(servletRequest); // Tweak the port if SERVER_PORT has been explicitly set. (We may have gone through Apache or Cisco LB). final String correctedVhost = Site.SERVER_PORT > 0 && vhost.indexOf(':') > 0 ? vhost.substring(0, vhost.indexOf(':') + 1) + Site.SERVER_PORT : vhost; LOG.trace(DEBUG_REQUESTED_VHOST + correctedVhost); // Construct the site object off the browser's locale, even if it won't finally be used. final Locale locale = servletRequest.getLocale(); final Site result; try { result = Site.valueOf(SITE_CONTEXT, correctedVhost, locale); final SiteConfiguration.Context siteConfCxt = UrlResourceLoader.newSiteConfigurationContext(result); final SiteConfiguration siteConf = SiteConfiguration.instanceOf(siteConfCxt); servletRequest.setAttribute(SiteConfiguration.NAME_KEY, siteConf); if (LOG.isTraceEnabled()) { // MessageFormat.format(..) is expensive LOG.trace(MessageFormat.format(LOCALE_DETAILS, locale.getLanguage(), locale.getCountry(), locale.getVariant())); } // Check if the browser's locale is supported by this skin. Use it if so. if (siteConf.isSiteLocaleSupported(locale)) { return result; } // Use the skin's default locale. For some reason that fails use JVM's default. final String[] prefLocale = null != siteConf.getProperty(SiteConfiguration.SITE_LOCALE_DEFAULT) ? siteConf.getProperty(SiteConfiguration.SITE_LOCALE_DEFAULT).split("_") : new String[] { Locale.getDefault().toString() }; switch (prefLocale.length) { case 3: LOG.trace(result + INFO_USING_DEFAULT_LOCALE + prefLocale[0] + '_' + prefLocale[1] + '_' + prefLocale[2]); return Site.valueOf(SITE_CONTEXT, correctedVhost, new Locale(prefLocale[0], prefLocale[1], prefLocale[2])); case 2: LOG.trace(result + INFO_USING_DEFAULT_LOCALE + prefLocale[0] + '_' + prefLocale[1]); return Site.valueOf(SITE_CONTEXT, correctedVhost, new Locale(prefLocale[0], prefLocale[1])); case 1: default: LOG.trace(result + INFO_USING_DEFAULT_LOCALE + prefLocale[0]); return Site.valueOf(SITE_CONTEXT, correctedVhost, new Locale(prefLocale[0])); } } catch (IllegalArgumentException iae) { return null; } }
From source file:de.iew.web.taglibs.requirejs.I18n.java
@Override protected int doStartTagInternal() throws Exception { Locale renderLocale = getRenderLocale(); if (renderLocale != null) { StringBuffer sb = new StringBuffer("i18n:{"); sb.append("locale:'").append(renderLocale.getLanguage().toLowerCase()).append("-") .append(renderLocale.getCountry().toLowerCase()).append("'").append("}"); RequireJS requireJS = (RequireJS) getParent(); requireJS.addRenderedConfig(sb.toString()); }//from w ww . j ava 2s. com return SKIP_BODY; }
From source file:org.openmrs.module.coreapps.fragment.controller.DiagnosesFragmentController.java
private ConceptName getPreferredName(Locale locale, Concept concept) { ConceptName name = concept.getPreferredName(locale); if (name == null && (StringUtils.isNotEmpty(locale.getCountry()) || StringUtils.isNotEmpty(locale.getVariant()))) { name = concept.getPreferredName(new Locale(locale.getLanguage())); }//from www. ja v a2 s . c o m if (name == null) { name = concept.getName(locale); } return name; }