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 revisionBoth sides next revision
tutorial:lang [2019/07/24 16:22] fudgetutorial:lang [2019/07/24 16:43] – Adding a new line fudge
Line 57: Line 57:
 In order to pass a string, we use ''%s'' instead of ''%d'' In order to pass a string, we use ''%s'' instead of ''%d''
 For more information, see [[https://dzone.com/articles/java-string-format-examples|Java String.format]] (it works the same way). For more information, see [[https://dzone.com/articles/java-string-format-examples|Java String.format]] (it works the same way).
 +
 +==== Adding a new line ====
 +Making ''\n'' work was far too difficult for Mojang, so in order to have a string with multiple lines you must split the translation key into multiple keys:
 +<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_2": "Line 2 of my tooltip" 
 +}
 +</code>
 +Then add the ''TranslatableText'' parts individually:
 +<code java>
 +tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip_1"));
 +tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip_2"));
 +</code>
 +And the tooltip will be displayed as:
 +<code>
 +Line 1 of my tooltip
 +Line 2 of my tooltip
 +</code>
  
 ====== Translation format ====== ====== Translation format ======
tutorial/lang.txt · Last modified: 2024/02/06 10:26 by rawdiamondmc