新增多语言支持。

This commit is contained in:
2022-01-03 20:45:25 +08:00
parent 737b2d5f07
commit cf7e51595e
14 changed files with 1705 additions and 159 deletions

View File

@ -1,4 +1,4 @@
#-*- coding:utf-8 -*-
# -*- coding:utf-8 -*-
# W-YI 金羿
@ -17,9 +17,47 @@
方便进行语言翻译支持。
'''
import sys
def __main__():
pass
textList = []
for fileName in sys.argv[1:]:
print('读取文件: {}'.format(fileName))
fileText = []
for line in open(fileName, 'r', encoding='utf-8'):
if line.count('"') >=2:
# 只有上帝看得懂我在写什么。
if line[line.index('"'):2+line[line.index('"')+1:].index('"')+len(line[:line.index('"')])] in textList:
thisText = textList.index(line[line.index('"'):2+line[line.index('"')+1:].index('"')+len(line[:line.index('"')])])
else:
thisText = len(textList)
textList.append(line[line.index('"'):2+line[line.index('"')+1:].index('"')+len(line[:line.index('"')])])
fileText.append(line.replace(
line[line.index('"'):2+line[line.index('"')+1:].index('"')+len(line[:line.index('"')])],
'READABLETEXT[{}]'.format(thisText)
))
else:
fileText.append(line)
open(fileName+'_C','w',encoding='utf-8').writelines(fileText)
outFile = open('lang.py','w',encoding='utf-8')
outFile.write('''# -*- coding:utf-8 -*-
# 由金羿翻译工具生成字符串列表
# 请在所需翻译文件前from 此文件 import READABLETEXT
READABLETEXT = {
''')
for i in range(len(textList)):
outFile.write(" {}:{},\n".format(i,textList[i]))
outFile.write('}')
outFile.close()
if __name__ == '__main__':
__main__
__main__()