Added i18n standard files
This commit is contained in:
parent
8c0dd3081c
commit
1485e5cee6
8 changed files with 207 additions and 11 deletions
|
|
@ -2,22 +2,70 @@
|
|||
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
from importlib import import_module
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
from settings import config
|
||||
|
||||
pattern=re.compile('^\w+\.py$')
|
||||
pattern=re.compile('^\w+\.(py|html|phtml)$')
|
||||
|
||||
ignored=re.compile('^[__|\.].*$')
|
||||
|
||||
lang_p=re.compile("I18n.lang\('(.*)',\s+'(.*)',\s+'(.*)'\)")
|
||||
lang_p=re.compile("I18n\.lang\('(.*?)',\s+'(.*?)',\s+'(.*?)'\)")
|
||||
lang_t=re.compile("\${lang\('(.*?)',\s+'(.*?)',\s+'(.*?)'\)\}")
|
||||
|
||||
def start():
|
||||
|
||||
# Module to search a file where save the file.
|
||||
|
||||
scandir('.')
|
||||
path_save='paramecio/i18n'
|
||||
|
||||
scandir('.', path_save)
|
||||
|
||||
#Save the files
|
||||
|
||||
file_lang=''
|
||||
|
||||
for module in I18n.l.keys():
|
||||
|
||||
for lang in I18n.dict_i18n:
|
||||
|
||||
try:
|
||||
path_module=path_save.replace('/', '.')+'.'+lang+'.'+module
|
||||
|
||||
import_module(path_module)
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
# Save in a file
|
||||
real_path=path_save+'/'+lang
|
||||
|
||||
if not os.path.isdir(real_path):
|
||||
|
||||
p=Path(real_path)
|
||||
p.mkdir(0o755, True)
|
||||
|
||||
|
||||
file_lang="#!/usr/bin/python3\n\n"
|
||||
|
||||
file_lang+="from paramecio.citoplasma.i18n import I18n\n\n"
|
||||
|
||||
for key, text in I18n.l[module].items():
|
||||
|
||||
file_lang+="I18n.l['"+module+"']['"+key+"']='"+text+"'\n\n"
|
||||
|
||||
final_file=real_path+'/'+module+'.py'
|
||||
|
||||
f=open(final_file, 'w')
|
||||
|
||||
f.write(file_lang)
|
||||
|
||||
f.close()
|
||||
|
||||
pass
|
||||
|
||||
def scandir(path):
|
||||
def scandir(path, module_search=''):
|
||||
|
||||
list=os.listdir(path)
|
||||
|
||||
|
|
@ -32,10 +80,34 @@ def scandir(path):
|
|||
|
||||
f=open(new_path)
|
||||
|
||||
|
||||
for line in f:
|
||||
|
||||
match_p=lang_p.search(line)
|
||||
match_t=lang_t.search(line)
|
||||
|
||||
if match_p!=None:
|
||||
#print(match_p.group(1))
|
||||
|
||||
module=match_p.group(1)
|
||||
symbol=match_p.group(2)
|
||||
text_default=match_p.group(3)
|
||||
|
||||
I18n.l[module]=I18n.l.get(module, {})
|
||||
|
||||
I18n.l[module][symbol]=I18n.l[module].get(symbol, text_default)
|
||||
|
||||
if match_t!=None:
|
||||
|
||||
module=match_t.group(1)
|
||||
symbol=match_t.group(2)
|
||||
text_default=match_t.group(3)
|
||||
|
||||
I18n.l[module]=I18n.l.get(module, {})
|
||||
|
||||
I18n.l[module][symbol]=I18n.l[module].get(symbol, text_default)
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
#print('archivo->'+path+'/'+name)
|
||||
# Open file
|
||||
# obtain modules, keys, and default text
|
||||
|
|
@ -49,5 +121,9 @@ def scandir(path):
|
|||
# THe array i18n is overwrited loading the lang files.
|
||||
|
||||
# Save the files in specified path.
|
||||
|
||||
if __name__=='__main__':
|
||||
|
||||
start()
|
||||
|
||||
|
||||
|
|
@ -6,11 +6,11 @@ def load_lang(*args):
|
|||
|
||||
for module in args:
|
||||
|
||||
lang_path=module+'.i18n.'+I18n.default_lang+'.'+module.split('.')[-1]
|
||||
lang_path=module[0]+'.i18n.'+I18n.default_lang+'.'+module[1]
|
||||
|
||||
try:
|
||||
i18n_module=import_module(module)
|
||||
|
||||
i18n_module=import_module(lang_path)
|
||||
|
||||
pass
|
||||
|
||||
except:
|
||||
|
|
|
|||
0
paramecio/i18n/__init__.py
Normal file
0
paramecio/i18n/__init__.py
Normal file
18
paramecio/i18n/en-US/admin.py
Normal file
18
paramecio/i18n/en-US/admin.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
|
||||
I18n.l['admin']['applications']='Applications'
|
||||
|
||||
I18n.l['admin']['sign_up']='Paramecio Sign up'
|
||||
|
||||
I18n.l['admin']['users_admin']='User\'s Admin'
|
||||
|
||||
I18n.l['admin']['selected_privileges']='Selected privileges'
|
||||
|
||||
I18n.l['admin']['login']='Paramecio Login'
|
||||
|
||||
I18n.l['admin']['without_privileges']='Without privileges'
|
||||
|
||||
I18n.l['admin']['administrator']='Administrator'
|
||||
|
||||
42
paramecio/i18n/en-US/common.py
Normal file
42
paramecio/i18n/en-US/common.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
|
||||
I18n.l['common']['repeat_password']='Repeat Password'
|
||||
|
||||
I18n.l['common']['add_new_item']='Add new item'
|
||||
|
||||
I18n.l['common']['error_username_or_password_exists']='Error: username or email exists in database'
|
||||
|
||||
I18n.l['common']['last']='Last'
|
||||
|
||||
I18n.l['common']['add_item']='Add new item'
|
||||
|
||||
I18n.l['common']['yes']='Yes'
|
||||
|
||||
I18n.l['common']['edit']='Edit'
|
||||
|
||||
I18n.l['common']['password_no_match']='Passwords doesn\'t match'
|
||||
|
||||
I18n.l['common']['delete']='Delete'
|
||||
|
||||
I18n.l['common']['login']='Login'
|
||||
|
||||
I18n.l['common']['no']='No'
|
||||
|
||||
I18n.l['common']['error_login']='Error, wrong username or password'
|
||||
|
||||
I18n.l['common']['sign_up']='Sign up'
|
||||
|
||||
I18n.l['common']['search']='Search'
|
||||
|
||||
I18n.l['common']['task_successful']='Task successful'
|
||||
|
||||
I18n.l['common']['home']='Home'
|
||||
|
||||
I18n.l['common']['edit_new_item']='Edit item'
|
||||
|
||||
I18n.l['common']['error_passwords_no_match']='Error: passwords doesn\'t match'
|
||||
|
||||
I18n.l['common']['options']='Options'
|
||||
|
||||
18
paramecio/i18n/es-ES/admin.py
Normal file
18
paramecio/i18n/es-ES/admin.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
|
||||
I18n.l['admin']['applications']='Applications'
|
||||
|
||||
I18n.l['admin']['sign_up']='Entrar en Paramecio'
|
||||
|
||||
I18n.l['admin']['users_admin']='Usuarios de administración'
|
||||
|
||||
I18n.l['admin']['selected_privileges']='Selected privileges'
|
||||
|
||||
I18n.l['admin']['login']='Entrar en Paramecio'
|
||||
|
||||
I18n.l['admin']['without_privileges']='Without privileges'
|
||||
|
||||
I18n.l['admin']['administrator']='Administrador'
|
||||
|
||||
42
paramecio/i18n/es-ES/common.py
Normal file
42
paramecio/i18n/es-ES/common.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
|
||||
I18n.l['common']['repeat_password']='Repeat Password'
|
||||
|
||||
I18n.l['common']['add_new_item']='Add new item'
|
||||
|
||||
I18n.l['common']['error_username_or_password_exists']='Error: username or email exists in database'
|
||||
|
||||
I18n.l['common']['last']='Last'
|
||||
|
||||
I18n.l['common']['add_item']='Add new item'
|
||||
|
||||
I18n.l['common']['yes']='Yes'
|
||||
|
||||
I18n.l['common']['edit']='Edit'
|
||||
|
||||
I18n.l['common']['password_no_match']='Passwords doesn\'t match'
|
||||
|
||||
I18n.l['common']['delete']='Delete'
|
||||
|
||||
I18n.l['common']['login']='Login'
|
||||
|
||||
I18n.l['common']['no']='No'
|
||||
|
||||
I18n.l['common']['error_login']='Error, wrong username or password'
|
||||
|
||||
I18n.l['common']['sign_up']='Sign up'
|
||||
|
||||
I18n.l['common']['search']='Search'
|
||||
|
||||
I18n.l['common']['task_successful']='Task successful'
|
||||
|
||||
I18n.l['common']['home']='Home'
|
||||
|
||||
I18n.l['common']['edit_new_item']='Edit item'
|
||||
|
||||
I18n.l['common']['error_passwords_no_match']='Error: passwords doesn\'t match'
|
||||
|
||||
I18n.l['common']['options']='Options'
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ from collections import OrderedDict
|
|||
|
||||
t=ptemplate('admin')
|
||||
|
||||
load_lang('paramecio.admin', 'paramecio.common')
|
||||
load_lang(['paramecio', 'admin'], ['paramecio', 'common'])
|
||||
|
||||
@get('/'+config.admin_folder)
|
||||
@get('/'+config.admin_folder+'/<module>')
|
||||
|
|
@ -75,7 +75,7 @@ def home(module=''):
|
|||
return t.load_template('admin/content.html', title=menu[module][0], content_index=new_module.admin(t), menu=menu)
|
||||
|
||||
else:
|
||||
return t.load_template('admin/index.html', title=I18n.lang('admin', 'welcome_to_paramecio', "Welcome to Paramecio Admin!!!"), menu=menu)
|
||||
return t.load_template('admin/index.html', title=I18n.lang('admin', 'welcome_to_paramecio', 'Welcome to Paramecio Admin!!!'), menu=menu)
|
||||
|
||||
else:
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue