Package org.nuclos.api.l10n
Class Translation
java.lang.Object
org.nuclos.api.l10n.Translation
The Translation class provides a way to translate text between different locales.
It supports various translation options including in-memory translations and translations with localization keys.
-
Constructor Summary
ConstructorsConstructorDescriptionTranslation
(String text) Creates a new Translation with the specified text.Translation
(String key, String text) Creates a new Translation with the specified localization key and text.Translation
(String key, String text, Locale sourceLocale) Creates a new Translation with the specified localization key, text, and source locale.Translation
(String key, String text, Locale sourceLocale, Locale targetLocale) Creates a new Translation with the specified localization key, text, source locale, and target locale.Translation
(String key, String text, Locale sourceLocale, Locale targetLocale, int timeoutMillisForTranslatorRequest) Creates a new Translation with the specified localization key, text, source locale, target locale, and custom timeout.Translation
(String key, String text, NuclosLocale sourceLocale) Creates a new Translation with the specified localization key, text, and Nuclos source locale.Translation
(String key, String text, NuclosLocale sourceLocale, NuclosLocale targetLocale) Creates a new Translation with the specified localization key, text, Nuclos source locale, and Nuclos target locale.Translation
(String key, String text, NuclosLocale sourceLocale, NuclosLocale targetLocale, int timeoutMillisForTranslatorRequest) Creates a new Translation with the specified localization key, text, Nuclos source locale, Nuclos target locale, and custom timeout.Translation
(String text, Locale sourceLocale) Creates a new Translation with the specified text and source locale.Translation
(String text, Locale sourceLocale, Locale targetLocale) Creates a new Translation with the specified text, source locale, and target locale.Translation
(String text, Locale sourceLocale, Locale targetLocale, int timeoutMillisForTranslatorRequest) Creates a new Translation with the specified text, source locale, target locale, and custom timeout.Translation
(String text, NuclosLocale sourceLocale) Creates a new Translation with the specified text and Nuclos source locale.Translation
(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale) Creates a new Translation with the specified text, Nuclos source locale, and Nuclos target locale.Translation
(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale, int timeoutMillisForTranslatorRequest) Creates a new Translation with the specified text, Nuclos source locale, Nuclos target locale, and custom timeout. -
Method Summary
Modifier and TypeMethodDescriptionget()
Gets the translated text.Gets the translated text and throws an exception if translation fails.Adds message format arguments to the translation.
-
Constructor Details
-
Translation
Creates a new Translation with the specified text.- Parameters:
text
- The text to translate
-
Translation
Creates a new Translation with the specified text and source locale.- Parameters:
text
- The text to translatesourceLocale
- The source locale of the text
-
Translation
Creates a new Translation with the specified text and Nuclos source locale.- Parameters:
text
- The text to translatesourceLocale
- The Nuclos source locale of the text
-
Translation
Creates a new Translation with the specified text, source locale, and target locale.- Parameters:
text
- The text to translatesourceLocale
- The source locale of the texttargetLocale
- The target locale for translation
-
Translation
Creates a new Translation with the specified text, Nuclos source locale, and Nuclos target locale.- Parameters:
text
- The text to translatesourceLocale
- The Nuclos source locale of the texttargetLocale
- The Nuclos target locale for translation
-
Translation
public Translation(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale, int timeoutMillisForTranslatorRequest) Creates a new Translation with the specified text, Nuclos source locale, Nuclos target locale, and custom timeout.- Parameters:
text
- The text to translatesourceLocale
- The Nuclos source locale of the texttargetLocale
- The Nuclos target locale for translationtimeoutMillisForTranslatorRequest
- The timeout in milliseconds for the translator request
-
Translation
public Translation(String text, Locale sourceLocale, Locale targetLocale, int timeoutMillisForTranslatorRequest) Creates a new Translation with the specified text, source locale, target locale, and custom timeout.- Parameters:
text
- The text to translatesourceLocale
- The source locale of the texttargetLocale
- The target locale for translationtimeoutMillisForTranslatorRequest
- The timeout in milliseconds for the translator request
-
Translation
Creates a new Translation with the specified localization key and text.- Parameters:
key
- The localization keytext
- The text to translate
-
Translation
Creates a new Translation with the specified localization key, text, and source locale.- Parameters:
key
- The localization keytext
- The text to translatesourceLocale
- The source locale of the text
-
Translation
Creates a new Translation with the specified localization key, text, and Nuclos source locale.- Parameters:
key
- The localization keytext
- The text to translatesourceLocale
- The Nuclos source locale of the text
-
Translation
Creates a new Translation with the specified localization key, text, source locale, and target locale.- Parameters:
key
- The localization keytext
- The text to translatesourceLocale
- The source locale of the texttargetLocale
- The target locale for translation
-
Translation
Creates a new Translation with the specified localization key, text, Nuclos source locale, and Nuclos target locale.- Parameters:
key
- The localization keytext
- The text to translatesourceLocale
- The Nuclos source locale of the texttargetLocale
- The Nuclos target locale for translation
-
Translation
public Translation(String key, String text, NuclosLocale sourceLocale, NuclosLocale targetLocale, int timeoutMillisForTranslatorRequest) Creates a new Translation with the specified localization key, text, Nuclos source locale, Nuclos target locale, and custom timeout.- Parameters:
key
- The localization keytext
- The text to translatesourceLocale
- The Nuclos source locale of the texttargetLocale
- The Nuclos target locale for translationtimeoutMillisForTranslatorRequest
- The timeout in milliseconds for the translator request
-
Translation
public Translation(String key, String text, Locale sourceLocale, Locale targetLocale, int timeoutMillisForTranslatorRequest) Creates a new Translation with the specified localization key, text, source locale, target locale, and custom timeout.- Parameters:
key
- The localization keytext
- The text to translatesourceLocale
- The source locale of the texttargetLocale
- The target locale for translationtimeoutMillisForTranslatorRequest
- The timeout in milliseconds for the translator request
-
-
Method Details
-
withArgs
Adds message format arguments to the translation. These arguments will be used for formatting the translated text using MessageFormatter.- Parameters:
args
- The message format arguments- Returns:
- This Translation instance for method chaining
-
get
Gets the translated text. If the translation has not been performed yet, it will be performed now. If message arguments have been provided, they will be applied to the translated text.- Returns:
- The translated text, or an empty string if the translated text is null
-
getChecked
Gets the translated text and throws an exception if translation fails. If the translation has not been performed yet, it will be performed now. If message arguments have been provided, they will be applied to the translated text.- Returns:
- The translated text, or an empty string if the translated text is null
- Throws:
Exception
- If translation fails
-