com.google.visualization.datasource.base
Class LocaleUtil

java.lang.Object
  extended by com.google.visualization.datasource.base.LocaleUtil

public class LocaleUtil
extends Object

A utility class for locale handling.

Author:
Yaniv S.

Method Summary
static com.ibm.icu.util.ULocale getDefaultLocale()
          Returns the default locale.
static Locale getLocaleFromLocaleString(String s)
          Converts a locale string from the RFC 3066 standard format to the Java locale format.
static String getLocalizedMessageFromBundle(String bundleName, String key, Locale locale)
          Returns a localized message from the specified ResourceBundle for the given key.
static String getLocalizedMessageFromBundleWithArguments(String bundleName, String key, String[] args, Locale locale)
          Returns a localized message from the specified ResourceBundle for the given key with the given arguments inserted to the message in the specified locations.
static void setDefaultLocale(com.ibm.icu.util.ULocale defaultLocale)
          Sets the default locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getLocaleFromLocaleString

public static Locale getLocaleFromLocaleString(String s)
Converts a locale string from the RFC 3066 standard format to the Java locale format. You can call this on any locale string obtained from an external source (cookie, URL parameter, header, etc.). This method accepts more than just the standard format and will also tolerate capitalization discrepancies and the use of an underscore in place of a hyphen.

Parameters:
s - The locale string.
Returns:
The locale for the given locale string.

setDefaultLocale

public static void setDefaultLocale(com.ibm.icu.util.ULocale defaultLocale)
Sets the default locale.

Parameters:
defaultLocale - The default locale.

getDefaultLocale

public static com.ibm.icu.util.ULocale getDefaultLocale()
Returns the default locale.

Returns:
The default locale.

getLocalizedMessageFromBundle

public static String getLocalizedMessageFromBundle(String bundleName,
                                                   String key,
                                                   Locale locale)
Returns a localized message from the specified ResourceBundle for the given key. In case the locale is null, uses the default locale. If locale is null, the default ResourceBundle is used.

Parameters:
bundleName - The name of the resource bundle.
key - The key of the requested string.
locale - The locale.
Returns:
A localized message from the bundle based on the given locale.

getLocalizedMessageFromBundleWithArguments

public static String getLocalizedMessageFromBundleWithArguments(String bundleName,
                                                                String key,
                                                                String[] args,
                                                                Locale locale)
Returns a localized message from the specified ResourceBundle for the given key with the given arguments inserted to the message in the specified locations. In case the locale is null, uses the default locale. If locale is null, the default ResourceBundle is used.

Parameters:
bundleName - The name of the resource bundle.
key - The key of the requested string.
args - Arguments to place in the error message.
locale - The locale.
Returns:
A localized message from the bundle based on the given locale.


Copyright © 2012 Google. All Rights Reserved.