From eb422b7db7528b89433a31254a813e4c3afa9e5b Mon Sep 17 00:00:00 2001 From: odudex Date: Tue, 17 Sep 2024 16:26:07 -0300 Subject: [PATCH] i18n more tests --- i18n/i18n.py | 2 +- tests/test_i18n.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/i18n/i18n.py b/i18n/i18n.py index a91e4fb6..91021383 100644 --- a/i18n/i18n.py +++ b/i18n/i18n.py @@ -26,7 +26,6 @@ from os import listdir, walk, mkdir from os.path import isfile, isdir, exists, join, basename import re -from translate import Translator SRC_DIR = "../src" TRANSLATION_FILES_DIR = "translations" @@ -117,6 +116,7 @@ def print_missing(): force_target = sys.argv[2] else: force_target = None + from translate import Translator slugs = find_translation_slugs() translation_filenames = [ diff --git a/tests/test_i18n.py b/tests/test_i18n.py index 633991d5..2b0a3b88 100644 --- a/tests/test_i18n.py +++ b/tests/test_i18n.py @@ -23,6 +23,8 @@ def test_translations(mocker, m5stickv): from krux.krux_settings import t, locale_control + from krux.translations import available_languages, ref_array + import binascii # Test default language assert t("Load Mnemonic") == "Load Mnemonic" @@ -33,3 +35,16 @@ def test_translations(mocker, m5stickv): # Test non existent slug assert t("New Text") == "New Text" + + # Cross-check available languages reference files + crc32_index = binascii.crc32("Load Mnemonic".encode("utf-8")) + reference_index = ref_array.index(crc32_index) + for lang in available_languages: + # Construct the path to the nested module + lang_module_path = f"krux.translations.{lang[:2]}" + # Import the top-level module (krux) + lang_trans_module = __import__(lang_module_path, fromlist=[""]) + # Access the translation_array variable from the nested module + lang_trans_array = getattr(lang_trans_module, "translation_array") + locale_control.load_locale(lang) + assert t("Load Mnemonic") == lang_trans_array[reference_index]