import os,re
c4d_rootdir = r"H:\c4d-s24\resource\modules"  # C4D安装目录下的modules
glossary_path_en = 'G:\C4D中英字典\en.txt'  # 随便写个
glossary_path_zh = 'G:\C4D中英字典\zh.txt'
glossary_path_jp = 'G:\C4D中英字典\jp.txt'
glossary_path_final = r'G:\C4D中英字典\final.txt'

en_glossary = [[],[]]
zh_glossary = [[],[]]
jp_glossary = [[],[]]

# 遍历文件
for root,dirs,files in os.walk(c4d_rootdir):
    for file in files:
        if file.startswith('c4d_strings'):
            # 判断是否是字典
            if root.endswith('strings_en-US') or root.endswith('strings_zh-CN') or root.endswith('strings_ja-JP'):
                FI = root.replace('\\','\\\\') + '\\\\' + file
                with open(FI,encoding='utf-8') as f:
                    content = f.read()
                    content = content[content.find('STRINGTABLE'):]

                pattern_value = re.compile(r'(?<=").+(?=")|""')
                pattern_key = re.compile(r'([A-Z0-9_]+|[A-Z0-9_]+RESTART_All)(?=\t+".*"| +".*"|\s+".*"|_QUESTION".*")')
                result_value = pattern_value .findall(content)
                if root.endswith('strings_en-US'):
                    result_key = pattern_key.findall(content)
                    en_glossary[0].extend(result_key)
                    en_glossary[1].extend(result_value)

                if root.endswith('strings_zh-CN'):
                    result_key_zh = pattern_key .findall(content)
                    zh_glossary[0].extend(result_key_zh)
                    zh_glossary[1].extend(result_value)

                if root.endswith('strings_ja-JP'):
                    result_key_jp = pattern_key .findall(content)
                    jp_glossary[0].extend(result_key_jp)
                    jp_glossary[1].extend(result_value)

final_list = [[],[],[]]
for i in range(len(en_glossary[0])):
    try:
        index = zh_glossary[0].index(en_glossary[0][i])
        # print(index)
        if index +1:
            final_list[0].append(en_glossary[1][i])
            final_list[1].append(zh_glossary[1][index])
            try:
                index2 = jp_glossary[0].index(en_glossary[0][i])
                final_list[2].append(jp_glossary[1][index2])
            except :
                final_list[2].append('')
    except :
        pass

print(len(final_list[0]))
print(len(final_list[1]))
print(len(final_list[2]))

with open(glossary_path_final,'w',encoding='utf-8') as f:
    txt = ''
    for i in range(len(final_list[0])):
        try:
            txt += final_list[0][i] + '\t' + final_list[1][i].encode('utf-8').decode('unicode-escape') + '\t' + final_list[2][i].encode('utf-8').decode('unicode-escape')  + '\n'
        except :
            pass
    f.write(txt)

with open(glossary_path_en,'w',encoding='utf-8') as f:
    txt = ''
    for i in range(len(en_glossary[0])):
        txt += en_glossary[0][i] + '\t' + en_glossary[1][i] + '\n'
    f.write(txt)
#
with open(glossary_path_zh,'w',encoding='utf-8') as f:
    txt = ''
    for i in range(len(zh_glossary[0])):
        cc = zh_glossary[1][i]
        cc = cc.encode('utf-8').decode('unicode-escape')
        txt += zh_glossary[0][i] + '\t' + cc + '\n'
    f.write(txt)

with open(glossary_path_jp,'w',encoding='utf-8') as f:
    txt = ''
    for i in range(len(jp_glossary[0])):
        cc = jp_glossary[1][i]
        cc = cc.encode('utf-8').decode('unicode-escape')
        txt += jp_glossary[0][i] + '\t' + cc + '\n'
    f.write(txt)


 

Leave a Reply

Your email address will not be published.

评论(1)

请下载到本地观看!因为pdf是用的阿里云盘预览,可能部分字体加载不了。

请安装油猴脚本,并下载月离的万事屋脚本

请在右上角三个点 - 下载管理 - 找到刚才的文件,选择允许下载。 或者换个浏览器
echo