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 [2019/12/18 11:10] – [名字翻译] lightcolourzh_cn:tutorial:lang [2024/08/25 14:38] (current) solidblock
Line 1: Line 1:
-====== 名字翻译 ====== +====== 创建语言文件====== 
-注意,具有奇怪的显示名称,例如//item.tutorial.my_item//这是因为您的品名称没有使用游戏选择的语言进行翻译。 翻译用于为单个字符串支持多种不同的语言。 +你有没有注意品显示名称比较奇怪,例如 //item.tutorial.my_item//这是因为您的品名称没有使用游戏选择的语言进行翻译。翻译用于为单个字符串支持多种不同的语言。
-===== 创建一个lang文件 ===== +
-您可以使用lang文件为游戏中的可翻译字符串提供翻译。 您需要使用适合您的语言的文件名来创建文件-要找到您的语言代码,请访问[[https://minecraft.gamepedia.com/Language|this link]]. 英语是en_us 简体中文是zh_cn 繁体中文是zh_tw 输入语言代码后, 在创建一个JSON文件 __resources/assets/modid/lang/__; 英文翻译文件的完整示例为 __resources/assets/tutorial/lang/en_us.json__. +
  
-===== Adding a translation ===== +===== 创建一个语言文件 ===== 
-创建lang文件后,您可以使用此基本模板添加翻译: +你可以使用语言文件为游戏内的可翻译字符串提供翻译。你需要创建的文件的名称应当是语言代码,参见 [[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''。  
-<code JavaScript resources/assets/tutorial/lang/en_us.json>+ 
 +===== 添加翻译 ===== 
 +创建语言文件后,您可以使用此基本模板添加翻译: 
 +<code JavaScript resources/assets/tutorial/lang/zh_cn.json>
 { {
-  "item.tutorial.my_item": "My Item", +  "item.tutorial.my_item": "我的物品", 
-  "item.tutorial.my_awesome.item": "My Awesome Item",+  "item.tutorial.my_awesome.item": "我的物品真棒",
   [...]   [...]
 } }
 </code> </code>
-其中第一个字符串任何可翻译的字符串(例如项目名称或TranslatableText)。 如果按照Wiki教程进行操作,请记住将modid更改为`tutorial`或您选择任何modid+其中 JSON 中的键是翻译。如果按照 wiki 教程操作,请记住将命名空间 ''tutorial'' 改成你实际使用命名空间
  
-===== Using custom translatable text ===== +===== 使用自定义可翻译文本 ===== 
-Whenever a function accepts ''Text'', you have the option of giving it a ''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()'',然后在语言文件中翻译该键。例如,添加工具提示时,可在物品类的子类执行以下操作: 
-which means minecraft will use the string in the constructor argument as-isHowever, this is not advisable because +<yarncode java>
-that would make it difficult to translate that text to another language, should you wish to do thatThis 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: +
-<code java>+
 @Override @Override
-public void appendTooltip(ItemStack itemStackWorld world, List<Text> tooltip, TooltipContext tooltipContext) { +public void method_9568(ItemStack stackTooltipContext context, List<Text> tooltip, TooltipType type) { 
-    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>
  
-And then add in the lang file: +然后在语言文件中添加: 
-<code JavaScript resources/assets/tutorial/lang/en_us.json>+<code JavaScript resources/assets/tutorial/lang/zh_cn.json>
 { {
-  "item.tutorial.fabric_item.tooltip": "My Tooltip"+  "item.tutorial.fabric_item.tooltip": "我的工具提示"
 } }
 </code> </code>
  
-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.  +假您希望文本根据某些变量(例如当前日期和月份)进行更改。对于动态的数字,可以在语言项的值中,在你需要数字显示的位置放个 ''%s'',例如
-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/assets/tutorial/lang/zh_cn.json>
-<code JavaScript resources/assets/tutorial/lang/en_us.json>+
 { {
-  "item.tutorial.fabric_item.tooltip": "My Tooltip in day %d, and month %d+  "item.tutorial.fabric_item.tooltip": "我在第%s天和第%s月的工具提示
 } }
 </code> </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>+<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".  +在译文中,变量的顺序可能变,因此可以使用 ''%1$s'' 或 ''%2$s'' 这样的来显式地指定变量的索引。
-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).+
  
-==== Adding a new line ==== +如果需要直接显示 ''%'',使用 ''%%''。更多信息请参见 [[https://dzone.com/articles/java-string-format-examples|Java String.format]]。 
-Making ''\n'' work was far too difficult for Mojang, so in order to have a string with multiple lines you must split the translation key into multiple keys:+ 
 +==== 添加新行 ==== 
 +换行符 ''\n'' 在命令输出中可正常使用,但是在工具提示等情形中,不会正常生效。因此如果在工具提示中需要多行字符串,需要将翻译键拆分成多个键:
 <code JavaScript resources/assets/tutorial/lang/en_us.json> <code JavaScript resources/assets/tutorial/lang/en_us.json>
 { {
-  "item.tutorial.fabric_item.tooltip_1": "Line of my tooltip"  +  "item.tutorial.fabric_item.tooltip_1": "我的工具提示的第1"  
-  "item.tutorial.fabric_item.tooltip_2": "Line of my tooltip+  "item.tutorial.fabric_item.tooltip_2": "我的工具提示的第2
 } }
 </code> </code>
-Then add the ''TranslatableText'' parts individually: +然后分别加入 ''<yarn class_2588>'' 或 ''Text.translatable'' 部分:
-<code java> +
-tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip_1")); +
-tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip_2")); +
-</code> +
-And the tooltip will be displayed as: +
-<code> +
-Line 1 of my tooltip +
-Line 2 of my tooltip +
-</code>+
  
-====== Translation format ====== +1.18.2之前: 
-The translation key for objects you have registered is in the form +<yarncode java
-<code><object-type>.<modid>.<registry-id></code>  +tooltip.add(new class_2588("item.tutorial.fabric_item.tooltip_1")); 
- +tooltip.add(new class_2588("item.tutorial.fabric_item.tooltip_2")); 
-^ Object Type      ^ Format       ^ Example          ^ +</yarncode>
-| Block          | <code>block.<modid>.<registry-id></code>     |<code>"block.tutorial.example_block": "Example Block"  </code>       | +
-| Item    |<code> item.<modid>.<registry-id> </code> |<code> "item.tutorial.my_item": "My Item"</code>+
-| ItemGroup | <code> itemGroup.<modid>.<registry-id></code> | <code> "itemGroup.tutorial.my_group": "My Group"</code>| +
-| Fluid | <code> fluid.<modid>.<registry-id> </code|| +
-| SoundEvent | <code> sound_event.<modid>.<registry-id> </code> || +
-| StatusEffect | <code> mob_effect.<modid>.<registry-id> </code> || +
-| Enchantment | <code> enchantment.<modid>.<registry-id> </code> || +
-| EntityType | <code> entity_type.<modid>.<registry-id> </code> || +
-| Potion | <code> potion.<modid>.<registry-id> </code> || +
-| Biome | <code> biome.<modid>.<registry-id> </code> || +
- +
-For types not in this list, see ''net.minecraft.util.registry.Registry.java''.+
  
 +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>
 +我的工具提示的第1行
 +我的工具提示的第2行
 +</code>
  
zh_cn/tutorial/lang.1576667416.txt.gz · Last modified: 2019/12/18 11:10 by lightcolour