====== Language Generation ======
You can generate translation entries from existing language files and classes that support translation keys.
Firstly, create a class that extends ''FabricLanguageProvider'' and implement the base methods like so:
private static class MyModEnglishLangProvider extends FabricLanguageProvider {
private MyModEnglishLangProvider(FabricDataOutput dataGenerator, CompletableFuture registryLookup) {
// Specifying en_us is optional, by default it is en_us.
super(dataGenerator, "en_us", registryLookup);
}
@Override
public void generateTranslations(class_7225.class_7874 registryLookup, TranslationBuilder translationBuilder) {
}
}
Lets add some translation entries:
@Override
public void generateTranslations(class_7225.class_7874 registryLookup, TranslationBuilder translationBuilder) {
translationBuilder.add(SIMPLE_ITEM, "Simple Item");
translationBuilder.add(SIMPLE_BLOCK, "Simple Block");
translationBuilder.add(SIMPLE_ITEM_GROUP, "Simple Item Group");
// Load an existing language file.
try {
Path existingFilePath = dataGenerator.getModContainer().findPath("assets/mymod/lang/en_us.existing.json").get();
translationBuilder.add(existingFilePath);
} catch (Exception e) {
throw new RuntimeException("Failed to add existing language file!", e);
}
}
Now, we will need to add the provider to our data generator in the ''onInitializeDataGenerator'' in your entrypoint class like so:
public class DataGeneration implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
Pack pack = fabricDataGenerator.createPack();
pack.addProvider(MyModEnglishLangProvider::new);
}
}
====== Supported Classes ======
These are the game objects that have a translation key for you to translate:
* ''Item''
* ''Block''
* ''ItemGroup''
* ''EntityType''
* ''Enchantment''
* ''EntityAttribute''
* ''StatType''
* ''StatusEffect''
* ''Identifier''