List of usage examples for java.util Locale getVariant
public String getVariant()
From source file:fr.gouv.culture.thesaurus.util.LangUtils.java
public static String localeString(Locale locale) { List<String> components = new LinkedList<String>(); if (StringUtils.isNotEmpty(locale.getLanguage())) { components.add(locale.getLanguage().toLowerCase()); }//w w w . jav a 2s . c o m if (StringUtils.isNotEmpty(locale.getCountry())) { components.add(locale.getCountry().toLowerCase()); } if (StringUtils.isNotEmpty(locale.getVariant())) { components.add(locale.getVariant().toLowerCase()); } return StringUtils.join(components, "-"); }
From source file:com.aoindustries.website.signup.ServerConfirmationCompletedActionHelper.java
public static String getHtmlLang(Locale locale) { String language = locale.getLanguage(); if (language != null) { String country = locale.getCountry(); if (country != null) { String variant = locale.getVariant(); if (variant != null) return language + "-" + country + "-" + variant; return language + "-" + country; }/*from w ww . j a v a 2s. c o m*/ return language; } return null; }
From source file:com.android.providers.contacts.LocaleSet.java
/** * Modified from:/*from ww w . j a v a2s . c om*/ * https://github.com/apache/cordova-plugin-globalization/blob/master/src/android/Globalization.java * * Returns a well-formed ITEF BCP 47 language tag representing this locale string * identifier for the client's current locale * * @return String: The BCP 47 language tag for the current locale */ private static String toBcp47Language(Locale loc) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return loc.toLanguageTag(); } // we will use a dash as per BCP 47 final char SEP = '-'; 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 = ""; } 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.jahia.utils.LanguageCodeConverters.java
private static boolean isSupportedLocale(Locale l) { // we do not support locales with variants // we do not support scripts return StringUtils.isEmpty(l.getVariant()) && (StringUtils.isEmpty(l.getScript())); }
From source file:at.porscheinformatik.common.spring.web.extended.util.LocaleUtils.java
public static Locale closestSupportedLocale(List<Locale> supportedLocales, Locale locale) { if (locale == null || supportedLocales == null) { return null; }// w ww.j ava 2 s . c o m Locale closest = null; int closestMatches = 0; for (Locale l : supportedLocales) { int matches = 0; // If the language does not match no more processing is needed if (ObjectUtils.equals(l.getLanguage(), locale.getLanguage())) { matches++; // if the country does not match no more processing is needed if (ObjectUtils.equals(l.getCountry(), locale.getCountry())) { matches++; if (ObjectUtils.equals(l.getVariant(), locale.getVariant())) { matches++; } } } /* * If language, country and variant match, we have our locale and no * more iteration is needed */ if (matches == 3) { return l; } if (matches > closestMatches) { closestMatches = matches; closest = l; } } return closest; }
From source file:com.googlecode.psiprobe.Utils.java
public static List getNamesForLocale(String baseName, Locale locale) { List result = new ArrayList(3); String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); StringBuffer temp = new StringBuffer(baseName); if (language.length() > 0) { temp.append('_').append(language); result.add(0, temp.toString());/*from www . j a v a2 s .co m*/ } if (country.length() > 0) { temp.append('_').append(country); result.add(0, temp.toString()); } if (variant.length() > 0) { temp.append('_').append(variant); result.add(0, temp.toString()); } return result; }
From source file:Main.java
/** * Calculate the postfixes along the search path from the base bundle to the * bundle specified by baseName and locale. Method copied from * java.util.ResourceBundle//w w w . j a va 2s . c om * * @param locale The locale. * @return a list of postfixes to add to filenames. * @since 2.1.0 */ public static List<String> calculatePostfixes(Locale locale) { final List<String> result = new ArrayList<String>(); // The default configuration file must be loaded to allow correct // definition inheritance. result.add(""); if (locale == null) { return result; } final String language = locale.getLanguage(); final int languageLength = language.length(); final String country = locale.getCountry(); final int countryLength = country.length(); final String variant = locale.getVariant(); final int variantLength = variant.length(); if (languageLength + countryLength + variantLength == 0) { // The locale is "", "", "". return result; } final StringBuffer temp = new StringBuffer(); temp.append('_'); temp.append(language); if (languageLength > 0) { result.add(temp.toString()); } if (countryLength + variantLength == 0) { return result; } temp.append('_'); temp.append(country); if (countryLength > 0) { result.add(temp.toString()); } if (variantLength == 0) { return result; } else { temp.append('_'); temp.append(variant); result.add(temp.toString()); return result; } }
From source file:com.limegroup.gnutella.gui.LanguageUtils.java
/** * Returns a score between -1 and 3 how well <code>specificLocale</code> * matches <code>genericLocale</code>. * /* ww w . j a v a 2s .c o m*/ * @return -1, if locales do not match, 3 if locales are equal */ public static int getMatchScore(Locale specificLocale, Locale genericLocale) { int i = 0; if (specificLocale.getLanguage().equals(genericLocale.getLanguage())) { i += 1; } else if (genericLocale.getLanguage().length() > 0) { return -1; } if (specificLocale.getCountry().equals(genericLocale.getCountry())) { i += 1; } else if (genericLocale.getCountry().length() > 0) { return -1; } if (specificLocale.getVariant().equals(genericLocale.getVariant())) { i += 1; } else if (genericLocale.getVariant().length() > 0) { return -1; } return i; }
From source file:com.microsoft.alm.plugin.context.soap.CatalogServiceImpl.java
private static String localeToRFC5646LanguageTag(final Locale locale) throws IllegalArgumentException { // language[-variant][-region] String result = locale.getLanguage(); if (locale.getVariant().length() > 0) { result = result + "-" + locale.getVariant(); //$NON-NLS-1$ }//from w ww. ja va 2 s .c om if (locale.getCountry().length() > 0) { result = result + "-" + locale.getCountry(); //$NON-NLS-1$ } return result; }
From source file:net.geoprism.localization.LocaleManager.java
public static String getLocaleName(Locale _locale) { StringBuffer buffer = new StringBuffer(); if (_locale.getLanguage() != null && _locale.getLanguage().length() > 0) { buffer.append(_locale.getLanguage()); }/*from w w w.j a va 2 s . c o m*/ if (_locale.getCountry() != null && _locale.getCountry().length() > 0) { buffer.append("-" + _locale.getCountry()); } if (_locale.getVariant() != null && _locale.getVariant().length() > 0) { buffer.append("-" + _locale.getVariant()); } return buffer.toString(); }