User Tools

Site Tools


tutorial:lang

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:lang [2019/07/24 17:13] – added escaping % fudgetutorial:lang [2024/02/06 10:26] (current) – minecraft wiki rawdiamondmc
Line 3: Line 3:
  
 ===== Creating a lang file ===== ===== Creating a lang file =====
-You can use lang files to provide translations for translatable strings in-game. You'll need to create a file with an appropriate file name for your language-- to find your languages' code, visit [[https://minecraft.gamepedia.com/Language|this link]]. English is en_us. Once you have your language code, create a JSON file at __resources/assets/modid/lang/__; a full example for an English translation file would be __resources/assets/tutorial/lang/en_us.json__. +You can use lang files to provide translations for translatable strings in-game. You'll need to create a file with an appropriate file name for your language-- to find your languages' code, visit [[https://minecraft.wiki/w/Language#Languages|Minecraft Wiki]]. English is en_us. Once you have your language code, create a JSON file at __resources/assets/modid/lang/__; a full example for an English translation file would be __resources/assets/tutorial/lang/en_us.json__. 
  
 ===== Adding a translation ===== ===== Adding a translation =====
Line 14: Line 14:
 } }
 </code> </code>
-where the first string is any translatable string (such as an item name, or TranslatableText). If you're following along in the wiki tutorial, remember to change modid to `tutorial`, or whatever modid you've chosen.+where the first string is any translatable string (such as an item name, or ''<yarn class_2588>''). If you're following along in the wiki tutorial, remember to change modid to `tutorial`, or whatever modid you've chosen.
  
 ===== Using custom translatable text ===== ===== Using custom translatable text =====
-Whenever a function accepts ''Text'', you have the option of giving it a ''new LiteralText()'',+Whenever a function accepts ''<yarn class_2561>'', you have the option of giving it a ''new <yarn class_2585>()'' or ''Text.literal()'' (for versions since 1.19),
 which means minecraft will use the string in the constructor argument as-is. However, this is not advisable because which means minecraft will use the string in the constructor argument as-is. However, this is not advisable because
 that would make it difficult to translate that text to another language, should you wish to do that. This is why that would make it difficult to translate that text to another language, should you wish to do that. This is why
-whenever a ''Text'' object is needed, you should give it a ''new TranslatableText()'' with a translation key,+whenever a ''<yarn class_2561>'' object is needed, you should give it a ''new <yarn class_2588>()'' or ''Text.translatable'' with a translation key,
 and then translate the key in the lang file.  and then translate the key in the lang file. 
 For example, when adding a tooltip, do: For example, when adding a tooltip, do:
-<code java>+<yarncode java>
 @Override @Override
-public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) { +public void method_9568(class_1799 itemStack, class_1937 world, List<class_2561> tooltip, class_1836 tooltipContext) { 
-    tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip"));+    // 1.18.2 and before 
 +    tooltip.add(new class_2588("item.tutorial.fabric_item.tooltip")); 
 +     
 +    // 1.19 and later 
 +    tooltip.add(Text.translatable("item.tutorial.fabric_item.tooltip"));
 } }
-</code>+</yarncode>
  
 And then add in the lang file: And then add in the lang file:
Line 37: Line 41:
 </code> </code>
  
-And the tooltip will be displayed as "My Tooltip" !+And the tooltip will be displayed as "My Tooltip"!
  
 ==== Adding dynamic values to translatable text ==== ==== Adding dynamic values to translatable text ====
Line 48: Line 52:
 </code> </code>
 Then we pass the variables we use in our string by the order it appears in the text. First the day, then the month: Then we pass the variables we use in our string by the order it appears in the text. First the day, then the month:
-<code java>+<yarncode java>
 int currentDay = 4; int currentDay = 4;
 int currentMonth = 7; int currentMonth = 7;
-tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip", currentDay, currentMonth)); + 
-</code>+// 1.18.2 and before: 
 +tooltip.add(new class_2588("item.tutorial.fabric_item.tooltip", currentDay, currentMonth)); 
 + 
 +// 1.19 and later: 
 +tooltip.add(Text.translatable("item.tutorial.fabric_item.tooltip", currentDay, currentMonth)); 
 +</yarncode>
  
 And the tooltip will be displayed as "My Tooltip in day 4, and month 7" And the tooltip will be displayed as "My Tooltip in day 4, and month 7"
