Class Messages

java.lang.Object
ch.autumo.ui.utils.Messages

public final class Messages extends Object
Thin i18n facade of the autumo-ui resource bundle.

The catalogue itself lives in autumo-ui: Helper.getMessageBundle(…) resolves the gettext PO files (lang/messages.<lang>.po, see PoResourceBundle) first and falls back to the framework bundle for the framework's own keys. This class therefore only adds the conventions that go beyond that lookup:

The language is resolved once at start-up (see BaseApp.resolveLanguage(java.util.Properties): request parameter, configuration, desktop language) and can be switched at runtime.

  • Field Details

    • LANG_EN

      public static final String LANG_EN
      The source language of the application; also the fallback for missing translations.
      See Also:
  • Method Details

    • getLanguage

      public static String getLanguage()
      The active language code, e.g. en or de.
      Returns:
      plain ISO 639-1 language code
    • setLanguage

      public static int setLanguage(String lang, BaseApp app)
      Switches the application language via the framework.

      A region is ignored (de_CH and de-CH both select German) and unknown or blank values fall back to English, exactly like Helper.setLanguage(String). The framework also moves the JVM default locale and the user.language system property, so framework bundles and the per-language About HTML follow the choice.

      Parameters:
      lang - language code, e.g. en or de
      app - base app
      Returns:
      number of translations in the catalogue (0 for English apart from the framework-key overrides)
    • t

      public static String t(String id, BaseApp app)
      Translates id and returns id itself when it is not translated.
      Parameters:
      id - message id, which is the English text
      app - base app
      Returns:
      translated text or the id
    • t

      public static String t(String id, String english, BaseApp app)
      Translates id and falls back to english when there is no translation.

      This is what the metadata-driven parameter labels use: their message id is the raw configuration key (e.g. data_path) and the fallback is the English label the code derives from that key ("Data path"). A catalogue can then translate the parameter by its key, and everything that is not translated stays as it is.

      Parameters:
      id - message id, e.g. the raw configuration key
      english - English fallback text
      app - base app
      Returns:
      translated text or english
    • format

      public static String format(String id, BaseApp app, Object... args)
      Translates id and formats it with MessageFormat ({0}, {1}, …).
      Parameters:
      id - message id
      app - base app
      args - MessageFormat arguments
      Returns:
      formatted text; the raw pattern when it is malformed
    • size

      public static int size(BaseApp app)
      Number of entries the PO catalogue of the active language carries.

      English is the source language and ships only the framework-key overrides, so a value of 0 means "no catalogue at all" (unknown language).

      Parameters:
      app - base app
      Returns:
      number of translated messages
    • setLanguage

      public static int setLanguage(String lang, String basePath)
      Switches the application language via the framework.

      A region is ignored (de_CH and de-CH both select German) and unknown or blank values fall back to English, exactly like Helper.setLanguage(String). The framework also moves the JVM default locale and the user.language system property, so framework bundles and the per-language About HTML follow the choice.

      Parameters:
      lang - language code, e.g. en or de
      basePath - base path, e.g. "ch/autumo/ui"
      Returns:
      number of translations in the catalogue (0 for English apart from the framework-key overrides)
    • t

      public static String t(String id, String basePath)
      Translates id and returns id itself when it is not translated.
      Parameters:
      id - message id, which is the English text
      basePath - base path, e.g. "ch/autumo/ui"
      Returns:
      translated text or the id
    • t

      public static String t(String id, String english, String basePath)
      Translates id and falls back to english when there is no translation.

      This is what the metadata-driven parameter labels use: their message id is the raw configuration key (e.g. data_path) and the fallback is the English label the code derives from that key ("Data path"). A catalogue can then translate the parameter by its key, and everything that is not translated stays as it is.

      Parameters:
      id - message id, e.g. the raw configuration key
      english - English fallback text
      basePath - base path, e.g. "ch/autumo/ui"
      Returns:
      translated text or english
    • format

      public static String format(String id, String basePath, Object... args)
      Translates id and formats it with MessageFormat ({0}, {1}, …).
      Parameters:
      id - message id
      basePath - base path, e.g. "ch/autumo/ui"
      args - MessageFormat arguments
      Returns:
      formatted text; the raw pattern when it is malformed
    • size

      public static int size(String basePath)
      Number of entries the PO catalogue of the active language carries.

      English is the source language and ships only the framework-key overrides, so a value of 0 means "no catalogue at all" (unknown language).

      Parameters:
      basePath - base path, e.g. "ch/autumo/ui"
      Returns:
      number of translated messages