Skip to content

Commit

Permalink
i18n more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odudex committed Sep 17, 2024
1 parent 1a4da99 commit eb422b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion i18n/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 = [
Expand Down
15 changes: 15 additions & 0 deletions tests/test_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]

0 comments on commit eb422b7

Please sign in to comment.