diff --git a/.gitignore b/.gitignore index af2f537..7a31788 100644 --- a/.gitignore +++ b/.gitignore @@ -47,7 +47,7 @@ coverage.xml .hypothesis/ # Translations -*.mo +#*.mo *.pot # Django stuff: diff --git a/paramecio2/libraries/i18n.py b/paramecio2/libraries/i18n.py index 5c80560..cc35722 100644 --- a/paramecio2/libraries/i18n.py +++ b/paramecio2/libraries/i18n.py @@ -29,7 +29,36 @@ def load_lang(*args): pass # 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): module=os.path.dirname(os.path.realpath(module_file)) diff --git a/paramecio2/libraries/mtemplates.py b/paramecio2/libraries/mtemplates.py index 39d324c..1cb8371 100644 --- a/paramecio2/libraries/mtemplates.py +++ b/paramecio2/libraries/mtemplates.py @@ -1,6 +1,6 @@ # Template frontend from mako. -import gettext +#import gettext from mako.template import Template from flask import session, url_for from mako.lookup import TemplateLookup @@ -12,9 +12,9 @@ except: theme='default' reloader=False -import gettext +#import gettext 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.formsutils import csrf_token @@ -120,7 +120,7 @@ class PTemplate: #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._) diff --git a/paramecio2/modules/admin/admin/ausers.py b/paramecio2/modules/admin/admin/ausers.py index 212e5ea..702cb15 100644 --- a/paramecio2/modules/admin/admin/ausers.py +++ b/paramecio2/modules/admin/admin/ausers.py @@ -2,12 +2,16 @@ from settings import config from flask import g, url_for from paramecio2.modules.admin.models.admin import UserAdmin 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 HiddenForm import copy from paramecio2.modules.admin import admin_app, t as admin_t +pgettext=PGetText(__file__+'/../') + +_=pgettext.gettext + t=copy.copy(admin_t) @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.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.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_email=False @@ -56,7 +60,7 @@ def ausers(): 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: return form_admin diff --git a/paramecio2/modules/admin/app.py b/paramecio2/modules/admin/app.py index 8ba36c9..9772755 100644 --- a/paramecio2/modules/admin/app.py +++ b/paramecio2/modules/admin/app.py @@ -1,6 +1,6 @@ from flask import Blueprint, redirect, session, url_for, request, g, make_response, abort 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.formsutils import show_form, generate_csrf, set_extra_forms_user, pass_values_to_form from paramecio2.libraries.db.webmodel import WebModel @@ -17,7 +17,11 @@ from paramecio2.libraries.sendmail import SendMail from paramecio2.libraries.formsutils import check_csrf #import gettext -_=pgettext(__file__) +#_=pgettext(__file__) + +gtext=PGetText(__file__) + +_=gtext.gettext yes_recovery_login=False email_address='localhost' @@ -262,6 +266,8 @@ def login(): arr_update['last_login']=now() + session['lang']=arr_user.get('lang', I18n.default_lang) + if len(arr_update)>0: user_admin.set_conditions('WHERE id=%s', [arr_user['id']]).update(arr_update) diff --git a/paramecio2/modules/admin/languages/es-ES/LC_MESSAGES/admin.mo b/paramecio2/modules/admin/languages/es-ES/LC_MESSAGES/admin.mo new file mode 100644 index 0000000..4a227a7 Binary files /dev/null and b/paramecio2/modules/admin/languages/es-ES/LC_MESSAGES/admin.mo differ diff --git a/paramecio2/modules/admin/languages/es-ES/LC_MESSAGES/admin.po b/paramecio2/modules/admin/languages/es-ES/LC_MESSAGES/admin.po new file mode 100644 index 0000000..36e622c --- /dev/null +++ b/paramecio2/modules/admin/languages/es-ES/LC_MESSAGES/admin.po @@ -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 , 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" diff --git a/paramecio2/modules/admin/settings/config_admin.py b/paramecio2/modules/admin/settings/config_admin.py index 0c285c0..6e942be 100644 --- a/paramecio2/modules/admin/settings/config_admin.py +++ b/paramecio2/modules/admin/settings/config_admin.py @@ -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']] -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')]) diff --git a/paramecio2/modules/admin/templates/dashboard.phtml b/paramecio2/modules/admin/templates/dashboard.phtml index bedaefd..64aedbd 100644 --- a/paramecio2/modules/admin/templates/dashboard.phtml +++ b/paramecio2/modules/admin/templates/dashboard.phtml @@ -107,7 +107,7 @@ ${load_js()|n}

${title}

- Dark Mode + ${_('Dark theme')}