Interface BundleTranslationSource

All Superinterfaces:
TranslationSource

public interface BundleTranslationSource extends TranslationSource
A translation source that can register strings from resource bundles, files and others.
  • Method Details

    • create

      static BundleTranslationSource create(Locale defaultLocale)
      Creates a new LocalizationSourceRegistry instance.
      Parameters:
      defaultLocale - the default locale of the localization source
      Returns:
      a new LocalizationSourceRegistry instance
    • registerAll

      default void registerAll(Locale locale, Map<String,Translation> translations)
      Registers a map of localized strings.
       
            final var strings = new HashMap<String, MessageFormat>();
            strings.put("example.hello", new MessageFormat("Hello {0}!", Locale.ENGLISH));
            strings.put("example.goodbye", new MessageFormat("Goodbye {0}!", Locale.ENGLISH));
            registry.registerAll(Locale.ENGLISH, strings);
        
      Parameters:
      locale - the locale to register the strings to
      translations - the map of localized strings
      Throws:
      IllegalArgumentException - if a key is already registered
    • registerAll

      default void registerAll(TranslationBundle bundle)
    • registerAll

      default void registerAll(Locale locale, Set<String> keys, Function<String,Translation> function)
      Registers a set of localized strings by using a mapping function to obtain each string.
      Parameters:
      locale - the locale to register the strings to
      keys - the set of keys to register
      function - the mapping function
      Throws:
      IllegalArgumentException - if the key is already registered
    • register

      void register(String key, Locale locale, Translation translation)
      Registers a localized string.
      Parameters:
      key - the key of the string
      locale - the locale to register the string to
      translation - the localized string
      Throws:
      IllegalArgumentException - if the key is already registered
    • registered

      boolean registered(String key)
      Checks if a key is already registered, for any locale.
      Parameters:
      key - the key to check
      Returns:
      true if the key is already registered, false otherwise
    • registered

      boolean registered(String key, Locale locale)
      Checks if a key is already registered for a specific locale.
      Parameters:
      key - the key to check
      locale - the locale to check
      Returns:
      true if the key is already registered for the specific locale, false otherwise
    • unregister

      void unregister(String key)
      Unregisters a localized string.
      Parameters:
      key - the key of the string
    • getDefaultLocale

      Locale getDefaultLocale()
      Returns the default locale of this source.