Java Code Examples for java.util.Locale.toString()

The following are Jave code examples for showing how to use toString() of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: TrueTypeFont.java   View Source Code Vote up 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 = 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 2
Project: jdk8u-jdk   File: TrueTypeFont.java   View Source Code Vote up 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 3
Project: fitnotifications   File: ULocale.java   View Source Code Vote up 6 votes
private static ULocale toULocale6(Locale loc) {
    ULocale uloc = null;
    String locStr = loc.toString();
    if (locStr.length() == 0) {
        uloc = ULocale.ROOT;
    } else {
        for (int i = 0; i < JAVA6_MAPDATA.length; i++) {
            if (JAVA6_MAPDATA[i][0].equals(locStr)) {
                LocaleIDParser p = new LocaleIDParser(JAVA6_MAPDATA[i][1]);
                p.setKeywordValue(JAVA6_MAPDATA[i][2], JAVA6_MAPDATA[i][3]);
                locStr = p.getName();
                break;
            }
        }
        uloc = new ULocale(getName(locStr), loc);
    }
    return uloc;
}
 
Example 4
Project: myfaces-trinidad   File: DateTimeConverter.java   View Source Code Vote up 6 votes
private String _getLocaleString (FacesContext context)
{
  Locale dateTimeConverterLocale = getLocale();
  if (dateTimeConverterLocale != null)
  {
    Locale defaultLocale = RenderingContext.getCurrentInstance()
        .getLocaleContext().getFormattingLocale();
    if (!(dateTimeConverterLocale.equals (defaultLocale)))
    {
      String loc = dateTimeConverterLocale.toString();
      StringBuffer sb = new StringBuffer (2 + loc.length());
      sb.append ("'");
      sb.append (loc);
      sb.append ("'");
      return (sb.toString());
    }
  }
  return "null";
}
 
Example 5
Project: myfaces-trinidad   File: OracleHelpProvider.java   View Source Code Vote up 6 votes
/**
 * The getHelpTopicURL() method should return a string URL
 * for the given key string (topic-id)
 * <p>
 * @param key criterion (topic-id)
 */
@Override
protected String getHelpTopicURL(Object key)
{
  String helpURL = null;
  if (key != null)
  {
    FacesContext context = FacesContext.getCurrentInstance();
    Locale locale = context.getViewRoot().getLocale();
    String servletLocation = _getLocaleSpecificServlet(context);
    boolean hasQueryParams = servletLocation.indexOf('?') >= 0;
    helpURL = (servletLocation + (hasQueryParams ? "&" : "?") +
               _TOPIC_PARAM + "=" + key.toString() + "&" +
               _LOCALE_PARAM + "=" + locale.toString());
  }

  return helpURL;
}
 
Example 6
Project: myfaces-trinidad   File: OracleHelpProvider.java   View Source Code Vote up 6 votes
/**
 * The getHelpSystemURL() method should return a string URL
 * for the given key string (HelpProvider key constant)
 * <p>
 * @param key criterion (HelpProvider key constant)
 */
@Override
protected String getHelpSystemURL(Object key)
{
  if (HelpProvider.FRONT_PAGE_KEY.equals(key))
  {
    FacesContext context = FacesContext.getCurrentInstance();
    Locale locale = context.getViewRoot().getLocale();
    String servletLocation = _getLocaleSpecificServlet(context);
    if (servletLocation != null)
    {
      boolean hasQueryParams = servletLocation.indexOf('?') >= 0;
      servletLocation  = servletLocation + (hasQueryParams ? "&" : "?") +
           _LOCALE_PARAM + "=" + locale.toString();
    }

    return servletLocation;
  }

  return null;
}
 
