Interface LocalizationSource
- All Known Subinterfaces:
ListLocalizationSource,LocalizationSourceRegistry
public interface LocalizationSource
A helper class for adding localization support to your plugin.
-
Method Summary
Modifier and TypeMethodDescriptiondefault StringShorthand method to directly format a localized string, with a failover to a default value???key???.@Nullable MessageFormatReturns the localized string for the given key ornullif absent.static LocalizationSourcerouter()Returns aLocalizationSourcefor the router language:^).
-
Method Details
-
router
Returns aLocalizationSourcefor the router language:^). -
localize
Returns the localized string for the given key ornullif 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, ornullif no string was found.
-
format
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 localizelocale- the locale to useargs- the arguments to pass to theFormat.format(Object)- Returns:
- the formatted string, or
???key???if no string was found.
-