List of usage examples for org.apache.commons.lang LocaleUtils toLocale
public static Locale toLocale(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("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.haulmont.cuba.security.auth.providers.AbstractAuthenticationProvider.java
protected Locale getUserLocale(LocalizedCredentials credentials, User user) { Locale userLocale = null;//from w w w. j a v a 2 s . co m if (credentials.isOverrideLocale()) { userLocale = credentials.getLocale(); } if (userLocale == null) { if (user.getLanguage() != null) { userLocale = LocaleUtils.toLocale(user.getLanguage()); } else { userLocale = messages.getTools().trimLocale(messages.getTools().getDefaultLocale()); } } return userLocale; }
From source file:com.jaspersoft.studio.swt.widgets.WLocale.java
public Locale getLocale() { int selectionIndex = combo.getSelectionIndex(); if (selectionIndex < 0) { if (Misc.isNullOrEmpty(combo.getText())) return Locale.getDefault(); return LocaleUtils.toLocale(combo.getText()); } else {/*from ww w . j a va2 s. c o m*/ String strLocale = strLocales[combo.getSelectionIndex()]; for (int i = 0; i < locales.length; i++) { if (locales[i].getDisplayName().equals(strLocale)) return locales[i]; } return Locale.getDefault(); } }
From source file:com.publicuhc.pluginframework.locale.BukkitLocaleProvider.java
@Override public Locale localeForCommandSender(CommandSender sender) { if (sender instanceof BlockCommandSender) return commandBlockLocale; if (sender instanceof ConsoleCommandSender) return consoleLocale; if (sender instanceof RemoteConsoleCommandSender) return remoteConsoleLocale; if (sender instanceof Player) return LocaleUtils.toLocale(fetcher.getLocaleForPlayer((Player) sender)); return Locale.ENGLISH; }
From source file:fr.hoteia.qalingo.core.domain.Localization.java
public Locale getLocale() { Locale locale = null;// w ww . j a v a 2 s .co m try { String stringLocale = ""; if (StringUtils.isNotEmpty(country) && !country.equalsIgnoreCase(language)) { stringLocale = language + "_" + country; } else { stringLocale = language; } locale = LocaleUtils.toLocale(stringLocale); } catch (Exception e) { // NO LOG - EXCEPTION IS CAUSE BY LocaleUtils AND A NON ISO CODE LIKE SIMPLY ZH } return locale; }
From source file:io.github.mywarp.mywarp.bukkit.settings.BukkitSettings.java
/** * Reloads the configuration./*w ww . j av a2s . c o m*/ */ public void reload() { config = createConfiguration(); // add defaults config.options().copyDefaults(true); config.setDefaults(defaultConfiguration); config.addDefault("storage.url", "jdbc:h2:" + configFile.getParentFile().getAbsolutePath() + "/warps"); //save defaults if we are reading from a file if (config instanceof FileConfiguration) { try { ((FileConfiguration) config).save(configFile); } catch (IOException e) { log.error(String.format( "Failed to save configuration to '%1$s', using build-in defaults for missing values.", configFile.getAbsolutePath()), e); } } // Bukkit's config does not support Locale objects and this call is quit // expensive so we cache the Locale String configuredLocale = config.getString("localization.defaultLocale"); defaultLocale = LocaleUtils.toLocale(configuredLocale); }
From source file:me.taylorkelly.mywarp.bukkit.util.parametric.ReflectiveLocaleResolver.java
/** * Resolves the locale of the given Player. * * @param player the Player/*from w ww . j ava 2 s . c o m*/ * @return the locale of this Player * @throws UnresolvableLocaleException if the locale cannot be resolved */ public Locale resolve(Player player) throws UnresolvableLocaleException { if (handleMethod == null) { try { //CraftBukkit implements Player in CraftPlayer with has the 'getHandle()' method handleMethod = player.getClass().getMethod("getHandle"); } catch (NoSuchMethodException e) { log.debug("Failed to resolve the locale because the 'getHandle()' method does not exist.", e); throw new UnresolvableLocaleException(e); } handleMethod.setAccessible(true); } if (localeField == null) { try { localeField = handleMethod.getReturnType().getDeclaredField("locale"); } catch (NoSuchFieldException e) { log.debug("Failed to resolve the locale because the 'locale' field does not exist.", e); throw new UnresolvableLocaleException(e); } localeField.setAccessible(true); } String rawLocale = null; try { rawLocale = (String) localeField.get(handleMethod.invoke(player)); } catch (IllegalAccessException e) { log.debug("Failed to resolve the locale.", e); throw new UnresolvableLocaleException(e); } catch (InvocationTargetException e) { log.debug("Failed to resolve the locale because of an unhandled exception.", e); throw new UnresolvableLocaleException(e); } Locale locale = cache.get(rawLocale); if (locale == null) { locale = LocaleUtils.toLocale(rawLocale); cache.put(rawLocale, locale); } return locale; }
From source file:com.liferay.portlet.wiki.engines.mediawiki.MediaWikiEngine.java
protected ParserInput getParserInput(long nodeId, String topicName) { ParserInput parserInput = new ParserInput("Special:Node:" + nodeId, topicName); // Dummy values parserInput.setContext("/wiki"); parserInput.setLocale(LocaleUtils.toLocale("en_US")); parserInput.setUserDisplay("0.0.0.0"); parserInput.setWikiUser(new WikiUser("DummyUser")); // Useful values parserInput.setAllowSectionEdit(false); // Table of contents TableOfContents tableOfContents = new TableOfContents(); tableOfContents.setForceTOC(true);//w w w.j av a 2s .c o m parserInput.setTableOfContents(tableOfContents); return parserInput; }
From source file:de.tudarmstadt.lt.lm.service.BreakIteratorStringProvider.java
@Override public List<String> tokenizeSentence_intern(String sentence, String language_code) { ArrayList<String> tokens = new ArrayList<String>(); BreakIterator token_bounds = BreakIterator.getWordInstance(LocaleUtils.toLocale(language_code)); token_bounds.setText(sentence.trim()); int begin_t = token_bounds.first(); for (int end_t = token_bounds.next(); end_t != BreakIterator.DONE; begin_t = end_t, end_t = token_bounds .next()) {/*www .j av a 2s .c o m*/ String token = de.tudarmstadt.lt.utilities.StringUtils .trim_and_replace_emptyspace(sentence.substring(begin_t, end_t), "_"); if (!token.isEmpty()) { // add token iff token is not empty tokens.add(token); } } return tokens; }
From source file:edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectionSetup.java
private Locale buildLocale(String localeString) throws IllegalArgumentException { Locale locale = LocaleUtils.toLocale(localeString); if (!"es_GO".equals(localeString) && // No complaint about bogus locale !LocaleUtils.isAvailableLocale(locale)) { ssWarning("'" + locale + "' is not a recognized locale."); }/*from ww w .j av a2 s .c o m*/ return locale; }
From source file:de.uni_tuebingen.ub.ixTheo.handler.component.FacetPrefixSortComponent.java
/** * Choose the collator according to the selected language *///from w w w . j a v a 2s . c om private void setCollator(final String langCode) { Locale locale = Locale.GERMAN; String transformedLangCode = ""; // Rewrite lang parameter to required layout Matcher m = LANG_CODE_TRANSFORMATION_PATTERN.matcher(langCode); StringBuffer sb = new StringBuffer(langCode.length()); while (m.find()) { if (m.group(1) != null) sb.append(m.group(1).toLowerCase()); if (m.group(2) != null) sb.append(m.group(2).equals("-") ? "_" : ""); if (m.group(3) != null) sb.append(m.group(3).toUpperCase()); transformedLangCode = sb.toString(); } try { locale = LocaleUtils.toLocale(transformedLangCode); } catch (IllegalArgumentException e) { } if (LocaleUtils.isAvailableLocale(locale)) collator = Collator.getInstance(locale); else collator = Collator.getInstance(Locale.GERMAN); }