From df9a71e450c9bd66db6a4d9b81013ff586f1f7b5 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 15 Dec 2015 04:46:52 +0100 Subject: [PATCH] Added new i18n files --- paramecio/citoplasma/check_i18n.py | 83 ++++++++++-------- paramecio/citoplasma/i18n.py | 26 ++++-- paramecio/cromosoma/corefields.py | 9 ++ paramecio/cromosoma/coreforms.py | 4 + paramecio/i18n/admin.py | 40 +++++++++ paramecio/i18n/common.py | 84 +++++++++++++++++++ paramecio/i18n/en-US/admin.py | 20 ----- paramecio/i18n/en-US/common.py | 42 ---------- paramecio/i18n/es-ES/admin.py | 20 ----- paramecio/i18n/es-ES/common.py | 42 ---------- paramecio/modules/admin/index.py | 20 +++-- .../modules/admin/templates/admin/home.html | 13 ++- 12 files changed, 232 insertions(+), 171 deletions(-) create mode 100644 paramecio/i18n/admin.py create mode 100644 paramecio/i18n/common.py delete mode 100644 paramecio/i18n/en-US/admin.py delete mode 100644 paramecio/i18n/en-US/common.py delete mode 100644 paramecio/i18n/es-ES/admin.py delete mode 100644 paramecio/i18n/es-ES/common.py diff --git a/paramecio/citoplasma/check_i18n.py b/paramecio/citoplasma/check_i18n.py index 736ad62..ad0625c 100644 --- a/paramecio/citoplasma/check_i18n.py +++ b/paramecio/citoplasma/check_i18n.py @@ -15,6 +15,8 @@ ignored=re.compile('^[__|\.].*$') lang_p=re.compile("I18n\.lang\('(.*?)',\s+'(.*?)',\s+'(.*?)'\)") lang_t=re.compile("\${lang\('(.*?)',\s+'(.*?)',\s+'(.*?)'\)\}") +tmp_lang={} + def start(): global lang_p @@ -58,42 +60,57 @@ def start(): file_lang='' - for module in I18n.l.keys(): + for module in tmp_lang.keys(): + + # Save in a file + real_path=path_save + + if not os.path.isdir(real_path): + + p=Path(real_path) + p.mkdir(0o755, True) + + try: + path_module=path_save.replace('/', '.')+'.'+module + + import_module(path_module) + + #Add values to tmp lang + + #for real_key, real_text in I18n.l[lang][module].items(): + #tmp_lang[module][real_key]=real_text + + except: + pass + + + file_lang="#!/usr/bin/python3\n\n" + + file_lang+="from paramecio.citoplasma.i18n import I18n\n\n" for lang in I18n.dict_i18n: - - try: - path_module=path_save.replace('/', '.')+'.'+lang+'.'+module + + file_lang+="I18n.l['"+lang+"']={'"+module+"': {}}\n\n" + + I18n.l[lang]=I18n.l.get(lang, {}) + + I18n.l[lang][module]=I18n.l[lang].get(module, {}) + + for key, text in tmp_lang[module].items(): - 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(): + if not key in I18n.l[lang][module]: + + I18n.l[lang][module][key]=text - file_lang+="I18n.l['"+module+"']['"+key+"']='"+text+"'\n\n" + file_lang+="I18n.l['"+lang+"']['"+module+"']['"+key+"']='"+I18n.l[lang][module][key]+"'\n\n" final_file=real_path+'/'+module+'.py' - f=open(final_file, 'w') - - f.write(file_lang) - - f.close() + f=open(final_file, 'w') + + f.write(file_lang) + + f.close() pass @@ -124,9 +141,9 @@ def scandir(path, module_search=''): symbol=match_p.group(2) text_default=match_p.group(3) - I18n.l[module]=I18n.l.get(module, {}) + tmp_lang[module]=tmp_lang.get(module, {}) - I18n.l[module][symbol]=I18n.l[module].get(symbol, text_default) + tmp_lang[module][symbol]=tmp_lang[module].get(symbol, text_default) if match_t!=None: @@ -134,9 +151,9 @@ def scandir(path, module_search=''): symbol=match_t.group(2) text_default=match_t.group(3) - I18n.l[module]=I18n.l.get(module, {}) + tmp_lang[module]=tmp_lang.get(module, {}) - I18n.l[module][symbol]=I18n.l[module].get(symbol, text_default) + tmp_lang[module][symbol]=tmp_lang[module].get(symbol, text_default) f.close() diff --git a/paramecio/citoplasma/i18n.py b/paramecio/citoplasma/i18n.py index 22678ce..5244718 100644 --- a/paramecio/citoplasma/i18n.py +++ b/paramecio/citoplasma/i18n.py @@ -1,15 +1,19 @@ #!/usr/bin/python3 from importlib import import_module +from paramecio.citoplasma.sessions import get_session + +i18n_module={} def load_lang(*args): for module in args: - - lang_path=module[0]+'.i18n.'+I18n.default_lang+'.'+module[1] - try: - i18n_module=import_module(lang_path) + lang_path=module[0]+'.i18n.'+module[1] + + try: + + i18n_module[lang_path]=import_module(lang_path) pass @@ -30,10 +34,18 @@ class I18n: @staticmethod def lang(module, symbol, text_default): - I18n.l[module]=I18n.l.get(module, {}) + s=get_session() - I18n.l[module][symbol]=I18n.l[module].get(symbol, text_default) + s['lang']=s.get('lang', I18n.default_lang) - return I18n.l[module][symbol] + lang=s['lang'] + + I18n.l[lang]=I18n.l.get(lang, {}) + + I18n.l[lang][module]=I18n.l[lang].get(module, {}) + + I18n.l[lang][module][symbol]=I18n.l[lang][module].get(symbol, text_default) + + return I18n.l[lang][module][symbol] diff --git a/paramecio/cromosoma/corefields.py b/paramecio/cromosoma/corefields.py index f54c638..f808836 100644 --- a/paramecio/cromosoma/corefields.py +++ b/paramecio/cromosoma/corefields.py @@ -33,6 +33,15 @@ class CharField(PhangoField): pass +class TextField(PhangoField): + + def __init__(self, name, required=False): + super().__init__(name, 11, required) + + def get_type_sql(self): + + return 'TEXT NOT NULL DEFAULT ""' + class ForeignKeyField(IntegerField): def __init__(self, name, related_table, size=11, required=False, identifier_field='id', named_field="id", select_fields=[]): diff --git a/paramecio/cromosoma/coreforms.py b/paramecio/cromosoma/coreforms.py index 9c64fab..285b51b 100644 --- a/paramecio/cromosoma/coreforms.py +++ b/paramecio/cromosoma/coreforms.py @@ -37,6 +37,10 @@ class TextForm(BaseForm): def __init__(self, name, value): super(TextForm, self).__init__(name, value) + + def form(self): + + return '' class PasswordForm(BaseForm): diff --git a/paramecio/i18n/admin.py b/paramecio/i18n/admin.py new file mode 100644 index 0000000..2a64002 --- /dev/null +++ b/paramecio/i18n/admin.py @@ -0,0 +1,40 @@ +#!/usr/bin/python3 + +from paramecio.citoplasma.i18n import I18n + +I18n.l['en-US']={'admin': {}} + +I18n.l['en-US']['admin']['welcome_to_paramecio']='Welcome to Paramecio Admin!!!' + +I18n.l['en-US']['admin']['administrator']='Administrator' + +I18n.l['en-US']['admin']['remember_login']='Remember login?' + +I18n.l['en-US']['admin']['login']='Paramecio Login' + +I18n.l['en-US']['admin']['selected_privileges']='Selected privileges' + +I18n.l['en-US']['admin']['without_privileges']='Without privileges' + +I18n.l['en-US']['admin']['sign_up']='Paramecio Sign up' + +I18n.l['en-US']['admin']['applications']='Applications' + +I18n.l['es-ES']={'admin': {}} + +I18n.l['es-ES']['admin']['welcome_to_paramecio']='Welcome to Paramecio Admin!!!' + +I18n.l['es-ES']['admin']['administrator']='Administrador' + +I18n.l['es-ES']['admin']['remember_login']='Remember login?' + +I18n.l['es-ES']['admin']['login']='Paramecio Login' + +I18n.l['es-ES']['admin']['selected_privileges']='Selected privileges' + +I18n.l['es-ES']['admin']['without_privileges']='Without privileges' + +I18n.l['es-ES']['admin']['sign_up']='Paramecio Sign up' + +I18n.l['es-ES']['admin']['applications']='Aplicaciones' + diff --git a/paramecio/i18n/common.py b/paramecio/i18n/common.py new file mode 100644 index 0000000..2af4219 --- /dev/null +++ b/paramecio/i18n/common.py @@ -0,0 +1,84 @@ +#!/usr/bin/python3 + +from paramecio.citoplasma.i18n import I18n + +I18n.l['en-US']={'common': {}} + +I18n.l['en-US']['common']['delete']='Delete' + +I18n.l['en-US']['common']['password_no_match']='Passwords doesn't match' + +I18n.l['en-US']['common']['error_login']='Error, wrong username or password' + +I18n.l['en-US']['common']['yes']='Yes' + +I18n.l['en-US']['common']['task_successful']='Task successful' + +I18n.l['en-US']['common']['error_passwords_no_match']='Error: passwords doesn't match' + +I18n.l['en-US']['common']['options']='Options' + +I18n.l['en-US']['common']['add_new_item']='Add new item' + +I18n.l['en-US']['common']['add_item']='Add new item' + +I18n.l['en-US']['common']['home']='Home' + +I18n.l['en-US']['common']['search']='Search' + +I18n.l['en-US']['common']['error_username_or_password_exists']='Error: username or email exists in database' + +I18n.l['en-US']['common']['no']='No' + +I18n.l['en-US']['common']['login']='Login' + +I18n.l['en-US']['common']['edit_new_item']='Edit item' + +I18n.l['en-US']['common']['sign_up']='Sign up' + +I18n.l['en-US']['common']['last']='Last' + +I18n.l['en-US']['common']['edit']='Edit' + +I18n.l['en-US']['common']['repeat_password']='Repeat Password' + +I18n.l['es-ES']={'common': {}} + +I18n.l['es-ES']['common']['delete']='Delete' + +I18n.l['es-ES']['common']['password_no_match']='Passwords doesn't match' + +I18n.l['es-ES']['common']['error_login']='Error, wrong username or password' + +I18n.l['es-ES']['common']['yes']='Yes' + +I18n.l['es-ES']['common']['task_successful']='Task successful' + +I18n.l['es-ES']['common']['error_passwords_no_match']='Error: passwords doesn't match' + +I18n.l['es-ES']['common']['options']='Options' + +I18n.l['es-ES']['common']['add_new_item']='Add new item' + +I18n.l['es-ES']['common']['add_item']='Add new item' + +I18n.l['es-ES']['common']['home']='Home' + +I18n.l['es-ES']['common']['search']='Search' + +I18n.l['es-ES']['common']['error_username_or_password_exists']='Error: username or email exists in database' + +I18n.l['es-ES']['common']['no']='No' + +I18n.l['es-ES']['common']['login']='Login' + +I18n.l['es-ES']['common']['edit_new_item']='Edit item' + +I18n.l['es-ES']['common']['sign_up']='Sign up' + +I18n.l['es-ES']['common']['last']='Last' + +I18n.l['es-ES']['common']['edit']='Edit' + +I18n.l['es-ES']['common']['repeat_password']='Repeat Password' + diff --git a/paramecio/i18n/en-US/admin.py b/paramecio/i18n/en-US/admin.py deleted file mode 100644 index a37ecaf..0000000 --- a/paramecio/i18n/en-US/admin.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/python3 - -from paramecio.citoplasma.i18n import I18n - -I18n.l['admin']['users_admin']='User's Admin' - -I18n.l['admin']['applications']='Applications' - -I18n.l['admin']['administrator']='Administrator' - -I18n.l['admin']['login']='Paramecio Login' - -I18n.l['admin']['sign_up']='Paramecio Sign up' - -I18n.l['admin']['without_privileges']='Without privileges' - -I18n.l['admin']['welcome_to_paramecio']='Welcome to Paramecio Admin!!!' - -I18n.l['admin']['selected_privileges']='Selected privileges' - diff --git a/paramecio/i18n/en-US/common.py b/paramecio/i18n/en-US/common.py deleted file mode 100644 index 5d7b797..0000000 --- a/paramecio/i18n/en-US/common.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python3 - -from paramecio.citoplasma.i18n import I18n - -I18n.l['common']['search']='Search' - -I18n.l['common']['delete']='Delete' - -I18n.l['common']['error_login']='Error, wrong username or password' - -I18n.l['common']['add_item']='Add new item' - -I18n.l['common']['edit']='Edit' - -I18n.l['common']['edit_new_item']='Edit item' - -I18n.l['common']['error_username_or_password_exists']='Error: username or email exists in database' - -I18n.l['common']['last']='Last' - -I18n.l['common']['no']='No' - -I18n.l['common']['add_new_item']='Add new item' - -I18n.l['common']['yes']='Yes' - -I18n.l['common']['options']='Options' - -I18n.l['common']['password_no_match']='Passwords doesn't match' - -I18n.l['common']['login']='Login' - -I18n.l['common']['error_passwords_no_match']='Error: passwords doesn't match' - -I18n.l['common']['sign_up']='Sign up' - -I18n.l['common']['task_successful']='Task successful' - -I18n.l['common']['repeat_password']='Repeat Password' - -I18n.l['common']['home']='Home' - diff --git a/paramecio/i18n/es-ES/admin.py b/paramecio/i18n/es-ES/admin.py deleted file mode 100644 index 0648695..0000000 --- a/paramecio/i18n/es-ES/admin.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/python3 - -from paramecio.citoplasma.i18n import I18n - -I18n.l['admin']['users_admin']='Usuarios de administración' - -I18n.l['admin']['applications']='Applications' - -I18n.l['admin']['administrator']='Administrador' - -I18n.l['admin']['login']='Entrar en Paramecio' - -I18n.l['admin']['sign_up']='Entrar en Paramecio' - -I18n.l['admin']['without_privileges']='Without privileges' - -I18n.l['admin']['welcome_to_paramecio']='Bienvenido a la administración de este site!!' - -I18n.l['admin']['selected_privileges']='Selected privileges' - diff --git a/paramecio/i18n/es-ES/common.py b/paramecio/i18n/es-ES/common.py deleted file mode 100644 index 5d7b797..0000000 --- a/paramecio/i18n/es-ES/common.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python3 - -from paramecio.citoplasma.i18n import I18n - -I18n.l['common']['search']='Search' - -I18n.l['common']['delete']='Delete' - -I18n.l['common']['error_login']='Error, wrong username or password' - -I18n.l['common']['add_item']='Add new item' - -I18n.l['common']['edit']='Edit' - -I18n.l['common']['edit_new_item']='Edit item' - -I18n.l['common']['error_username_or_password_exists']='Error: username or email exists in database' - -I18n.l['common']['last']='Last' - -I18n.l['common']['no']='No' - -I18n.l['common']['add_new_item']='Add new item' - -I18n.l['common']['yes']='Yes' - -I18n.l['common']['options']='Options' - -I18n.l['common']['password_no_match']='Passwords doesn't match' - -I18n.l['common']['login']='Login' - -I18n.l['common']['error_passwords_no_match']='Error: passwords doesn't match' - -I18n.l['common']['sign_up']='Sign up' - -I18n.l['common']['task_successful']='Task successful' - -I18n.l['common']['repeat_password']='Repeat Password' - -I18n.l['common']['home']='Home' - diff --git a/paramecio/modules/admin/index.py b/paramecio/modules/admin/index.py index 518d6ca..ccbdbd1 100644 --- a/paramecio/modules/admin/index.py +++ b/paramecio/modules/admin/index.py @@ -7,7 +7,6 @@ from paramecio.citoplasma.urls import make_url, add_get_parameters from paramecio.citoplasma.sessions import get_session from bottle import get,post,response,request from settings import config -from settings import config_admin from paramecio.citoplasma.lists import SimpleList from paramecio.citoplasma.generate_admin_class import GenerateAdminClass from paramecio.citoplasma.httputils import GetPostFiles @@ -23,19 +22,21 @@ from os import path #from citoplasma.login import LoginClass # Check login +load_lang(['paramecio', 'admin'], ['paramecio', 'common']) + key_encrypt=create_key_encrypt() module_admin=path.dirname(__file__) t=ptemplate(__file__) -load_lang(['paramecio', 'admin'], ['paramecio', 'common']) - @get('/'+config.admin_folder) @get('/'+config.admin_folder+'/') @post('/'+config.admin_folder+'/') def home(module=''): + from settings import config_admin + t.clean_header_cache() #check if login @@ -48,6 +49,13 @@ def home(module=''): s['id']=s.get('id', 0) + s['lang']=s.get('lang', None) + + lang=None + + if s['lang']!=None: + lang=s['lang'] + user_admin.conditions=['WHERE id=%s', [s['id']]] # Check if user id exists in session @@ -81,10 +89,10 @@ def home(module=''): if config.reloader: reload(new_module) - return t.load_template('admin/content.html', title=menu[module][0], content_index=new_module.admin(t), menu=menu) + return t.load_template('admin/content.html', title=menu[module][0], content_index=new_module.admin(t), menu=menu, lang=lang, arr_i18n=I18n.dict_i18n) 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, lang=lang, arr_i18n=I18n.dict_i18n) else: @@ -180,7 +188,7 @@ def login(): timestamp=time()+315360000 - random_text=sha512(urandom(10)).hexdigest() + random_text=create_key_encrypt() #Update user with autologin token diff --git a/paramecio/modules/admin/templates/admin/home.html b/paramecio/modules/admin/templates/admin/home.html index f74b14f..c307384 100644 --- a/paramecio/modules/admin/templates/admin/home.html +++ b/paramecio/modules/admin/templates/admin/home.html @@ -20,7 +20,18 @@ ${HeaderHTML.header_home()|n}
- +