🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for version:
1.21.4
PREREQUISITES
Make sure you've completed the datagen setup process first.
First, we'll make our provider. Remember, providers are what actually generate data for us. Create a class that extends FabricLanguageProvider and fill out the base methods:
public class FabricDocsReferenceEnglishLangProvider extends FabricLanguageProvider {
protected FabricDocsReferenceEnglishLangProvider(FabricDataOutput dataOutput, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
// Specifying en_us is optional, as it's the default language code
super(dataOutput, "en_us", registryLookup);
}
@Override
public void generateTranslations(RegistryWrapper.WrapperLookup wrapperLookup, TranslationBuilder translationBuilder) {
}
}TIP
You will need a different provider for each language you want to generate (eg. one ExampleEnglishLangProvider and one ExamplePirateLangProvider).
To finish setup, add this provider to your DataGeneratorEntrypoint within the onInitializeDataGenerator method.
pack.addProvider(FabricDocsReferenceEnglishLangProvider::new);Along with creating raw translations, translations from Identifiers, and copying them from an already existing file (by passing a Path), there are helper methods for translating items, blocks, tags, stats, entities, status effects, item groups, entity attributes, and enchantments. Simply call add on the translationBuilder with what you want to translate and what it should translate to:
translationBuilder.add("text.fabric_docs_reference.greeting", "Hello there!");Generated translations take the place of a lot of translations added in other tutorials, but you can also use them anywhere you use a Text object. In our example, if we wanted to allow resource packs to translate our greeting, we use Text.translatable instead of Text.of:
ChatHud chatHud = MinecraftClient.getInstance().inGameHud.getChatHud();
chatHud.addMessage(Text.literal("Hello there!"));
chatHud.addMessage(Text.translatable("text.fabric_docs_reference.greeting"));