diff --git a/paramecio2/libraries/check_i18n.py b/paramecio2/libraries/check_i18n.py index 0a826f0..2082e51 100644 --- a/paramecio2/libraries/check_i18n.py +++ b/paramecio2/libraries/check_i18n.py @@ -28,6 +28,7 @@ import re from pathlib import Path from importlib import import_module from paramecio2.libraries.i18n import I18n +from paramecio2.libraries.slugify import slugify try: from settings import config except: @@ -45,6 +46,12 @@ ignored=re.compile(r'^[__|\.].*$') lang_p=re.compile(r"I18n\.lang\('(.*?)',\s+'(.*?)',\s+'(.*?)'\)") lang_t=re.compile(r"\${lang\('(.*?)',\s+'(.*?)',\s+'(.*?)'\)\}") +lang_s=re.compile(r"i18n\.slang\('(.*?)',\s+'(.*?)'\)") +lang_ts=re.compile(r"\${slang\('(.*?)',\s+'(.*?)'\)\}") + +lang_tl=re.compile(r"i18n\.tlang\('(.*?)'\)") +lang_ttl=re.compile(r"\${tlang\('(.*?)'\)\}") + tmp_lang={} def start(): @@ -53,12 +60,16 @@ def start(): global lang_p global lang_t + global lang_s + global lang_tl + global lang_ts + global lang_ttl # Module to search a file where save the file. parser = argparse.ArgumentParser(description='A tool for create python language files') - parser.add_argument('--module', help='The module where search lang files', required=False) + parser.add_argument('--module', help='The module where search lang files', required=True) args = parser.parse_args() @@ -86,7 +97,7 @@ def start(): exit(1) - scandir(path, path_save) + scandir(path, path_save, module_base) #Save the files @@ -155,7 +166,7 @@ def start(): pass -def scandir(path, module_search=''): +def scandir(path, module_search='', module_base=None): list=os.listdir(path) @@ -177,6 +188,19 @@ def scandir(path, module_search=''): match_p=lang_p.findall(line) match_t=lang_t.findall(line) + match_s=lang_s.findall(line) + match_ts=lang_ts.findall(line) + + match_tl=lang_tl.findall(line) + match_ttl=lang_ttl.findall(line) + + """ + global lang_s + global lang_tl + global lang_ts + global lang_ttl + """ + if match_p!=None: for m in match_p: @@ -207,7 +231,45 @@ def scandir(path, module_search=''): tmp_lang[module]=tmp_lang.get(module, {}) tmp_lang[module][symbol]=tmp_lang[module].get(symbol, text_default) - + + if module_base: + + if match_s!=None: + + for m in match_s: + module=base_module + symbol=m[0] + text_default=m[1] + + tmp_lang[module]=tmp_lang.get(module, {}) + tmp_lang[module][symbol]=tmp_lang[module].get(symbol, text_default) + + for m in match_ts: + module=base_module + symbol=m[0] + text_default=m[1] + + tmp_lang[module]=tmp_lang.get(module, {}) + tmp_lang[module][symbol]=tmp_lang[module].get(symbol, text_default) + + + for m in match_tl: + module=base_module + symbol=slugify(m[0]) + text_default=m[0] + + tmp_lang[module]=tmp_lang.get(module, {}) + tmp_lang[module][symbol]=tmp_lang[module].get(symbol, text_default) + + for m in match_ttl: + module=base_module + symbol=slugify(m[0][:40]) + text_default=m[0] + + tmp_lang[module]=tmp_lang.get(module, {}) + tmp_lang[module][symbol]=tmp_lang[module].get(symbol, text_default) + + f.close() diff --git a/paramecio2/libraries/i18n.py b/paramecio2/libraries/i18n.py index 516a879..42188f8 100644 --- a/paramecio2/libraries/i18n.py +++ b/paramecio2/libraries/i18n.py @@ -105,6 +105,35 @@ class I18n: l={} + def __init__(self, module): + + self.module=module + + def slang(self, symbol, text_default, lang=None): + """Method for get a string from selected language but object oriented + + Method for get a string from selected language but object oriented + + Args: + symbol (str): The symbol used for identify the text string. + text_default (str): The text default used. You have use how base for translations. + """ + return I18n.lang(self.module, symbol, text_default, lang) + + def tlang(self, text_default, lang=None): + """Method for get a string from selected language but object oriented and using module and symbol by default + + Method for get a string from selected language but object oriented and using module and symbol by default + + Args: + symbol (str): The symbol used for identify the text string. + text_default (str): The text default used. You have use how base for translations. + """ + + symbol=text_default[:60] + + return I18n.lang(self.module, symbol, text_default, lang) + #@staticmethod #def set_lang(code_lang): # if default_lang diff --git a/paramecio2/libraries/mtemplates.py b/paramecio2/libraries/mtemplates.py index 9b9f0b8..9eb44ff 100644 --- a/paramecio2/libraries/mtemplates.py +++ b/paramecio2/libraries/mtemplates.py @@ -159,6 +159,12 @@ class PTemplate: self.l=PGetText(module_env+'/app.py') self.add_filter(self._) + + self.i18n=I18n(base_name) + + self.add_filter(self.i18n.slang) + + self.add_filter(self.i18n.tlang) def _(self, text):