Class ViewerResourceBundle

java.lang.Object
java.util.ResourceBundle
io.goobi.viewer.messages.ViewerResourceBundle

public class ViewerResourceBundle extends ResourceBundle

ViewerResourceBundle class.

  • Field Details

    • localBundles

      protected static Map<Locale,ResourceBundle> localBundles
      Constant localBundles
    • reloadNeededMap

      protected static Map<String,Boolean> reloadNeededMap
      Constant reloadNeededMap
    • defaultLocale

      protected static volatile Locale defaultLocale
      Constant defaultLocale
  • Constructor Details

    • ViewerResourceBundle

      public ViewerResourceBundle()

      Constructor for ViewerResourceBundle.

    • ViewerResourceBundle

      public ViewerResourceBundle(Path localConfigPath)
  • Method Details

    • getDefaultLocale

      public static Locale getDefaultLocale()

      Getter for the field defaultLocale.

      Returns:
      a Locale object.
    • getFallbackLocale

      public static Locale getFallbackLocale()
      Returns a locale for the configured fallback language. Does not use FacesContext.
      Returns:
      Locale for the language code returned by the configuration getter
    • handleGetObject

      protected Object handleGetObject(String key)
      This is the method that is called for HTML translations.
      Specified by:
      handleGetObject in class ResourceBundle
    • getTranslation

      public static String getTranslation(String key, Locale locale)

      getTranslation.

      Parameters:
      key - a String object.
      locale - a Locale object.
      Returns:
      a String object.
    • getTranslationWithParameters

      public static String getTranslationWithParameters(String key, Locale locale, boolean removeRemainingPlaceholders, String... params)

      getTranslationWithParameters.

      Parameters:
      key - a String object.
      locale - a Locale object.
      removeRemainingPlaceholders - If true, any placeholders in the value not replaced by params are removed
      params - One or more parameter values to replace the placeholders
      Returns:
      a String object.
    • getTranslation

      public static String getTranslation(String key, Locale locale, boolean useFallback)

      getTranslation.

      Parameters:
      key - a String object.
      locale - a Locale object.
      useFallback - If true, get default locale translation if there is none for the given locale
      Returns:
      Translated message key
    • getTranslation

      public static String getTranslation(String key, Locale locale, boolean useFallback, boolean cleanup)
      Parameters:
      key -
      locale -
      useFallback -
      cleanup -
      Returns:
      Translated message key
    • getTranslation

      public static String getTranslation(String key, Locale locale, boolean useFallback, boolean reversePriority, boolean cleanup)

      getTranslation.

      Parameters:
      key - Message key to translate
      locale - Desired locale
      useFallback - If true, get default locale translation if there is none for the given locale
      reversePriority - If true, the global bundle will be checked first, then the local
      cleanup - If true, elements such as 'zzz' will be removed from the translation
      Returns:
      Translated message key
    • getTranslation

      public static String getTranslation(String key, Locale inLocale, boolean useFallback, boolean returnKeyIfNoneFound, boolean reversePriority, boolean cleanup)

      getTranslation.

      Parameters:
      key - Message key to translate
      inLocale - Desired locale
      useFallback - If true, get default locale translation if there is none for the given locale
      returnKeyIfNoneFound - If true, the key will be returned as translation value; null otherwise
      reversePriority - If true, the global bundle will be checked first, then the local
      cleanup - If true, elements such as 'zzz' will be removed from the translation
      Returns:
      Translated message key
    • getTranslation

      protected static String getTranslation(String key, ResourceBundle fallbackBundle, ResourceBundle preferredBundle, boolean cleanup)
      Translation method with ResourceBundle parameters. It can be overridden from inheriting classes which may pass their own bundles.
      Parameters:
      key - Message key
      fallbackBundle - Fallback bundle if no value is found in preferredBundle
      preferredBundle - Check for a translation in this bundle first
      cleanup - If true, elements such as 'zzz' will be removed from the translation
      Returns:
      Translated message key
    • cleanUpTranslation

      public static String cleanUpTranslation(String value)
      Removes the "zzz" marker from the given string.
      Parameters:
      value - a String object.
      Returns:
      Cleaned-up value
    • getMessagesValues

      public static List<String> getMessagesValues(Locale locale, String keyPrefix)

      getMessagesValues.

      Parameters:
      locale - a Locale object.
      keyPrefix - a String object.
      Returns:
      a List object.
    • getKeys

      public Enumeration<String> getKeys()
      Specified by:
      getKeys in class ResourceBundle
    • getTranslations

      public static de.intranda.metadata.multilanguage.IMetadataValue getTranslations(String key)
      Returns a Multilanguage metadata value containing all found translations for the key, or the key itself if not translations were found
      Parameters:
      key - the message key
      Returns:
      A Multilanguage metadata value containing all found translations for the key, or the key itself if not translations were found
    • getTranslations

      public static de.intranda.metadata.multilanguage.IMetadataValue getTranslations(String key, boolean allowKeyAsTranslation)
    • getTranslations

      public static de.intranda.metadata.multilanguage.IMetadataValue getTranslations(String key, List<Locale> locales, boolean allowKeyAsTranslation)
    • getAllLocales

      public static List<Locale> getAllLocales()

      Getter for the field allLocales.

      Returns:
      a List object.
    • getAllLocales

      public static List<Locale> getAllLocales(javax.servlet.ServletContext servletContext)
      Parameters:
      servletContext -
      Returns:
      List of all configured Locales
    • getDefaultLocale

      public static Locale getDefaultLocale(javax.servlet.ServletContext servletContext)
      Parameters:
      servletContext -
      Returns:
      Default Locale
    • getFacesLocales

      public static List<Locale> getFacesLocales()
    • getLocalesFromFacesConfig

      public static List<Locale> getLocalesFromFacesConfig(javax.servlet.ServletContext servletContext)
      Get locales configured in faces-config, ordered by appearance in file
      Parameters:
      servletContext -
      Returns:
      a list of Locale objects, or null if the list could not be retrieved
    • getDefaultLocaleFromFacesConfig

      public static Locale getDefaultLocaleFromFacesConfig(javax.servlet.ServletContext servletContext)
      Parameters:
      servletContext -
      Returns:
      Default Locale
    • createLocalMessageFiles

      public static void createLocalMessageFiles()
      Creates a local messages_xx.properties file for every locale in the Faces context, if not already present.
    • getLocalesFromFile

      public static List<Locale> getLocalesFromFile(Path facesConfigPath) throws IOException, org.jdom2.JDOMException
      Parameters:
      facesConfigPath -
      Returns:
      Locales configured in given file path
      Throws:
      IOException
      org.jdom2.JDOMException
    • getDefaultLocaleFromFile

      public static Locale getDefaultLocaleFromFile(Path facesConfigPath) throws IOException, org.jdom2.JDOMException
      Parameters:
      facesConfigPath -
      Returns:
      Default Locale configured in given file path
      Throws:
      IOException
      org.jdom2.JDOMException
    • init

      public static void init(javax.servlet.ServletContext servletContext)
      Parameters:
      servletContext -
    • getAllKeys

      public static Set<String> getAllKeys()
      Returns:
      All message keys in the bundle
    • getAllLocalKeys

      public static Set<String> getAllLocalKeys()
      Returns:
      Set of message keys from local messages_*.properties
    • updateLocalMessageKey

      public static boolean updateLocalMessageKey(String key, String value, String language)
      Parameters:
      key - Message key
      value - Message value
      language - ISO 639-1 language code
      Returns:
      true if file updated successfully; false otherwise
    • getLocalTranslationFile

      public static File getLocalTranslationFile(String language)