List of usage examples for java.util Locale getVariant
public String getVariant()
From source file:org.b3log.latke.plugin.AbstractPlugin.java
/** * Processes languages. Retrieves language labels with default locale, then sets them into the specified data model. * /*from w w w .ja v a 2s . c o m*/ * @param dataModel the specified data model */ private void handleLangs(final Map<String, Object> dataModel) { final Locale locale = Latkes.getLocale(); final String language = locale.getLanguage(); final String country = locale.getCountry(); final String variant = locale.getVariant(); final StringBuilder keyBuilder = new StringBuilder(language); if (!Strings.isEmptyOrNull(country)) { keyBuilder.append("_").append(country); } if (!Strings.isEmptyOrNull(variant)) { keyBuilder.append("_").append(variant); } final String localKey = keyBuilder.toString(); final Properties props = langs.get(localKey); if (null == props) { return; } final Set<Object> keySet = props.keySet(); for (final Object key : keySet) { dataModel.put((String) key, props.getProperty((String) key)); } }
From source file:org.parosproxy.paros.extension.option.OptionsParamView.java
public void setLocale(Locale locale) { if (locale != null) { StringBuilder sb = new StringBuilder(); sb.append(locale.getLanguage()); if (locale.getCountry().length() > 0) sb.append("_").append(locale.getCountry()); if (locale.getVariant().length() > 0) sb.append("_").append(locale.getVariant()); setLocale(sb.toString());/* ww w. j a va2s .co m*/ } }
From source file:com.processpuzzle.internalization.domain.ProcessPuzzleLocale.java
public boolean equals(Object other) { Locale javaLocale = getJavaLocale(); if (this == other) return true; if (!this.getClass().equals(other.getClass())) return false; if (!(other instanceof ProcessPuzzleLocale)) return false; boolean result = false; ProcessPuzzleLocale o = (ProcessPuzzleLocale) other; result = new EqualsBuilder().append(this.getLanguage(), o.getLanguage()) .append(this.getCountry(), o.getCountry()).append(javaLocale.getVariant(), o.getVariant()) .isEquals();/*from w w w.j a v a 2 s. c om*/ return result; }
From source file:com.liferay.portal.struts.PortalTilesDefinitionsFactory.java
/** * Calculate the suffixes based on the locale. * @param locale the locale/*from w w w . j ava 2 s. com*/ */ private List calculateSuffixes(Locale locale) { List suffixes = new ArrayList(3); String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); StringBuffer suffix = new StringBuffer(); suffix.append('_'); suffix.append(language); if (language.length() > 0) { suffixes.add(suffix.toString()); } suffix.append('_'); suffix.append(country); if (country.length() > 0) { suffixes.add(suffix.toString()); } suffix.append('_'); suffix.append(variant); if (variant.length() > 0) { suffixes.add(suffix.toString()); } return suffixes; }
From source file:wicket.resource.PropertiesFactory.java
/** * Create a unique key to identify the properties file in the cache * /*from w w w. j av a 2s. c o m*/ * @param componentClass * The class that resources are bring loaded for * @param locale * The locale to load reosurces for * @param style * The style to load resources for (see {@link wicket.Session}) * @return The resource key */ public final String createResourceKey(final Class componentClass, final Locale locale, final String style) { final AppendingStringBuffer buffer = new AppendingStringBuffer(80); if (componentClass != null) { buffer.append(componentClass.getName()); } if (style != null) { buffer.append(Component.PATH_SEPARATOR); buffer.append(style); } if (locale != null) { buffer.append(Component.PATH_SEPARATOR); boolean l = locale.getLanguage().length() != 0; boolean c = locale.getCountry().length() != 0; boolean v = locale.getVariant().length() != 0; buffer.append(locale.getLanguage()); if (c || (l && v)) { // This may just append '_' buffer.append('_').append(locale.getCountry()); } if (v && (l || c)) { buffer.append('_').append(locale.getVariant()); } } final String id = buffer.toString(); return id; }
From source file:org.wso2.carbon.utils.i18n.ResourceBundle.java
protected Properties loadProperties(String basename, ClassLoader loader, Locale locale, Properties props) { String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); if (variant != null && variant.trim().length() == 0) { variant = null;//from w w w . j a v a 2s. c o m } if (language != null) { if (country != null) { if (variant != null) { props = merge(props, loadProperties( basename + "_" + language + "_" + country + "_" + variant + PROPERTY_EXT, loader)); } props = merge(props, loadProperties(basename + "_" + language + "_" + country + PROPERTY_EXT, loader)); } props = merge(props, loadProperties(basename + "_" + language + PROPERTY_EXT, loader)); } return props; }
From source file:org.phenotips.vocabulary.internal.solr.AbstractSolrVocabularyTerm.java
@Override public Collection<?> getTranslatedValues(String property) { Locale currentLocale = getCurrentLocale(); if (StringUtils.isEmpty(currentLocale.getLanguage())) { return getValues(property); }// www.ja v a 2s .co m Collection<Object> result = getValues(property + '_' + currentLocale.toString()); // If the locale has language, country, and variant, try without the variant if (CollectionUtils.isEmpty(result) && StringUtils.isNoneEmpty(currentLocale.getVariant(), currentLocale.getCountry())) { result = getValues(property + '_' + currentLocale.getLanguage() + '_' + currentLocale.getCountry()); } // If the locale has language and country, try without the country if (CollectionUtils.isEmpty(result) && StringUtils.isNoneEmpty(currentLocale.getLanguage(), currentLocale.getCountry())) { result = getValues(property + '_' + currentLocale.getLanguage()); } // If the locale has no country, then the first call included the language only; // at this point, it's certain that no translation is available, return the untranslated default if (CollectionUtils.isEmpty(result)) { result = getValues(property); } return result; }
From source file:org.apache.cordova.globalization.Globalization.java
private String toBcp47Language(Locale loc) { final char SEP = '-'; // we will use a dash as per BCP 47 String language = loc.getLanguage(); String region = loc.getCountry(); String variant = loc.getVariant(); // special case for Norwegian Nynorsk since "NY" cannot be a variant as per BCP 47 // this goes before the string matching since "NY" wont pass the variant checks if (language.equals("no") && region.equals("NO") && variant.equals("NY")) { language = "nn"; region = "NO"; variant = ""; }//from w w w . ja va2 s .c o m if (language.isEmpty() || !language.matches("\\p{Alpha}{2,8}")) { language = "und"; // Follow the Locale#toLanguageTag() implementation // which says to return "und" for Undetermined } else if (language.equals("iw")) { language = "he"; // correct deprecated "Hebrew" } else if (language.equals("in")) { language = "id"; // correct deprecated "Indonesian" } else if (language.equals("ji")) { language = "yi"; // correct deprecated "Yiddish" } // ensure valid country code, if not well formed, it's omitted if (!region.matches("\\p{Alpha}{2}|\\p{Digit}{3}")) { region = ""; } // variant subtags that begin with a letter must be at least 5 characters long if (!variant.matches("\\p{Alnum}{5,8}|\\p{Digit}\\p{Alnum}{3}")) { variant = ""; } StringBuilder bcp47Tag = new StringBuilder(language); if (!region.isEmpty()) { bcp47Tag.append(SEP).append(region); } if (!variant.isEmpty()) { bcp47Tag.append(SEP).append(variant); } return bcp47Tag.toString(); }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileUtils.java
public static String getLocalizedString(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Node localizedStringNode, IPentahoLocale pentahoLocale) throws RepositoryException { Assert.isTrue(isLocalizedString(session, pentahoJcrConstants, localizedStringNode)); boolean isLocaleNull = pentahoLocale == null; if (pentahoLocale == null) { pentahoLocale = new PentahoLocale(); }//from w w w. j a v a 2s . c o m Locale locale = pentahoLocale.getLocale(); final String UNDERSCORE = "_"; //$NON-NLS-1$ final String COLON = ":"; //$NON-NLS-1$ boolean hasLanguage = StringUtils.hasText(locale.getLanguage()); boolean hasCountry = StringUtils.hasText(locale.getCountry()); boolean hasVariant = StringUtils.hasText(locale.getVariant()); List<String> candidatePropertyNames = new ArrayList<String>(3); if (hasVariant) { candidatePropertyNames.add( locale.getLanguage() + UNDERSCORE + locale.getCountry() + UNDERSCORE + locale.getVariant()); } if (hasCountry) { candidatePropertyNames.add(locale.getLanguage() + UNDERSCORE + locale.getCountry()); } if (hasLanguage) { candidatePropertyNames.add(locale.getLanguage()); } for (String propertyName : candidatePropertyNames) { if (localizedStringNode.hasProperty(propertyName)) { return localizedStringNode.getProperty(propertyName).getString(); } } String prefix = session.getNamespacePrefix(PentahoJcrConstants.PHO_NS); Assert.hasText(prefix); String propertyStr = isLocaleNull ? pentahoJcrConstants.getPHO_ROOTLOCALE() : prefix + COLON + locale.getLanguage(); return localizedStringNode.getProperty(propertyStr).getString(); }
From source file:org.parancoe.web.util.ReloadableResourceBundleMessageSource.java
/** * Calculate the filenames for the given bundle basename and Locale, appending language code, * country code, and variant code. E.g.: basename "messages", Locale "de_AT_oo" -> * "messages_de_AT_OO", "messages_de_AT", "messages_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 ava 2 s. com * @return the List of filenames to check */ protected 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; }