Class Translation

java.lang.Object
org.nuclos.api.l10n.Translation

public class Translation extends Object
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

    Constructors
    Constructor
    Description
    Creates a new Translation with the specified 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 Type
    Method
    Description
    get()
    Gets the translated text.
    Gets the translated text and throws an exception if translation fails.
    withArgs(Object... args)
    Adds message format arguments to the translation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Translation

      public Translation(String text)
      Creates a new Translation with the specified text.
      Parameters:
      text - The text to translate
    • Translation

      public Translation(String text, Locale sourceLocale)
      Creates a new Translation with the specified text and source locale.
      Parameters:
      text - The text to translate
      sourceLocale - The source locale of the text
    • Translation

      public Translation(String text, NuclosLocale sourceLocale)
      Creates a new Translation with the specified text and Nuclos source locale.
      Parameters:
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
    • Translation

      public Translation(String text, Locale sourceLocale, Locale targetLocale)
      Creates a new Translation with the specified text, source locale, and target locale.
      Parameters:
      text - The text to translate
      sourceLocale - The source locale of the text
      targetLocale - The target locale for translation
    • Translation

      public Translation(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale)
      Creates a new Translation with the specified text, Nuclos source locale, and Nuclos target locale.
      Parameters:
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
      targetLocale - 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 translate
      sourceLocale - The Nuclos source locale of the text
      targetLocale - The Nuclos target locale for translation
      timeoutMillisForTranslatorRequest - 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 translate
      sourceLocale - The source locale of the text
      targetLocale - The target locale for translation
      timeoutMillisForTranslatorRequest - The timeout in milliseconds for the translator request
    • Translation

      public Translation(String key, String text)
      Creates a new Translation with the specified localization key and text.
      Parameters:
      key - The localization key
      text - The text to translate
    • Translation

      public Translation(String key, String text, Locale sourceLocale)
      Creates a new Translation with the specified localization key, text, and source locale.
      Parameters:
      key - The localization key
      text - The text to translate
      sourceLocale - The source locale of the text
    • Translation

      public Translation(String key, String text, NuclosLocale sourceLocale)
      Creates a new Translation with the specified localization key, text, and Nuclos source locale.
      Parameters:
      key - The localization key
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
    • Translation

      public Translation(String key, String text, Locale sourceLocale, Locale targetLocale)
      Creates a new Translation with the specified localization key, text, source locale, and target locale.
      Parameters:
      key - The localization key
      text - The text to translate
      sourceLocale - The source locale of the text
      targetLocale - The target locale for translation
    • Translation

      public 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.
      Parameters:
      key - The localization key
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
      targetLocale - 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 key
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
      targetLocale - The Nuclos target locale for translation
      timeoutMillisForTranslatorRequest - 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 key
      text - The text to translate
      sourceLocale - The source locale of the text
      targetLocale - The target locale for translation
      timeoutMillisForTranslatorRequest - The timeout in milliseconds for the translator request
  • Method Details

    • withArgs

      public Translation withArgs(Object... args)
      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

      public String 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

      public String getChecked() throws Exception
      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