Skip to content

zh_cn_key

KlparetlR edited this page Jun 8, 2024 · 5 revisions

实战部分二:提取一个正确key

可能需要汉化的文本类型都是字符串,它们是用" "包起来的(不一定用它包起来的都是要汉化的),并且文本颜色在文本编辑器中也辨别度很高

知识点

  • 知识点1:内容大量带__.的都不用提取

    setRegistryName() 注册名 该模组在游戏里的名字 不是你看的

    StringTextComponent() 字符串文本组件 为该物品创建展示文字 这就是我们需要汉化的

实列

#需要汉化
msg1 = TextFormatting.GRAY + "You need to wager an XP Coin in your Off Hand to play!";
return new TextComponent("Loot Statue Options");
player.m_6352_((new TextComponent("Bronze is no longer used to reroll bounties. Removed all existing bronze from your bounty table and placed in your inventory or dropped if your inventory is full.")).m_130940_(ChatFormatting.YELLOW), player.m_142081_());
list.add(new StringTextComponent("§7Sonic The Hedgehog"));
    public String getName() {
        return "Mekanism Logic";
    }
#不需要汉化
this.setRegistryName("cartridge_sonic_1");
public static BasicItem VAULT_ROCK = new BasicItem(VaultMod.id("vault_rock"));
CRYSTAL_SHARD_BENEVOLENT = new CrystalShardItem(VaultMod.id("shard_benevolent"), VAULT_MOD_GROUP, new MutableComponent[]{new TranslatableComponent("tooltip.the_vault.shard_benevolent")});

这里面将" "包起来的内容就可以算一个key:

You need to wager an XP Coin in your Off Hand to play!
Loot Statue Options
Bronze is no longer used to reroll bounties. Removed all existing bronze from your bounty table and placed in your inventory or dropped if your inventory is full.
§7Sonic The Hedgehog
Mekanism Logic

这就完成了对直接硬编码的字符串提取工作(这块有很多要摸索,欢迎进群讨论( • ̀ω•́ )✧)

但是还有一些内容,它是在经过代码处理后显示的,这种不会给你直接硬编码的字符串拿去替换

比如"vault_rock",如果有代码调用它,转成“Vault Rock”,然后存在变量里或其他类型,这时候你就需要为target_class提供更详细的参数,就可以指向这个变量,然后替换这个变量里的内容

获取完key之后就可以开始编写模块内容

比如在“terrails/xnetgases/module/logic/XGLogicChannelModule”有:

public class XGLogicChannelModule extends ChannelModule
{
    public String getID() {
        return "mekanism.logic";
    }
    
    public String getName() {
        return "Mekanism Logic";
    }
......}

提取出来:

  {
    "t": {
      "name": "terrails/xnetgases/module/slurry/SlurryChannelSettings"
    },
    "p": [
      {
        "k": "Slurry distribution mode",
        "v": "XXX模式"
      }
    ]
  }

这里的“mekanism.logic”直接替换会报错奔溃,想要看怎么处理的可以前往配置存储地查看,链接

一个基于py语言的,方便编写配置的代码

逻辑这么简单应该一眼就懂吧~ 不用我解释什么填数据

import json,pyperclip
def remove_duplicates(case_sensitive_list): # 去除重复内容
    seen = set()
    result = []
    for item in case_sensitive_list:
        lower_item = item
        if lower_item not in seen:
            seen.add(lower_item)
            result.append(item)
    return result

name = "terrails/xnetgases/module/slurry/SlurryConnectorSettings"
method = "createGui"
keydata = [
"Slurry extraction rate|(max ",
"Slurry insertion rate|(max ",
"Keep this amount of|slurry in tank",
"Disable insertion if|slurry level is too high"
]
result = []
for item in remove_duplicates(keydata):
    result.append({"k": item, 'v': "※"+item})
name = name.replace("\\",".").replace("/",".")
output = {
    "t": {
        "name": name,
        "method": method
    },
    "p": result
}

print(json.dumps(output, indent=4))
pyperclip.copy(json.dumps(output, indent=4)) #复制到剪贴板

第三章:更精确的匹配