List of usage examples for java.util Locale getVariant
public String getVariant()
From source file:org.sakaiproject.adminsiteperms.tool.ResourceLoaderMessageSource.java
protected MessageFormat resolveCode(String code, Locale locale) { if (locale != null && resourceLoader.getLocale() == null) { resourceLoader.setContextLocale(locale); } else {//from ww w.ja v a 2 s . co m locale = resourceLoader.getLocale(); } String msg; if ("DEBUG".equals(locale.getVariant()) || "XX".equals(locale.getCountry())) { msg = "** " + code + " **"; } else { msg = resourceLoader.getString(code); } if (log.isTraceEnabled()) log.trace("MSG resolveCode: " + code + " (" + locale.getLanguage() + "_" + locale.getCountry() + (locale.getVariant() == null ? "" : " -" + locale.getVariant()) + ") into msg: " + msg); return createMessageFormat(msg, locale); }
From source file:org.sakaiproject.adminsiteperms.tool.ResourceLoaderMessageSource.java
protected String resolveCodeWithoutArguments(String code, Locale locale) { if (locale != null && resourceLoader.getLocale() == null) { resourceLoader.setContextLocale(locale); } else {/* ww w .j a va 2 s . c o m*/ locale = resourceLoader.getLocale(); } String msg; if ("DEBUG".equals(locale.getVariant()) || "XX".equals(locale.getCountry())) { msg = "** " + code + " **"; } else { msg = resourceLoader.getString(code); } if (log.isTraceEnabled()) log.trace("MSG resolveCode (noargs): " + code + " (" + locale.getLanguage() + "_" + locale.getCountry() + (locale.getVariant() == null ? "" : " -" + locale.getVariant()) + ") into msg: " + msg); return msg; }
From source file:com.surveypanel.utils.DBMessageSource.java
/** * build an array of alternative locales for the given locale <br/> * result does not contain original locale * @param locale the locale to find alternatives for * @return an array of alternative locales *///from w w w.j a va 2s . c o m private Locale[] getAlternativeLocales(Locale locale) { Locale[] locales = new Locale[3]; int count = 0; if (locale.getVariant().length() > 0) { // add a locale without the variant locales[count] = new Locale(locale.getLanguage(), locale.getCountry()); count++; } if (locale.getCountry().length() > 0) { // add a locale without the country locales[count] = new Locale(locale.getLanguage()); count++; } if (fallbackLocale != null) { locales[count] = fallbackLocale; } return locales; }
From source file:com.swtxml.i18n.ResourceBundleLabelTranslator.java
private List<String> getResourceBundleNames(String baseName, Locale locale) { List<String> results = new ArrayList<String>(4); if (StringUtils.isNotEmpty(locale.getLanguage())) { if (StringUtils.isNotEmpty(locale.getCountry())) { if (StringUtils.isNotEmpty(locale.getVariant())) { results.add(baseName + "_" + locale.getLanguage() + "_" + locale.getCountry() + "_" + locale.getVariant()); }/*from w ww . j av a2 s . com*/ results.add(baseName + "_" + locale.getLanguage() + "_" + locale.getCountry()); } results.add(baseName + "_" + locale.getLanguage()); } results.add(baseName); return results; }
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;//from w w w . j av 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//from www. j a va 2s . 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:com.processpuzzle.internalization.domain.ProcessPuzzleLocale.java
public ProcessPuzzleLocale(Locale locale) { this(locale.getLanguage(), locale.getCountry(), locale.getVariant()); try {// w ww . ja v a 2s. c o m this.setLegalTender(new Currency("", java.util.Currency.getInstance(locale).toString())); } catch (IllegalArgumentException e) { } }
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);/*from w w w . ja v a 2 s. c o 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: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())); }//ww w. j a v a2 s . c o m if (name == null) { name = concept.getName(locale); } return name; }
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 w w .j ava2s.c om } else { result = StringUtils.isEmpty(locale.getLanguage()) && StringUtils.isEmpty(locale.getCountry()) && StringUtils.isEmpty(locale.getVariant()); } return result; }