Browse Source

i18n tested

master
Ulrich Carmesin 2 years ago
parent
commit
6fc30c3c85
  1. 7
      test/test_08i18n.py
  2. 16
      utils/i18n_tool.py

7
test/test_08i18n.py

@ -15,6 +15,7 @@ import test.testtools
import utils.path_const as P
import utils.i18n_tool
import basic.constants as B
import utils.data_const as D
HOME_PATH = test.constants.HOME_PATH
OS_SYSTEM = test.constants.OS_SYSTEM
@ -83,7 +84,11 @@ class MyTestCase(unittest.TestCase):
# i18n.getText("EXP_KEY_MISSING", EXP_KEY_MISSING, job)
res = i18n.getAliasList(f"{EXP_KEY_MISSING=}", job)
if verbose: print("RESULT "+str(res))
self.assertEqual(res, ['key is missing {}', 'Schluesselwort fehlt {}'])
self.assertEqual(res, ['key is missing {}', 'key is missing {}', 'Schluesselwort fehlt {}'])
cnttest += 1
res = i18n.getAliasList(f"{D.DATA_ATTR_ALIAS=}", job)
if verbose: print("RESULT "+str(res))
self.assertEqual(res, ["_alias"])
cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)

16
utils/i18n_tool.py

@ -6,6 +6,7 @@
# ---------------------------------------------------------------------------------------------------------
import utils.config_tool
import utils.path_const as P
import basic.constants as B
import basic.program
DEFAULT_LANGUAGE = "en"
@ -39,18 +40,12 @@ class I18n:
def getText(self, key, job=None):
"""
this function gets the text depending on language which is set in job.conf
:param domain:
:param key:
:param key: MUST GIVEN WITH (f"{CONST=}", ..
:return:
if not (isinstance(langue, str) and len(langue)):
raise Exception(EXP_KEY_MISSING, (domain, key))
if not (isinstance(key, str) and len(key)):
raise Exception(EXP_KEY_MISSING, (langue, key))
return self.cache[langue][key]
return self.cache[language][key]
"""
if job is None:
jon = basic.program.Job.getInstance()
job = basic.program.Job.getInstance()
language = job.conf.confs["language"]
if language not in self.cache:
raise Exception(EXP_KEY_MISSING, (key))
@ -67,8 +62,11 @@ class I18n:
if job is None:
jon = basic.program.Job.getInstance()
out = []
out.append(self.extractText(key))
key = self.extractKey(key)
for language in self.cache:
if key not in self.cache[language]:
continue
out.append(self.cache[language][key])
return out

Loading…
Cancel
Save