Data-Test-Executer Framework speziell zum Test von Datenverarbeitungen mit Datengenerierung, Systemvorbereitungen, Einspielungen, ganzheitlicher diversifizierender Vergleich
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.8 KiB

2 years ago
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import utils.config_tool
import utils.path_const as P
2 years ago
import basic.constants as B
2 years ago
import basic.program
DEFAULT_LANGUAGE = "en"
EXP_KEY_MISSING = "key is missing {}"
EXP_KEY_DOESNT_EXIST = "key doesnt exist in domain {}"
class I18n:
__instance = None
cache = {}
"""
in this class there should be managed each defined key-value-pairs
the pairs ara loaded from the path testdata/catalog:
* initially the csv-file catalog.csv
* on demand other csv-files in the path
"""
def __init__(self):
self.cache = {}
self.cache = utils.config_tool.getConfig(None, P.KEY_TOOL, "i18n")
2 years ago
I18n.__instance = self
pass
@staticmethod
def getInstance():
if I18n.__instance == None:
return I18n()
return I18n.__instance
def getMessage(self, job, key, args=[]):
print("getMessage "+key+" "+str(args))
out = self.getText(key, job)
out = out.format(args)
return out
def getText(self, key, job):
2 years ago
"""
this function gets the text depending on language which is set in job.conf
2 years ago
:param key: MUST GIVEN WITH (f"{CONST=}", ..
2 years ago
:return:
2 years ago
return self.cache[language][key]
2 years ago
"""
if "language" in job.conf.confs:
2 years ago
language = job.conf.confs["language"]
else:
language = "en"
2 years ago
if language not in self.cache:
raise Exception(EXP_KEY_MISSING, (key))
if "=" in key:
out = self.extractText(key)
key = self.extractKey(key)
2 years ago
if key in self.cache[language]:
out = self.cache[language][key]
elif key in self.cache[DEFAULT_LANGUAGE]:
out = self.cache[DEFAULT_LANGUAGE][key]
return out
def getAliasList(self, key, job):
2 years ago
out = []
2 years ago
out.append(self.extractText(key))
2 years ago
key = self.extractKey(key)
for language in self.cache:
2 years ago
if key not in self.cache[language]:
continue
2 years ago
out.append(self.cache[language][key])
return out
def extractKey(self, key):
if "=" in key:
i = key.find("=")
x = key[0:i]
if "." in x:
i = x.find(".")
y = x[i + 1:]
else:
y = x
key = y
else:
y = key
return key
def extractText(self, key):
if "=" in key:
i = key.find("=")
return key[i + 2:-1]
return ""