Interface TranslationSource

All Known Subinterfaces:
BundleTranslationSource, TranslationSourceRegistry

public interface TranslationSource
A helper class for adding translation support to your plugin.
  • Method Details

    • router

      static TranslationSource router()
      Returns a TranslationSource for the router language :^).
    • getTranslation

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

      default Translation getTranslationOrDefault(String key, Locale locale, Function<String,Translation> fallback)
    • getTranslationOrMissing

      default Translation getTranslationOrMissing(String key, Locale locale)