Added language files for spanish, default is english

This commit is contained in:
absurdo 2023-12-18 21:14:44 +01:00
parent 2f1d79ffc4
commit 9cd3ada7b4
9 changed files with 183 additions and 16 deletions

2
.gitignore vendored
View file

@ -47,7 +47,7 @@ coverage.xml
.hypothesis/ .hypothesis/
# Translations # Translations
*.mo #*.mo
*.pot *.pot
# Django stuff: # Django stuff:

View file

@ -30,6 +30,35 @@ def load_lang(*args):
# here load the language # here load the language
class PGetText:
# Dict where all gettext domain are saved -> domain=name, example, admin, libraries, pastafari2, etc...
l={}
def __init__(self, module_file):
module_dir=os.path.dirname(os.path.realpath(module_file))
module_name=os.path.basename(module_dir)
if module_name not in PGetText.l:
PGetText.l[module_name]={}
for i in I18n.dict_i18n:
if i not in PGetText.l[module_name]:
PGetText.l[module_name][i]=gettext.translation(module_name, module_dir+'/languages/', languages=[i], fallback=True)
PGetText.l[module_name][i].install()
self.module=module_name
def gettext(self, text):
return PGetText.l[self.module][I18n.get_default_lang()].gettext(text)
def pgettext(module_file): def pgettext(module_file):
module=os.path.dirname(os.path.realpath(module_file)) module=os.path.dirname(os.path.realpath(module_file))

View file

@ -1,6 +1,6 @@
# Template frontend from mako. # Template frontend from mako.
import gettext #import gettext
from mako.template import Template from mako.template import Template
from flask import session, url_for from flask import session, url_for
from mako.lookup import TemplateLookup from mako.lookup import TemplateLookup
@ -12,9 +12,9 @@ except:
theme='default' theme='default'
reloader=False reloader=False
import gettext #import gettext
import sys import sys
from paramecio2.libraries.i18n import I18n from paramecio2.libraries.i18n import I18n, PGetText
from paramecio2.libraries.urls import make_url, make_media_url, add_get_parameters from paramecio2.libraries.urls import make_url, make_media_url, add_get_parameters
from paramecio2.libraries.formsutils import csrf_token from paramecio2.libraries.formsutils import csrf_token
@ -120,7 +120,7 @@ class PTemplate:
#print(path.basename(module_env)+' '+base_name+'/languages/') #print(path.basename(module_env)+' '+base_name+'/languages/')
self.l=gettext.translation(path.basename(module_env), base_name+'/languages/', languages=I18n.get_default_lang(), fallback=True) self.l=PGetText(module_env+'/app.py')
self.add_filter(self._) self.add_filter(self._)

View file

