Interface TranslationSource
- All Known Subinterfaces:
BundleTranslationSource,TranslationSourceRegistry
public interface TranslationSource
A helper class for adding translation support to your plugin.
-
Method Summary
Modifier and TypeMethodDescription@Nullable TranslationgetTranslation(String key, Locale locale) Returns the localized string for the given key ornullif absent.default TranslationgetTranslationOrDefault(String key, Locale locale, Function<String, Translation> fallback) default TranslationgetTranslationOrMissing(String key, Locale locale) static TranslationSourcerouter()Returns aTranslationSourcefor the router language:^).
-
Method Details
-
router
Returns aTranslationSourcefor the router language:^). -
getTranslation
Returns the localized string for the given key ornullif 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, ornullif no string was found.
-
getTranslationOrDefault
default Translation getTranslationOrDefault(String key, Locale locale, Function<String, Translation> fallback) -
getTranslationOrMissing
-