Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于nbt翻译 #19

Open
Heylylyl opened this issue May 3, 2024 · 5 comments
Open

关于nbt翻译 #19

Heylylyl opened this issue May 3, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@Heylylyl
Copy link

Heylylyl commented May 3, 2024

值为[TAG_String: xxxxx]的项遇到错误can only concatenate list (not "NoneType") to list,请手动处理!
进入游戏后详细描述无法翻译
image

@XDawned
Copy link
Owner

XDawned commented May 3, 2024

感谢反馈,但需要你提供snbt任务文件来帮助定位具体问题

@Heylylyl
Copy link
Author

Heylylyl commented May 3, 2024

感谢反馈,但需要你提供snbt任务文件来帮助定位具体问题

ftbquests.zip

@XDawned XDawned added the bug Something isn't working label May 3, 2024
@XDawned
Copy link
Owner

XDawned commented May 3, 2024

问题已定位,将会在下个版本中修复
目前可以暂时将配置文件config.json中的保留原文选项关闭来规避(即将KEEP_ORIGINAL置为false

@Heylylyl
Copy link
Author

Heylylyl commented May 3, 2024

问题已定位,将会在下个版本中修复 目前可以暂时将配置文件config.json中的保留原文选项关闭来规避(即将KEEP_ORIGINAL置为false

是多行文本翻译中更新翻结果时quest[key]与quest[key][index]混淆出现错误,可以通过在134行for循环:for index in range(0, len(line_list)):中最后加入quest[key][index].value = post_translate,可以在对应对行文本进行修改。154与156行quest[key].value = post_translate无法进行翻译结果更新

@qyy2333
Copy link

qyy2333 commented Aug 7, 2024

def trans_field_nbt(quest):
    quest = copy(quest)
    trans_key = ['title', 'description', 'text']
    KEEP_ORIGINAL = global_var.get_value('KEEP_ORIGINAL')
    for key in quest.keys():
        try:
            if key in trans_key:  # 匹配到关键key才进行翻译
                if type(quest[key]) == nbt.TAG_List:  # 文本可能多行,以list形式为判断
                    line_list = quest[key]
                    for index in range(0, len(line_list)):
                        if bool(re.search('[a-zA-Z]', line_list[index].value)):  # 忽略无字母的无效行
                            pre_line = pre_process(line_list[index].value)
                            if pre_line:  # 空返回为图片,保留,不处理
                                translate = translate_line(pre_line)
                                post_translate = post_process(pre_line, translate)
                                line_list[index].value = post_translate  # 更新对应行的翻译结果
                                print(f"\r翻译中:\n{TextStyle.YELLOW+pre_line}\n{TextStyle.GREEN+post_translate+TextStyle.RESET}")
                    if quest[key].value is None:
                        quest[key].value = []
                    if KEEP_ORIGINAL:
                        quest[key].value = [line.value for line in line_list] + quest[key].value
                    else:
                        quest[key].value = [line.value for line in line_list]

                else:  # 单行文本
                    line = quest[key].value
                    pre_line = pre_process(line)
                    if pre_line:
                        translate = translate_line(pre_line)
                        post_translate = post_process(quest[key].value, translate)
                        print(f"\r翻译中:\n{TextStyle.YELLOW+line}\n{TextStyle.GREEN+post_translate+TextStyle.RESET}")
                        if KEEP_ORIGINAL:
                            quest[key].value = f"{line}[--{post_translate}--]"
                        else:
                            quest[key].value = post_translate
        except Exception as e:
            print(TextStyle.RED + f'值为{quest[key]}的项遇到错误{e},请手动处理' + TextStyle.RESET)
            continue
    return quest
这样可以解决问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants