User Tools

Site Tools


tutorial:datagen_language

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorial:datagen_language [2022/09/18 13:32] – created nexus-dinotutorial:datagen_language [2023/06/20 11:13] (current) – Fix usage of wrong variable in example entrypoint mattidragon
Line 1: Line 1:
-**TODO**: Will be done as soon as ''[[https://github.com/FabricMC/fabric/pull/2451|#2451]]'' is reviewed and merged+====== 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: 
 + 
 +<code java> 
 +private static class MyModEnglishLangProvider extends FabricLanguageProvider { 
 + private MyModEnglishLangProvider(FabricDataOutput dataGenerator) { 
 +                // Specifying en_us is optional, by default is is en_us. 
 + super(dataGenerator, "en_us"); 
 +
 + 
 + @Override 
 + public void generateTranslations(TranslationBuilder translationBuilder) { 
 +  
 +
 +
 +</code> 
 + 
 +Lets add some translation entries: 
 + 
 +<code java> 
 +@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); 
 +
 +
 +</code> 
 + 
 +Now, we will need to add the provider to our data generator in the ''onInitializeDataGenerator'' in your entrypoint class like so: 
 + 
 +<code java> 
 +public class DataGeneration implements DataGeneratorEntrypoint { 
 +    @Override 
 +    public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { 
 +        Pack pack = fabricDataGenerator.createPack(); 
 +        pack.addProvider(MyModEnglishLangProvider::new); 
 +    } 
 +
 +</code> 
 + 
 +====== 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.1663507979.txt.gz · Last modified: 2022/09/18 13:32 by nexus-dino