Localization
A TranslatableComponent contains a key instead of text. The vanilla client resolves keys against its own language files, so Component.translatable("block.minecraft.stone") is displayed as "Stone" if the player's language is set to English.
Keys missing from the client's language files are resolved server-side. Adventure's GlobalTranslator does this from a ResourceBundle per locale:
ResourceBundle bundle = ResourceBundle.getBundle("messages", Locale.US);
TranslationStore.StringBased<MessageFormat> store = TranslationStore.messageFormat(Key.key("minestom:messages"));
store.registerAll(Locale.US, bundle, true);
GlobalTranslator.translator().addSource(store);
player.sendMessage(Component.translatable("minestom.welcome"));Automatic translation
Every outgoing component can be rendered against the receiving player's locale. This is disabled by default and controlled by ServerFlag#AUTOMATIC_COMPONENT_TRANSLATION, read from the minestom.automatic-component-translation system property:
-Dminestom.automatic-component-translation=trueThe flag is read once and cannot be changed at runtime. Setting the system property from code has no effect unless it happens before the server is initialized.
When enabled, components in outgoing packets are passed through MinestomAdventure#COMPONENT_TRANSLATOR, which defaults to GlobalTranslator::render. Replace it to translate through something other than Adventure's registry:
MinestomAdventure.COMPONENT_TRANSLATOR = (component, locale) -> myTranslator.render(component, locale);Players that have not sent a locale use MinestomAdventure#getDefaultLocale(), which is the JVM default until changed:
MinestomAdventure.setDefaultLocale(Locale.US);Serializing translated text
The plain text, legacy, and ANSI serializers use Minestom's component flattener, which resolves translation keys through COMPONENT_TRANSLATOR at the default locale.
The flattener only resolves keys when automatic translation is enabled. With the flag off, which is the default, a TranslatableComponent contributes no text to the flattened string, and the key does not appear in the output. Enable the flag, or resolve the component before serializing it.
