Class I18nUtil

java.lang.Object
com.serinity.accesscontrol.util.I18nUtil

public final class I18nUtil extends Object
Utility class for application internationalization (i18n)

Provides helper methods to manage the current Locale, load message ResourceBundles based on PropertyBundle, retrieve localized messages, and ensure that the active locale is one of the configured supported languages.


I18nUtil.applySupportedLocale();
Since:
2026-01-29 I18nUtil.java
Version:
1.0
Author:
@ZouariOmar (zouariomar20@gmail.com)
  • Method Details

    • getValue

      public static String getValue(String key)
      Returns the localized string for the given message key.
      Parameters:
      key - the i18n message key (e.g., "greeting")
      Returns:
      the localized string value
    • setLocale

      public static void setLocale(Locale locale)
      Changes the active locale and reloads the resource bundle accordingly.
      Parameters:
      locale - the new Locale to apply
    • getLocale

      public static Locale getLocale()
      Returns the currently active Locale.
      Returns:
      the current locale
    • getBundle

      public static ResourceBundle getBundle()
      Returns the currently loaded ResourceBundle.
      Returns:
      the active resource bundle
    • getSupportedLanguages

      public static List<Locale> getSupportedLanguages()
      Returns the list of supported Locale instances loaded from the supported-languages property bundle.
      Returns:
      list of supported locales
    • getSupportedLanguagesToString

      public static List<String> getSupportedLanguagesToString()
      Returns the list of supported language tags (e.g., "en", "fr") as plain strings, suitable for populating UI combo-boxes.
      Returns:
      list of supported language tag strings
    • applySupportedLocale

      public static void applySupportedLocale()
      Applies the best matching supported locale to the current runtime locale.

      First tries an exact match; if none is found, falls back to matching by language tag only (e.g., en_USen). If no match is found at all, the current locale remains unchanged.