chessbase的中文语言strings文件比较与生成工具

news2024/10/6 22:25:42

请支持我的店铺tao 宝 王后兵 店

把chessbase17或fritz19根目录(如C:\Program Files\ChessBase\CBase17)的messages文件夹复制到本py文件所在的文件夹,运行本py文件可以生成新的Chinese strings文件。

strings2.py

"""strings文件的中文、英文的比较和新中文strings的生成"""

import os  # 判断文件夹是否已存在和创建新文件夹用到
import shutil  # 用于复制文件到另一个目录

root_path = "./messages"
en = "english"
cn = "chinese"
cn_new = "new_chinese"
cn_new_file_path = f"{root_path}/{cn_new}/"


def genCapWordsList(file_name, sub_dir_name):
    """生成大写符号的列表的函数(中文、英文都是用这个函数)"""

    file = open(f"{root_path}/{sub_dir_name}/{file_name}.strings", mode="r", encoding='utf-8')

    cap_words_list = []
    line_nums = 0
    content_begin_line_max = 21
    content_flag = False
    for line in file:
        line_nums += 1
        if line_nums < content_begin_line_max:
            if line.startswith('M_'):
                content_flag = True  # 如果20行以内行以M_打头则正文起始了。因为如果全文都检测是浪费性能。
        if content_flag and line.strip().endswith('";'):  # 正文起头了,并且都是以";结尾的正规行
            cap_words = line.split(',')[0]  # 从正文起头后,大写字符提取出来 。
            cap_words_list.append(cap_words)  # 大写字符就加到列表中。

    file.close()
    return cap_words_list


def genLangDictList(file_name, sub_dir_name=en):
    """生成英文大写符号-字符串字典的列表"""
    file = open(f"{root_path}/{sub_dir_name}/{file_name}.strings", mode="r", encoding='utf-8')
    en_dict_list = []
    line_nums = 0
    content_begin_line_max = 21
    content_flag = False
    for line in file:
        line_nums += 1
        if line_nums < content_begin_line_max:
            if line.startswith('M_'):
                content_flag = True
        if content_flag and line.strip().endswith('";'):
            cap_words = line.split(',')[0]
            enDict = {cap_words: line.split(',')[1].split('"')[1]}
            en_dict_list.append(enDict)  # 得到英语文件的字典列表

    file.close()
    return en_dict_list


def genCnDict(file_name):
    """生成中文大写符号-中文翻译的字典"""
    file = open(f"{root_path}/{cn}/{file_name}.strings", mode="r", encoding='utf-8')
    cn_dict = {}
    line_nums = 0
    content_begin_line_max = 21
    content_flag = False
    for line in file:
        line_nums += 1
        if line_nums < content_begin_line_max:
            if line.startswith('M_'):
                content_flag = True
        if content_flag and line.strip().endswith('";'):
            cap_words = line.split(',')[0]
            cn_dict[cap_words] = line.split(',')[1].split('"')[1]  # 得到中文文件的字典

    file.close()
    return cn_dict


def isCnEnEqual(file_name):
    """中文和英文strings文件的大写符号列表是否相同"""
    is_equal = False
    if genCapWordsList(file_name, en) == genCapWordsList(file_name, cn):
        is_equal = True
    return is_equal


def getMaxLen(file_name):
    """新生成的Chinese.strings中第一个英文引号" 放在哪一列"""
    Max_len = len(sorted(genCapWordsList(file_name, en), key=len, reverse=True)[0]) + 4
    return Max_len


def writeHeaders(file_name, file_path=cn_new_file_path, create_time="yyyy/mm/dd", author="yourName"):
    """写入统一headers"""
    if not os.path.exists(file_path):
        os.makedirs(file_path)
    cn_new_file = open(f"{file_path}/{file_name}.strings", mode='w', encoding='utf-8')
    uni_headers = f'''/*
    Generated with StringsTool
    版本: 0.1
    创建日期: {create_time}
    作者: {author}
    IMPORTANT: 
    0. 不要在";后面再加任何注释//等字符(空白字符没关系)
    1. Please do not change or translate the symbols in capital letters.
    2. Do not remove or add commas and semicolons.
    3. Make sure that every string is included into quotes.
*/

'''
    cn_new_file.write(uni_headers)
    cn_new_file.close()


