User Tools

Site Tools


zh_cn:tutorial:lang

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
zh_cn:tutorial:lang [2021/11/16 10:59] – [添加翻译] solidblockzh_cn:tutorial:lang [2024/02/06 10:25] (current) – minecraft wiki rawdiamondmc
Line 1: Line 1:
 ====== 名字翻译 ====== ====== 名字翻译 ======
-注意,具有奇怪的显示名称,例如//item.tutorial.my_item//这是因为您的物品名称没有使用游戏选择的语言进行翻译。 翻译用于为单个字符串支持多种不同的语言。+你有没有注意品显示名称比较奇怪,例如 //item.tutorial.my_item// 这是因为您的物品名称没有使用游戏选择的语言进行翻译。翻译用于为单个字符串支持多种不同的语言。
 ===== 创建一个语言文件 ===== ===== 创建一个语言文件 =====
-你可以使用语言文件为游戏内的可翻译字符串提供翻译。你需要创建的文件的名称应当是语言代码,参见[[https://minecraft.fandom.com/zh/语言|此链接]]。英语是en_us,简体中文是zh_cn,台湾繁体中文是zh_tw,香港繁体中文是zh_hk,文言文是lzh。有了语言代码后,在 __resources/assets/模组id/lang/__ 的位置创建JSON文件,例如英文翻译的文件位置是 __resources/assets/tutorial/lang/en_us.json__。 +你可以使用语言文件为游戏内的可翻译字符串提供翻译。你需要创建的文件的名称应当是语言代码,参见[[https://zh.minecraft.wiki/w/%E8%AF%AD%E8%A8%80#%E5%8F%AF%E7%94%A8%E8%AF%AD%E8%A8%80|Minecraft WIKI]]。英语是 en_us,简体中文是 zh_cn,台湾繁体中文是 zh_tw,香港繁体中文是 zh_hk,文言文是 lzh。有了语言代码后,在 __resources/assets/模组id/lang/__ 的位置创建JSON文件,例如英文翻译的文件位置是 __resources/assets/tutorial/lang/en_us.json__。 
  
 ===== 添加翻译 ===== ===== 添加翻译 =====
Line 13: Line 13:
 } }
 </code> </code>
-其中第一个字符串是任何可翻译的字符串(例如物品名称或TranslatableText)。如果您按照Wiki教程进行操作,请记住将模组id更改为`tutorial`或你自己的模组的id。+其中第一个字符串是任何可翻译的字符串(例如物品名称或 or ''<yarn class_2588>'')。如果您按照 wiki 教程进行操作,请记住将模组id更改为 `tutorial` 或你自己的模组的id。
 ===== 使用自定义可翻译文本 ===== ===== 使用自定义可翻译文本 =====
-每当函数接受''文本''时,您可以选择为其赋予''new LiteralText()'' +每当函数接受 ''<yarn class_2561>'' 时,您可以选择提供一个 ''new <yarn class_2585>()''1.18.2之前或 ''Text.literal()''(1.19之后),这意味着 Minecraft 将按原样使用构造函数参数中的字符串。但是,这是不可取的,因为如果这样做,将很难将文本翻译成另一种语言。 这就是为什么每当需要 ''<yarn class_2561>'' 对象时,都应给它一个带有翻译键的 ''new <yarn class_2588>()'' 或 ''Text.translatable()'',然后在语言文件中翻译该键。例如,添加工具提示时,可在物品类的子类执行以下操作: 
-这意味着我的世界将按原样使用构造函数参数中的字符串。 但是,这是不可取的,因为 +<yarncode java>
-如果您希望这样做,将很难将文本翻译成另一种语言。 这就是为什么 +
-每当需要''文本''对象时,都应给它一个带有翻译键的''new TranslatableText()'' +
-然后在lang文件中翻译密钥 +
-例如,添加工具提示时,执行以下操作: +
-<code java>+
 @Override @Override
-public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) { +public void method_9568(class_1799 itemStack, class_1937 world, List<class_2561> tooltip, class_1836 tooltipContext) { 
-    tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip"));+    // 1.18.2 之前 
 +    tooltip.add(new class_2588("item.tutorial.fabric_item.tooltip")); 
 +     
 +    // 1.19 之后 
 +    tooltip.add(Text.translatable("item.tutorial.fabric_item.tooltip"));
 } }
-</code>+</yarncode>
  
