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/05/30 20:37] – Add file name jamieswhiteshirt | tutorial:lang [2019/07/24 16:43] – Adding a new line fudge | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Name translations ====== | ====== Name translations ====== | ||
- | Notice how your item has a weird display name, such as //item.modid.my_item//? This is because your item's name doesn' | + | Notice how your item has a weird display name, such as //item.tutorial.my_item//? This is because your item's name doesn' |
===== 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 ===== | ||
After you've created the lang file, you can use this basic template to add translations: | After you've created the lang file, you can use this basic template to add translations: | ||
- | <code JavaScript resources/ | + | <code JavaScript resources/ |
{ | { | ||
- | "item.modid.my_item": | + | "item.tutorial.my_item": |
- | "item.modid.my_awesome.item": | + | "item.tutorial.my_awesome.item": |
[...] | [...] | ||
} | } | ||
</ | </ | ||
- | where the first string is any translatable string (such as an item name, or TranslatableTextComponent). If you're following along in the wiki tutorial, remember to change modid to wikitut, or whatever modid you've chosen. | + | 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. |
+ | |||
+ | ===== Using custom translatable text ===== | ||
+ | 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: | ||
+ | <code java> | ||
+ | @Override | ||
+ | public void appendTooltip(ItemStack itemStack, World world, List< | ||
+ | tooltip.add(new TranslatableText(" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | And then add in the lang file: | ||
+ | <code JavaScript resources/ | ||
+ | { | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | And the tooltip will be displayed as "My Tooltip" | ||
+ | |||
+ | ==== Adding dynamic values to translatable text ==== | ||
+ | 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: | ||
+ | <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: | ||
+ | <code java> | ||
+ | int currentDay = 4; | ||
+ | int currentMonth = 7; | ||
+ | tooltip.add(new TranslatableText(" | ||
+ | </ | ||
+ | |||
+ | And the tooltip will be displayed as "My Tooltip in day 4, and month 7". | ||
+ | In order to pass a string, we use '' | ||
+ | For more information, | ||
+ | |||
+ | ==== Adding a new line ==== | ||
+ | Making '' | ||
+ | <code JavaScript resources/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | 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 | < | ||
+ | | Potion | < | ||
+ | | Biome | < | ||
+ | |||
+ | For types not in this list, see '' | ||
+ | |||
+ |
tutorial/lang.txt · Last modified: 2024/02/06 10:26 by rawdiamondmc