tutorial:lang
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:lang [2019/07/24 12:56] – fudge | tutorial:lang [2021/02/11 07:23] – ytg1234 | ||
---|---|---|---|
Line 20: | Line 20: | ||
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 ' | + | whenever a ''Text'' object is needed, you should give it 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: | ||
Line 37: | Line 37: | ||
</ | </ | ||
- | And the tooltip will be displayed as "My Tooltip" | + | And the tooltip will be displayed as "My Tooltip" |
- | ====== Translation format ====== | + | ==== Adding dynamic values to translatable text ==== |
- | The translation key for objects | + | Say you want the text to change based on some variable, like the current day and month. |
- | < | + | For a dynamic number, we put a %d where you want the number to show in the lang entry value, for example: |
+ | < | ||
+ | { | ||
+ | "item.tutorial.fabric_item.tooltip": | ||
+ | } | ||
+ | </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: | ||
+ | <code java> | ||
+ | int currentDay = 4; | ||
+ | int currentMonth = 7; | ||
+ | tooltip.add(new TranslatableText(" | ||
+ | </ | ||
- | ^ Object Type ^ Format | + | And the tooltip will be displayed as "My Tooltip in day 4, and month 7". |
- | | Block | < | + | In order to pass a string, we use '' |
- | | Item |< | + | For more information, |
- | | ItemGroup | < | + | |
- | | Fluid | < | + | |
- | | SoundEvent | < | + | |
- | | StatusEffect | < | + | |
- | | Enchantment | < | + | |
- | | EntityType | < | + | |
- | | Potion | < | + | |
- | | Biome | < | + | |
- | For types not in this list, see '' | + | ==== Adding a new line ==== |
+ | Making | ||
+ | <code JavaScript resources/ | ||
+ | { | ||
+ | "item.tutorial.fabric_item.tooltip_1": | ||
+ | "item.tutorial.fabric_item.tooltip_2": | ||
+ | } | ||
+ | </ | ||
+ | Then add the '' | ||
+ | <code java> | ||
+ | tooltip.add(new TranslatableText(" | ||
+ | tooltip.add(new TranslatableText(" | ||
+ | </ | ||
+ | And the tooltip will be displayed as: | ||
+ | < | ||
+ | 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 | ||
+ | | Block | '' | ||
+ | | Item |'' | ||
+ | | ItemGroup | '' | ||
+ | | Fluid | '' | ||
+ | | SoundEvent | '' | ||
+ | | StatusEffect | '' | ||
+ | | Enchantment | '' | ||
+ | | EntityType | '' | ||
+ | | Biome | '' | ||
+ | | Stat | '' | ||
+ | For types not in this list, see '' |
tutorial/lang.txt · Last modified: 2024/02/06 10:26 by rawdiamondmc