Package io.goobi.viewer.messages
Class ViewerResourceBundle
java.lang.Object
java.util.ResourceBundle
io.goobi.viewer.messages.ViewerResourceBundle
ViewerResourceBundle class.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.ResourceBundle
ResourceBundle.Control
-
Field Summary
Modifier and TypeFieldDescriptionprotected static Locale
ConstantdefaultLocale
protected static Map<Locale,
ResourceBundle> ConstantlocalBundles
ConstantreloadNeededMap
Fields inherited from class java.util.ResourceBundle
parent
-
Constructor Summary
ConstructorDescriptionConstructor for ViewerResourceBundle.ViewerResourceBundle
(Path localConfigPath) -
Method Summary
Modifier and TypeMethodDescriptionstatic String
cleanUpTranslation
(String value) Removes the "zzz" marker from the given string.static void
Creates a local messages_xx.properties file for every locale in the Faces context, if not already present.Getter for the fieldallLocales
.getAllLocales
(javax.servlet.ServletContext servletContext) static Locale
Getter for the fielddefaultLocale
.static Locale
getDefaultLocale
(javax.servlet.ServletContext servletContext) static Locale
getDefaultLocaleFromFacesConfig
(javax.servlet.ServletContext servletContext) static Locale
getDefaultLocaleFromFile
(Path facesConfigPath) static Locale
Returns a locale for the configured fallback language.getKeys()
getLocalesFromFacesConfig
(javax.servlet.ServletContext servletContext) Get locales configured in faces-config, ordered by appearance in filegetLocalesFromFile
(Path facesConfigPath) static File
getLocalTranslationFile
(String language) getMessagesValues
(Locale locale, String keyPrefix) getMessagesValues.static String
getTranslation
(String key, Locale locale) getTranslation.static String
getTranslation
(String key, Locale locale, boolean useFallback) getTranslation.static String
getTranslation
(String key, Locale locale, boolean useFallback, boolean cleanup) static String
getTranslation
(String key, Locale locale, boolean useFallback, boolean reversePriority, boolean cleanup) getTranslation.static String
getTranslation
(String key, Locale inLocale, boolean useFallback, boolean returnKeyIfNoneFound, boolean reversePriority, boolean cleanup) getTranslation.protected static String
getTranslation
(String key, ResourceBundle fallbackBundle, ResourceBundle preferredBundle, boolean cleanup) Translation method with ResourceBundle parameters.static de.intranda.metadata.multilanguage.IMetadataValue
getTranslations
(String key) Returns a Multilanguage metadata value containing all found translations for thekey
, or the key itself if not translations were foundstatic de.intranda.metadata.multilanguage.IMetadataValue
getTranslations
(String key, boolean allowKeyAsTranslation) static de.intranda.metadata.multilanguage.IMetadataValue
getTranslations
(String key, List<Locale> locales, boolean allowKeyAsTranslation) static String
getTranslationWithParameters
(String key, Locale locale, boolean removeRemainingPlaceholders, String... params) getTranslationWithParameters.protected Object
handleGetObject
(String key) This is the method that is called for HTML translations.static void
init
(javax.servlet.ServletContext servletContext) static boolean
updateLocalMessageKey
(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()Constructor for ViewerResourceBundle.
-
ViewerResourceBundle
-
-
Method Details
-
getDefaultLocale
Getter for the field
defaultLocale
.- Returns:
- a
Locale
object.
-
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:
handleGetObject
in classResourceBundle
-
getTranslation
getTranslation.
-
getTranslationWithParameters
public static String getTranslationWithParameters(String key, Locale locale, boolean removeRemainingPlaceholders, String... params) getTranslationWithParameters.
-
translate
-
getTranslation
getTranslation.
-
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 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
- aString
object.- Returns:
- Cleaned-up value
-
getMessagesValues
getMessagesValues.
-
getKeys
- Specified by:
getKeys
in 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 field
allLocales
.- Returns:
- a
List
object.
-
getAllLocales
- Parameters:
servletContext
-- Returns:
- List of all configured
Locale
s
-
getDefaultLocale
- Parameters:
servletContext
-- Returns:
- Default
Locale
-
getFacesLocales
-
getLocalesFromFacesConfig
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
- 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:
Locale
s 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
- 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
-