tutorial:lang
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:lang [2021/02/11 07:13] – [Translation format] Stat type added arbee | tutorial:lang [2024/08/25 14:35] (current) – [Adding a translation] solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
Notice how your item has a weird display name, such as // | Notice how your item has a weird display name, such as // | ||
===== 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' | + | 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' |
===== Adding a translation ===== | ===== Adding a translation ===== | ||
Line 14: | Line 14: | ||
} | } | ||
</ | </ | ||
- | where the first string | + | where the keys in JSON is the translation key. If you're following along in the wiki tutorial, remember to change |
===== Using custom translatable text ===== | ===== Using custom translatable text ===== | ||
- | Whenever a function accepts '' | + | Whenever a function accepts '' |
- | 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 | + | |
- | whenever a '' | + | |
- | 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 |
@Override | @Override | ||
- | public void appendTooltip(ItemStack | + | public void method_9568(ItemStack |
- | tooltip.add(new | + | // 1.18.2 and before |
+ | tooltip.add(new | ||
+ | |||
+ | // 1.19 and later | ||
+ | tooltip.add(Text.translatable(" | ||
} | } | ||
- | </code> | + | </yarncode> |
And then add in the lang file: | And then add in the lang file: | ||
Line 37: | Line 38: | ||
</ | </ | ||
- | 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 ===== |
- | Say you want the text to change based on some variable, like the current day and month. | + | Say you want the text to change based on some variable, like the current day and month. For a dynamic number, we put a '' |
- | For a dynamic number, we put a %d where you want the number to show in the lang entry value, for example: | + | |
<code JavaScript resources/ | <code JavaScript resources/ | ||
{ | { | ||
- | " | + | " |
} | } | ||
</ | </ | ||
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 |
int currentDay = 4; | int currentDay = 4; | ||
int currentMonth = 7; | int currentMonth = 7; | ||
- | tooltip.add(new TranslatableText(" | ||
- | </ | ||
- | And the tooltip | + | // 1.18.2 and before: |
- | In order to pass a string, we use '' | + | tooltip.add(new class_2588(" |
+ | |||
+ | // 1.19 and later: | ||
+ | tooltip.add(Text.translatable("item.tutorial.fabric_item.tooltip", | ||
+ | </ | ||
+ | |||
+ | In translations, | ||
+ | |||
+ | If you want for it to literally show '' | ||
For more information, | For more information, | ||
==== Adding a new line ==== | ==== Adding a new line ==== | ||
- | Making | + | The line-break |
<code JavaScript resources/ | <code JavaScript resources/ | ||
{ | { | ||
- | " | + | " |
" | " | ||
} | } | ||
</ | </ | ||
- | Then add the '' | + | Then add the '' |
- | <code java> | + | <yarncode |
- | tooltip.add(new | + | // 1.18.2 and below: |
- | tooltip.add(new | + | tooltip.add(new |
- | </code> | + | tooltip.add(new |
+ | |||
+ | // 1.19 and later | ||
+ | tooltip.add(Text.translatable(" | ||
+ | tooltip.add(Text.translatable(" | ||
+ | </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 ====== | + | |
- | The translation key for objects you have registered is in the form | + | |
- | < | + | |
- | + | ||
- | ^ Object Type ^ Format | + | |
- | | Block | < | + | |
- | | Item |< | + | |
- | | ItemGroup | < | + | |
- | | Fluid | < | + | |
- | | SoundEvent | < | + | |
- | | StatusEffect | < | + | |
- | | Enchantment | < | + | |
- | | EntityType | < | + | |
- | | Biome | < | + | |
- | | Stat | < | + | |
- | + | ||
- | For types not in this list, see '' | + | |
- | + | ||
tutorial/lang.1613027610.txt.gz · Last modified: 2021/02/11 07:13 by arbee