59 lines
1.3 KiB
Python
Executable File
59 lines
1.3 KiB
Python
Executable File
#!/usr/bin/pyhton3
|
|
import os
|
|
import re
|
|
from lib.translate import translate
|
|
|
|
|
|
def scan_files(path) -> list:
|
|
"""
|
|
Scans dirs and subdirs in PATH to gind *.lua files
|
|
:param path: set path to scan
|
|
:return: list of files in dir and subdir
|
|
"""
|
|
list_files = []
|
|
for root, dirs, files in os.walk(path):
|
|
for file in files:
|
|
if '.lua' in file: list_files.append(f'{root}/{file}')
|
|
|
|
return list_files
|
|
|
|
|
|
# name = "weapongenerator.lua"
|
|
|
|
|
|
def parsing_file(f):
|
|
with open(f) as _f:
|
|
_cached = _f.read()
|
|
|
|
_list = _cached.split('\n')
|
|
_to_translate = []
|
|
|
|
for _str in _list:
|
|
if _str.find('%_t') != -1 or _str.find('%_T') != -1:
|
|
_to_translate.append(_str)
|
|
|
|
return _to_translate
|
|
|
|
|
|
def pars_file(name: str) -> list:
|
|
"""
|
|
:param name: name of file
|
|
:return:
|
|
"""
|
|
list_to_translate: 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
|
|
|
|
|
|
def all_to_translate():
|
|
_files = scan_files(r'C:/Users/riksl/PycharmProjects/weapon-project-extended/')
|
|
print(_files)
|
|
# for _file in _files:
|
|
# _strings = pars_file(_file)
|
|
# print(_strings)
|
|
|
|
if __name__ == '__main__':
|
|
all_to_translate()
|