Class PI18nHelper

java.lang.Object
com.portal.ctrl.PI18nHelper

public class PI18nHelper extends Object
PI18nHelper is a place holder for any internationalization related helper functions. Currently, it provides following functions: 1. Locale aware name formatting function. Whenever you need to combine first name and last name, or first name, middle name and last name, call the formatName() function with the account locale. 2. CJK locale checking function. You can call this function to find out it a locale is a Chinese, Japanese or Korean locale. 3. Set a font style for a component. This function avoids setting a bold font style for CJK locale component. CJK characters are very difficult to read in bold style. We want to avoid using the bold style in any components where we may display CJK characters. 4. String to locale conversion. The locale we get from JavaPCM is a String object. To use the locale in Java, we need to convert it to a Locale object. This function converts the locale in String object to a Locale object. Notes: If you need to add more functions to this class or have any comments and suggestions, please contact Justin Zhou.
  • Constructor Details

    • PI18nHelper

      public PI18nHelper()
      Constructor of PI18NHelper
  • Method Details

    • formatName

      public static String formatName(Locale locale, String first, String middle, String last)
      Format a name based on locale. If the locale is null, you will get a NullPointerException.
      Parameters:
      locale - Portal account locale
      first - The first name from nameinfo
      middle - The middle name from nameinfo
      last - The last name from nameinfo
      Returns:
      combined name
    • formatName

      public static String formatName(Locale locale, String first, String last)
    • getString

      public static String getString(ResourceBundle bundle, String tag, Locale locale)
      Retrieve a resource string for a locale. The format string's key for tag could be tag_CJK, or tag. When loading the format string for a locale, we check if the locale is a CJK locale or non-CJK locale. If the locale is a CJK locale, we will look for tag_CJK; otherwise we will look for tag. By default, for each name related format strings, there are two format strings, one for CJK locales and one for non-CJK locales. For example, if we have a format string common.nametitle.format = {0} {1} in NextGenResource.properties Here the tag is common.nametitle.format. We will also provide a CJK verion of format string common.nametitle.format_CJK = {1}{0}
      Parameters:
      bundle - Resource bundle that has the format strings
      tag - The tag of a format string
      locale - Account locale or system locale
      Returns:
      A resource string. If the resource for the locale is missing in the bundle, you will get a MissingResourceException exception.
    • isCJKLocale

      public static boolean isCJKLocale(Locale locale)
      Find out if a locale is a Chinese, Japanese or Korean locale. If the locale is null, you will get a NullPointerException.
      Parameters:
      locale - Account locale or system locale
      Returns:
      true if the locale is a Chinese, Japanese or Korean locale; otherwise false.
    • setFontStyle

      public static void setFontStyle(Component c, int style)
      Avoid setting the BOLD font style for a CJK(Chinese, Japanese or Korean) locale. If you get an IllegalComponentStateExceptionn exception, you need to move the invocation of your method to the appropriate location in your code. In Java, a widget does not have its font and locale info until after addNotify() is called.
      Parameters:
      c - The component
      style - The new font style you want to set for the font used in the component
    • stringToLocale

      public static Locale stringToLocale(String locStr)
      Convert the locale string such as "en_US" to Java's Locale object
      Parameters:
      locStr - the locale string such as "en_US" or "zh_TW"
      Returns:
      Java Locale object corresponding to the locale in string format. If the locString is an empty string or locStr is null, system's default locale will be returned.