Package io.goobi.viewer.messages
Class ViewerResourceBundle
java.lang.Object
java.util.ResourceBundle
io.goobi.viewer.messages.ViewerResourceBundle
Custom ResourceBundle implementation that loads and merges viewer message files from configurable locations.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.ResourceBundle
ResourceBundle.Control -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static LocaleConstantdefaultLocale.protected static Map<Locale, ResourceBundle> ConstantlocalBundles.ConstantreloadNeededMap.Fields inherited from class java.util.ResourceBundle
parent -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new ViewerResourceBundle instance.ViewerResourceBundle(Path localConfigPath) Creates a new ViewerResourceBundle instance with the given local config path. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcleanUpTranslation(String value) Removes the "zzz" marker from the given string.static voidCreates a local messages_xx.properties file for every locale in the Faces context, if not already present.Getter for the fieldallLocales.getAllLocales(ServletContext servletContext) static LocaleGetter for the fielddefaultLocale.static LocalegetDefaultLocale(ServletContext servletContext) static LocalegetDefaultLocaleFromFacesConfig(ServletContext servletContext) static LocalegetDefaultLocaleFromFile(Path facesConfigPath) static LocaleReturns a locale for the configured fallback language.getKeys()getLocalesFromFacesConfig(ServletContext servletContext) Gets locales configured in faces-config, ordered by appearance in file.getLocalesFromFile(Path facesConfigPath) static FilegetLocalTranslationFile(String language) getMessagesValues(Locale locale, String keyPrefix) getMessagesValues.static StringgetTranslation(String key, Locale locale) getTranslation.static StringgetTranslation(String key, Locale locale, boolean useFallback) getTranslation.static StringgetTranslation(String key, Locale locale, boolean useFallback, boolean cleanup) static StringgetTranslation(String key, Locale locale, boolean useFallback, boolean reversePriority, boolean cleanup) getTranslation.static StringgetTranslation(String key, Locale inLocale, boolean useFallback, boolean returnKeyIfNoneFound, boolean reversePriority, boolean cleanup) getTranslation.protected static StringgetTranslation(String key, ResourceBundle fallbackBundle, ResourceBundle preferredBundle, boolean cleanup) Translation method with ResourceBundle parameters.static de.intranda.metadata.multilanguage.IMetadataValuegetTranslations(String key) Returns a Multilanguage metadata value containing all found translations for thekey, or the key itself if not translations were found.static de.intranda.metadata.multilanguage.IMetadataValuegetTranslations(String key, boolean allowKeyAsTranslation) static de.intranda.metadata.multilanguage.IMetadataValuegetTranslations(String key, List<Locale> locales, boolean allowKeyAsTranslation) static StringgetTranslationWithParameters(String key, Locale locale, boolean removeRemainingPlaceholders, String... params) getTranslationWithParameters.protected ObjecthandleGetObject(String key) static voidinit(ServletContext servletContext) static voidshutdown()static booleanupdateLocalMessageKey(String key, String value, String language) Methods inherited from class java.util.ResourceBundle
clearCache, clearCache, containsKey, getBaseBundleName, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, handleKeySet, keySet, setParent
-
Field Details
-
localBundles
ConstantlocalBundles. -
reloadNeededMap
ConstantreloadNeededMap. -
defaultLocale
ConstantdefaultLocale.
-
-
Constructor Details
-
ViewerResourceBundle
public ViewerResourceBundle()Creates a new ViewerResourceBundle instance. -
ViewerResourceBundle
Creates a new ViewerResourceBundle instance with the given local config path.- Parameters:
localConfigPath- path to the local configuration directory containing messages files
-
-
Method Details
-
shutdown
public static void shutdown() -
getDefaultLocale
Getter for the fielddefaultLocale.- Returns:
- the default application locale, falling back to English if not configured
-
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
This is the method that is called for HTML translations.
- Specified by:
handleGetObjectin classResourceBundle
-
getTranslation
getTranslation.- Parameters:
key- message key to translatelocale- desired locale for the translation- Returns:
- the translated message for the given key and locale, or the key itself if no translation is found
-
getTranslationWithParameters
public static String getTranslationWithParameters(String key, Locale locale, boolean removeRemainingPlaceholders, String... params) getTranslationWithParameters.- Parameters:
key- message key to translatelocale- desired locale for the translationremoveRemainingPlaceholders- If true, any placeholders in the value not replaced by params are removedparams- One or more parameter values to replace the placeholders- Returns:
- the translated message for the given key with parameters substituted
-
translate
-
getTranslation
getTranslation.- Parameters:
key- message key to translatelocale- desired locale for the translationuseFallback- 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- message key to translatelocale- locale for which to retrieve the translationuseFallback- if true, fall back to default locale when no translation foundcleanup- if true, remove markers such as 'zzz' from the result- 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 translatelocale- Desired localeuseFallback- If true, get default locale translation if there is none for the given localereversePriority- If true, the global bundle will be checked first, then the localcleanup- 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 translateinLocale- Desired localeuseFallback- If true, get default locale translation if there is none for the given localereturnKeyIfNoneFound- If true, the key will be returned as translation value; null otherwisereversePriority- If true, the global bundle will be checked first, then the localcleanup- 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 keyfallbackBundle- Fallback bundle if no value is found in preferredBundlepreferredBundle- Check for a translation in this bundle firstcleanup- If true, elements such as 'zzz' will be removed from the translation- Returns:
- Translated message key
-
cleanUpTranslation
Removes the "zzz" marker from the given string.- Parameters:
value- translation string to clean up- Returns:
- Cleaned-up value
-
getMessagesValues
getMessagesValues.- Parameters:
locale- locale of the resource bundle to searchkeyPrefix- prefix that returned keys must start with- Returns:
- a list of message key strings from the given locale's resource bundle that start with the given prefix
-
getKeys
- Specified by:
getKeysin classResourceBundle
-
getTranslations
Returns a Multilanguage metadata value containing all found translations for thekey, 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
-
getAllLocales
Getter for the fieldallLocales.- Returns:
- a list of all locales supported by the JSF application
-
getAllLocales
- Parameters:
servletContext- servlet context used to locate the faces-config.xml- Returns:
- List of all configured
Locales
-
getDefaultLocale
- Parameters:
servletContext- servlet context used to locate the faces-config.xml- Returns:
- Default
Locale
-
getFacesLocales
-
getLocalesFromFacesConfig
Gets locales configured in faces-config, ordered by appearance in file.- Parameters:
servletContext- servlet context used to locate the faces-config.xml- Returns:
- a list of Locale objects, or null if the list could not be retrieved
-
getDefaultLocaleFromFacesConfig
- Parameters:
servletContext- servlet context used to locate the faces-config.xml- 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- path to the faces-config.xml file to parse- Returns:
Locales configured in given file path- Throws:
IOExceptionorg.jdom2.JDOMException
-
getDefaultLocaleFromFile
public static Locale getDefaultLocaleFromFile(Path facesConfigPath) throws IOException, org.jdom2.JDOMException - Parameters:
facesConfigPath- path to the faces-config.xml file to parse- Returns:
- Default
Localeconfigured in given file path - Throws:
IOExceptionorg.jdom2.JDOMException
-
init
- Parameters:
servletContext- servlet context used to initialize locales and default locale
-
getAllKeys
- Returns:
- All message keys in the bundle
-
getAllLocalKeys
- Returns:
- Set of message keys from local messages_*.properties
-
updateLocalMessageKey
- Parameters:
key- Message keyvalue- Message valuelanguage- ISO 639-1 language code- Returns:
- true if file updated successfully; false otherwise
-
getLocalTranslationFile
-