tutorial:lang
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:lang [2019/07/24 16:22] – fudge | tutorial: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' | + | 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 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 ''< |
===== 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 | 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 '' | + | whenever a ''< |
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 |
@Override | @Override | ||
- | public void appendTooltip(ItemStack | + | public void method_9568(class_1799 |
- | 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 41: | ||
</ | </ | ||
- | 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: | ||
</ | </ | ||
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 | + | |
- | </code> | + | // 1.18.2 and before: |
+ | tooltip.add(new | ||
+ | |||
+ | // 1.19 and later: | ||
+ | tooltip.add(Text.translatable(" | ||
+ | </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" | ||
- | In order to pass a string, we use '' | + | In order to pass a string, we use '' |
For more information, | For more information, | ||
- | ====== Translation format ====== | + | ==== Adding a new line ==== |
- | The translation key for objects you have registered is in the form | + | Making '' |
- | < | + | < |
+ | { | ||
+ | "item.tutorial.fabric_item.tooltip_1": | ||
+ | " | ||
+ | } | ||
+ | </code> | ||
+ | Then add the '' | ||
+ | <yarncode java> | ||
+ | // 1.18.2 and below: | ||
+ | tooltip.add(new class_2588(" | ||
+ | tooltip.add(new class_2588(" | ||
- | ^ Object Type ^ Format | + | // 1.19 and later |
- | | Block | < | + | tooltip.add(Text.translatable(" |
- | | Item |< | + | tooltip.add(Text.translatable("item.tutorial.fabric_item.tooltip_2")); |
- | | ItemGroup | < | + | </yarncode> |
- | | Fluid | < | + | And the tooltip will be displayed as: |
- | | SoundEvent | < | + | |
- | | StatusEffect | < | + | |
- | | Enchantment | < | + | |
- | | EntityType | < | + | |
- | | Potion | < | + | |
- | | Biome | < | + | |
- | For types not in this list, see '' | + | < |
+ | Line 1 of my tooltip | ||
+ | Line 2 of my tooltip | ||
+ | </ | ||
+ | ====== Translation format ====== | ||
+ | The translation key for objects you have registered is in the form | ||
+ | ''< | ||
+ | ^ Object Type ^ Format | ||
+ | | <yarn class_2248> | ||
+ | | <yarn class_1792> | ||
+ | | <yarn class_1761> | ||
+ | | <yarn class_3611> | ||
+ | | <yarn class_3414> | ||
+ | | <yarn class_1291> | ||
+ | | <yarn class_1887> | ||
+ | | <yarn class_1299> | ||
+ | | <yarn class_1959> | ||
+ | | <yarn class_3445> | ||
+ | For types not in this list, see ''< |
tutorial/lang.1563985378.txt.gz · Last modified: 2019/07/24 16:22 by fudge