Added new i18n files

This commit is contained in:
Antonio de la Rosa 2015-12-15 04:46:52 +01:00
parent 59083cdd3a
commit df9a71e450
12 changed files with 232 additions and 171 deletions

View file

@ -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,34 +60,49 @@ def start():
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
for module in tmp_lang.keys():
# Save in a file
real_path=path_save+'/'+lang
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 key, text in I18n.l[module].items():
for lang in I18n.dict_i18n:
file_lang+="I18n.l['"+module+"']['"+key+"']='"+text+"'\n\n"
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():
if not key in I18n.l[lang][module]:
I18n.l[lang][module][key]=text
file_lang+="I18n.l['"+lang+"']['"+module+"']['"+key+"']='"+I18n.l[lang][module][key]+"'\n\n"
final_file=real_path+'/'+module+'.py'
@ -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()

View file

@ -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]
lang_path=module[0]+'.i18n.'+module[1]
try:
i18n_module=import_module(lang_path)
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]

View file

@ -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=[]):

View file

@ -38,6 +38,10 @@ class TextForm(BaseForm):
def __init__(self, name, value):
super(TextForm, self).__init__(name, value)
def form(self):
return '<textarea class="'+self.css+'" name="'+self.name+'" id="'+self.name+'_form">'+self.setform(self.default_value)+'</textarea>'
class PasswordForm(BaseForm):
def __init__(self, name, value):

40
paramecio/i18n/admin.py Normal file
View file

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

84
paramecio/i18n/common.py Normal file
View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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+'/<module>')
@post('/'+config.admin_folder+'/<module>')
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

View file

@ -20,7 +20,18 @@ ${HeaderHTML.header_home()|n}
</div>
<div id="center_body">
<div id="header"><span id="title_phango">Paramecio</span> <span id="title_framework">Framework!</span> </div>
<div id="header">
<span id="title_phango">Paramecio</span> <span id="title_framework">Framework!</span>
<div id="languages_general">
% if lang!=None:
% for i18n in arr_i18n:
<a class="" href="/change_lang/${i18n}"><img src="" alt="${i18n}"/></a>
% endfor
% endif
</div>
</div>
<div class="content_admin">
<div id="menu">
<div class="menu_title">${lang('admin', 'applications', 'Applications')}</div>