Fixes in paramecio2
This commit is contained in:
parent
348f3f06f1
commit
59c1e30863
3 changed files with 101 additions and 4 deletions
|
|
@ -28,6 +28,7 @@ import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from paramecio2.libraries.i18n import I18n
|
from paramecio2.libraries.i18n import I18n
|
||||||
|
from paramecio2.libraries.slugify import slugify
|
||||||
try:
|
try:
|
||||||
from settings import config
|
from settings import config
|
||||||
except:
|
except:
|
||||||
|
|
@ -45,6 +46,12 @@ ignored=re.compile(r'^[__|\.].*$')
|
||||||
lang_p=re.compile(r"I18n\.lang\('(.*?)',\s+'(.*?)',\s+'(.*?)'\)")
|
lang_p=re.compile(r"I18n\.lang\('(.*?)',\s+'(.*?)',\s+'(.*?)'\)")
|
||||||
lang_t=re.compile(r"\${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={}
|
tmp_lang={}
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
|
|
@ -53,12 +60,16 @@ def start():
|
||||||
|
|
||||||
global lang_p
|
global lang_p
|
||||||
global lang_t
|
global lang_t
|
||||||
|
global lang_s
|
||||||
|
global lang_tl
|
||||||
|
global lang_ts
|
||||||
|
global lang_ttl
|
||||||
|
|
||||||
# Module to search a file where save the file.
|
# Module to search a file where save the file.
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='A tool for create python language files')
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
@ -86,7 +97,7 @@ def start():
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
scandir(path, path_save)
|
scandir(path, path_save, module_base)
|
||||||
|
|
||||||
#Save the files
|
#Save the files
|
||||||
|
|
||||||
|
|
@ -155,7 +166,7 @@ def start():
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def scandir(path, module_search=''):
|
def scandir(path, module_search='', module_base=None):
|
||||||
|
|
||||||
list=os.listdir(path)
|
list=os.listdir(path)
|
||||||
|
|
||||||
|
|
@ -177,6 +188,19 @@ def scandir(path, module_search=''):
|
||||||
match_p=lang_p.findall(line)
|
match_p=lang_p.findall(line)
|
||||||
match_t=lang_t.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:
|
if match_p!=None:
|
||||||
|
|
||||||
for m in match_p:
|
for m in match_p:
|
||||||
|
|
@ -207,7 +231,45 @@ def scandir(path, module_search=''):
|
||||||
tmp_lang[module]=tmp_lang.get(module, {})
|
tmp_lang[module]=tmp_lang.get(module, {})
|
||||||
|
|
||||||
tmp_lang[module][symbol]=tmp_lang[module].get(symbol, text_default)
|
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()
|
f.close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,35 @@ class I18n:
|
||||||
|
|
||||||
l={}
|
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
|
#@staticmethod
|
||||||
#def set_lang(code_lang):
|
#def set_lang(code_lang):
|
||||||
# if default_lang
|
# if default_lang
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,12 @@ class PTemplate:
|
||||||
self.l=PGetText(module_env+'/app.py')
|
self.l=PGetText(module_env+'/app.py')
|
||||||
|
|
||||||
self.add_filter(self._)
|
self.add_filter(self._)
|
||||||
|
|
||||||
|
self.i18n=I18n(base_name)
|
||||||
|
|
||||||
|
self.add_filter(self.i18n.slang)
|
||||||
|
|
||||||
|
self.add_filter(self.i18n.tlang)
|
||||||
|
|
||||||
def _(self, text):
|
def _(self, text):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue