changed main
This commit is contained in:
43
main.py
43
main.py
@@ -20,6 +20,15 @@ def scan_files(path) -> list:
|
||||
return list_files
|
||||
|
||||
|
||||
def open_translate(arg, lang='ru'):
|
||||
translation_file = arg + fr'/data/localization/{lang}.po'
|
||||
with open(translation_file, 'r') as f:
|
||||
translation_text = f.read()
|
||||
translation_json = translation_text.split('\n\n')
|
||||
print(translation_json)
|
||||
return translation_json
|
||||
|
||||
|
||||
def parsing_file(f):
|
||||
with open(f) as _f:
|
||||
_cached = _f.read()
|
||||
@@ -39,21 +48,40 @@ def pars_file(name: str) -> list:
|
||||
:param name: name of file
|
||||
:return:
|
||||
"""
|
||||
list_to_translate: list = []
|
||||
_list: list = []
|
||||
for _str in parsing_file(name):
|
||||
string_to_translate = re.findall('"(.*[^/])(?: /\* (.*)\*/)?"%_[t|T]', _str)
|
||||
list_to_translate.append(string_to_translate)
|
||||
return list_to_translate
|
||||
_str_parsed = re.findall('"([^/\"]*)(?: /\*(.*)\*/)?"%_[t,T]', _str)
|
||||
_list.append(_str_parsed)
|
||||
return _list
|
||||
|
||||
|
||||
def all_to_translate(_dir):
|
||||
_files = scan_files(_dir)
|
||||
to_file: str = ''
|
||||
_str = ''
|
||||
for _file in _files:
|
||||
_strings = pars_file(_file)
|
||||
if len(_strings) > 0: to_file = f'{_file}\n {_strings} \n {len(_strings)}\n\n\n'
|
||||
_list = []
|
||||
if len(_strings) > 0:
|
||||
for _string in _strings:
|
||||
_list.append(_string)
|
||||
_title = f'# ========== {_file.split("WPE2")[1]} ==========\n'
|
||||
_str = _str + _title
|
||||
print(f'Generate translation file for {_file.split("WPE2")[1]}')
|
||||
# print(_list)
|
||||
for _name in _list:
|
||||
_msgctxt = ''
|
||||
if len(_name[0][1]) > 1:
|
||||
_msgctxt = f'msgctxt "{_name[0][1]}"\n'
|
||||
|
||||
_msgid = f'msgid "{_name[0][0]}"\n'
|
||||
|
||||
_entity = f'#: {_file.split("WPE2")[1]}:\n{_msgctxt}{_msgid}msgstr ""\n\n'
|
||||
_str = _str + _entity
|
||||
with open('test.txt', 'w') as f:
|
||||
f.write(to_file)
|
||||
f.write(_str)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -63,3 +91,4 @@ if __name__ == '__main__':
|
||||
arg = r'C:\Users\riksl\AppData\Roaming\Avorion\mods\WPE2'
|
||||
|
||||
all_to_translate(arg)
|
||||
# open_translate(arg)
|
||||
|
||||
Reference in New Issue
Block a user