PREREQUISITES
Make sure you've completed the datagen setup process first.
Setup
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:
java
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) {
}
}1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
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.
java
pack.addProvider(FabricDocsReferenceEnglishLangProvider::new);1
Creating Translations
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:
java
translationBuilder.add("text.fabric_docs_reference.greeting", "Hello there!");1
Using Translations
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:
java
ChatHud chatHud = MinecraftClient.getInstance().inGameHud.getChatHud();
chatHud.addMessage(Text.literal("Hello there!"));
chatHud.addMessage(Text.translatable("text.fabric_docs_reference.greeting")); 1
2
3
2
3