Example 7
Project: logistimo-web-service   File: Resources.java   View Source Code Vote up 6 votes
public ResourceBundle getBundle(String baseName, Locale locale) throws MissingResourceException {
  if (baseName == null || locale == null) {
    return null;
  }
  // Get the resource bundle, if not already present
  String key = baseName + "_" + locale.toString();
  xLogger.fine("Resources.getBundle(): trying first key = {0}", key);
  ResourceBundle bundle = rmap.get(key);
  if (bundle == null) {
    key = baseName + "_" + locale.getLanguage();
    bundle = rmap.get(key);
    xLogger.fine("Resources.getBundle(): tried second key = {0}, bundle = {1}", key, bundle);
    if (bundle == null) {
      bundle = getUTF8Bundle(baseName, locale);
      key =
          baseName + "_" + bundle.getLocale()
              .toString(); // actual (fallback) locale used to get the file
      xLogger.fine(
          "Resource.getBundle(): getting it first time using locale = {0}, actual key = {0}",
          locale.toString(), key);
      rmap.put(key, bundle);
    }
  }
  return bundle;
}
 
Example 8
Project: boohee_v5.6   File: ICUCompatIcs.java   View Source Code Vote up 5 votes
private static String addLikelySubtags(Locale locale) {
    String localeStr = locale.toString();
    try {
        if (sAddLikelySubtagsMethod != null) {
            return (String) sAddLikelySubtagsMethod.invoke(null, new Object[]{localeStr});
        }
    } catch (IllegalAccessException e) {
        Log.w(TAG, e);
    } catch (InvocationTargetException e2) {
        Log.w(TAG, e2);
    }
    return localeStr;
}
 
Example 9
Project: firefox-tv   File: LocaleListPreference.java   View Source Code Vote up 5 votes
public LocaleDescriptor(Locale locale, String tag) {
    this.tag = tag;

    final String displayName;

    if (languageCodeToNameMap.containsKey(locale.getLanguage())) {
        displayName = languageCodeToNameMap.get(locale.getLanguage());
    } else {
        displayName = locale.getDisplayName(locale);
    }

    if (TextUtils.isEmpty(displayName)) {
        // There's nothing sane we can do.
        Log.w(LOG_TAG, "Display name is empty. Using " + locale.toString());
        this.nativeName = locale.toString();
        return;
    }

    // For now, uppercase the first character of LTR locale names.
    // This is pretty much what Android does. This is a reasonable hack
    // for Bug 1014602, but it won't generalize to all locales.
    final byte directionality = Character.getDirectionality(displayName.charAt(0));
    if (directionality == Character.DIRECTIONALITY_LEFT_TO_RIGHT) {
        this.nativeName = displayName.substring(0, 1).toUpperCase(locale) +
                displayName.substring(1);
        return;
    }

    this.nativeName = displayName;
}
 
Example 10
Project: Equella   File: MultiEditBox.java   View Source Code Vote up 5 votes
@Override
protected void prepareModel(RenderContext info)
{
	super.prepareModel(info);
	final MultiEditBoxState state = getState(info);
	Map<String, HtmlValueState> map = new LinkedHashMap<String, HtmlValueState>();

	TreeSet<Locale> languages = new TreeSet<Locale>(localeComparator);
	languages.addAll(getContributeLocales());
	languages.addAll(getBundleLocales(info));

	for( Locale locale : languages )
	{
		String id = locale.toString();
		HtmlValueState valState = langMap.getValueState(info, id);

		// Build format into: Language [(country)] where country
		String displayString = Constants.BLANK;

		String displayLanguage = locale.getDisplayLanguage();
		String displayCountry = locale.getCountry();
		displayString = !Check.isEmpty(displayCountry) ? MessageFormat.format(
			"{0} ({1})", displayLanguage, displayCountry) : displayLanguage; //$NON-NLS-1$

		valState.setLabel(new TextLabel(displayString));
		map.put(id, valState);
	}
	state.setSize(size);
	state.setLocaleMap(map);
}
 
