User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

These pages will help you setup a productive development environment and semi-automated releases.

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

tutorial:datagen_language

:!: This content is pending a PR merge. ''#2451''

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(FabricDataGenerator dataGenerator) {
                // Specifying en_us is optional, by default is is en_us.
		super(dataGenerator, "en_us");
	}
 
	@Override
	public void generateTranslations(TranslationBuilder translationBuilder) {
 
	}
}

Lets add some translation entries:

@Override
public void generateTranslations(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 MyModDatagen implements DataGeneratorEntrypoint {
    @Override
    public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
        fabricDataGenerator.addProvider(MyModEnglishLangProvider::new);
    }
}

Supported Classes

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
tutorial/datagen_language.txt · Last modified: 2022/09/23 17:37 by nexus-dino