de.caff.i18n

## Class I18n

- java.lang.Object
- - de.caff.i18n.I18n

- Direct Known Subclasses:
    DefaultI18n

      public abstract class I18n
      extends java.lang.Object

  Application specific support for internationalisation. This allows support for several resource classes for one application but has the big disadvantage that separate resource bundles may not define the same keys. Beware of that! You can switch DEBUG on to see if this happens.

  This design should be overworked when possible.

  To allow for enhancements the previous static design is now switched to something more object-oriented. This allows to take advantages of the new possibilities introduced with Java 1.2.

  Author:
    Rammi

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `ACTION_SUFFIX` General suffix for action specific resources.
    `(package private) static boolean` | `DEBUG` Switch on to see whether there are key clashes.
    `static java.lang.String` | `SUFFIX_ACCELERATOR` The i18n tag suffix added for an accelarator.
    `static java.lang.String` | `SUFFIX_DESCRIPTION` The i18n tag suffix added for a description.
    `static java.lang.String` | `SUFFIX_DISABLED_ICON` The i18n tag suffix added for the path of an icon used for the disabled state.
    `static java.lang.String` | `SUFFIX_ICON` The i18n tag suffix added for an icon path.
    `static java.lang.String` | `SUFFIX_INACTIVE_ICON` The i18n tag suffix added for the path of an icon used for the inactive state.
    `static java.lang.String` | `SUFFIX_MNEMONIC` The i18n tag suffix added for a mnemonic.
    `static java.lang.String` | `SUFFIX_TEXT` The i18n tag suffix added for a label/button text/menu text.
    `static java.lang.String` | `SUFFIX_TOOLTIP` The i18n tag suffix added for a tooltip.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `I18n()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract void` | `_addAppResourceBase(java.lang.String base, boolean prepend)` Add an application specific resource class base name.
    `protected abstract void` | `_addLocalizationChangeListener(Localizable localizable)` Add a listener for localization changes.
    `protected abstract void` | `_dumpResources(java.io.PrintStream out, java.util.Locale locale)` Dump the complete currently known i18n resources for a given locale.
    `protected abstract void` | `_fireLocaleChanged(java.util.Locale locale)` Tell all registered localizables of localization changes.
    `protected abstract java.util.ResourceBundle` | `_getBundle(java.util.Locale l)` Get a ResourceBundle for a locale.
    `protected abstract java.util.Locale` | `_getDefaultLocale()` Get the locale to be used as a default for the application.
    `protected abstract java.util.ResourceBundle` | `_getFallbackBundle()` Get the fallback resource bundle.
    `protected abstract void` | `_removeLocalizationChangeListener(Localizable localizable)` Remove a listener for localization changes.
    `protected abstract void` | `_setDefaultLocale(java.util.Locale l)` Set the locale to be used as a default for the application.
    `static void` | `addAppResourceBase(java.lang.String base)` Add an application specific resource class base name.
    `static void` | `addAppResourceBase(java.lang.String base, boolean prepend)` Add an application specific resource class base name.
    `static void` | `addLocalizationChangeListener(Localizable localizable)` Add a listener for localization changes.
    `static void` | `dump(java.io.PrintStream out, java.util.Locale locale)` Dump the complete currently known i18n resources for a given locale.
    `static java.lang.String` | `format(java.util.Locale l, java.lang.String tag, java.lang.Object... args)` Compile a String with a format.
    `static java.lang.String` | `format(java.lang.String tag, java.lang.Object... args)` Compile a String with a format using the default locale.
    `static java.util.Locale` | `getDefaultLocale()` Get the locale to be used as a default for the application.
    `static java.lang.String` | `getFormattedString(java.util.Locale l, java.lang.String tag, java.lang.Object... args)` Compile a String with a format.
    `static java.lang.String` | `getFormattedString(java.lang.String tag, java.lang.Object... args)` Compile a String with a format using the default locale.
    `static javax.swing.Icon` | `getIcon(java.lang.String tag)` Get an icon from a tag defining its location, using the default locale.
    `static javax.swing.Icon` | `getIcon(java.lang.String tag, java.util.Locale locale)` Get an icon from a tag defining its location.
    `static java.lang.String` | `getString(java.lang.String tag)` Get a string for the default locale.
    `static java.lang.String` | `getString(java.lang.String tag, java.util.Locale l)` Get a String specified by a Locale.
    `static void` | `removeLocalizationChangeListener(Localizable localizable)` Remove a listener for localization changes.
    `static void` | `setDefaultLocale(java.util.Locale l)` Set the locale to be used as a default for the application.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEBUG

          static final boolean DEBUG

      Switch on to see whether there are key clashes.
      See Also:
        Constant Field Values

    - #### ACTION_SUFFIX

          public static final java.lang.String ACTION_SUFFIX

      General suffix for action specific resources.
      See Also:
        Constant Field Values

    - #### SUFFIX_TEXT

          public static final java.lang.String SUFFIX_TEXT

      The i18n tag suffix added for a label/button text/menu text.
      See Also:
        Constant Field Values

    - #### SUFFIX_TOOLTIP

          public static final java.lang.String SUFFIX_TOOLTIP

      The i18n tag suffix added for a tooltip.
      See Also:
        Constant Field Values

    - #### SUFFIX_DESCRIPTION

          public static final java.lang.String SUFFIX_DESCRIPTION

      The i18n tag suffix added for a description.
      See Also:
        Constant Field Values

    - #### SUFFIX_ACCELERATOR

          public static final java.lang.String SUFFIX_ACCELERATOR

      The i18n tag suffix added for an accelarator.
      See Also:
        Constant Field Values

    - #### SUFFIX_MNEMONIC

          public static final java.lang.String SUFFIX_MNEMONIC

      The i18n tag suffix added for a mnemonic.
      See Also:
        Constant Field Values

    - #### SUFFIX_ICON

          public static final java.lang.String SUFFIX_ICON

      The i18n tag suffix added for an icon path.
      See Also:
        Constant Field Values

    - #### SUFFIX_DISABLED_ICON

          public static final java.lang.String SUFFIX_DISABLED_ICON

      The i18n tag suffix added for the path of an icon used for the disabled state.
      See Also:
        Constant Field Values

    - #### SUFFIX_INACTIVE_ICON

          public static final java.lang.String SUFFIX_INACTIVE_ICON

      The i18n tag suffix added for the path of an icon used for the inactive state.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### I18n

          public I18n()

  - ### Method Detail

    - #### addAppResourceBase

          public static void addAppResourceBase(@NotNull
                                                java.lang.String base)

      Add an application specific resource class base name. This should be called by any application/applet before any other i18n specific code is used.
      Parameters:
        `base` - base class name for resources
      See Also:
        `ResourceBundle`

    - #### addAppResourceBase

          public static void addAppResourceBase(@NotNull
                                                java.lang.String base,
                                                boolean prepend)

      Add an application specific resource class base name. This should be called by any application/applet before any other i18n specific code is used.
      Parameters:
        `base` - base class name for resources
        `prepend` - prepend this resource base?
      See Also:
        `ResourceBundle`

    - #### _addAppResourceBase

          protected abstract void _addAppResourceBase(@NotNull
                                                      java.lang.String base,
                                                      boolean prepend)

      Add an application specific resource class base name. This should be called by any application/applet before any other i18n specific code is used.
      Parameters:
        `base` - base class name for resources
        `prepend` - prepend this resource base?
      See Also:
        `ResourceBundle`

    - #### setDefaultLocale

          public static void setDefaultLocale(java.util.Locale l)

      Set the locale to be used as a default for the application.
      Parameters:
        `l` - locale to be used as default

    - #### _setDefaultLocale

          protected abstract void _setDefaultLocale(@Nullable
                                                    java.util.Locale l)

      Set the locale to be used as a default for the application.
      Parameters:
        `l` - locale to be used as default (system default if `null`)

    - #### getDefaultLocale

          @NotNull
          public static java.util.Locale getDefaultLocale()

      Get the locale to be used as a default for the application.
      Returns:
        locale to be used as default

    - #### _getDefaultLocale

          @NotNull
          protected abstract java.util.Locale _getDefaultLocale()

      Get the locale to be used as a default for the application.
      Returns:
        locale to be used as default

    - #### _getFallbackBundle

          protected abstract java.util.ResourceBundle _getFallbackBundle()

      Get the fallback resource bundle.
      Returns:
        fallback bundle

    - #### _getBundle

          @NotNull
          protected abstract java.util.ResourceBundle _getBundle(@Nullable
                                                                          java.util.Locale l)
                                                                   throws java.util.MissingResourceException

      Get a ResourceBundle for a locale.
      Parameters:
        `l` - locale
      Returns:
        ResourceBundle for that Locale
      Throws:
        `java.util.MissingResourceException` - when no appResourceBase is set

    - #### _dumpResources

          protected abstract void _dumpResources(@NotNull
                                                 java.io.PrintStream out,
                                                 @Nullable
                                                 java.util.Locale locale)

      Dump the complete currently known i18n resources for a given locale.
      Parameters:
        `out` - print stream where to dump to
        `locale` - locale for which to dump the resources

    - #### dump

          public static void dump(@NotNull
                                  java.io.PrintStream out,
                                  @Nullable
                                  java.util.Locale locale)

      Dump the complete currently known i18n resources for a given locale.
      Parameters:
        `out` - print stream where to dump to
        `locale` - locale for which to dump the resources

    - #### getString

          @NotNull
          public static java.lang.String getString(@NotNull
                                                            java.lang.String tag)
                                                     throws java.util.MissingResourceException

      Get a string for the default locale.
      Parameters:
        `tag` - resource tag
      Returns:
        localized string
      Throws:
        `java.util.MissingResourceException` - when no appResourceBase is set

    - #### getString

          @NotNull
          public static java.lang.String getString(@NotNull
                                                            java.lang.String tag,
                                                            @Nullable
                                                            java.util.Locale l)
                                                     throws java.util.MissingResourceException

      Get a String specified by a Locale.
      Parameters:
        `tag` - resource tag
        `l` - Locale to be used
      Returns:
        localized String
      Throws:
        `java.util.MissingResourceException` - when no appResourceBase is set
      See Also:
        `ResourceBundle.getString(java.lang.String)`

    - #### format

          @NotNull
          public static java.lang.String format(@NotNull
                                                         java.lang.String tag,
                                                         java.lang.Object... args)
                                                  throws java.util.MissingResourceException

      Compile a String with a format using the default locale.
      Parameters:
        `tag` - resource tag of format
        `args` - arguments
      Returns:
        formatted string
      Throws:
        `java.util.MissingResourceException` - when no appResourceBase is set
      See Also:
        `Utility.compileString(java.lang.String, java.lang.Object[], java.util.ResourceBundle)`

    - #### format

          @NotNull
          public static java.lang.String format(@Nullable
                                                         java.util.Locale l,
                                                         @NotNull
                                                         java.lang.String tag,
                                                         java.lang.Object... args)
                                                  throws java.util.MissingResourceException

      Compile a String with a format.
      Parameters:
        `l` - locale
        `tag` - resource tag of format
        `args` - arguments
      Returns:
        formatted string
      Throws:
        `java.util.MissingResourceException` - when no appResourceBase is set
      See Also:
        `Utility.compileString(java.lang.String, java.lang.Object[], java.util.ResourceBundle)`

    - #### getFormattedString

          @NotNull
          public static java.lang.String getFormattedString(@NotNull
                                                                     java.lang.String tag,
                                                                     java.lang.Object... args)
                                                              throws java.util.MissingResourceException

      Compile a String with a format using the default locale.
      Parameters:
        `tag` - resource tag of format
        `args` - arguments
      Returns:
        formatted string
      Throws:
        `java.util.MissingResourceException` - when no appResourceBase is set
      See Also:
        `Utility.compileString(java.lang.String, java.lang.Object[], java.util.ResourceBundle)`

    - #### getFormattedString

          @NotNull
          public static java.lang.String getFormattedString(@Nullable
                                                                     java.util.Locale l,
                                                                     @NotNull
                                                                     java.lang.String tag,
                                                                     java.lang.Object... args)
                                                              throws java.util.MissingResourceException

      Compile a String with a format.
      Parameters:
        `l` - locale
        `tag` - resource tag of format
        `args` - arguments
      Returns:
        formatted string
      Throws:
        `java.util.MissingResourceException` - when no appResourceBase is set
      See Also:
        `Utility.compileString(java.lang.String, java.lang.Object[], java.util.ResourceBundle)`

    - #### addLocalizationChangeListener

          public static void addLocalizationChangeListener(@NotNull
                                                           Localizable localizable)

      Add a listener for localization changes.
      Parameters:
        `localizable` - listener for changes

    - #### _addLocalizationChangeListener

          protected abstract void _addLocalizationChangeListener(@NotNull
                                                                 Localizable localizable)

      Add a listener for localization changes.
      Parameters:
        `localizable` - listener for changes

    - #### removeLocalizationChangeListener

          public static void removeLocalizationChangeListener(@NotNull
                                                              Localizable localizable)

      Remove a listener for localization changes.
      Parameters:
        `localizable` - listener to be removed

    - #### _removeLocalizationChangeListener

          protected abstract void _removeLocalizationChangeListener(@NotNull
                                                                    Localizable localizable)

      Remove a listener for localization changes.
      Parameters:
        `localizable` - listener to be removed

    - #### _fireLocaleChanged

          protected abstract void _fireLocaleChanged(java.util.Locale locale)

      Tell all registered localizables of localization changes.
      Parameters:
        `locale` - new locale

    - #### getIcon

          @Nullable
          public static javax.swing.Icon getIcon(@NotNull
                                                           java.lang.String tag)

      Get an icon from a tag defining its location, using the default locale.
      Parameters:
        `tag` - i18n tag
      Returns:
        icon or `null` if there is no icon defined for the tag or it cannot be loaded

    - #### getIcon

          @Nullable
          public static javax.swing.Icon getIcon(@NotNull
                                                           java.lang.String tag,
                                                           @Nullable
                                                           java.util.Locale locale)

      Get an icon from a tag defining its location.
      Parameters:
        `tag` - i18n tag
        `locale` - locale
      Returns:
        icon or `null` if there is no icon defined for the tag or it cannot be loaded