Class SimpleTextResourcesImpl
java.lang.Object
ch.tocco.nice2.textresources.impl.SimpleTextResourcesImpl
- All Implemented Interfaces:
TextResources
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionformatTextMessage(TextMessage textMessage) Formats a text message object and returns the formatted string.formatTextMessage(TextMessage textMessage, Locale locale) Formats a text message object and returns the formatted string.Get information for this key.Same behaviour asTextResources.getAll(Pattern, Locale)but theLocaleof the current Thread will be used.Same behaviour asTextResources.getAll(Pattern, Locale)but this method will determine the bestLocalefrom the givenListitself.Returns all texts for the given locale which match a regex pattern.getFormattedTextWithParameter(String textResourceKey, String parameter) Replaces [param] in the text resource with the passed parameter and formats the text messagegetLocalesWithText(String key) Tells which locales have a (possibly empty) text defined.Get a text for this specific key.Get a text for this specific key and locale.voidbooleanisTextMissingString(String message) Tells if the message returned by theTextResources.getText(java.lang.String)methods is a constructed fallback message because a real translation was missing.voidonReload()voidsetTextResourceProviders(List<TextResourceProvider> providers) @Nullable StringtryGetText(String key) Same asTextResources.getText(String), but returns null if the resource doesn't exist, and logs no error.@Nullable StringtryGetText(String key, Locale locale) Same asTextResources.getText(String), but returns null if the resource doesn't exist, and logs no error.
-
Constructor Details
-
SimpleTextResourcesImpl
-
-
Method Details
-
initialize
@PostConstruct public void initialize() -
formatTextMessage
Description copied from interface:TextResourcesFormats a text message object and returns the formatted string.- Specified by:
formatTextMessagein interfaceTextResources- Returns:
- The formatted string text.
-
getFormattedTextWithParameter
Description copied from interface:TextResourcesReplaces [param] in the text resource with the passed parameter and formats the text message- Specified by:
getFormattedTextWithParameterin interfaceTextResources- Returns:
- The formatted string text.
-
formatTextMessage
Description copied from interface:TextResourcesFormats a text message object and returns the formatted string.- Specified by:
formatTextMessagein interfaceTextResources- Returns:
- The formatted string text.
-
get
- Specified by:
getin interfaceTextResources
-
get
Description copied from interface:TextResourcesGet information for this key. The fallback behavior depends on the environment. If there is no message defined in a desired language then: + in production: any other language is chosen (preferably a close one, or a common one, no guarantee) the Boolean is set to false, and the Locale tells which language was finally chosen. in case there isn't a message in ANY language then the behavior is as in dev/test. + in development and test: a message containing the message key is used, clearly stating that such a message is missing. the string does not use placeholders where variables could be put in, thus any variables (message formatting) should be appended by the formatter.- Specified by:
getin interfaceTextResources- Returns:
- the elements are: String message, Boolean if succeeded (otherwise fallback message), Locale the chosen one (null if none)
-
get
- Specified by:
getin interfaceTextResources
-
onReload
public void onReload()- Specified by:
onReloadin interfaceTextResources
-
getAll
Description copied from interface:TextResourcesSame behaviour asTextResources.getAll(Pattern, Locale)but theLocaleof the current Thread will be used.- Specified by:
getAllin interfaceTextResources- Parameters:
pattern- eg "^client\\..*"- Returns:
- May be empty, may contain null values!
-
getAll
Description copied from interface:TextResourcesReturns all texts for the given locale which match a regex pattern. May contain null values. That is the case if there is no definition for a key in the desired locale.- Specified by:
getAllin interfaceTextResources- Parameters:
pattern- eg "^client\\..*"
-
getAll
Description copied from interface:TextResourcesSame behaviour asTextResources.getAll(Pattern, Locale)but this method will determine the bestLocalefrom the givenListitself.- Specified by:
getAllin interfaceTextResources- Parameters:
pattern- eg "^client\\..*"- Returns:
- May be empty, may contain null values!
-
getText
Description copied from interface:TextResourcesGet a text for this specific key. Same behaviour asTextResources.getText(String, Locale)but uses theLocaleprovided byL10N.currentLocale()and the calling module as module. Reports (logs) in case the text is missing.- Specified by:
getTextin interfaceTextResources- Parameters:
key- the key- Returns:
- the text
-
getText
Description copied from interface:TextResourcesGet a text for this specific key and locale. Reports (logs) in case the text is missing.- Specified by:
getTextin interfaceTextResources- Parameters:
key- the keypreferredLocale- the locale- Returns:
- the text
-
tryGetText
Description copied from interface:TextResourcesSame asTextResources.getText(String), but returns null if the resource doesn't exist, and logs no error.- Specified by:
tryGetTextin interfaceTextResources- Parameters:
key- the key- Returns:
- the text, or null if not there
-
tryGetText
Description copied from interface:TextResourcesSame asTextResources.getText(String), but returns null if the resource doesn't exist, and logs no error.- Specified by:
tryGetTextin interfaceTextResources- Parameters:
key- the key- Returns:
- the text, or null if not there
-
isTextMissingString
Description copied from interface:TextResourcesTells if the message returned by theTextResources.getText(java.lang.String)methods is a constructed fallback message because a real translation was missing. Maybe we'll have to add more overloaded getText() methods with another param by ref that tells if the resource was missing, or which locale was chosen, null if failed. This method just checks if the message starts with the failing indicator "##". Works for now.- Specified by:
isTextMissingStringin interfaceTextResources- Parameters:
message- the result of aTextResources.getText(java.lang.String)call- Returns:
- if the message was missing
-
getLocalesWithText
Tells which locales have a (possibly empty) text defined. This can be used for choosing a fallback language to at least display something human-readable in a production environment. This method does not log anything missing.- Returns:
- may be empty
-
setTextResourceProviders
-