Java Code Examples for java.util.Locale#toString()
The following examples show how to use
java.util.Locale#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocaleTargetIdManager.java From engine with GNU General Public License v3.0 | 6 votes |
@Override public List<String> getAvailableTargetIds() { String[] availableTargetIds = SiteProperties.getAvailableTargetIds(); if (ArrayUtils.isEmpty(availableTargetIds)) { List<Locale> availableLocales = LocaleUtils.availableLocaleList(); List<String> availableLocaleStrs = new ArrayList<>(availableLocales.size()); for (Locale locale : availableLocales) { String localeStr = locale.toString(); // Ignore empty ROOT locale if (StringUtils.isNotEmpty(localeStr)) { availableLocaleStrs.add(StringUtils.lowerCase(localeStr)); } } return availableLocaleStrs; } else { return Arrays.asList(availableTargetIds); } }
Example 2
Source File: StaticMessageSource.java From java-technology-stack with MIT License | 6 votes |
@Override @Nullable protected MessageFormat resolveCode(String code, Locale locale) { String key = code + '_' + locale.toString(); String msg = this.messages.get(key); if (msg == null) { return null; } synchronized (this.cachedMessageFormats) { MessageFormat messageFormat = this.cachedMessageFormats.get(key); if (messageFormat == null) { messageFormat = createMessageFormat(msg, locale); this.cachedMessageFormats.put(key, messageFormat); } return messageFormat; } }
Example 3
Source File: LintProblemFormatter.java From rdflint with MIT License | 6 votes |
/** * dump problem message. */ public static String dumpMessage(String key, Locale locale, Object... args) { final String keyName = key.substring(key.lastIndexOf('.') + 1); final String pkgName = key.substring(0, key.lastIndexOf('.')); final String bundleKey = locale == null ? pkgName : pkgName + "_" + locale.toString(); ResourceBundle messages = LintProblemFormatter.messagesMap.get(bundleKey); if (messages == null) { try { if (locale != null) { messages = ResourceBundle.getBundle(pkgName + ".messages", locale); } else { messages = ResourceBundle.getBundle(pkgName + ".messages"); } LintProblemFormatter.messagesMap.put(bundleKey, messages); } catch (MissingResourceException ex) { // skip } } if (messages != null && messages.containsKey(keyName)) { return MessageFormat.format(messages.getString(keyName), args); } return StringUtils.join(args, ", "); }
Example 4
Source File: TrueTypeFont.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private static short getLCIDFromLocale(Locale locale) { // optimize for common case if (locale.equals(Locale.US)) { return US_LCID; } if (lcidMap == null) { createLCIDMap(); } String key = locale.toString(); while (!"".equals(key)) { Short lcidObject = (Short) lcidMap.get(key); if (lcidObject != null) { return lcidObject.shortValue(); } int pos = key.lastIndexOf('_'); if (pos < 1) { return US_LCID; } key = key.substring(0, pos); } return US_LCID; }
Example 5
Source File: CharSetMap.java From ganttproject with GNU General Public License v3.0 | 6 votes |
/** * Gets the charset for a locale. First a locale specific charset is searched * for, then a country specific one and lastly a language specific one. If * none is found, the default charset is returned. * * @param locale * the locale. * @return the charset. */ public String getCharSet(Locale locale) { // Check the cache first. String key = locale.toString(); if (key.length() == 0) { key = "__" + locale.getVariant(); if (key.length() == 2) { return DEFAULT_CHARSET; } } String charset = searchCharSet(key); if (charset.length() == 0) { // Not found, perform a full search and update the cache. String[] items = new String[3]; items[2] = locale.getVariant(); items[1] = locale.getCountry(); items[0] = locale.getLanguage(); charset = searchCharSet(items); if (charset.length() == 0) { charset = DEFAULT_CHARSET; } mappers[MAP_CACHE].put(key, charset); } return charset; }
Example 6
Source File: TrueTypeFont.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static short getLCIDFromLocale(Locale locale) { // optimize for common case if (locale.equals(Locale.US)) { return US_LCID; } if (lcidMap == null) { createLCIDMap(); } String key = locale.toString(); while (!"".equals(key)) { Short lcidObject = (Short) lcidMap.get(key); if (lcidObject != null) { return lcidObject.shortValue(); } int pos = key.lastIndexOf('_'); if (pos < 1) { return US_LCID; } key = key.substring(0, pos); } return US_LCID; }
Example 7
Source File: CLDRLocaleProviderAdapter.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * This method returns equivalent CLDR supported locale * for no, no-NO locales so that COMPAT locales do not precede * those locales during ResourceBundle search path, also if an alias exists for a locale, * it returns equivalent locale, e.g for zh_HK it returns zh_Hant-HK. */ private static Locale getEquivalentLoc(Locale locale) { switch (locale.toString()) { case "no": case "no_NO": return Locale.forLanguageTag("nb"); } return applyAliases(locale); }
Example 8
Source File: UserUtil.java From wechat-mp-sdk with Apache License 2.0 | 5 votes |
public static UserInfoJsonRtn getUserInfo(License license, String openId, Locale local) { if (StringUtils.isEmpty(openId)) { return JsonRtnUtil.buildFailureJsonRtn(UserInfoJsonRtn.class, "missing openId"); } String lang = local != null ? local.toString() : StringUtils.EMPTY; Map<String, String> paramMap = ImmutableMap.of("openid", openId, "lang", lang); return HttpUtil.getRequest(WechatRequest.GET_USER_INFO, license, paramMap, UserInfoJsonRtn.class); }
Example 9
Source File: InputMethodPopupMenu.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Returns a localized locale name for input methods with the * given locale. It falls back to Locale.getDisplayName() and * then to Locale.toString() if no localized locale name is found. * * @param locale Locale for which localized locale name is obtained */ String getLocaleName(Locale locale) { String localeString = locale.toString(); String localeName = Toolkit.getProperty("AWT.InputMethodLanguage." + localeString, null); if (localeName == null) { localeName = locale.getDisplayName(); if (localeName == null || localeName.length() == 0) localeName = localeString; } return localeName; }
Example 10
Source File: MLTokenDuplicator.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
public MLTokenDuplicator(TokenStream source, Locale locale, Reader reader, MLAnalysisMode mlAnalysisMode) { this.source = source; this.locale = locale; Collection<Locale> locales = MLAnalysisMode.getLocales(mlAnalysisMode, locale, false); prefixes = new HashSet<String>(locales.size()); for(Locale toAdd : locales) { String localeString = toAdd.toString(); if(localeString.length() == 0) { prefixes.add(""); } else { StringBuilder builder = new StringBuilder(16); builder.append("{").append(localeString).append("}"); prefixes.add(builder.toString()); } } if(s_logger.isDebugEnabled()) { s_logger.debug("Locale "+ locale +" using "+mlAnalysisMode+" is "+prefixes); } }
Example 11
Source File: LocaleEnhanceTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void testBug7023613() { String[][] testdata = { {"en-Latn", "en__#Latn"}, {"en-u-ca-japanese", "en__#u-ca-japanese"}, }; for (String[] data : testdata) { String in = data[0]; String expected = (data.length == 1) ? data[0] : data[1]; Locale loc = Locale.forLanguageTag(in); String out = loc.toString(); assertEquals("Empty country field with non-empty script/extension with input: " + in, expected, out); } }
Example 12
Source File: SystemHelper.java From fess with Apache License 2.0 | 5 votes |
public List<Map<String, String>> getLanguageItems(final Locale locale) { try { final String localeStr = locale.toString(); return langItemsCache.get(localeStr); } catch (final ExecutionException e) { final List<Map<String, String>> langItems = new ArrayList<>(supportedLanguages.length); final String msg = ComponentUtil.getMessageManager().getMessage(locale, "labels.allLanguages"); final Map<String, String> defaultMap = new HashMap<>(2); defaultMap.put(Constants.ITEM_LABEL, msg); defaultMap.put(Constants.ITEM_VALUE, "all"); langItems.add(defaultMap); return langItems; } }
Example 13
Source File: SakaiDateFormatProvider.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Returns a date pattern with the given formatting style for the specified * locale. * * @param style the given date formatting style. * @param locale the desired locale. * @return a date pattern. * @throws IllegalArgumentException if <code>style</code> is invalid, or if * <code>locale</code> isn't available. * @throws NullPointerException if <code>locale</code> is <code>null</code>. */ protected String getDateFormatString(final int style, final Locale locale) throws IllegalArgumentException, NullPointerException { if (locale == null) { throw new NullPointerException("locale:null"); } else if (!SakaiLocaleServiceProviderUtil.isAvailableLocale(locale)) { throw new IllegalArgumentException("locale:" + locale.toString()); } String key; switch (style) { case DateFormat.SHORT: key = "DateFormat.SHORT"; break; case DateFormat.MEDIUM: key = "DateFormat.MEDIUM"; break; case DateFormat.LONG: key = "DateFormat.LONG"; break; case DateFormat.FULL: key = "DateFormat.FULL"; break; default: throw new IllegalArgumentException("style:" + style); } return SakaiLocaleServiceProviderUtil.getString(key, locale); }
Example 14
Source File: MessageBundleServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * internal work for responding to a save or update request. This method will add new bundles data * if it doesn't exist, otherwise updates the data preserving any current value if its been modified. * This approach allows for upgrades to automatically detect and persist new keys, as well as updating * any default values that flow in from an upgrade. * * @param baseName * @param moduleName * @param newBundle * @param loc */ protected void saveOrUpdateInternal(String baseName, String moduleName, Map<String, String> newBundle, Locale loc) { String keyName = getIndexKeyName(baseName, moduleName, loc.toString()); if (indexedList.contains(keyName)) { log.debug("skip bundle as its already happened once for: {}", keyName); return; } for (Entry<String, String> entry : newBundle.entrySet()) { String value = entry.getValue(); MessageBundleProperty mbp = new MessageBundleProperty(baseName, moduleName, loc.toString(), entry.getKey()); MessageBundleProperty existingMbp = getProperty(mbp); if (existingMbp == null) { // new property so add mbp.setDefaultValue(value); updateMessageBundleProperty(mbp); log.debug("adding message bundle: {}", mbp.toString()); } else { // update an existing properties default value if different if (!StringUtils.equals(value, existingMbp.getDefaultValue())) { existingMbp.setDefaultValue(value); updateMessageBundleProperty(existingMbp); log.debug("updating message bundle: {}", existingMbp.toString()); } } } indexedList.add(keyName); }
Example 15
Source File: SpellingConfigurationBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the locale codes for the locale list. * * @param locales * The list of locales * @return Array of locale codes for the list */ protected static String[] getDictionaryCodes(final Set<Locale> locales) { int index= 0; Locale locale= null; final String[] codes= new String[locales.size() + 1]; for (final Iterator<Locale> iterator= locales.iterator(); iterator.hasNext();) { locale= iterator.next(); codes[index++]= locale.toString(); } codes[index++]= PREF_VALUE_NO_LOCALE; return codes; }
Example 16
Source File: ExploitFixerCommand.java From ExploitFixer with GNU General Public License v3.0 | 4 votes |
@Override public void execute(final CommandSender commandSender, final String[] args) { String lang = "en"; final int length = args.length; if (commandSender instanceof ProxiedPlayer) { final Locale locale = ((ProxiedPlayer) commandSender).getLocale(); if (locale != null) { final String localeString = locale.toString(); if (localeString.length() > 1) { lang = localeString.substring(0, 2); } } } if (length < 1 || args[0].equals("help")) { commandSender .sendMessage(new TextComponent(messagesModule.getHelp(lang).replace("%command%", "exploitfixer"))); } else if (args[0].equals("reload")) if (commandSender.hasPermission("exploitfixer.admin")) { ExploitFixer.getInstance().reload(); commandSender.sendMessage(new TextComponent(messagesModule.getReload(lang))); } else commandSender.sendMessage(new TextComponent(messagesModule.getPermission(lang))); else if (args[0].equals("stats")) if (commandSender.hasPermission("exploitfixer.admin")) commandSender.sendMessage(new TextComponent(messagesModule.getStats(lang) .replace("%players_punished%", String.valueOf(exploitPlayerManager.getPunishments())) .replace("%players_cached%", String.valueOf(exploitPlayerManager.getSize())))); else commandSender.sendMessage(new TextComponent(messagesModule.getPermission(lang))); else if (args[0].equalsIgnoreCase("notifications")) { if (commandSender instanceof ProxiedPlayer) { if (commandSender.hasPermission("exploitfixer.admin") || commandSender.hasPermission("exploitfixer.notifications")) { final ProxiedPlayer proxiedPlayer = (ProxiedPlayer) commandSender; if (!notificationsVariables.isNotifications(proxiedPlayer)) { notificationsVariables.setNotifications(proxiedPlayer, true); commandSender.sendMessage(new TextComponent(messagesModule.getEnable(lang))); } else { notificationsVariables.setNotifications(proxiedPlayer, false); commandSender.sendMessage(new TextComponent(messagesModule.getDisable(lang))); } } else commandSender.sendMessage(new TextComponent(messagesModule.getPermission(lang))); } else commandSender.sendMessage(new TextComponent(messagesModule.getConsole(lang))); } else commandSender.sendMessage(new TextComponent(messagesModule.getUnknown(lang))); }
Example 17
Source File: SakaiDecimalFormatSymbolsProvider.java From sakai with Educational Community License v2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public DecimalFormatSymbols getInstance(final Locale locale) throws IllegalArgumentException, NullPointerException { if (locale == null) { throw new NullPointerException("locale:null"); } else if (!SakaiLocaleServiceProviderUtil.isAvailableLocale(locale)) { throw new IllegalArgumentException("locale:" + locale.toString()); } DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator( SakaiLocaleServiceProviderUtil.getChar("DecimalSeparator", locale)); symbols.setDigit( SakaiLocaleServiceProviderUtil.getChar("Digit", locale)); symbols.setExponentSeparator( SakaiLocaleServiceProviderUtil.getString("ExponentSeparator", locale)); symbols.setGroupingSeparator( SakaiLocaleServiceProviderUtil.getChar("GroupingSeparator", locale)); symbols.setInfinity( SakaiLocaleServiceProviderUtil.getString("Infinity", locale)); symbols.setInternationalCurrencySymbol( SakaiLocaleServiceProviderUtil.getString("InternationalCurrencySymbol", locale)); symbols.setCurrencySymbol( SakaiLocaleServiceProviderUtil.getString("CurrencySymbol", locale)); symbols.setMinusSign( SakaiLocaleServiceProviderUtil.getChar("MinusSign", locale)); symbols.setMonetaryDecimalSeparator( SakaiLocaleServiceProviderUtil.getChar("MonetaryDecimalSeparator", locale)); symbols.setNaN( SakaiLocaleServiceProviderUtil.getString("NaN", locale)); symbols.setPatternSeparator( SakaiLocaleServiceProviderUtil.getChar("PatternSeparator", locale)); symbols.setPercent( SakaiLocaleServiceProviderUtil.getChar("Percent", locale)); symbols.setPerMill( SakaiLocaleServiceProviderUtil.getChar("PerMill", locale)); symbols.setZeroDigit( SakaiLocaleServiceProviderUtil.getChar("ZeroDigit", locale)); return symbols; }
Example 18
Source File: NbBundle.java From netbeans with Apache License 2.0 | 4 votes |
/** * Get a resource bundle by name. * Like {@link ResourceBundle#getBundle(String,Locale,ClassLoader)} but faster, * and also understands branding. * First looks for <samp>.properties</samp>-based bundles, then <samp>.class</samp>-based. * @param name the base name of the bundle, e.g. <samp>org.netbeans.modules.foo.Bundle</samp> * @param locale the locale to use * @param loader a class loader to search in * @return a resource bundle (locale- and branding-merged), or null if not found */ private static ResourceBundle getBundleFast(String name, Locale locale, ClassLoader loader) { Map<String,Reference<ResourceBundle>> m; synchronized (bundleCache) { m = bundleCache.get(loader); if (m == null) { bundleCache.put(loader, m = new HashMap<String,Reference<ResourceBundle>>()); } } //A minor optimization to cut down on StringBuffer allocations - OptimizeIt //showed the commented out code below was a major source of them. This //just does the same thing with a char array - Tim String localeStr = locale.toString(); char[] k = new char[name.length() + ((brandingToken != null) ? brandingToken.length() : 1) + 2 + localeStr.length()]; name.getChars(0, name.length(), k, 0); k[name.length()] = '/'; //NOI18N int pos = name.length() + 1; if (brandingToken == null) { k[pos] = '-'; //NOI18N pos++; } else { brandingToken.getChars(0, brandingToken.length(), k, pos); pos += brandingToken.length(); } k[pos] = '/'; //NOI18N pos++; localeStr.getChars(0, localeStr.length(), k, pos); String key = new String(k); /* String key = name + '/' + (brandingToken != null ? brandingToken : "-") + '/' + locale; // NOI18N */ synchronized (m) { Reference<ResourceBundle> o = m.get(key); ResourceBundle b = o != null ? o.get() : null; if (b != null) { return b; } else { b = loadBundle(name, locale, loader); if (b != null) { m.put(key, new TimedSoftReference<ResourceBundle>(b, m, key)); } else { // Used to cache misses as well, to make the negative test faster. // However this caused problems: see #31578. } return b; } } }
Example 19
Source File: SakaiDateFormatSymbolsProvider.java From sakai with Educational Community License v2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public DateFormatSymbols getInstance(final Locale locale) throws IllegalArgumentException, NullPointerException { if (locale == null) { throw new NullPointerException("locale:null"); } else if (!SakaiLocaleServiceProviderUtil.isAvailableLocale(locale)) { throw new IllegalArgumentException("locale:" + locale.toString()); } DateFormatSymbols symbols = new DateFormatSymbols(); symbols.setEras(new String[] { SakaiLocaleServiceProviderUtil.getString("Eras.BC", locale), SakaiLocaleServiceProviderUtil.getString("Eras.AD", locale) }); symbols.setMonths(new String[] { SakaiLocaleServiceProviderUtil.getString("Months.JAN", locale), SakaiLocaleServiceProviderUtil.getString("Months.FEB", locale), SakaiLocaleServiceProviderUtil.getString("Months.MAR", locale), SakaiLocaleServiceProviderUtil.getString("Months.APR", locale), SakaiLocaleServiceProviderUtil.getString("Months.MAY", locale), SakaiLocaleServiceProviderUtil.getString("Months.JUN", locale), SakaiLocaleServiceProviderUtil.getString("Months.JUL", locale), SakaiLocaleServiceProviderUtil.getString("Months.AUG", locale), SakaiLocaleServiceProviderUtil.getString("Months.SEP", locale), SakaiLocaleServiceProviderUtil.getString("Months.OCT", locale), SakaiLocaleServiceProviderUtil.getString("Months.NOV", locale), SakaiLocaleServiceProviderUtil.getString("Months.DEC", locale) }); symbols.setShortMonths(new String[] { SakaiLocaleServiceProviderUtil.getString("ShortMonths.JAN", locale), SakaiLocaleServiceProviderUtil.getString("ShortMonths.FEB", locale), SakaiLocaleServiceProviderUtil.getString("ShortMonths.MAR", locale), SakaiLocaleServiceProviderUtil.getString("ShortMonths.APR", locale), SakaiLocaleServiceProviderUtil.getString("ShortMonths.MAY", locale), SakaiLocaleServiceProviderUtil.getString("ShortMonths.JUN", locale), SakaiLocaleServiceProviderUtil.getString("ShortMonths.JUL", locale), SakaiLocaleServiceProviderUtil.getString("ShortMonths.AUG", locale), SakaiLocaleServiceProviderUtil.getString("ShortMonths.SEP", locale), SakaiLocaleServiceProviderUtil.getString("ShortMonths.OCT", locale), SakaiLocaleServiceProviderUtil.getString("ShortMonths.NOV", locale), SakaiLocaleServiceProviderUtil.getString("ShortMonths.DEC", locale) }); symbols.setWeekdays(new String[] {"", SakaiLocaleServiceProviderUtil.getString("Weekdays.SUN", locale), SakaiLocaleServiceProviderUtil.getString("Weekdays.MON", locale), SakaiLocaleServiceProviderUtil.getString("Weekdays.TUE", locale), SakaiLocaleServiceProviderUtil.getString("Weekdays.WED", locale), SakaiLocaleServiceProviderUtil.getString("Weekdays.THU", locale), SakaiLocaleServiceProviderUtil.getString("Weekdays.FRI", locale), SakaiLocaleServiceProviderUtil.getString("Weekdays.SAT", locale) }); symbols.setShortWeekdays(new String[] {"", SakaiLocaleServiceProviderUtil.getString("ShortWeekdays.SUN", locale), SakaiLocaleServiceProviderUtil.getString("ShortWeekdays.MON", locale), SakaiLocaleServiceProviderUtil.getString("ShortWeekdays.TUE", locale), SakaiLocaleServiceProviderUtil.getString("ShortWeekdays.WED", locale), SakaiLocaleServiceProviderUtil.getString("ShortWeekdays.THU", locale), SakaiLocaleServiceProviderUtil.getString("ShortWeekdays.FRI", locale), SakaiLocaleServiceProviderUtil.getString("ShortWeekdays.SAT", locale) }); symbols.setAmPmStrings(new String[] { SakaiLocaleServiceProviderUtil.getString("AmPmStrings.AM", locale), SakaiLocaleServiceProviderUtil.getString("AmPmStrings.PM", locale) }); symbols.setLocalPatternChars(SakaiLocaleServiceProviderUtil.getString( "LocalPatternChars", locale)); // Not support Zone Strings return symbols; }
Example 20
Source File: ContextHelpManager.java From olat with Apache License 2.0 | 2 votes |
/** * Method to calculate a key that identifies a help page uniquely * * @param locale * @param bundleName * @param page * @return */ public String calculateCombinedKey(Locale locale, String bundleName, String page) { return locale.toString() + ":" + bundleName + ":" + page; }