def writeMainContents(file_name, dir_path=cn_new_file_path):
    """写入新的翻译内容"""
    cn_new_file = open(f"{dir_path}/{file_name}.strings", mode='a', encoding='utf-8')

    # 确定翻译内容部分,及每一行的内容的确定。用f字符串
    cap_words_list = genCapWordsList(file_name, en)
    Max_len = getMaxLen(file_name)
    en_list = genLangDictList(file_name)
    cn_dict = genCnDict(file_name)

    for element in cap_words_list:
        default_value = en_list[cap_words_list.index(element)][element]
        value = cn_dict.get(element, default_value)

        spaces = " " * (Max_len - len(element))
        line = f'{element},{spaces}"{value}";\n'

        cn_new_file.write(line)

    cn_new_file.close()


def compareAndGenerate(file_name):
    """比较和生成新的Chinese strings文件"""
    is_cn_en_equal = isCnEnEqual(file_name)
    if not is_cn_en_equal:
        print(f"{file_name}中文对比英文不同,将会生成新的{file_name}中文strings")
        writeHeaders(file_name, create_time="20240519", author="yourName")
        writeMainContents(file_name)
        print(f"新建new_chinese {file_name}.strings成功\n")
    else:
        print(f"{file_name}中文对比英文相同,原有的中文{file_name}.strings可以继续使用")
        source_path = f"{root_path}/{cn}/{file_name}.strings"  
        dest_path = f"{cn_new_file_path}/{file_name}.strings"
        if not os.path.exists(source_path):  
            print(f"源文件 {source_path} 不存在")  
        else:
            if not os.path.exists(dest_path):
                os.makedirs(cn_new_file_path, exist_ok=True)
                shutil.copy2(source_path, dest_path)
                print(f"{file_name}.strings已复制到new_chinese文件夹\n")


if __name__ == "__main__":
    name_lists = ["analysis", "app", "countries", "frame", "posTutor", "replayTraining", "textures"]
    nums = 0
    for name in name_lists:
        nums += 1
        print(nums, end=' ')
        compareAndGenerate(name)
    input("按下回车继续...")

下面这个py文件可以把 英文和中文的strings合并到csv文件。csv文件可以用vscode edit csv插件 打开方便进行修改翻译。(注意不要用Excel)

to_csv.py


import strings2

def toCsv(file_name="app"):
    """英文和中文的strings合并到csv文件"""
    cap_words_list = strings2.genCapWordsList(file_name, sub_dir_name=strings2.en)
    lists_len = len(cap_words_list)

    en_dict_list = strings2.genLangDictList(file_name, sub_dir_name=strings2.en)
    cn_dict_list = strings2.genLangDictList(file_name, sub_dir_name=strings2.cn_new)

    comments_list = "-" * lists_len

    csv_file = open(f"{file_name}.csv", mode="wt", encoding="utf-8")

    csv_file.write("大写符号,英语,汉语翻译,注释\n")

    for i in range(lists_len):
        key = cap_words_list[i]
        line = f"{key},{en_dict_list[i][key]},{cn_dict_list[i][key]},{comments_list[i]}\n"
        csv_file.write(line)

    csv_file.close()

if __name__ == "__main__":
    toCsv("app")

下面这个py文件可以在上面修改翻译保存后,从csv文件重新创建Chinese的strings文件。

backto_strings.py


import strings2

cn_new02 = "new_chinese02"

def writeBackToStrings(file_name):
    """从csv文件写回Chinese的strings文件"""
    csv_file = open(f"{file_name}.csv", mode="rt", encoding="utf-8")

    strings2.writeHeaders(file_name, file_path=f"{strings2.root_path}/{cn_new02}",create_time="2024", author="zhw")  # 

    file = open(f"{strings2.root_path}/{cn_new02}/{file_name}.strings", mode='a', encoding='utf-8')

    Max_len = strings2.getMaxLen(file_name)

    first_line = True

    for line in csv_file:
        if first_line:
            first_line = False
            continue
        line_list = line.strip().split(",")
        spaces = " " * (Max_len - len(line_list[0]))
        file.write(f'{line_list[0]},{spaces}"{line_list[2]}";\n')

    file.close()