-然后添加lang文件:+然后在语言文件中添加
 <code JavaScript resources/assets/tutorial/lang/zh_cn.json> <code JavaScript resources/assets/tutorial/lang/zh_cn.json>
 { {
Line 35: Line 34:
 </code> </code>
  
-tooltip将显示为“我的工具提示” !+当游戏语言为简体中文时,该工具的提示将显示为“我的工具提示”
  
 ==== 向可翻译文本添加动态值 ==== ==== 向可翻译文本添加动态值 ====
-假设您希望文本根据某些变量(例如当前日期和月份)进行更改。 +假设您希望文本根据某些变量(例如当前日期和月份)进行更改。对于动态数字,可以语言项的值中,在你需要数字显示的位置放个 %d,例如:
-对于动态数字,我们您希望数字显示在lang条目值中的位置放d,例如:+
 <code JavaScript resources/assets/tutorial/lang/zh_cn.json> <code JavaScript resources/assets/tutorial/lang/zh_cn.json>
 { {
-  "item.tutorial.fabric_item.tooltip": "我在第d天和第d的工具提示" +  "item.tutorial.fabric_item.tooltip": "我在第%d天和第%d的工具提示" 
 } }
 </code> </code>
-然后我们按照字符串在文本中出现的顺序传递在字符串中使用的变量。 首先然后是月: +然后我们按照在文本中出现的顺序依次入我们使用的变量。第一个日期第二个是月:  
-<code java>+<yarncode java>
 int currentDay = 4; int currentDay = 4;
 int currentMonth = 7; int currentMonth = 7;
-tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip", currentDay, currentMonth)); +// 1.18 之前 
-</code>+tooltip.add(new class_2588("item.tutorial.fabric_item.tooltip", currentDay, currentMonth)); 
 +// 1.19 之后 
 +tooltip.add(Text.translatable("item.tutorial.fabric_item.tooltip", currentDay, currentMonth)); 
 +</yarncode>
  
-And the tooltip will be displayed as "My Tooltip in day 4, and month 7".  +然后该工具提示将会显示为“我在第4天和第7月的工具提示”。如果需要传入字符串,使用 ''%s'' 而非 ''%d''。如果需要直接显示 ''%'',使用 ''%%''。如果需要指定顺序,可以使用如 ''%1$s''、''%2%s'' 这样的语法。更多信息请参见 [[https://dzone.com/articles/java-string-format-examples|Java String.format]]
-In order to pass a string, we use ''%s'' instead of ''%d''. If you want for it to literally show ''%'', use ''%%''.  +
-For more information, see [[https://dzone.com/articles/java-string-format-examples|Java String.format]] (it works the same way).+
  
 ==== 添加新行 ==== ==== 添加新行 ====
-于Mojang来说使''\ n''工作太困难了,因此使字符串具有多行必须将翻译键拆分多个键: +于 Mojang 的充满独特特性的代码,在工具提示中,''\n'' 不会正常生效。因此如果需多行字符串,需要将翻译键拆分多个键: 
-<code JavaScript resources/assets/tutorial/lang/zh_cn.json>+<code JavaScript resources/assets/tutorial/lang/en_us.json>
 { {
-  "item.tutorial.fabric_item.tooltip_1": "第一行我的工具提示"  +  "item.tutorial.fabric_item.tooltip_1": "我的工具提示的第1行"  
-  "item.tutorial.fabric_item.tooltip_2": "第二行我的工具提示" +  "item.tutorial.fabric_item.tooltip_2": "我的工具提示的第2行
 } }
 </code> </code>
-然后分别加''TranslatableText''部分: +然后分别加入 ''<yarn class_2588>'' 或 ''Text.translatable'' 部分: 
-<code java> + 
-tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip_1")); +1.18.2之前: 
-tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip_2")); +<yarncode java> 
-</code+tooltip.add(new class_2588("item.tutorial.fabric_item.tooltip_1")); 
-And the tooltip will be displayed as:+tooltip.add(new class_2588("item.tutorial.fabric_item.tooltip_2")); 
 +</yarncode> 
 + 
 +1.19之后: 
 +<yarncode java
 +tooltip.add(Text.translatable("item.tutorial.fabric_item.tooltip_1")); 
 +tooltip.add(Text.translatable("item.tutorial.fabric_item.tooltip_2")); 
 +</yarncode> 
 + 
 +工具提示就会显示为:
 <code> <code>
-第一行我的工具提示 +我的工具提示1 
-行我的工具提示+我的工具提示的第2行
 </code> </code>
  
 ====== 翻译格式 ====== ====== 翻译格式 ======
-您注册的对象的翻译''''的格式为 +您注册的对象的翻译键的格式为''<对象类型>.<命名空间>.<路径>''(命名空间和路径就像在 ''<yarn class_2960>'' 中注册的那样)。
-<code><object-type>.<modid>.<registry-id></code+
  
 ^ 对象类型      ^ 格式       ^ 例子          ^ ^ 对象类型      ^ 格式       ^ 例子          ^
-| 方块          | <code>block.<modid>.<registry-id></code>     |<code>"block.tutorial.example_block": "Example Block"  </code>       | +| 方块          | ''block.<modid>.<registry-id>''     |''"block.tutorial.example_block": "Example Block"''       | 
-| 物品    |<code> item.<modid>.<registry-id> </code> |<code> "item.tutorial.my_item": "My Item"</code> +| 物品    |'' item.<modid>.<registry-id> '' |'' "item.tutorial.my_item": "My Item"'' 
-| 物品组 | <code> itemGroup.<modid>.<registry-id></code> <code> "itemGroup.tutorial.my_group": "My Group"</code>+| 物品组 | '' itemGroup.<modid>.<registry-id>'' '' "itemGroup.tutorial.my_group": "My Group"''
-| 流体 | <code> fluid.<modid>.<registry-id> </code> || +| 流体 | '' fluid.<modid>.<registry-id> '' || 
-| 声音事件 | <code> sound_event.<modid>.<registry-id> </code> || +| 声音事件 | '' sound_event.<modid>.<registry-id> '' || 
-| 状态效果 | <code> mob_effect.<modid>.<registry-id> </code> || +| 状态效果 | '' mob_effect.<modid>.<registry-id> '' || 
-| 附魔 | <code> enchantment.<modid>.<registry-id> </code> || +| 附魔 | '' enchantment.<modid>.<registry-id> '' || 
-| 实体类型 | <code> entity_type.<modid>.<registry-id> </code> || +| 实体类型 | '' entity_type.<modid>.<registry-id> '' || 
-| 药水 | <code> potion.<modid>.<registry-id> </code> || +| 药水 | '' potion.<modid>.<registry-id> '' || 
-| 生物群系 | <code> biome.<modid>.<registry-id> </code> ||+| 生物群系 | '' biome.<modid>.<registry-id> '' ||
  
-对于不在此列表中的类型,请参见''net.minecraft.util.registry.Registry.java''+对于不在此列表中的类型,请参见 ''<yarn net.minecraft.class_2378>''
  
  
  
zh_cn/tutorial/lang.1637060381.txt.gz · Last modified: 2021/11/16 10:59 by solidblock