@ -2,12 +2,16 @@ from settings import config
from flask import g, url_for from flask import g, url_for
from paramecio2.modules.admin.models.admin import UserAdmin from paramecio2.modules.admin.models.admin import UserAdmin
from paramecio2.libraries.generate_admin_class import GenerateAdminClass from paramecio2.libraries.generate_admin_class import GenerateAdminClass
from paramecio2.libraries.i18n import I18n from paramecio2.libraries.i18n import I18n, PGetText
from paramecio2.libraries.db.coreforms import SelectForm from paramecio2.libraries.db.coreforms import SelectForm
from paramecio2.libraries.db.coreforms import HiddenForm from paramecio2.libraries.db.coreforms import HiddenForm
import copy import copy
from paramecio2.modules.admin import admin_app, t as admin_t from paramecio2.modules.admin import admin_app, t as admin_t
pgettext=PGetText(__file__+'/../')
_=pgettext.gettext
t=copy.copy(admin_t) t=copy.copy(admin_t)
@admin_app.route('/admin/ausers/', methods=['GET', 'POST']) @admin_app.route('/admin/ausers/', methods=['GET', 'POST'])
@ -29,15 +33,15 @@ def ausers():
user_admin.create_forms(['username', 'password', 'email', 'privileges', 'lang', 'dark_theme', 'disabled', 'double_auth', 'last_login']) user_admin.create_forms(['username', 'password', 'email', 'privileges', 'lang', 'dark_theme', 'disabled', 'double_auth', 'last_login'])
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['disabled'].arr_select={0: I18n.lang('admin', 'user_enabled', 'User enabled'), 1: I18n.lang('admin', 'user_disabled', 'User disabled')} user_admin.forms['disabled'].arr_select={0: _('User enabled'), 1: _('User disabled')}
user_admin.forms['double_auth'].arr_select={0: I18n.lang('admin', 'no', 'No'), 1: I18n.lang('admin', 'yes', 'Yes')} user_admin.forms['double_auth'].arr_select={0: _('No'), 1: _('Yes')}
user_admin.fields['password'].protected=False user_admin.fields['password'].protected=False
user_admin.forms['dark_theme'].arr_select={0: I18n.lang('admin', 'light_theme', 'Light theme'), 1: I18n.lang('admin', 'dark_theme', 'Dark theme')} user_admin.forms['dark_theme'].arr_select={0: _('Light theme'), 1: _('Dark theme')}
user_admin.check_user=False user_admin.check_user=False
user_admin.check_email=False user_admin.check_email=False
@ -56,7 +60,7 @@ def ausers():
if type(form_admin).__name__=='str': if type(form_admin).__name__=='str':
return t.load_template('content.phtml', title=I18n.lang('admin', 'users_edit', 'Users edit'), contents=form_admin, path_module='admin_app.ausers') return t.load_template('content.phtml', title=_('Users edit'), contents=form_admin, path_module='admin_app.ausers')
else: else:
return form_admin return form_admin

View file

@ -1,6 +1,6 @@
from flask import Blueprint, redirect, session, url_for, request, g, make_response, abort from flask import Blueprint, redirect, session, url_for, request, g, make_response, abort
from settings import config from settings import config
from paramecio2.libraries.i18n import I18n, pgettext from paramecio2.libraries.i18n import I18n, PGetText
from paramecio2.libraries.datetime import now, format_local_strtime, timestamp_to_datetime, obtain_timestamp from paramecio2.libraries.datetime import now, format_local_strtime, timestamp_to_datetime, obtain_timestamp
from paramecio2.libraries.formsutils import show_form, generate_csrf, set_extra_forms_user, pass_values_to_form from paramecio2.libraries.formsutils import show_form, generate_csrf, set_extra_forms_user, pass_values_to_form
from paramecio2.libraries.db.webmodel import WebModel from paramecio2.libraries.db.webmodel import WebModel
@ -17,7 +17,11 @@ from paramecio2.libraries.sendmail import SendMail
from paramecio2.libraries.formsutils import check_csrf from paramecio2.libraries.formsutils import check_csrf
#import gettext #import gettext
_=pgettext(__file__) #_=pgettext(__file__)
gtext=PGetText(__file__)
_=gtext.gettext
yes_recovery_login=False yes_recovery_login=False
email_address='localhost' email_address='localhost'
@ -262,6 +266,8 @@ def login():
arr_update['last_login']=now() arr_update['last_login']=now()
session['lang']=arr_user.get('lang', I18n.default_lang)
if len(arr_update)>0: if len(arr_update)>0:
user_admin.set_conditions('WHERE id=%s', [arr_user['id']]).update(arr_update) user_admin.set_conditions('WHERE id=%s', [arr_user['id']]).update(arr_update)

View file