if __name__ == "__main__":
    writeBackToStrings(file_name="app")

新代码和可执行程序在gitee上了。

chessbase strings比较生成和修改工具: chessbase strings比较、生成和中文翻译修改工具。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1688959.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

第52期|GPTSecurity周报

GPTSecurity是一个涵盖了前沿学术研究和实践经验分享的社区&#xff0c;集成了生成预训练Transformer&#xff08;GPT&#xff09;、人工智能生成内容&#xff08;AIGC&#xff09;以及大语言模型&#xff08;LLM&#xff09;等安全领域应用的知识。在这里&#xff0c;您可以找…

Vitis HLS 学习笔记--基本指针和算术指针

目录 1. 简介 2. 基本指针 3. 算术指针 4. 疑点解答 4.1 疑点1 4.2 疑点2 5. 总结 1. 简介 在 C/C 语言中&#xff0c;指针被广泛用来表示内存中的地址信息&#xff0c;它们是理解和使用这些语言的核心概念之一。然而&#xff0c;在 Vitis HLS 中&#xff0c;指针的使用…

Unity射击游戏开发教程:(20)增加护盾强度

在本文中,我们将增强护盾,使其在受到超过 1 次攻击后才会被禁用。 Player 脚本具有 Shield PowerUp 方法,我们需要调整盾牌在被摧毁之前可以承受的数量,因此我们将声明一个 int 变量来设置盾牌可以承受的击中数量。

【大模型】fineturn Q-wen

github上下载qwen1_5源码 修改finetun.sh 然后在路径qwen1_5/examples/sft下修改finetun.sh, 内容如下 #!/bin/bash export CUDA_DEVICE_MAX_CONNECTIONS1 DIRpwd# Guide: # This script supports distributed training on multi-gpu workers (as well as single-worker trai…

大数据Hadoop之-工具HIVE(一)

大数据Hadoop之——数据仓库Hive HIVE介绍Hive是基于Hadoop的一个数据仓库(Data Aarehouse,简称数仓、DW),可以将结构化的数据文件映射为一张数据库表,并提供类SQL查询功能。是用于存储、分析、报告的数据系统。 在Hadoop生态系统中,HDFS用于存储数据,Yarn用于资源管理…

WSL调用docker

WSL&#xff08;windows subsystem linux&#xff09;是window系统的原生linux子系统&#xff0c;用于代码开发很方便。 希望在wsl里面运行docker&#xff0c;首先要安装docker在WSL中使用&#xff0c;大部分人的第一想法肯定是用以下命令行安装&#xff08;个人不推荐&#x…

大语言模型本地部署与使用_ollama_open-webui

概述 本文主要记录如何使用ollama运行开源的大语言模型如llama3等&#xff0c;以及如何使用open-webui进行交互。 ollama支持MacOS、Linux、Windows等操作系统&#xff0c;这里主要以Linux和Windows为主&#xff0c;讲述如何在本地运行大语言模型。 一 安装ollama 1.1 Wind…

centos 8.5 yum 更换阿里云源

在CentOS 8上更换为阿里云源,步骤操作&#xff1a; 1 备份当前的yum源配置文件 cp -a /etc/yum.repos.d /etc/yum.repos.d.backup 2 清理原来 官方默认源 rm -rf /etc/yum.repos.d/*.repo 3 下载阿里云CentOS 8的yum源配置文件 curl -o /etc/yum.repos.d/CentOS-Base.rep…

桌面藏线大法

1有线改无线&#xff1a; 蓝牙鼠标 蓝牙键盘 蓝牙耳机 2将排插贴到桌子底下 购物软件上搜 3断舍离 不要的电子产品统统扔掉 4 洞洞板和挂钩 这个不用介绍了

由于找不到mfc140u.dll怎么办,介绍5种靠谱有效的解决方法

当您的电脑显示“mfc140u.dll丢失”的错误时&#xff0c;通常是因为系统中缺少了某个必要的动态链接库文件。这个问题可能会导致某些应用程序无法正常运行&#xff0c;给用户带来困扰。下面我将详细介绍解决该问题的五种方法。 一&#xff0c;关于mfc140u.dll文件的概述 mfc14…

如何在 ASP.NET Core 中实现中间件管道

概述:借助 ASP.NET Core,中间件流水线可以作为一种轻量级、灵活的机制,使开发人员能够在请求流水线的不同阶段插入功能。这些中间件组件可以执行各种任务,例如日志记录、身份验证、授权、异常处理等。它们提供了一种封装和组织代码的方法,促进了更简洁、更易于维护的应用程…

Java类和对象(五)—— 抽象类、接口、Object类和内部类

抽象类 在继承体系下&#xff0c;父类有些方法可能是要被重写的&#xff0c;如果我们事先就知道某些方法需要重写的话&#xff0c;我们可以不用在父类里面具体实现这个方法&#xff0c;这时候我们会用到抽象方法&#xff0c;这时候我们会用到关键字abstract关键字来修饰 publ…

618值得买的好物清单,这些数码好物你千万不能错过!

​随着618购物节的距离越来越近&#xff0c;你是不是已经开始疯狂浏览购物app&#xff0c;准备大肆采购一番了&#xff1f;但是在购物之前&#xff0c;还是得先做一做功课&#xff0c;避免陷入购物陷阱&#xff0c;而作为一名经验丰富的数码爱好者&#xff0c;想通过这次机会给…

Xinstall助力实现App间直接跳转,提升用户体验

在移动互联网时代&#xff0c;App已成为我们日常生活中不可或缺的一部分。然而&#xff0c;在使用各类App时&#xff0c;我们经常会遇到需要在不同App之间切换的情况&#xff0c;这时如果能够直接跳转&#xff0c;将会大大提升用户体验。而Xinstall正是这样一款能够帮助开发者实…

Python语法学习之 - 生成器表达式(Generator Expression)

第一次见这样的语法 本人之前一直是Java工程师&#xff0c;最近接触了一个Python项目&#xff0c;第一次看到如下的代码&#xff1a; i sum(letter in target_arr for letter in source_arr)这条语句是计算source 与 target 数组中有几个单词是相同的。 当我第一眼看到这样…

Docker镜像源自动测试镜像速度,并选择速度最快的镜像

国内执行如下代码 bash <(curl -sSL https://gitee.com/xjxjin/scripts/raw/main/check_docker_registry.sh)国外执行如下代码 bash <(curl -sSL https://github.com/xjxjin/scripts/raw/main/check_docker_registry.sh)如果有老铁有比较不错的镜像源&#xff0c;可以提…

浏览器API与协议

现代浏览器是一个囊括了数百个组件的操作系统&#xff0c;包括进程管理、安全沙箱、分层的优化缓存、JavaScript虚拟机、图形渲染和GPU管道、存储系统、传感器、音频和视频&#xff0c;网络机制等等。 在浏览器上运行的应用的性能。&#xff0c;取决于多个组件&#xff1a;解析…

完整的数据可视化方法集

在当前的大数据时代&#xff0c;了解如何可视化数据是UI/UX设计师技能的重要组成部分。如今&#xff0c;几乎所有的公司都需要良好的数据可视化作为确定业务方向和决策的参考。数据的可视化结果越好&#xff0c;用户的决策就越科学。 1、什么是数据可视化 数据可视化是将信息…

The Missing Semester of Your CS Education(计算机教育中缺失的一课)

Shell 工具和脚本(Shell Tools and Scripting) 一、shell脚本 1.1、变量赋值 在bash中为变量赋值的语法是foobar&#xff0c;访问变量中存储的数值&#xff0c;其语法为 $foo。 需要注意的是&#xff0c;foo bar &#xff08;使用空格隔开&#xff09;是不能正确工作的&…

Html中,想利用JS引入Jquery文件;$.getScript()无效

在使用$.getScript()时&#xff0c;会爆出错误&#xff1a;ReferenceError: $ is not defined &#xff0c;这是因为没有在JS文件前引入Jquery。 那么可以这样使用&#xff1a;(这个方式只适合放在页面代码最后面使用) (function () {var script window.document.createEleme…