Example 11
Project: spring-i18n-support   File: PropertiesWriter.java   View Source Code Vote up 5 votes
public void writePropertiesSet(	List<MessageResourceEntry> entries,
								Set<Locale> locales,
								Locale defaultLocale,
								String resourceName,
								File outputDir,
								String encoding,
								long lastModified) throws I18nException
{
	if (!outputDir.exists())
	{
		LOG.info("create output directory  [{}]", outputDir.getName());
		outputDir.mkdirs();
	}

	String fileName = resourceName + ".properties";
	File master = new File(outputDir, fileName);
	if (this.checkLastModified && master.exists() && master.lastModified() >= lastModified)
	{
		LOG.info("skip properties creation, files ({}) are newer then source ({})", new Date(master.lastModified()), new Date(lastModified));
		return;
	}
	LOG.info("write master properties file {}", master.getAbsoluteFile());
	this.writeProperties(entries, defaultLocale, master, encoding);
	for (Locale locale : locales)
	{
		String name = resourceName + "_" + locale.toString() + ".properties";
		File file = new File(outputDir, name);
		LOG.info("write locale [{}] properties file {}", locale, file);
		this.writeProperties(entries, locale, file, encoding);
	}
}
 
Example 12
Project: Equella   File: I18nTextField.java   View Source Code Vote up 5 votes
public PopupPanel(JPopupMenu popup)
{
	this.popup = popup;
	this.mapping = new HashMap<Locale, JTextComponent>();

	setLayout(new MigLayout("wrap,fill", "[grow]r[]", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	for( Locale locale : editableLocales )
	{
		String actionCommand = locale.toString();
		JTextComponent field = getTextComponent();

		JButton button = new JButton(locale.getDisplayName());
		button.setActionCommand(actionCommand);
		button.addActionListener(this);

		field.setText(textMap.get(locale));
		mapping.put(locale, field);

		add(prepareTextComponent(field), "growx, sizegroup f, hmax 100px"); //$NON-NLS-1$
		add(button, "sizegroup b"); //$NON-NLS-1$
	}

	closeButton = new JLinkButton(CurrentLocale.get("prompts.close")); //$NON-NLS-1$
	closeButton.addActionListener(this);
	closeButton.setActionCommand(""); //$NON-NLS-1$
	closeButton.setIcon(new ArrowIcon(SwingConstants.NORTH));
	closeButton.setHorizontalTextPosition(SwingConstants.LEFT);
	add(closeButton, "span 2, align right, shrink"); //$NON-NLS-1$

	setBorder(BorderFactory.createLineBorder(Color.BLACK));

	final int width = Math.max(400, I18nTextField.this.getSize().width);
	setPreferredSize(new Dimension(width, getPreferredSize().height));

	popup.addPopupMenuListener(this);
}
 
Example 13
Project: openjdk-jdk10   File: CLDRLocaleProviderAdapter.java   View Source Code Vote up 5 votes
/**
 * This method returns equivalent CLDR supported locale for zh-HK,
 * no, no-NO locales so that COMPAT locales do not precede
 * those locales during ResourceBundle search path.
 */
private static Locale getEquivalentLoc(Locale locale) {
    switch (locale.toString()) {
        case "zh_HK":
            return Locale.forLanguageTag("zh-Hant-HK");
        case "no":
        case "no_NO":
            return Locale.forLanguageTag("nb");
    }
    return locale;
}
 
Example 14
Project: jaffa-framework   File: PropertyMessageResources.java   View Source Code Vote up 5 votes
/** Compute and return a key to be used in caching information by a Locale.
 * This appends the variation for the authenticated user to the toString() output of the Locale object.
 * @param locale The locale for which a key is desired
 * @return a key to be used in caching information by a Locale.
 */
protected String localeKey(Locale locale) {
    if (locale == null)
        return "";
    else if (locale.getVariant() != null && locale.getVariant().length() > 0)
        return locale.toString();
    else
        return locale.toString() + '_' + VariationContext.getVariation();
}
 
Example 15
Project: oscm   File: LocalizerServiceBean.java   View Source Code Vote up 5 votes
/**
 * Depending on the number of key values passed queries for the localized
 * string matching the given resource. If two matches are found, always the
 * one matching the given key, not it's parent key, is returned.
 *
 * @param objectType
 *            The object type the localized resource has to be retrieved
 *            for.
 * @param locale
 *            The locale the information has to be retrieved for.
 * @param keysForObjects
 *            The key values the resource must have assigned.
 * @return The localized resource.
 */
private LocalizedResource getResourceFromDatabase(
        LocalizedObjectTypes objectType, Locale locale,
        KeysForOneObject keysForObjects) {

    LocalizedResource resource = null;
    if (keysForObjects.getAllObjKeys().size() == 1) {
        LocalizedResource template = new LocalizedResource(
                locale.toString(), keysForObjects.getPrimaryObjKey()
                        .longValue(), objectType);
        resource = (LocalizedResource) dm.find(template);
    } else {
        Query query = dm
                .createNamedQuery("LocalizedResource.getForCurrAndParentKey");
        query.setParameter("locale", locale.getLanguage());
        query.setParameter("objectType", objectType);
        query.setParameter("objectKeyChild",
                keysForObjects.getPrimaryObjKey());
        query.setParameter("objectKeyParent", keysForObjects
                .getAllObjKeys().get(1));

        List<LocalizedResource> resultList = ParameterizedTypes.list(
                query.getResultList(), LocalizedResource.class);
        if (resultList.size() == 1) {
            resource = resultList.get(0);
        } else if (resultList.size() == 2) {
            if (resultList.get(0).getObjectKey() == keysForObjects
                    .getPrimaryObjKey().longValue()) {
                resource = resultList.get(0);
            } else {
                resource = resultList.get(1);
            }
        }
    }

    return resource;
}
 
Example 16
Project: AOSP-Kayboard-7.1.2   File: KeyboardTextsTable.java   View Source Code Vote up 5 votes
public static String[] getTextsTable(final Locale locale) {
    final String localeKey = locale.toString();
    if (sLocaleToTextsTableMap.containsKey(localeKey)) {
        return sLocaleToTextsTableMap.get(localeKey);
    }
    final String languageKey = locale.getLanguage();
    if (sLocaleToTextsTableMap.containsKey(languageKey)) {
        return sLocaleToTextsTableMap.get(languageKey);
    }
    return TEXTS_DEFAULT;
}
 
Example 17
Project: logistimo-web-service   File: RESTUtil.java   View Source Code Vote up 5 votes
private static String getKioskDataExportJsonOutput(Locale locale, boolean status, String message)
    throws ProtocolException {
  String localeStr = Constants.LANG_DEFAULT;
  if (locale != null) {
    localeStr = locale.toString();
  }
  // Form the basic out and sent back JSON return string
  BasicOutput jsonOutput =
      new BasicOutput(status, message, null, localeStr, RESTUtil.VERSION_01);
  return jsonOutput.toJSONString();
}
 
Example 18
Project: AOSP-Kayboard-7.1.2   File: ExpandableBinaryDictionary.java   View Source Code Vote up 4 votes
public static String getDictName(final String name, final Locale locale,
        final File dictFile) {
    return dictFile != null ? dictFile.getName() : name + "." + locale.toString();
}
 
Example 19
Project: oscm   File: DefaultMessages.java   View Source Code Vote up 4 votes
/**
 * Returns the path to the UI properties for the given locale
 */
static String uiMessagesPath(Locale locale) {
    return DbMessages.class.getPackage().getName().replaceAll("\\.", "/")
            + "/Messages_" + locale.toString() + ".properties";
}
 
Example 20
Project: oscm   File: DefaultMessages.java   View Source Code Vote up 4 votes
/**
 * Returns the path to the exception messages for the given locale
 */
static String exceptionMessagesPath(Locale locale) {
    return "ExceptionMessages_" + locale.toString() + ".properties";
}