Package ch.tocco.nice2.textresources.api
Interface TextResources
- All Known Implementing Classes:
SimpleTextResourcesImpl
public interface TextResources
provides access to all text resources
-
Method Summary
Modifier and TypeMethodDescriptionformatTextMessage
(TextMessage textMessage) Formats a text message object and returns the formatted string.formatTextMessage
(TextMessage msg, @Nullable Locale locale) Formats a text message object and returns the formatted string.Get information for this key.Same behaviour asgetAll(Pattern, Locale)
but theLocale
of the current Thread will be used.Same behaviour asgetAll(Pattern, Locale)
but this method will determine the bestLocale
from the givenList
itself.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 messageGet a text for this specific key.Get a text for this specific key and locale.boolean
isTextMissingString
(String message) Tells if the message returned by thegetText(java.lang.String)
methods is a constructed fallback message because a real translation was missing.void
onReload()
@Nullable String
tryGetText
(String key) Same asgetText(String)
, but returns null if the resource doesn't exist, and logs no error.@Nullable String
tryGetText
(String key, Locale locale) Same asgetText(String)
, but returns null if the resource doesn't exist, and logs no error.
-
Method Details
-
formatTextMessage
Formats a text message object and returns the formatted string.- Returns:
- The formatted string text.
-
getFormattedTextWithParameter
Replaces [param] in the text resource with the passed parameter and formats the text message- Returns:
- The formatted string text.
-
formatTextMessage
Formats a text message object and returns the formatted string.- Returns:
- The formatted string text.
-
get
Get 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.- Returns:
- the elements are: String message, Boolean if succeeded (otherwise fallback message), Locale the chosen one (null if none)
-
get
-
onReload
void onReload() -
get
-
getText
Get a text for this specific key. Same behaviour asgetText(String, Locale)
but uses theLocale
provided byL10N.currentLocale()
and the calling module as module. Reports (logs) in case the text is missing.- Parameters:
key
- the key- Returns:
- the text
-
getText
Get a text for this specific key and locale. Reports (logs) in case the text is missing.- Parameters:
key
- the keylocale
- the locale- Returns:
- the text
-
tryGetText
Same asgetText(String)
, but returns null if the resource doesn't exist, and logs no error.- Parameters:
key
- the key- Returns:
- the text, or null if not there
-
tryGetText
Same asgetText(String)
, but returns null if the resource doesn't exist, and logs no error.- Parameters:
key
- the key- Returns:
- the text, or null if not there
-
isTextMissingString
Tells if the message returned by thegetText(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.- Parameters:
message
- the result of agetText(java.lang.String)
call- Returns:
- if the message was missing
-
getAll
Same behaviour asgetAll(Pattern, Locale)
but theLocale
of the current Thread will be used.- Parameters:
pattern
- eg "^client\\..*"- Returns:
- May be empty, may contain null values!
-
getAll
Returns 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.- Parameters:
pattern
- eg "^client\\..*"
-
getAll
Same behaviour asgetAll(Pattern, Locale)
but this method will determine the bestLocale
from the givenList
itself.- Parameters:
pattern
- eg "^client\\..*"- Returns:
- May be empty, may contain null values!
-