Fixes in lang
This commit is contained in:
parent
464754f5d3
commit
9be42a2a4b
9 changed files with 77 additions and 91 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from paramecio.libraries.sessions import get_session
|
from paramecio.libraries.sessionplugin import get_session
|
||||||
from paramecio.libraries.urls import make_url
|
from paramecio.libraries.urls import make_url
|
||||||
from paramecio.libraries.i18n import I18n
|
from paramecio.libraries.i18n import I18n
|
||||||
from paramecio.libraries.httputils import GetPostFiles
|
from paramecio.libraries.httputils import GetPostFiles
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,14 @@ from bottle import request
|
||||||
from paramecio.libraries.urls import add_get_parameters, redirect
|
from paramecio.libraries.urls import add_get_parameters, redirect
|
||||||
from paramecio.libraries.mtemplates import set_flash_message
|
from paramecio.libraries.mtemplates import set_flash_message
|
||||||
from paramecio.libraries.db.formsutils import show_form
|
from paramecio.libraries.db.formsutils import show_form
|
||||||
from paramecio.libraries.i18n import I18n
|
from paramecio.libraries.i18n import I18n, PGetText
|
||||||
from paramecio.libraries.httputils import GetPostFiles
|
from paramecio.libraries.httputils import GetPostFiles
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
gtext=PGetText(__file__)
|
||||||
|
|
||||||
|
_=gtext.gettext
|
||||||
|
|
||||||
class GenerateAdminClass:
|
class GenerateAdminClass:
|
||||||
|
|
||||||
def __init__(self, model, url, t):
|
def __init__(self, model, url, t):
|
||||||
|
|
@ -53,7 +57,7 @@ class GenerateAdminClass:
|
||||||
|
|
||||||
self.post_update=None
|
self.post_update=None
|
||||||
|
|
||||||
self.text_home=I18n.lang('common', 'home', 'Home')
|
self.text_home=_('Home')
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
|
|
||||||
|
|
@ -218,7 +222,7 @@ class GenerateConfigClass:
|
||||||
|
|
||||||
self.post_update=None
|
self.post_update=None
|
||||||
|
|
||||||
self.text_home=I18n.lang('common', 'home', 'Home')
|
self.text_home=_('Home')
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
|
|
||||||
|
|
@ -232,7 +236,7 @@ class GenerateConfigClass:
|
||||||
|
|
||||||
self.model.create_forms()
|
self.model.create_forms()
|
||||||
|
|
||||||
title_edit=I18n.lang('common', 'edit', 'Edit')+' '+self.title_name
|
title_edit=_('Edit')+' '+self.title_name
|
||||||
|
|
||||||
edit_forms=OrderedDict()
|
edit_forms=OrderedDict()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from paramecio.libraries.sessions import get_session
|
from paramecio.libraries.sessionplugin import get_session
|
||||||
from paramecio.libraries.i18n import I18n
|
from paramecio.libraries.i18n import I18n
|
||||||
from settings import config
|
from settings import config
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,17 @@
|
||||||
from paramecio.libraries.pages import Pages
|
from paramecio.libraries.pages import Pages
|
||||||
from paramecio.libraries.urls import add_get_parameters
|
from paramecio.libraries.urls import add_get_parameters
|
||||||
from paramecio.libraries.sessions import get_session
|
from paramecio.libraries.sessions import get_session
|
||||||
from paramecio.libraries.i18n import I18n
|
from paramecio.libraries.i18n import I18n, PGetText
|
||||||
from paramecio.libraries.httputils import GetPostFiles
|
from paramecio.libraries.httputils import GetPostFiles
|
||||||
from bottle import request
|
from bottle import request
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
from paramecio.libraries.pages import Pages
|
from paramecio.libraries.pages import Pages
|
||||||
|
|
||||||
|
gtext=PGetText(__file__)
|
||||||
|
|
||||||
|
_=gtext.gettext
|
||||||
|
|
||||||
class SimpleList:
|
class SimpleList:
|
||||||
|
|
||||||
def __init__(self, model, url, t):
|
def __init__(self, model, url, t):
|
||||||
|
|
@ -76,7 +80,7 @@ class SimpleList:
|
||||||
|
|
||||||
#self.yes_options=True
|
#self.yes_options=True
|
||||||
|
|
||||||
self.arr_extra_fields=[I18n.lang('common', 'options', 'Options')]
|
self.arr_extra_fields=[_('Options')]
|
||||||
|
|
||||||
self.arr_extra_options=[SimpleList.standard_options]
|
self.arr_extra_options=[SimpleList.standard_options]
|
||||||
|
|
||||||
|
|
@ -167,8 +171,8 @@ class SimpleList:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def standard_options(url, id, arr_row):
|
def standard_options(url, id, arr_row):
|
||||||
options=[]
|
options=[]
|
||||||
options.append('<a href="'+add_get_parameters(url, op_admin=1, id=id)+'">'+I18n.lang('common', 'edit', 'Edit')+'</a>')
|
options.append('<a href="'+add_get_parameters(url, op_admin=1, id=id)+'">'+_('Edit')+'</a>')
|
||||||
options.append('<a href="'+add_get_parameters(url, op_admin=3, id=id)+'">'+I18n.lang('common', 'delete', 'Delete')+'</a>')
|
options.append('<a href="'+add_get_parameters(url, op_admin=3, id=id)+'">'+_('Delete')+'</a>')
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
|
|
@ -310,7 +314,7 @@ class AjaxList(SimpleList):
|
||||||
|
|
||||||
pages=Pages()
|
pages=Pages()
|
||||||
|
|
||||||
html_pages=I18n.lang('cuchulu', 'pages', 'Pages')+': '+pages.show( begin_page, total_elements, limit, '#' ,initial_num_pages=self.initial_num_pages, variable='begin_page', label='', func_jscript='')
|
html_pages=_('Pages')+': '+pages.show( begin_page, total_elements, limit, '#' ,initial_num_pages=self.initial_num_pages, variable='begin_page', label='', func_jscript='')
|
||||||
|
|
||||||
with self.db.query(str_query, params) as cursor:
|
with self.db.query(str_query, params) as cursor:
|
||||||
for row in cursor:
|
for row in cursor:
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@ from os import path
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from paramecio.wsgiapp import app
|
from paramecio.wsgiapp import app
|
||||||
|
|
||||||
|
gtext=PGetText(__file__)
|
||||||
|
|
||||||
|
_=gtext.gettext
|
||||||
|
|
||||||
# Preparing envs for views of modules, and views of
|
# Preparing envs for views of modules, and views of
|
||||||
|
|
||||||
def env_theme(module, cache_enabled=True, cache_impl='', cache_args={}, module_directory="./tmp/modules"):
|
def env_theme(module, cache_enabled=True, cache_impl='', cache_args={}, module_directory="./tmp/modules"):
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
from math import ceil, floor
|
from math import ceil, floor
|
||||||
from paramecio.libraries.urls import add_get_parameters
|
from paramecio.libraries.urls import add_get_parameters
|
||||||
from paramecio.libraries.i18n import I18n
|
from paramecio.libraries.i18n import I18n, PGetText
|
||||||
|
|
||||||
|
gtext=PGetText(__file__)
|
||||||
|
|
||||||
|
_=gtext.gettext
|
||||||
|
|
||||||
class Pages:
|
class Pages:
|
||||||
|
|
||||||
|
|
@ -64,7 +68,7 @@ class Pages:
|
||||||
middle_link=add_get_parameters(link, **{variable: str(x+num_elements)} );
|
middle_link=add_get_parameters(link, **{variable: str(x+num_elements)} );
|
||||||
last_link=add_get_parameters(link, **{variable: str( ( ( total_page*num_elements ) - num_elements) ) } )
|
last_link=add_get_parameters(link, **{variable: str( ( ( total_page*num_elements ) - num_elements) ) } )
|
||||||
|
|
||||||
pages += "<a class=\""+Pages.css_class+"\" href=\""+middle_link+"\" onclick=\"func_jscript\">>></a> <a class=\"link_pages\" href=\""+last_link+"\" onclick=\"func_jscript\">"+I18n.lang('common', 'last', 'Last')+"</a>"
|
pages += "<a class=\""+Pages.css_class+"\" href=\""+middle_link+"\" onclick=\"func_jscript\">>></a> <a class=\"link_pages\" href=\""+last_link+"\" onclick=\"func_jscript\">"+_('Last')+"</a>"
|
||||||
|
|
||||||
|
|
||||||
return pages
|
return pages
|
||||||
|
|
|
||||||
|
|
@ -1,60 +1,30 @@
|
||||||
#!/usr/bin/python
|
"""
|
||||||
|
Paramecio2fm is a series of wrappers for Flask, mako and others and construct a simple headless cms.
|
||||||
|
|
||||||
#A very simple version of strtr of php.
|
Copyright (C) 2023 Antonio de la Rosa Caballero
|
||||||
|
|
||||||
def strtr(str_in, pat_str, rep_str):
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
ret_str=''
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
arr_dict={}
|
|
||||||
|
|
||||||
if(len(pat_str)!=len(rep_str)):
|
|
||||||
raise NameError('Ups, pat_str len != rep_str len')
|
|
||||||
|
|
||||||
#Create dictionary
|
|
||||||
|
|
||||||
for (i, l) in enumerate(pat_str):
|
|
||||||
arr_dict[l]=rep_str[i]
|
|
||||||
|
|
||||||
#Make a for to the str_in and substr.
|
|
||||||
|
|
||||||
for le in str_in:
|
|
||||||
|
|
||||||
if le in arr_dict:
|
|
||||||
|
|
||||||
ret_str+=arr_dict[le]
|
|
||||||
|
|
||||||
else:
|
|
||||||
ret_str+=le
|
|
||||||
|
|
||||||
return (ret_str)
|
|
||||||
|
|
||||||
def slugify(str_in, respect_upper=False, replace_space='-', replace_dot=False, replace_barr=False):
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
str_out=''
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
from_str='àáâãäåæçèéêëìíîïðòóôõöøùúûýþÿŕñÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÒÓÔÕÖØÙÚÛÝỲŸÞŔÑ¿?!¡()"|#*%,;+&$ºª<>`çÇ{}@~=^:´[]\''
|
|
||||||
to_str= 'aaaaaaaceeeeiiiidoooooouuuybyrnAAAAAACEEEEIIIIDOOOOOOUUUYYYBRN----------------------------------'
|
|
||||||
|
|
||||||
if replace_dot==True:
|
|
||||||
|
|
||||||
from_str+='.'
|
|
||||||
from_to+='-'
|
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
if replace_barr==True:
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
from_str+="/"
|
|
||||||
to_str+="-"
|
|
||||||
|
|
||||||
str_out=str_in.strip()
|
|
||||||
|
|
||||||
str_out=strtr(str_out, from_str, to_str)
|
|
||||||
|
|
||||||
str_out=str_out.replace(" ", replace_space)
|
from slugify import slugify as slugify_func
|
||||||
|
|
||||||
if respect_upper==False:
|
def slugify(slug, *args, **wargs):
|
||||||
str_out=str_out.lower()
|
"""Simple wrapper for slugify module https://github.com/un33k/python-slugify
|
||||||
|
|
||||||
return str_out
|
Args:
|
||||||
|
slug (str): The string to be slugified
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
return slugify_func(slug, *args, **wargs)
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,9 @@ def home_admin(session={}):
|
||||||
|
|
||||||
#s=get_session()
|
#s=get_session()
|
||||||
|
|
||||||
i18n=I18n('admin2')
|
#i18n=I18n('admin2')
|
||||||
|
|
||||||
return t.load_template('layout.phtml', title=i18n.tlang('Admin'), module_selected='home_admin', session=session)
|
return t.load_template('layout.phtml', title=_('Admin'), module_selected='home_admin', session=session)
|
||||||
#return {}
|
#return {}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -103,9 +103,9 @@ def login_admin(session={}):
|
||||||
|
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
i18n=I18n('admin2')
|
#i18n=I18n('admin2')
|
||||||
|
|
||||||
return t.load_template('login.phtml', title=i18n.tlang('Login'))
|
return t.load_template('login.phtml', title=_('Login'))
|
||||||
|
|
||||||
@admin_app.get('/signup', skip=[check_login], name='admin_app.signup_admin')
|
@admin_app.get('/signup', skip=[check_login], name='admin_app.signup_admin')
|
||||||
def signup_admin(session={}):
|
def signup_admin(session={}):
|
||||||
|
|
@ -120,20 +120,20 @@ def signup_admin(session={}):
|
||||||
|
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
i18n=I18n('admin2')
|
#i18n=I18n('admin2')
|
||||||
|
|
||||||
return t.load_template('signup.phtml', title=i18n.tlang('Signup'))
|
return t.load_template('signup.phtml', title=_('Signup'))
|
||||||
|
|
||||||
@admin_app.post('/login', skip=[check_login], name='admin_app.check_login_admin')
|
@admin_app.post('/login', skip=[check_login], name='admin_app.check_login_admin')
|
||||||
def check_login_admin(session={}):
|
def check_login_admin(session={}):
|
||||||
|
|
||||||
db=WebModel.connection()
|
db=WebModel.connection()
|
||||||
|
|
||||||
i18n=I18n('admin2')
|
#i18n=I18n('admin2')
|
||||||
|
|
||||||
error=1
|
error=1
|
||||||
|
|
||||||
message=i18n.tlang('Invalid user and password')
|
message=_('Invalid user and password')
|
||||||
|
|
||||||
no_login=check_login_tries(request, db)
|
no_login=check_login_tries(request, db)
|
||||||
|
|
||||||
|
|
@ -183,7 +183,7 @@ def check_login_admin(session={}):
|
||||||
|
|
||||||
sendmail=SendMail(ssl=True)
|
sendmail=SendMail(ssl=True)
|
||||||
|
|
||||||
sendmail.send(config.portal_email, [result['email']], i18n.tlang('Code for complete login'), i18n.tlang('We send to you a code for activate your account using double authentication:')+"\n"+token_auth, content_type='plain', attachments=[])
|
sendmail.send(config.portal_email, [result['email']], _('Code for complete login'), _('We send to you a code for activate your account using double authentication:')+"\n"+token_auth, content_type='plain', attachments=[])
|
||||||
|
|
||||||
if result['privileges']==0:
|
if result['privileges']==0:
|
||||||
with db.query('select module from privilegesmodule2 WHERE user_id=%s', [result['id']]) as cursor:
|
with db.query('select module from privilegesmodule2 WHERE user_id=%s', [result['id']]) as cursor:
|
||||||
|
|
@ -221,7 +221,7 @@ def check_login_admin(session={}):
|
||||||
@admin_app.post('/signup', skip=[check_login], name='admin_app.signup_insert_admin')
|
@admin_app.post('/signup', skip=[check_login], name='admin_app.signup_insert_admin')
|
||||||
def signup_insert_admin(session={}):
|
def signup_insert_admin(session={}):
|
||||||
|
|
||||||
i18n=I18n('admin2')
|
#i18n=I18n('admin2')
|
||||||
|
|
||||||
error=1
|
error=1
|
||||||
|
|
||||||
|
|
@ -260,7 +260,7 @@ def signup_insert_admin(session={}):
|
||||||
error=0
|
error=0
|
||||||
message="User added!"
|
message="User added!"
|
||||||
else:
|
else:
|
||||||
message=i18n.tlang('Sorry, cannot create the new user')
|
message=_('Sorry, cannot create the new user')
|
||||||
|
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
@ -315,9 +315,9 @@ def change_theme(session={}):
|
||||||
@admin_app.get('/need_auth', skip=[check_login], name='admin_app.need_auth')
|
@admin_app.get('/need_auth', skip=[check_login], name='admin_app.need_auth')
|
||||||
def need_auth(session={}):
|
def need_auth(session={}):
|
||||||
|
|
||||||
i18n=I18n('admin2')
|
#i18n=I18n('admin2')
|
||||||
|
|
||||||
return t.load_template('need_auth.phtml', title=i18n.tlang('Auth check'))
|
return t.load_template('need_auth.phtml', title=_('Auth check'))
|
||||||
|
|
||||||
@admin_app.post('/auth_check', skip=[check_login], name='admin_app.auth_check')
|
@admin_app.post('/auth_check', skip=[check_login], name='admin_app.auth_check')
|
||||||
def auth_check(session={}):
|
def auth_check(session={}):
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ env=env_theme(__file__)
|
||||||
|
|
||||||
t=PTemplate(env)
|
t=PTemplate(env)
|
||||||
|
|
||||||
i18n=I18n('admin2')
|
#i18n=I18n('admin2')
|
||||||
|
|
||||||
gtext=PGetText(__file__)
|
gtext=PGetText(__file__)
|
||||||
|
|
||||||
|
|
@ -59,11 +59,11 @@ def admin_users(session={}):
|
||||||
|
|
||||||
user_admin.create_forms(['username', 'password', 'email', 'privileges', 'lang', 'dark_theme', 'double_auth'])
|
user_admin.create_forms(['username', 'password', 'email', 'privileges', 'lang', 'dark_theme', 'double_auth'])
|
||||||
|
|
||||||
user_admin.forms['privileges'].arr_select={0: I18n.lang('admin', 'without_privileges', 'Without privileges'), 1: I18n.lang('admin', 'selected_privileges', 'Selected privileges'), 2: I18n.lang('admin', 'administrator', 'Administrator')}
|
user_admin.forms['privileges'].arr_select={0: _('Without privileges'), 1: _('Selected privileges'), 2: _('Administrator')}
|
||||||
|
|
||||||
user_admin.forms['dark_theme'].arr_select={0: i18n.tlang('Light theme'), 1: i18n.tlang('Dark theme')}
|
user_admin.forms['dark_theme'].arr_select={0: _('Light theme'), 1: _('Dark theme')}
|
||||||
|
|
||||||
user_admin.forms['double_auth'].arr_select={0: i18n.tlang('No'), 1: i18n.tlang('Yes')}
|
user_admin.forms['double_auth'].arr_select={0: _('No'), 1: _('Yes')}
|
||||||
|
|
||||||
user_admin.fields['password'].protected=False
|
user_admin.fields['password'].protected=False
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ def admin_users(session={}):
|
||||||
|
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
return t.load_template('users.phtml', title=i18n.tlang('Admin users'), tlang=i18n.tlang, module_selected='admin_app.admin_users', slist=slist, session=session)
|
return t.load_template('users.phtml', title=_('Admin users'), tlang=_, module_selected='admin_app.admin_users', slist=slist, session=session)
|
||||||
|
|
||||||
@admin_app.get('/ausers/permissions/<user_id:int>', name="admin_app.admin_permissions")
|
@admin_app.get('/ausers/permissions/<user_id:int>', name="admin_app.admin_permissions")
|
||||||
@admin_app.post('/ausers/permissions/<user_id:int>', name="admin_app.admin_permissions")
|
@admin_app.post('/ausers/permissions/<user_id:int>', name="admin_app.admin_permissions")
|
||||||
|
|
@ -129,18 +129,18 @@ def admin_permissions(user_id, session={}):
|
||||||
privileges_admin=admin.show()
|
privileges_admin=admin.show()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
arr_user={'username': i18n.tlang('User not found')}
|
arr_user={'username': _('User not found')}
|
||||||
privileges_admin=''
|
privileges_admin=''
|
||||||
|
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
return t.load_template('access.phtml', title=i18n.tlang('Users permissions'), privileges_admin=privileges_admin, user=arr_user, module_selected='admin_app.admin_users')
|
return t.load_template('access.phtml', title=_('Users permissions'), privileges_admin=privileges_admin, user=arr_user, module_selected='admin_app.admin_users')
|
||||||
|
|
||||||
def user_options(url, id, arr_row):
|
def user_options(url, id, arr_row):
|
||||||
|
|
||||||
options=[]
|
options=[]
|
||||||
options.append('<a href="'+add_get_parameters(url, op_admin=1, id=id)+'">'+I18n.lang('common', 'edit', 'Edit')+'</a>')
|
options.append('<a href="'+add_get_parameters(url, op_admin=1, id=id)+'">'+_('Edit')+'</a>')
|
||||||
if not arr_row['privileges']:
|
if not arr_row['privileges']:
|
||||||
options.append(f'<a href="{app.get_url('admin_app.admin_permissions', user_id=id)}">'+i18n.tlang('User access')+'</a>')
|
options.append(f'<a href="{app.get_url('admin_app.admin_permissions', user_id=id)}">'+_('User access')+'</a>')
|
||||||
options.append('<a href="'+add_get_parameters(url, op_admin=3, id=id)+'">'+I18n.lang('common', 'delete', 'Delete')+'</a>')
|
options.append('<a href="'+add_get_parameters(url, op_admin=3, id=id)+'">'+_('Delete')+'</a>')
|
||||||
return options
|
return options
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue