This is an old revision of the document!
Table of Contents
Name translations
Notice how your item has a weird display name, such as item.tutorial.my_item? This is because your item's name doesn't have a translation in your game's selected language. Translations are used to support multiple different languages for a single string.
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' code, visit this link. English is en_us. Once you have your language code, create a JSON file at resources/assets/modid/lang/; a full example for an English translation file would be resources/assets/tutorial/lang/en_us.json.
Adding a translation
After you've created the lang file, you can use this basic template to add translations:
- resources/assets/tutorial/lang/en_us.json
{ "item.tutorial.my_item": "My Item", "item.tutorial.my_awesome.item": "My Awesome Item", [...] }
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 Text
, you have the option of giving it a new LiteralText()
,
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 'Text' object is needed, you should give it a new TranslatableText()
with a translation key,
and then translate the key in the lang file.
For example, when adding a tooltip, do:
@Override public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) { tooltip.add(new TranslatableText("tutorial.my_tooltip")); }
And then add in the lang file:
- resources/assets/tutorial/lang/en_us.json
{ "tutorial.my_tooltip": "My Tooltip" }
And the tooltip will be displayed as “My Tooltip” !
Translation format
The translation key for objects you have registered is in the form
<object-type>.<modid>.<registry-id>
Object Type | Format | Example |
---|---|---|
Block | block.<modid>.<registry-id> | "block.tutorial.example_block": "Example Block" |
Item | item.<modid>.<registry-id> | "item.tutorial.my_item": "My Item" |
ItemGroup | itemGroup.<modid>.<registry-id> | "itemGroup.tutorial.my_group": "My Group" |
Fluid | fluid.<modid>.<registry-id> |
|
SoundEvent | sound_event.<modid>.<registry-id> |
|
StatusEffect | mob_effect.<modid>.<registry-id> |
|
Enchantment | enchantment.<modid>.<registry-id> |
|
EntityType | entity_type.<modid>.<registry-id> |
|
Potion | potion.<modid>.<registry-id> |
|
Biome | biome.<modid>.<registry-id> |
For types not in this list, see net.minecraft.util.registry.Registry.java
.