Interface LocalizationSource

All Known Subinterfaces:
ListLocalizationSource, LocalizationSourceRegistry

public interface LocalizationSource
A helper class for adding localization support to your plugin.
  • Method Summary

    Modifier and Type
    Method
    Description
    default String
    format(String key, Locale locale, Object... args)
    Shorthand method to directly format a localized string, with a failover to a default value ???key???.
    @Nullable MessageFormat
    localize(String key, Locale locale)
    Returns the localized string for the given key or null if absent.
    Returns a LocalizationSource for the router language :^).
  • Method Details

    • router

      static LocalizationSource router()
      Returns a LocalizationSource for the router language :^).
    • localize

      @Nullable MessageFormat localize(String key, Locale locale)
      Returns the localized string for the given key or null if absent.
       
            // Send a localized message to every player
            final LocalizationSource source = ...;
            Groups.player.each(player -> {
                final var locale = Locale.forLanguageTag(player.locale().replace('_', '-'));
                final var message = source.localize("example.key", locale);
                player.sendMessage(message == null ? "???example.key???" : message);
            }
        
      Parameters:
      key - the key of the string to localize
      Returns:
      the localized string contained in a MessageFormat, or null if no string was found.
    • format

      default String format(String key, Locale locale, Object... args)
      Shorthand method to directly format a localized string, with a failover to a default value ???key???.
       
            // Send a localized message to every player
            final LocalizationSource source = ...;
            Groups.player.each(player -> {
                final var locale = Locale.forLanguageTag(player.locale().replace('_', '-'));
                player.sendMessage(source.format("example.key", locale));
            }
        
      Parameters:
      key - the key of the string to localize
      locale - the locale to use
      args - the arguments to pass to the Format.format(Object)
      Returns:
      the formatted string, or ???key??? if no string was found.