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<RegistryWrapper.WrapperLookup> registryLookup) { // Specifying en_us is optional, by default it is en_us. super(dataGenerator, "en_us", registryLookup); } @Override public void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, TranslationBuilder translationBuilder) { } }
Lets add some translation entries:
@Override public void generateTranslations(RegistryWrapper.WrapperLookup 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); } }
These are the game objects that have a translation key for you to translate:
Item
Block
ItemGroup
EntityType<T>
Enchantment
EntityAttribute
StatType<T>
StatusEffect
Identifier