Class LocalizationProvider

java.lang.Object
org.nuclos.api.provider.LocalizationProvider

public class LocalizationProvider extends Object
Provider class for localization and translation services in the Nuclos system. This class offers methods to translate text with or without persistence, get formatting information, and handle locale-specific operations.
  • Field Details

    • DEFAULT_TRANSLATOR_REQUEST_TIMEOUT_IN_MILLIS

      public static final int DEFAULT_TRANSLATOR_REQUEST_TIMEOUT_IN_MILLIS
      See Also:
  • Constructor Details

    • LocalizationProvider

      LocalizationProvider()
  • Method Details

    • setLocalizationService

      public void setLocalizationService(LocalizationService service)
    • getDateFormatShort

      public static String getDateFormatShort()
      Gets the short date format pattern for the current locale.
      Returns:
      The short date format pattern
    • getTimeFormatShort

      public static String getTimeFormatShort()
      Gets the short time format pattern for the current locale.
      Returns:
      The short time format pattern
    • getTimeFormatMedium

      public static String getTimeFormatMedium()
      Gets the medium time format pattern for the current locale.
      Returns:
      The medium time format pattern
    • getGroupingSeparator

      public static String getGroupingSeparator()
      Gets the grouping separator for numbers in the current locale.
      Returns:
      The grouping separator
    • getDecimalSeparator

      public static String getDecimalSeparator()
      Gets the decimal separator for numbers in the current locale.
      Returns:
      The decimal separator
    • translateInMemory

      public static String translateInMemory(String text)
      Translates a text in memory only (not persisted) using the best matching source locale.
      Parameters:
      text - The text to translate
      Returns:
      The translated text
    • translateInMemory

      public static String translateInMemory(String text, Locale sourceLocale)
      Translates a text in memory only (not persisted) using the specified source locale.
      Parameters:
      text - The text to translate
      sourceLocale - The source locale of the text
      Returns:
      The translated text
    • translateInMemory

      public static String translateInMemory(String text, NuclosLocale sourceLocale)
      Translates a text in memory only (not persisted) using the specified Nuclos source locale.
      Parameters:
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
      Returns:
      The translated text
    • translateInMemory

      public static String translateInMemory(String text, Locale sourceLocale, Locale targetLocale)
      Translates a text in memory only (not persisted) using the specified source and target locales.
      Parameters:
      text - The text to translate
      sourceLocale - The source locale of the text
      targetLocale - The target locale for translation
      Returns:
      The translated text
    • translateInMemory

      public static String translateInMemory(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale)
      Translates a text in memory only (not persisted) using the specified Nuclos source and target locales.
      Parameters:
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
      targetLocale - The Nuclos target locale for translation
      Returns:
      The translated text
    • translateInMemory

      public static String translateInMemory(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale, int timeoutMillisForTranslatorRequest)
      Translates a text in memory only (not persisted) using the specified Nuclos source and target locales with a 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
      Returns:
      The translated text
    • translateInMemory

      public static String translateInMemory(String text, Locale sourceLocale, Locale targetLocale, int timeoutMillisForTranslatorRequest)
      Translates a text in memory only (not persisted) using the specified source and target locales with a 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
      Returns:
      The translated text
    • translate

      public static String translate(String text, Locale sourceLocale, Locale targetLocale)
      Translates a text using the specified source and target locales.
      Parameters:
      text - The text to translate
      sourceLocale - The source locale of the text
      targetLocale - The target locale for translation
      Returns:
      The translated text
    • translate

      public static String translate(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale)
      Translates a text using the specified Nuclos source and target locales.
      Parameters:
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
      targetLocale - The Nuclos target locale for translation
      Returns:
      The translated text
    • translate

      public static String translate(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale, int timeoutMillisForTranslatorRequest)
      Translates a text using the specified Nuclos source and target locales with a 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
      Returns:
      The translated text
    • translate

      public static String translate(String text, Locale sourceLocale, Locale targetLocale, int timeoutMillisForTranslatorRequest)
      Translates a text using the specified source and target locales with a 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
      Returns:
      The translated text
    • translate_en

      public static String translate_en(String key, String enText)
      Translates a text from English using the specified key.
      Parameters:
      key - The localization key
      enText - The English text to translate
      Returns:
      The translated text
    • translate_de

      public static String translate_de(String key, String deText)
      Translates a text from German using the specified key.
      Parameters:
      key - The localization key
      deText - The German text to translate
      Returns:
      The translated text
    • translate

      public static String translate(String key, String text)
      Translates a text using the specified key and the best matching source locale.
      Parameters:
      key - The localization key
      text - The text to translate
      Returns:
      The translated text
    • translate

      public static String translate(String key, String text, Locale sourceLocale)
      Translates a text using the specified key and source locale.
      Parameters:
      key - The localization key
      text - The text to translate
      sourceLocale - The source locale of the text
      Returns:
      The translated text
    • translate

      public static String translate(String key, String text, NuclosLocale sourceLocale)
      Translates a text using the specified key and Nuclos source locale.
      Parameters:
      key - The localization key
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
      Returns:
      The translated text
    • translate

      public static String translate(String key, String text, Locale sourceLocale, Locale targetLocale)
      Translates a text using the specified key, 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
      Returns:
      The translated text
    • translate

      public static String translate(String key, String text, NuclosLocale sourceLocale, NuclosLocale targetLocale)
      Translates a text using the specified key, 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
      Returns:
      The translated text
    • translate

      public static String translate(String key, String text, NuclosLocale sourceLocale, NuclosLocale targetLocale, int timeoutMillisForTranslatorRequest)
      Translates a text using the specified key, 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
      Returns:
      The translated text
    • translate

      public static String translate(String key, String text, Locale sourceLocale, Locale targetLocale, int timeoutMillisForTranslatorRequest)
      Translates a text using the specified key, 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
      Returns:
      The translated text
    • translateCheckedInMemory

      public static String translateCheckedInMemory(String text) throws Exception
      Translates a text in memory only (not persisted) and throws an exception if translation fails.
      Parameters:
      text - The text to translate
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateCheckedInMemory

      public static String translateCheckedInMemory(String text, Locale sourceLocale) throws Exception
      Translates a text in memory only (not persisted) using the specified source locale and throws an exception if translation fails.
      Parameters:
      text - The text to translate
      sourceLocale - The source locale of the text
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateCheckedInMemory

      public static String translateCheckedInMemory(String text, NuclosLocale sourceLocale) throws Exception
      Translates a text in memory only (not persisted) using the specified Nuclos source locale and throws an exception if translation fails.
      Parameters:
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateCheckedInMemory

      public static String translateCheckedInMemory(String text, Locale sourceLocale, Locale targetLocale) throws Exception
      Translates a text in memory only (not persisted) using the specified source and target locales and throws an exception if translation fails.
      Parameters:
      text - The text to translate
      sourceLocale - The source locale of the text
      targetLocale - The target locale for translation
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateCheckedInMemory

      public static String translateCheckedInMemory(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale) throws Exception
      Translates a text in memory only (not persisted) using the specified Nuclos source and target locales and throws an exception if translation fails.
      Parameters:
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
      targetLocale - The Nuclos target locale for translation
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateCheckedInMemory

      public static String translateCheckedInMemory(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale, int timeoutMillisForTranslatorRequest) throws Exception
      Translates a text in memory only (not persisted) using the specified Nuclos source and target locales with a custom timeout and throws an exception if translation fails.
      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
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateCheckedInMemory

      public static String translateCheckedInMemory(String text, Locale sourceLocale, Locale targetLocale, int timeoutMillisForTranslatorRequest) throws Exception
      Translates a text in memory only (not persisted) using the specified source and target locales with a custom timeout and throws an exception if translation fails.
      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
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked

      public static String translateChecked(String text, Locale sourceLocale, Locale targetLocale) throws Exception
      Translates a text and throws an exception if translation fails.
      Parameters:
      text - The text to translate
      sourceLocale - The source locale of the text
      targetLocale - The target locale for translation
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked

      public static String translateChecked(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale) throws Exception
      Translates a text using the specified Nuclos source and target locales and throws an exception if translation fails.
      Parameters:
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
      targetLocale - The Nuclos target locale for translation
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked

      public static String translateChecked(String text, NuclosLocale sourceLocale, NuclosLocale targetLocale, int timeoutMillisForTranslatorRequest) throws Exception
      Translates a text using the specified Nuclos source and target locales with a custom timeout and throws an exception if translation fails.
      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
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked

      public static String translateChecked(String text, Locale sourceLocale, Locale targetLocale, int timeoutMillisForTranslatorRequest) throws Exception
      Translates a text using the specified source and target locales with a custom timeout and throws an exception if translation fails.
      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
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked_en

      public static String translateChecked_en(String key, String enText) throws Exception
      Translates a text from English using the specified key and throws an exception if translation fails.
      Parameters:
      key - The localization key
      enText - The English text to translate
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked_de

      public static String translateChecked_de(String key, String deText) throws Exception
      Translates a text from German using the specified key and throws an exception if translation fails.
      Parameters:
      key - The localization key
      deText - The German text to translate
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked

      public static String translateChecked(String key, String text) throws Exception
      Translates a text using the specified key and the best matching source locale and throws an exception if translation fails.
      Parameters:
      key - The localization key
      text - The text to translate
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked

      public static String translateChecked(String key, String text, Locale sourceLocale) throws Exception
      Translates a text using the specified key and source locale and throws an exception if translation fails.
      Parameters:
      key - The localization key
      text - The text to translate
      sourceLocale - The source locale of the text
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked

      public static String translateChecked(String key, String text, NuclosLocale sourceLocale) throws Exception
      Translates a text using the specified key and Nuclos source locale and throws an exception if translation fails.
      Parameters:
      key - The localization key
      text - The text to translate
      sourceLocale - The Nuclos source locale of the text
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked

      public static String translateChecked(String key, String text, Locale sourceLocale, Locale targetLocale) throws Exception
      Translates a text using the specified key, source locale, and target locale and throws an exception if translation fails.
      Parameters:
      key - The localization key
      text - The text to translate
      sourceLocale - The source locale of the text
      targetLocale - The target locale for translation
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked

      public static String translateChecked(String key, String text, NuclosLocale sourceLocale, NuclosLocale targetLocale) throws Exception
      Translates a text using the specified key, Nuclos source locale, and Nuclos target locale and throws an exception if translation fails.
      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
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked

      public static String translateChecked(String key, String text, NuclosLocale sourceLocale, NuclosLocale targetLocale, int timeoutMillisForTranslatorRequest) throws Exception
      Translates a text using the specified key, Nuclos source locale, Nuclos target locale, and custom timeout and throws an exception if translation fails.
      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
      Returns:
      The translated text
      Throws:
      Exception - If translation fails
    • translateChecked

      public static String translateChecked(String key, String text, Locale sourceLocale, Locale targetLocale, int timeoutMillisForTranslatorRequest) throws Exception
      Translates a text using the specified key, source locale, target locale, and custom timeout and throws an exception if translation fails.
      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
      Returns:
      The translated text
      Throws:
      Exception - If translation fails