Interface Translator
- All Known Subinterfaces:
GlobalTranslator, MiniMessageTranslationStore, TranslationStore<T>, TranslationStore.StringBased<T>
- All Known Implementing Classes:
AbstractTranslationStore, AbstractTranslationStore.StringBased, MiniMessageTranslator
public interface Translator
A message translator.
To see how to create a Translator with a ResourceBundle
see TranslationStore.StringBased.registerAll(Locale, ResourceBundle, boolean)
To bypass vanilla's MessageFormat-based translation system,
see translate(TranslatableComponent, Locale)
After creating a Translator you can add it to the GlobalTranslator
to enable automatic translations by the platforms.
- Since:
- 4.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleancanTranslate(String key, Locale locale) Checks if this translator can translate the given key and locale pair.default TriStateChecks if this translator has any translations.name()A key identifying this translation source.static @Nullable LocaleparseLocale(String string) @Nullable MessageFormatGets a message format from a key and locale.default @Nullable Componenttranslate(TranslatableComponent component, Locale locale) Gets a translated component from a translatable component and locale.
-
Method Details
-
parseLocale
-
name
Key name()A key identifying this translation source.Intended to be used for display to users.
- Returns:
- an identifier for this translation source
- Since:
- 4.0.0
-
hasAnyTranslations
Checks if this translator has any translations.- Returns:
TriState.TRUEif any,TriState.NOT_SETif unknown, orTriState.FALSEif none- Since:
- 4.15.0
-
canTranslate
-
translate
Gets a message format from a key and locale.When used in the
GlobalTranslator, this method is called only iftranslate(TranslatableComponent, Locale)returnsnull.- Parameters:
key- a translation keylocale- a locale- Returns:
- a message format or
nullto skip translation - Since:
- 4.0.0
-
translate
Gets a translated component from a translatable component and locale.Care should be taken to ensure you do not unintentionally remove the children or style of
component. This can be avoided by copying over the children/style using the following code as an example:final Component myNewComponent = ...; // get your component here return myNewComponent .append(component.children()) // ensure it has the original components children as well .applyFallbackStyle(component.style()); // apply a "fallback" style- Parameters:
component- a translatable componentlocale- a locale- Returns:
- a translated component or
nullto usetranslate(String, Locale)instead (if available) - Since:
- 4.13.0
-