@ -0,0 +1,128 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-12-18 20:47+0100\n"
"PO-Revision-Date: 2023-12-18 20:53+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.4.1\n"
#: admin/modules.py:51
msgid "Error: git url wrong"
msgstr "Error: Url git equivocada"
#: admin/modules.py:58
msgid "Error: cannot install the module, view the error in wsgi server log"
msgstr "Error: no puedo instalar el módulo, ver el error en el servidor wsgi"
#: admin/ausers.py:36
msgid "Without privileges"
msgstr "Sin privilegios"
#: admin/ausers.py:36
msgid "Selected privileges"
msgstr "Privilegios seleccionados"
#: admin/ausers.py:36
msgid "Administrator"
msgstr "Administrador"
#: admin/ausers.py:38
msgid "User enabled"
msgstr "Usuario activado"
#: admin/ausers.py:38
msgid "User disabled"
msgstr "Usuario desactivado"
#: admin/ausers.py:40
msgid "No"
msgstr "No"
#: admin/ausers.py:40
msgid "Yes"
msgstr "Sí"
#: admin/ausers.py:44
msgid "Light theme"
msgstr "Tema claro"
#: admin/ausers.py:44
msgid "Dark theme"
msgstr "Tema oscuro"
#: admin/ausers.py:63
msgid "Users edit"
msgstr "Editar usuarios"
#: app.py:126
msgid "Admin"
msgstr "Admin"
#: app.py:260
msgid "Code for complete login"
msgstr "Código para completar login"
#: app.py:260
msgid ""
"We send to you a code for activate your account using double authentication:"
msgstr ""
"Te enviaremos un código para activr tu cuenta usando doble autenticación"
#: templates/modules.phtml:3
msgid "Add new module"
msgstr "Añadir nuevo módulo"
#: templates/home.phtml:4 templates/users.phtml:4
msgid "Welcome to Paramecio Admin"
msgstr "Bienvenido a Paramecio Admin"
#: templates/home.phtml:7 templates/users.phtml:7
msgid "From here you can admin your site"
msgstr "Desde aquí puedes administrar tu sitio"
#: templates/login.phtml:4 templates/login.phtml:99 templates/need_auth.phtml:2
#: templates/need_auth.phtml:6
msgid "Paramecio Login"
msgstr "Paramecio login"
#: templates/login.phtml:103
msgid "Remember login?"
msgstr "¿Recordar login?"
#: templates/login.phtml:110
msgid "Recovery password?"
msgstr "¿Recuperar contraseña?"
#: templates/login.phtml:112
msgid "Remember that only have 3 attempts"
msgstr "Recuera que sólo tienes 3 intentos"
#: templates/register.phtml:51 templates/register.phtml:55
msgid "Paramecio Sign up"
msgstr "Paramecio Registro"
#: templates/dashboard.phtml:66
msgid "Applications"
msgstr "Aplicaciones"
#: templates/need_auth.phtml:9
msgid ""
"Check your email for get instructions for complete login with double auth or"
msgstr ""
"Mira tu email para obtener instrucciones para completar el login con doble "
"autenticación o"
#: templates/need_auth.phtml:10
msgid "Code"
msgstr "Código"

View file

@ -3,9 +3,9 @@ from paramecio2.libraries.i18n import I18n
#modules_admin=[[I18n.lang('admin', 'users_admin', 'User\'s Admin'), 'paramecio.modules.admin.admin.ausers', 'ausers']] #modules_admin=[[I18n.lang('admin', 'users_admin', 'User\'s Admin'), 'paramecio.modules.admin.admin.ausers', 'ausers']]
config_admin.append([I18n.lang('admin', 'users', 'Users')]) config_admin.append([_('Users')])
config_admin.append([I18n.lang('admin', 'users_edit', 'Users edit'), 'paramecio2.modules.admin.admin.ausers', 'admin_app.ausers', 'fa-user']) config_admin.append([_('Users edit'), 'paramecio2.modules.admin.admin.ausers', 'admin_app.ausers', 'fa-user'])
#config_admin.append([I18n.lang('admin', 'modules', 'Modules')]) #config_admin.append([I18n.lang('admin', 'modules', 'Modules')])

View file

@ -107,7 +107,7 @@ ${load_js()|n}
<h1>${title}</h1> <h1>${title}</h1>
<div class="switch-btn"> <div class="switch-btn">
<div class="switch-text"> <div class="switch-text">
Dark Mode ${_('Dark theme')}
</div> </div>
<div class="switch-slider"> <div class="switch-slider">
<label class="switch"> <label class="switch">