From 1485e5cee6c535f803c19bf82f5da32c5af8650c Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sat, 12 Dec 2015 02:51:38 +0100 Subject: [PATCH] Added i18n standard files --- paramecio/citoplasma/check_i18n.py | 88 ++++++++++++++++++++++++++++-- paramecio/citoplasma/i18n.py | 6 +- paramecio/i18n/__init__.py | 0 paramecio/i18n/en-US/admin.py | 18 ++++++ paramecio/i18n/en-US/common.py | 42 ++++++++++++++ paramecio/i18n/es-ES/admin.py | 18 ++++++ paramecio/i18n/es-ES/common.py | 42 ++++++++++++++ paramecio/modules/admin/index.py | 4 +- 8 files changed, 207 insertions(+), 11 deletions(-) create mode 100644 paramecio/i18n/__init__.py create mode 100644 paramecio/i18n/en-US/admin.py create mode 100644 paramecio/i18n/en-US/common.py create mode 100644 paramecio/i18n/es-ES/admin.py create mode 100644 paramecio/i18n/es-ES/common.py diff --git a/paramecio/citoplasma/check_i18n.py b/paramecio/citoplasma/check_i18n.py index 3076784..458ff6c 100644 --- a/paramecio/citoplasma/check_i18n.py +++ b/paramecio/citoplasma/check_i18n.py @@ -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() \ No newline at end of file diff --git a/paramecio/citoplasma/i18n.py b/paramecio/citoplasma/i18n.py index 89978f7..22678ce 100644 --- a/paramecio/citoplasma/i18n.py +++ b/paramecio/citoplasma/i18n.py @@ -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: diff --git a/paramecio/i18n/__init__.py b/paramecio/i18n/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/paramecio/i18n/en-US/admin.py b/paramecio/i18n/en-US/admin.py new file mode 100644 index 0000000..98ebc47 --- /dev/null +++ b/paramecio/i18n/en-US/admin.py @@ -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' + diff --git a/paramecio/i18n/en-US/common.py b/paramecio/i18n/en-US/common.py new file mode 100644 index 0000000..8e7b73a --- /dev/null +++ b/paramecio/i18n/en-US/common.py @@ -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' + diff --git a/paramecio/i18n/es-ES/admin.py b/paramecio/i18n/es-ES/admin.py new file mode 100644 index 0000000..60433f0 --- /dev/null +++ b/paramecio/i18n/es-ES/admin.py @@ -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' + diff --git a/paramecio/i18n/es-ES/common.py b/paramecio/i18n/es-ES/common.py new file mode 100644 index 0000000..8e7b73a --- /dev/null +++ b/paramecio/i18n/es-ES/common.py @@ -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' + diff --git a/paramecio/modules/admin/index.py b/paramecio/modules/admin/index.py index f4300ff..c17b49d 100644 --- a/paramecio/modules/admin/index.py +++ b/paramecio/modules/admin/index.py @@ -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+'/') @@ -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: