List of usage examples for org.apache.commons.lang3 LocaleUtils toLocale
public static Locale toLocale(final String str)
Converts a String to a Locale.
This method takes the string format of a locale and creates the locale object from it.
LocaleUtils.toLocale("") = new Locale("", "") LocaleUtils.toLocale("en") = new Locale("en", "") LocaleUtils.toLocale("en_GB") = new Locale("en", "GB") LocaleUtils.toLocale("en_GB_xxx") = new Locale("en", "GB", "xxx") (#)
(#) The behaviour of the JDK variant constructor changed between JDK1.3 and JDK1.4.
From source file:com.norconex.jefmon.server.JEFMonServer.java
public static void main(String[] args) throws Exception { Properties props = getSetupProperties(); String localesString = props.getString("locales"); String[] localeStrings = localesString.split(","); Locale[] locales = new Locale[localeStrings.length]; for (int i = 0; i < localeStrings.length; i++) { locales[i] = LocaleUtils.toLocale(localeStrings[i].trim()); }/* w ww . java 2 s . c o m*/ final JEFMonServer server = new JEFMonServer(props.getInt("port", 80), props.getBoolean("https", false), locales); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { server.stop(); } catch (Exception e) { e.printStackTrace(); } } }); server.run(); }
From source file:com.esofthead.mycollab.configuration.LocaleHelper.java
public static Locale toLocale(String language) { if (language == null) { return Locale.US; }//w w w .j av a2 s . co m Locale locale = LocaleUtils.toLocale(language); return (locale != null) ? locale : SiteConfiguration.getDefaultLocale(); }
From source file:com.netflix.imfutility.itunes.locale.LocaleHelper.java
public static Locale fromITunesLocale(String locale) { return LocaleUtils.toLocale(locale.replace("-", "_")); }
From source file:com.github.jknack.handlebars.internal.Locales.java
/** * <p>Converts {@link String}s to {@link Locale}s. Supports both * <a href="https://en.wikipedia.org/wiki/IETF_language_tag">IETF language tags</a> * using hyphens (e.g. "de-AT") and the Java format using underscores * (e.g. "de_AT").</p> * * @param string the local string either in IETF or Java format * @return The matching Locale//from w w w .j a v a2s. com */ public static Locale fromString(final String string) { if (string == null) { return null; } else { try { /* * prefer https://en.wikipedia.org/wiki/IETF_language_tag * (only Locale.Builder throws exception for illegal format) */ return new Locale.Builder().setLanguageTag(string).build(); } catch (final IllformedLocaleException ex) { // use fallback return LocaleUtils.toLocale(string); } } }
From source file:com.michellemay.mappings.EnglishNamesMapping.java
/** * Instantiates a new English names mapping. */ public EnglishNamesMapping() { super(NAME, LocaleUtils.toLocale("en_US")); }
From source file:com.astamuse.asta4d.util.i18n.LocalizeUtil.java
public static Locale getLocale(String localeStr) { if (StringUtils.isEmpty(localeStr)) { return null; }//from w ww .j a v a2 s . com try { return LocaleUtils.toLocale(localeStr); } catch (IllegalArgumentException e) { return null; } }
From source file:com.michellemay.mappings.DisplayNamesMapping.java
/** * Instantiates a new Display names mapping. * * @param name the name// w w w .jav a2 s . com * @param displayLocale the display locale */ public DisplayNamesMapping(String name, Locale displayLocale) { super(name); this.displayLocale = displayLocale; // Build reverse map HashMap<String, Locale> map = new HashMap<String, Locale>(); for (String isoCode : Locale.getISOLanguages()) { Locale loc = LocaleUtils.toLocale(isoCode); String displayName = loc.getDisplayName(displayLocale).toLowerCase(); if (isoCode.length() > 0 && !map.containsKey(displayName)) { map.put(displayName, loc); } } this.withMapping(map).withCaseSensitive(false); }
From source file:com.michellemay.mappings.ISO639Alpha2Mapping.java
/** * Instantiates a new ISO 639 alpha 2 mapping. *///from w w w . j a va 2s. co m public ISO639Alpha2Mapping() { super(NAME); // Build reverse map HashMap<String, Locale> map = new HashMap<String, Locale>(); for (String isoCode : Locale.getISOLanguages()) { if (isoCode.length() > 0) { String displayValue = isoCode.toLowerCase(); if (!map.containsKey(displayValue)) { map.put(displayValue, LocaleUtils.toLocale(isoCode)); } } } this.withMapping(map).withCaseSensitive(false); }
From source file:com.michellemay.mappings.ISO639Alpha3Mapping.java
/** * Instantiates a new ISO 639 alpha 3 mapping. *///from w w w . j a v a 2s . c om public ISO639Alpha3Mapping() { super(NAME); // Build reverse map HashMap<String, Locale> map = new HashMap<String, Locale>(); for (Locale loc : LocaleUtils.availableLocaleList()) { String isoCode = loc.getLanguage(); if (isoCode.length() > 0) { String displayValue = loc.getISO3Language().toLowerCase(); if (!map.containsKey(displayValue)) { map.put(displayValue, LocaleUtils.toLocale(isoCode)); } } } this.withMapping(map).withCaseSensitive(false); }
From source file:com.ejisto.modules.factory.impl.LocaleFactory.java
@Override public Locale create(MockedField m, Locale actualValue) { Locale locale;/* ww w . ja v a 2s. c o m*/ try { locale = LocaleUtils.toLocale(m.getFieldValue()); } catch (IllegalArgumentException e) { locale = null; } return ObjectUtils.defaultIfNull(locale, actualValue); }