Debian Codegraph @

intl/crowdin_translate.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 import core_option_translation as t
4
5 if __name__ == '__main__':
6 try:
7 if t.os.path.isfile(t.sys.argv[1]) or t.sys.argv[1].endswith('.h'):
8 _temp = t.os.path.dirname(t.sys.argv[1])
9 else:
10 _temp = t.sys.argv[1]
11 while _temp.endswith('/') or _temp.endswith('\\'):
12 _temp = _temp[:-1]
13 TARGET_DIR_PATH = _temp
14 except IndexError:
15 TARGET_DIR_PATH = t.os.path.dirname(t.os.path.dirname(t.os.path.realpath(__file__)))
16 print("No path provided, assuming parent directory:\n" + TARGET_DIR_PATH)
17
18 CORE_NAME = t.clean_file_name(t.sys.argv[2])
19 DIR_PATH = t.os.path.dirname(t.os.path.realpath(__file__))
20 LOCALISATIONS_PATH = t.os.path.join(DIR_PATH, CORE_NAME)
21 US_FILE_PATH = t.os.path.join(LOCALISATIONS_PATH, '_us.h')
22 H_FILE_PATH = t.os.path.join(TARGET_DIR_PATH, 'libretro_core_options.h')
23 INTL_FILE_PATH = t.os.path.join(TARGET_DIR_PATH, 'libretro_core_options_intl.h')
24
25 print('Getting texts from libretro_core_options.h')
26 with open(H_FILE_PATH, 'r+', encoding='utf-8') as _h_file:
27 _main_text = _h_file.read()
28 _hash_n_str = t.get_texts(_main_text)
29 _files = t.create_msg_hash(DIR_PATH, CORE_NAME, _hash_n_str)
30 _source_jsons = t.h2json(_files)
31
32 print('Converting translations *.json to *.h:')
33 localisation_files = t.os.scandir(LOCALISATIONS_PATH)
34 t.json2h(LOCALISATIONS_PATH, localisation_files)
35
36 print('Constructing libretro_core_options_intl.h')
37 t.create_intl_file(INTL_FILE_PATH, LOCALISATIONS_PATH, _main_text, _files["_us"])
38
39 print('\nAll done!')