Line 62: Line 71:
 <code JavaScript resources/assets/tutorial/lang/en_us.json> <code JavaScript resources/assets/tutorial/lang/en_us.json>
 { {
-  "item.tutorial.fabric_item.tooltip_1": "Line 1 of my tooltip" +  "item.tutorial.fabric_item.tooltip_1": "Line 1 of my tooltip"
   "item.tutorial.fabric_item.tooltip_2": "Line 2 of my tooltip"    "item.tutorial.fabric_item.tooltip_2": "Line 2 of my tooltip" 
 } }
 </code> </code>
-Then add the ''TranslatableText'' parts individually: +Then add the ''<yarn class_2588>'' parts individually: 
-<code java> +<yarncode java> 
-tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip_1")); +// 1.18.2 and below: 
-tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip_2")); +tooltip.add(new class_2588("item.tutorial.fabric_item.tooltip_1")); 
-</code>+tooltip.add(new class_2588("item.tutorial.fabric_item.tooltip_2")); 
 + 
 +// 1.19 and later 
 +tooltip.add(Text.translatable("item.tutorial.fabric_item.tooltip_1")); 
 +tooltip.add(Text.translatable("item.tutorial.fabric_item.tooltip_2")); 
 +</yarncode>
 And the tooltip will be displayed as: And the tooltip will be displayed as:
-<code>+ 
 +<yarncode>
 Line 1 of my tooltip Line 1 of my tooltip
 Line 2 of my tooltip Line 2 of my tooltip
-</code>+</yarncode>
  
 ====== Translation format ====== ====== Translation format ======
 The translation key for objects you have registered is in the form The translation key for objects you have registered is in the form
-<code><object-type>.<modid>.<registry-id></code+''<object-type>.<namespace>.<path>'' (namespace and path as defined by the registered ''<yarn class_2960>'').
  
 ^ Object Type      ^ Format       ^ Example          ^ ^ Object Type      ^ Format       ^ Example          ^
-| Block          | <code>block.<modid>.<registry-id></code>     |<code>"block.tutorial.example_block": "Example Block"  </code>       | +| <yarn class_2248         | ''block.<namespace>.<path>''     |''"block.tutorial.example_block": "Example Block"''       | 
-| Item    |<code> item.<modid>.<registry-id> </code> |<code> "item.tutorial.my_item": "My Item"</code> +| <yarn class_1792   |''item.<namespace>.<path>'' |''"item.tutorial.my_item": "My Item"'' 
-| ItemGroup | <code> itemGroup.<modid>.<registry-id></code> | <code> "itemGroup.tutorial.my_group": "My Group"</code>+| <yarn class_1761| ''itemGroup.<namespace>.<path>'' ''"itemGroup.tutorial.my_group": "My Group"''
-| Fluid | <code> fluid.<modid>.<registry-id> </code> || +| <yarn class_3611| ''fluid.<namespace>.<path>''|| 
-| SoundEvent | <code> sound_event.<modid>.<registry-id> </code> || +| <yarn class_3414| ''sound_event.<namespace>.<path>''|| 
-| StatusEffect | <codemob_effect.<modid>.<registry-id> </code> || +| <yarn class_1291| ''effect.<namespace>.<path>''|| 
-| Enchantment | <code> enchantment.<modid>.<registry-id> </code> || +| <yarn class_1887| ''enchantment.<namespace>.<path>''|| 
-| EntityType | <codeentity_type.<modid>.<registry-id> </code> || +| <yarn class_1299| ''entity.<namespace>.<path>''|| 
-| Potion | <codepotion.<modid>.<registry-id> </code> || +| <yarn class_1959| ''biome.<namespace>.<path>''|| 
-| Biome | <codebiome.<modid>.<registry-id> </code> || +| <yarn class_3445| ''stat.<namespace>.<path>''||
- +
-For types not in this list, see ''net.minecraft.util.registry.Registry.java''+
- +
  
 +For types not in this list, see ''<yarn net.minecraft.class_2378>''.
tutorial/lang.1563988402.txt.gz · Last modified: 2019/07/24 17:13 by fudge