Fix in mtemplate conflict

This commit is contained in:
Antonio de la Rosa 2025-04-05 00:59:30 +02:00
commit 4b919b16f4
5 changed files with 103 additions and 8 deletions

View file

@ -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()

View file

@ -30,7 +30,7 @@ class DateForm(BaseForm):
super().__init__(name, value)
self.yes_time=False
self.yes_time=True
self.t=standard_t
def form(self):

View file

@ -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

View file

@ -162,6 +162,10 @@ class PTemplate:
self.add_filter(self._)
self.i18n=I18n(base_name)
self.add_filter(self.i18n.slang)
self.add_filter(self.i18n.tlang)
def _(self, text):

View file

@ -4,9 +4,9 @@ ${add_js('jquery.min.js', 'admin')}
<input type="number" min="1" max="12" name="${form}_month" id="time_${form}_month" class="form_month" value="${m}" size="2" maxlength="2"/>
<input type="number" name="${form}_year" id="time_${form}_year" class="form_year" value="${y}" size="4" maxlength="4"/>
% if yes_time==True:
<input type="text" min="0" max="23" name="${form}_hour" id="time_${form}_hour" class="form_hour" value="${h}" size="2" maxlength="2"/>
<input type="text" min="0" max="60" name="${form}_minute" id="time_${form}_minute" class="form_minute" value="${min}" size="2" maxlength="2"/>
<input type="text" min="0" max="60" name="${form}_second" id="time_${form}_second" class="form_second" value="${s}" size="2" maxlength="2"/>
<input type="number" min="0" max="23" name="${form}_hour" id="time_${form}_hour" class="form_hour" value="${h}" size="2" maxlength="2"/>
<input type="number" min="0" max="60" name="${form}_minute" id="time_${form}_minute" class="form_minute" value="${min}" size="2" maxlength="2"/>
<input type="number" min="0" max="60" name="${form}_second" id="time_${form}_second" class="form_second" value="${s}" size="2" maxlength="2"/>
% endif
<input type="hidden" name="${form}" id="time_${form}" value="" />