diff options
author | Alvin Wong <[email protected]> | 2021-04-12 17:20:19 +0800 |
---|---|---|
committer | Alvin Wong <[email protected]> | 2021-04-12 17:20:19 +0800 |
commit | 2f2575c0b7760d36838644eb2a171f94088375e6 (patch) | |
tree | e00cf8a0c287e42720c4e34dd7fbd74ecf159563 | |
parent | 570fa16d442587b4eb1d9926fa2da64a766b28d6 (diff) | |
download | IronOS-2f2575c0b7760d36838644eb2a171f94088375e6.tar.gz IronOS-2f2575c0b7760d36838644eb2a171f94088375e6.zip |
Refactor make_translation.py to split parsing and writing
-rwxr-xr-x | Translations/make_translation.py | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/Translations/make_translation.py b/Translations/make_translation.py index a05643a6..c7787c94 100755 --- a/Translations/make_translation.py +++ b/Translations/make_translation.py @@ -406,18 +406,37 @@ def escape(string: str) -> str: @dataclass
-class TranslationItem:
- info: str
- str_index: int
+class LanguageData:
+ lang: dict
+ defs: dict
+ build_version: str
+ sym_list: List[str]
+ font_map: FontMap
+ symbol_conversion_table: Dict[str, bytes]
-def write_language(lang: dict, defs: dict, build_version: str, f: TextIO) -> None:
+def prepare_language(lang: dict, defs: dict, build_version: str) -> LanguageData:
language_code: str = lang["languageCode"]
- logging.info(f"Generating block for {language_code}")
+ logging.info(f"Preparing language data for {language_code}")
# Iterate over all of the text to build up the symbols & counts
text_list = get_letter_counts(defs, lang, build_version)
# From the letter counts, need to make a symbol translator & write out the font
sym_list, font_map, symbol_conversion_table = get_font_map_and_table(text_list)
+ return LanguageData(
+ lang, defs, build_version, sym_list, font_map, symbol_conversion_table
+ )
+
+
+def write_language(data: LanguageData, f: TextIO) -> None:
+ lang = data.lang
+ defs = data.defs
+ build_version = data.build_version
+ sym_list = data.sym_list
+ font_map = data.font_map
+ symbol_conversion_table = data.symbol_conversion_table
+
+ language_code: str = lang["languageCode"]
+ logging.info(f"Generating block for {language_code}")
font_table_text = make_font_table_cpp(sym_list, font_map, symbol_conversion_table)
try:
@@ -470,6 +489,12 @@ def get_translation_common_text( return translation_common_text
+@dataclass
+class TranslationItem:
+ info: str
+ str_index: int
+
+
def get_translation_strings_and_indices_text(
lang: dict, defs: dict, symbol_conversion_table: Dict[str, bytes]
) -> str:
@@ -730,9 +755,10 @@ def main() -> None: lang_ = read_translation(json_dir, args.languageCode)
defs_ = load_json(os.path.join(json_dir, "translations_def.js"), True)
+ language_data = prepare_language(lang_, defs_, build_version)
out_ = args.output
write_start(out_)
- write_language(lang_, defs_, build_version, out_)
+ write_language(language_data, out_)
logging.info("Done")
|