List of usage examples for java.util Locale getVariant
public String getVariant()
From source file:it.cnr.icar.eric.client.ui.thin.UserPreferencesBean.java
/** Sets the locales to 1st supported locale (directly or indirectly). */ private void initLocales() { Iterator<?> requestLocales = FacesContext.getCurrentInstance().getExternalContext().getRequestLocales(); Collection<Locale> supportedLocales = getSupportedUiLocales(); //iterate though client preferred locales until find supported while (requestLocales.hasNext()) { Locale loc = (Locale) requestLocales.next(); // try direct match if (supportedLocales.contains(loc)) { init(loc);/*from w w w.j a v a 2 s .c om*/ return; } // try to use language country, without variant if (loc.getVariant() != null && !"".equals(loc.getVariant())) { loc = new Locale(loc.getLanguage(), loc.getCountry()); if (supportedLocales.contains(loc)) { init(loc); return; } } // try to use language without country and variant if (loc.getCountry() != null && !"".equals(loc.getCountry())) { loc = new Locale(loc.getLanguage()); if (supportedLocales.contains(loc)) { init(loc); return; } } } // fall to default locale, from properties (or en_US, if not defined) init(getDefaultLocale()); }
From source file:com.haulmont.cuba.core.global.MessageTools.java
/** * @return whether to use a full locale representation, or language only. Returns true if all locales listed * in {@code cuba.availableLocales} app property are language only. *//*from w w w . j a v a2 s . c om*/ public boolean useLocaleLanguageOnly() { if (useLocaleLanguageOnly == null) { boolean found = false; for (Locale locale : globalConfig.getAvailableLocales().values()) { if (!StringUtils.isEmpty(locale.getCountry()) || !StringUtils.isEmpty(locale.getVariant())) { useLocaleLanguageOnly = false; found = true; break; } } if (!found) useLocaleLanguageOnly = true; } return useLocaleLanguageOnly; }
From source file:com.processpuzzle.internalization.domain.ProcessPuzzleLocale.java
public int compareTo(Object other) { Locale javaLocale = getJavaLocale(); int result = 0; if (other instanceof ProcessPuzzleLocale) { ProcessPuzzleLocale o = (ProcessPuzzleLocale) other; result = new CompareToBuilder().append(javaLocale.getLanguage(), o.getLanguage()) .append(javaLocale.getCountry(), o.getCountry()).append(javaLocale.getVariant(), o.getVariant()) .toComparison();// w w w. j av a 2s . c om } return result; }
From source file:jp.terasoluna.fw.message.DataSourceMessageSource.java
/** * ???? ??//from w w w. j a v a 2s . c om * ???????? * locale?????? * locale?????? * ??????? * ????? * ???? * * @param locale * * * @return ??? */ protected List<Locale> getAlternativeLocales(Locale locale) { List<Locale> locales = new ArrayList<Locale>(); // ????? if (locale.getVariant().length() > 0) { // Locale(language,country,"") locales.add(new Locale(locale.getLanguage(), locale.getCountry())); } // ???? if (locale.getCountry().length() > 0) { // Locale(language,"","") locales.add(new Locale(locale.getLanguage())); } // ????? if (defaultLocale != null && !locale.equals(defaultLocale)) { if (defaultLocale.getVariant().length() > 0) { // Locale(language,country,"") locales.add(defaultLocale); } if (defaultLocale.getCountry().length() > 0) { // Locale(language,country,"") locales.add(new Locale(defaultLocale.getLanguage(), defaultLocale.getCountry())); } // ???? if (defaultLocale.getLanguage().length() > 0) { // Locale(language,"","") locales.add(new Locale(defaultLocale.getLanguage())); } } return locales; }
From source file:net.technicpack.ui.lang.ResourceLoader.java
private Locale matchClosestSupportedLocale(Locale definiteLocale) { Locale bestSupportedLocale = null; int bestLocaleScore = 0; for (int i = 0; i < locales.length; i++) { Locale testLocale = locales[i]; int testScore = 0; if (testLocale.getLanguage().equals(definiteLocale.getLanguage())) { testScore++;//from ww w . j av a2 s . c om if (testLocale.getCountry().equals(definiteLocale.getCountry())) { testScore++; if (testLocale.getVariant().equals(definiteLocale.getVariant())) { testScore++; } } } if (testScore != 0 && testScore > bestLocaleScore) { bestLocaleScore = testScore; bestSupportedLocale = testLocale; } } if (bestSupportedLocale != null) { return bestSupportedLocale; } else { return Locale.getDefault(); } }
From source file:org.primeframework.mvc.control.form.LocaleSelect.java
/** * Adds the countries Map and then calls super. *//*from w w w .j a v a 2 s. c o m*/ @Override protected Map<String, Object> makeParameters() { LinkedHashMap<String, String> locales = new LinkedHashMap<>(); String preferred = (String) attributes.get("preferredLocales"); if (preferred != null) { String[] parts = preferred.split(","); for (String part : parts) { Locale locale = LocaleUtils.toLocale(part); locales.put(locale.toString(), locale.getDisplayName(locale)); } } boolean includeCountries = attributes.containsKey("includeCountries") ? (Boolean) attributes.get("includeCountries") : true; List<Locale> allLocales = new ArrayList<>(); Collections.addAll(allLocales, Locale.getAvailableLocales()); allLocales.removeIf((locale) -> locale.getLanguage().isEmpty() || locale.hasExtensions() || !locale.getScript().isEmpty() || !locale.getVariant().isEmpty() || (!includeCountries && !locale.getCountry().isEmpty())); allLocales.sort((one, two) -> one.getDisplayName(locale).compareTo(two.getDisplayName(locale))); for (Locale locale : allLocales) { if (!locales.containsKey(locale.getCountry())) { locales.put(locale.toString(), locale.getDisplayName(this.locale)); } } attributes.put("items", locales); return super.makeParameters(); }
From source file:org.apache.tapestry.engine.DefaultComponentMessagesSource.java
private Properties assembleProperties(IResourceLocation baseResourceLocation, Locale locale) { boolean debug = LOG.isDebugEnabled(); if (debug)/*from w w w . j a v a 2 s . c om*/ LOG.debug("Assembling properties for " + baseResourceLocation + " " + locale); String name = baseResourceLocation.getName(); int dotx = name.indexOf('.'); String baseName = name.substring(0, dotx); String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); Properties parent = (Properties) _cache.get(baseResourceLocation); if (parent == null) { parent = readProperties(baseResourceLocation, baseName, null, null); if (parent == null) parent = _emptyProperties; _cache.put(baseResourceLocation, parent); } Properties result = parent; if (!Tapestry.isBlank(language)) { Locale l = new Locale(language, ""); MultiKey key = buildKey(baseResourceLocation, l); result = (Properties) _cache.get(key); if (result == null) result = readProperties(baseResourceLocation, baseName, l, parent); _cache.put(key, result); parent = result; } else language = ""; if (Tapestry.isNonBlank(country)) { Locale l = new Locale(language, country); MultiKey key = buildKey(baseResourceLocation, l); result = (Properties) _cache.get(key); if (result == null) result = readProperties(baseResourceLocation, baseName, l, parent); _cache.put(key, result); parent = result; } else country = ""; if (Tapestry.isNonBlank(variant)) { Locale l = new Locale(language, country, variant); MultiKey key = buildKey(baseResourceLocation, l); result = (Properties) _cache.get(key); if (result == null) result = readProperties(baseResourceLocation, baseName, l, parent); _cache.put(key, result); } return result; }
From source file:org.azyva.dragom.cliutil.CliUtil.java
/** * Returns the version of a text resource appropriate for the current default * Locale./*from w w w. ja v a2s . c o m*/ * * <p>A Reader is returned so that character encoding is taken into consideration. * The text resource is assumed to be encoded with UTF-8, regardless of the * platform default encoding. * * <p>The algorithm used for selecting the appropriate resource is similar to the * one implemented by ResourceBundle.getBundle. * <p>The resource base name is split on the last ".", if any, and the candidate * variants are inserted before it. * * @param clazz Class to which the resource belongs. * @param resourceBaseName Base name of the resource. * @return Resource as an InputStream, just as Class.getResourceAsStream would * return. null if no resource version exists. */ public static Reader getLocalizedTextResourceReader(Class<?> clazz, String resourceBaseName) { int indexDot; String resourceBaseNamePrefix; String resourceBaseNameSuffix; Locale locale; String[] arrayCandidate; indexDot = resourceBaseName.lastIndexOf('.'); if (indexDot != -1) { resourceBaseNamePrefix = resourceBaseName.substring(0, indexDot); resourceBaseNameSuffix = resourceBaseName.substring(indexDot); } else { resourceBaseNamePrefix = resourceBaseName; resourceBaseNameSuffix = ""; } locale = Locale.getDefault(); arrayCandidate = new String[7]; arrayCandidate[0] = resourceBaseNamePrefix + "_" + locale.getLanguage() + "_" + locale.getScript() + "_" + locale.getCountry() + "_" + locale.getVariant(); arrayCandidate[1] = resourceBaseNamePrefix + "_" + locale.getLanguage() + "_" + locale.getScript() + "_" + locale.getCountry(); arrayCandidate[2] = resourceBaseNamePrefix + "_" + locale.getLanguage() + "_" + locale.getScript(); arrayCandidate[3] = resourceBaseNamePrefix + "_" + locale.getLanguage() + "_" + locale.getCountry() + "_" + locale.getVariant(); arrayCandidate[4] = resourceBaseNamePrefix + "_" + locale.getLanguage() + "_" + locale.getCountry(); arrayCandidate[5] = resourceBaseNamePrefix + "_" + locale.getLanguage(); arrayCandidate[6] = resourceBaseNamePrefix; for (String candidate : arrayCandidate) { if (!candidate.endsWith("_")) { InputStream inputStreamResource; inputStreamResource = clazz.getResourceAsStream(candidate + resourceBaseNameSuffix); if (inputStreamResource != null) { try { return new InputStreamReader(inputStreamResource, "UTF-8"); } catch (UnsupportedEncodingException uee) { throw new RuntimeException(uee); } } } } return null; }
From source file:edu.ku.brc.af.core.SchemaI18NService.java
/** * @param lang/* w w w . ja v a 2 s.co m*/ * @param country * @param variant * @return */ public Locale getLocaleByLangCountry(final String lang, final String country, final String variant) { if (lang != null) { for (Locale l : locales) { if (l.getLanguage().equals(lang)) { if (country == null && variant == null) { return l; } if (l.getCountry() != null && l.getCountry().equals(country)) { if (variant == null) { return l; } if (l.getVariant() != null && l.getVariant().equals(variant)) { return l; } } } } } return null; }
From source file:org.springframework.integration.expression.ReloadableResourceBundleExpressionSource.java
/** * Calculate the filenames for the given bundle basename and Locale, * appending language code, country code, and variant code. * E.g.: basename "expressions", Locale "de_AT_oo" -> "expressions_de_AT_OO", * "expressions_de_AT", "expressions_de". * <p>Follows the rules defined by {@link java.util.Locale#toString()}. * @param basename the basename of the bundle * @param locale the locale//from w w w .j a v a 2 s . co m * @return the List of filenames to check */ private List<String> calculateFilenamesForLocale(String basename, Locale locale) { List<String> result = new ArrayList<String>(3); String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); StringBuilder temp = new StringBuilder(basename); temp.append('_'); if (language.length() > 0) { temp.append(language); result.add(0, temp.toString()); } temp.append('_'); if (country.length() > 0) { temp.append(country); result.add(0, temp.toString()); } if (variant.length() > 0 && (language.length() > 0 || country.length() > 0)) { temp.append('_').append(variant); result.add(0, temp.toString()); } return result; }