zh_cn:tutorial:lang
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
zh_cn:tutorial:lang [2019/12/18 11:09] – lightcolour | zh_cn:tutorial:lang [2024/02/06 10:25] (current) – minecraft wiki rawdiamondmc | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== 名字翻译 ====== | ====== 名字翻译 ====== | ||
- | Notice how your item has a weird display name, such as // | + | 你有没有注意到,你的物品显示的名称比较奇怪,例如 |
+ | ===== 创建一个语言文件 ===== | ||
+ | 你可以使用语言文件为游戏内的可翻译字符串提供翻译。你需要创建的文件的名称应当是语言代码,参见[[https:// | ||
- | ===== 创建一个lang文件 | + | ===== 添加翻译 |
- | 您可以使用lang文件为游戏中的可翻译字符串提供翻译。 您需要使用适合您的语言的文件名来创建文件-要找到您的语言代码,请访问[[https:// | + | 创建语言文件后,您可以使用此基本模板添加翻译: |
- | + | <code JavaScript resources/ | |
- | ===== Adding a translation ===== | + | |
- | 创建lang文件后,您可以使用此基本模板添加翻译: | + | |
- | <code JavaScript resources/ | + | |
{ | { | ||
- | " | + | " |
- | " | + | " |
[...] | [...] | ||
} | } | ||
</ | </ | ||
- | 其中第一个字符串是任何可翻译的字符串(例如项目名称或TranslatableText)。 如果您按照Wiki教程进行操作,请记住将modid更改为`tutorial`或您选择的任何modid。 | + | 其中第一个字符串是任何可翻译的字符串(例如物品名称或 |
- | + | ===== 使用自定义可翻译文本 | |
- | ===== Using custom translatable text ===== | + | 每当函数接受 |
- | Whenever a function accepts | + | <yarncode |
- | 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 | @Override | ||
- | public void appendTooltip(ItemStack | + | public void method_9568(class_1799 |
- | tooltip.add(new | + | // 1.18.2 之前 |
+ | tooltip.add(new | ||
+ | |||
+ | // 1.19 之后 | ||
+ | tooltip.add(Text.translatable(" | ||
} | } | ||
- | </code> | + | </yarncode> |
- | And then add in the lang file: | + | 然后在语言文件中添加: |
- | <code JavaScript resources/ | + | <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/ |
- | <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> | + | <yarncode |
int currentDay = 4; | int currentDay = 4; | ||
int currentMonth = 7; | int currentMonth = 7; | ||
- | tooltip.add(new | + | // 1.18 之前 |
- | </code> | + | tooltip.add(new |
+ | // 1.19 之后 | ||
+ | tooltip.add(Text.translatable(" | ||
+ | </yarncode> | ||
- | And the tooltip will be displayed as "My Tooltip in day 4, and month 7". | + | 然后该工具提示将会显示为“我在第4天和第7月的工具提示”。如果需要传入字符串,使用 |
- | In order to pass a string, we use '' | + | |
- | For more information, | + | |
- | ==== Adding a new line ==== | + | ==== 添加新行 |
- | Making | + | 由于 Mojang 的充满独特特性的代码,在工具提示中,'' |
<code JavaScript resources/ | <code JavaScript resources/ | ||
{ | { | ||
- | " | + | " |
- | " | + | " |
} | } | ||
</ | </ | ||
- | Then add the '' | + | 然后分别加入 |
- | <code java> | + | |
- | tooltip.add(new | + | 1.18.2之前: |
- | tooltip.add(new | + | <yarncode |
- | </code> | + | tooltip.add(new |
- | And the tooltip | + | tooltip.add(new |
+ | </yarncode> | ||
+ | |||
+ | 1.19之后: | ||
+ | < | ||
+ | tooltip.add(Text.translatable(" | ||
+ | tooltip.add(Text.translatable(" | ||
+ | </ | ||
+ | |||
+ | 工具提示就会显示为: | ||
< | < | ||
- | Line 1 of my tooltip | + | 我的工具提示的第1行 |
- | Line 2 of my tooltip | + | 我的工具提示的第2行 |
</ | </ | ||
- | ====== | + | ====== |
- | The translation key for objects you have registered is in the form | + | 您注册的对象的翻译键的格式为'' |
- | < | + | |
- | ^ Object Type | + | ^ 对象类型 |
- | | Block | + | | 方块 |
- | | Item |< | + | | 物品 |
- | | ItemGroup | + | | 物品组 |
- | | Fluid | < | + | | 流体 |
- | | SoundEvent | + | | 声音事件 |
- | | StatusEffect | + | | 状态效果 |
- | | Enchantment | + | | 附魔 |
- | | EntityType | + | | 实体类型 |
- | | Potion | + | | 药水 |
- | | Biome | < | + | | 生物群系 |
- | For types not in this list, see '' | + | 对于不在此列表中的类型,请参见 |
zh_cn/tutorial/lang.txt · Last modified: 2024/02/06 10:25 by rawdiamondmc