Class I18NBundle

java.lang.Object
gaiasky.util.i18n.I18NBundle

public class I18NBundle extends Object
Fork of Libgdx I18NBundle that improves performance by disabling exceptions by default and returning null.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    static I18NBundle
    createBundle(com.badlogic.gdx.files.FileHandle baseFileHandle)
    Creates a new bundle using the specified baseFileHandle, the default locale and the default encoding "UTF-8".
    static I18NBundle
    createBundle(com.badlogic.gdx.files.FileHandle baseFileHandle, String encoding)
    Creates a new bundle using the specified baseFileHandle and encoding; the default locale is used.
    static I18NBundle
    createBundle(com.badlogic.gdx.files.FileHandle baseFileHandle, Locale locale)
    Creates a new bundle using the specified baseFileHandle and locale; the default encoding "UTF-8" is used.
    static I18NBundle
    createBundle(com.badlogic.gdx.files.FileHandle baseFileHandle, Locale locale, String encoding)
    Creates a new bundle using the specified baseFileHandle, locale and encoding.
    void
    debug(String placeholder)
    Sets the value of all localized strings to String placeholder so hardcoded, unlocalized values can be easily spotted.
    format(String key, Object... args)
    Gets the string with the specified key from this bundle or one of its parent after replacing the given arguments if they occur.
    get(String key)
    Gets a string for the given key from this bundle or one of its parents.
    Returns the locale of this bundle.
    static boolean
    Returns the flag indicating whether to use the simplified message pattern syntax (default is false).
    Gets a key set of loaded properties.
    protected void
    load(Reader reader)
    Load the properties from the specified reader.
    static void
    setSimpleFormatter(boolean enabled)
    Sets the flag indicating whether to use the simplified message pattern.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • I18NBundle

      public I18NBundle()
  • Method Details

    • getSimpleFormatter

      public static boolean getSimpleFormatter()
      Returns the flag indicating whether to use the simplified message pattern syntax (default is false). This flag is always assumed to be true on GWT backend.
    • setSimpleFormatter

      public static void setSimpleFormatter(boolean enabled)
      Sets the flag indicating whether to use the simplified message pattern. The flag must be set before calling the factory methods createBundle. Notice that this method has no effect on the GWT backend where it's always assumed to be true.
    • createBundle

      public static I18NBundle createBundle(com.badlogic.gdx.files.FileHandle baseFileHandle)
      Creates a new bundle using the specified baseFileHandle, the default locale and the default encoding "UTF-8".
      Parameters:
      baseFileHandle - the file handle to the base of the bundle
      Returns:
      a bundle for the given base file handle and the default locale
      Throws:
      NullPointerException - if baseFileHandle is null
      MissingResourceException - if no bundle for the specified base file handle can be found
    • createBundle

      public static I18NBundle createBundle(com.badlogic.gdx.files.FileHandle baseFileHandle, Locale locale)
      Creates a new bundle using the specified baseFileHandle and locale; the default encoding "UTF-8" is used.
      Parameters:
      baseFileHandle - the file handle to the base of the bundle
      locale - the locale for which a bundle is desired
      Returns:
      a bundle for the given base file handle and locale
      Throws:
      NullPointerException - if baseFileHandle or locale is null
      MissingResourceException - if no bundle for the specified base file handle can be found
    • createBundle

      public static I18NBundle createBundle(com.badlogic.gdx.files.FileHandle baseFileHandle, String encoding)
      Creates a new bundle using the specified baseFileHandle and encoding; the default locale is used.
      Parameters:
      baseFileHandle - the file handle to the base of the bundle
      encoding - the character encoding
      Returns:
      a bundle for the given base file handle and locale
      Throws:
      NullPointerException - if baseFileHandle or encoding is null
      MissingResourceException - if no bundle for the specified base file handle can be found
    • createBundle

      public static I18NBundle createBundle(com.badlogic.gdx.files.FileHandle baseFileHandle, Locale locale, String encoding)
      Creates a new bundle using the specified baseFileHandle, locale and encoding.
      Parameters:
      baseFileHandle - the file handle to the base of the bundle
      locale - the locale for which a bundle is desired
      encoding - the character encoding
      Returns:
      a bundle for the given base file handle and locale
      Throws:
      NullPointerException - if baseFileHandle, locale or encoding is null
      MissingResourceException - if no bundle for the specified base file handle can be found
    • load

      protected void load(Reader reader) throws IOException
      Load the properties from the specified reader.
      Parameters:
      reader - the reader
      Throws:
      IOException - if an error occurred when reading from the input stream.
    • getLocale

      public Locale getLocale()
      Returns the locale of this bundle. This method can be used after a call to createBundle() to determine whether the resource bundle returned really corresponds to the requested locale or is a fallback.
      Returns:
      the locale of this bundle
    • contains

      public boolean contains(String key)
    • get

      public String get(String key)
      Gets a string for the given key from this bundle or one of its parents.
      Parameters:
      key - the key for the desired string
      Returns:
      the string for the given key or null.
    • keys

      public Set<String> keys()
      Gets a key set of loaded properties. Keys will be copied into a new set and returned.
      Returns:
      a key set of loaded properties. Never null, might be an empty set
    • format

      public String format(String key, Object... args)
      Gets the string with the specified key from this bundle or one of its parent after replacing the given arguments if they occur.
      Parameters:
      key - the key for the desired string
      args - the arguments to be replaced in the string associated to the given key.
      Returns:
      the string for the given key formatted with the given arguments
      Throws:
      NullPointerException - if key is null
      MissingResourceException - if no string for the given key can be found
    • debug

      public void debug(String placeholder)
      Sets the value of all localized strings to String placeholder so hardcoded, unlocalized values can be easily spotted. The I18NBundle won't be able to reset values after calling debug and should only be using during testing.