From 61273dcee746a5fa3557b7fa90482c391370d9ec Mon Sep 17 00:00:00 2001 From: Appuchia Date: Mon, 24 Nov 2025 19:38:07 +0100 Subject: [PATCH 1/5] feat: Base de las traducciones. Ruta para cambiar el idioma --- hackackathon/settings.py | 15 ++++++++- hackackathon/urls.py | 3 ++ hackackathon/views.py | 27 +++++++++++++++ locale/en/LC_MESSAGES/django.mo | Bin 0 -> 1111 bytes locale/en/LC_MESSAGES/django.po | 56 ++++++++++++++++++++++++++++++++ locale/gl/LC_MESSAGES/django.mo | Bin 0 -> 1115 bytes locale/gl/LC_MESSAGES/django.po | 55 +++++++++++++++++++++++++++++++ 7 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 hackackathon/views.py create mode 100644 locale/en/LC_MESSAGES/django.mo create mode 100644 locale/en/LC_MESSAGES/django.po create mode 100644 locale/gl/LC_MESSAGES/django.mo create mode 100644 locale/gl/LC_MESSAGES/django.po diff --git a/hackackathon/settings.py b/hackackathon/settings.py index 278a287..7a35826 100644 --- a/hackackathon/settings.py +++ b/hackackathon/settings.py @@ -5,6 +5,7 @@ from pathlib import Path from zoneinfo import ZoneInfo +from django.utils.translation import gettext_lazy as _ from dotenv import load_dotenv load_dotenv() @@ -236,7 +237,7 @@ # Internationalization # https://docs.djangoproject.com/en/5.1/topics/i18n/ -LANGUAGE_CODE = "es-es" +LANGUAGE_CODE = "es" TIME_ZONE = "Europe/Madrid" @@ -244,6 +245,18 @@ USE_TZ = True +# Translations +# https://docs.djangoproject.com/en/5.1/topics/i18n/translation/ +# ./manage.py makemessages --all +# ./manage.py compilemessages +LANGUAGES = [ + ("es", _("Castellano")), + ("gl", _("Gallego")), + ("en", _("Inglés")), +] +LANGUAGE_COOKIE_NAME = "lang" +LOCALE_PATHS = (BASE_DIR / "locale",) + # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/5.1/howto/static-files/ diff --git a/hackackathon/urls.py b/hackackathon/urls.py index c41ae22..9e82ff1 100644 --- a/hackackathon/urls.py +++ b/hackackathon/urls.py @@ -5,10 +5,13 @@ from django.contrib import admin from django.urls import include, path +from hackackathon import views + admin.site.site_header = "Hackackathon Admin" urlpatterns = [ path("admin/", admin.site.urls), + path("idioma/", views.idioma, name="idioma"), path("", include("gestion.urls")), ] diff --git a/hackackathon/views.py b/hackackathon/views.py new file mode 100644 index 0000000..b391bdb --- /dev/null +++ b/hackackathon/views.py @@ -0,0 +1,27 @@ +# Copyright (C) 2025-now p.fernandezf & iago.rivas + +from django.conf import settings +from django.contrib import messages +from django.http import HttpRequest +from django.shortcuts import redirect +from django.utils import translation +from django.utils.translation import gettext_lazy as _ + + +def idioma(request: HttpRequest, codigo: str): + idiomas_validos = [codigo for codigo, nombre in settings.LANGUAGES] + + if codigo in idiomas_validos: + translation.activate(codigo) + else: + messages.error( + request, + _("Código de idioma no válido. Los posibles son") + + ": " + + ", ".join(idiomas_validos), + ) + + if siguiente := request.GET.get("next"): + return redirect(siguiente) + + return redirect("registro") diff --git a/locale/en/LC_MESSAGES/django.mo b/locale/en/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..9cec58582f7104d391b8f25433d2676aa3ae082d GIT binary patch literal 1111 zcma)5O>Yx15M7{rXt{CbFdR@p$bnWusscL94p5QT?-a6cAm25a-cLgfeHa7LM?ga6s$$0iSoiq~2Vl<|_JsJKQ>y zk}DmwxRhAxpsh;z<)aOHM!&+`v39}s(O98X1iL(c?LTg$73?SdLA%=t`&en?SY}I6 zu&3kFvZ0P3>~&cmkA*+T8r)$7FOs;=vMy`Hu-lEY_Jfz*P7_2ta@PA= z?NPX+>FO1gn^e?~!#D0>CAmT8;e=bY>P`m^ z3*f2%H^K=`;#d|wb>QcExr<$$xmY+sga7Zd*grJ^TpHxX & iago.rivas +# This file is distributed under the same license as the Hackackathon package. +# p.fernandezf , 2025. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: Hackackathon VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-11-24 19:05+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: gestion/admin.py:47 +#, python-format +msgid "" +"%d participante no tiene el correo verificado y no se ha podido aceptar." +msgid_plural "" +"%d participantes no tienen el correo verificado y no se han podido aceptar." +msgstr[0] "" +"%d participant's email wasn't verified and they couldn't be accepted." +msgstr[1] "" +"%d participants' emails weren't verified and they couldn't be accepted" + +#: gestion/admin.py:59 +#, python-format +msgid "%d participante ya estaba aceptado." +msgid_plural "%d participantes ya estaban aceptados." +msgstr[0] "%d participant was already accepted." +msgstr[1] "%d participants were already accepted." + +#: gestion/admin.py:70 +#, python-format +msgid "%d participante aceptado." +msgid_plural "%d participantes aceptados." +msgstr[0] "%d participant accepted." +msgstr[1] "%d participants accepted." + +#: hackackathon/settings.py:254 +msgid "Castellano" +msgstr "Spanish" + +#: hackackathon/settings.py:255 +msgid "Gallego" +msgstr "Galician" + +#: hackackathon/settings.py:256 +msgid "Inglés" +msgstr "English" diff --git a/locale/gl/LC_MESSAGES/django.mo b/locale/gl/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..0e5b10e55a89b8ced46636004176c57e4150e25d GIT binary patch literal 1115 zcma)4zi$&U7&TBp92+yk$AAPv4zv+w>I7rT-On|5q-o>#2bWLpAnA{ zUl8vQzYxz5uP+heA%8`7z2E-w59B7|C&Kk@T_NNx@(9`W{YJilyt_fjHRKrC_4kmm zgMCE;@R z&B`NhPvO-|JZ@6pJeHr@heghWtU@|s+HhMN^c!@0sdHl;aZN*+;)Tl0hwVdQy-q&X zET;{nkBtwqm~BmMs|xeS+C2$(YOr~~>Ya^O`R}i|qeUiH22bL=64Z*=aSW4mxhux& kGUrUDpDyCVHG2LpzHoYx$d#gn(NL9 & iago.rivas +# Este arquivo distriúese baixo a mesma licenza que o paquete Hackackathon. +# p.fernandezf , 2025. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: Hackackathon VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-11-24 19:05+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: gestion/admin.py:47 +#, python-format +msgid "" +"%d participante no tiene el correo verificado y no se ha podido aceptar." +msgid_plural "" +"%d participantes no tienen el correo verificado y no se han podido aceptar." +msgstr[0] "%d participante non ten o correo verificado e non se puido aceptar." +msgstr[1] "" +"%d participantes non teñen o correo verificado e non se puideron aceptar." + +#: gestion/admin.py:59 +#, python-format +msgid "%d participante ya estaba aceptado." +msgid_plural "%d participantes ya estaban aceptados." +msgstr[0] "%d participante xa estaba aceptado." +msgstr[1] "%d participantes xa estaban aceptados." + +#: gestion/admin.py:70 +#, python-format +msgid "%d participante aceptado." +msgid_plural "%d participantes aceptados." +msgstr[0] "%d participante aceptado." +msgstr[1] "%d participantes aceptados." + +#: hackackathon/settings.py:254 +msgid "Castellano" +msgstr "Castelán" + +#: hackackathon/settings.py:255 +msgid "Gallego" +msgstr "Galego" + +#: hackackathon/settings.py:256 +msgid "Inglés" +msgstr "Inglés" From 4aa5af28e6e3ee3624f2351d9273d20c0596424c Mon Sep 17 00:00:00 2001 From: Appuchia Date: Mon, 24 Nov 2025 19:56:31 +0100 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20Selector=20de=20idioma=20en=20la=20?= =?UTF-8?q?cabecera=20con=20el=20estilo=20de=20la=20p=C3=A1gina=20principa?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hackackathon/views.py | 2 ++ staticfiles/css/style.css | 38 ++++++++++++++++++++++++++++++++++++++ templates/marco.html | 16 +++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/hackackathon/views.py b/hackackathon/views.py index b391bdb..c19e063 100644 --- a/hackackathon/views.py +++ b/hackackathon/views.py @@ -2,12 +2,14 @@ from django.conf import settings from django.contrib import messages +from django.contrib.auth.decorators import login_not_required from django.http import HttpRequest from django.shortcuts import redirect from django.utils import translation from django.utils.translation import gettext_lazy as _ +@login_not_required def idioma(request: HttpRequest, codigo: str): idiomas_validos = [codigo for codigo, nombre in settings.LANGUAGES] diff --git a/staticfiles/css/style.css b/staticfiles/css/style.css index 78f9a2f..fb068cf 100644 --- a/staticfiles/css/style.css +++ b/staticfiles/css/style.css @@ -84,6 +84,44 @@ button.boton { .transparente { background-color: transparent;} +/* Footer */ +.nav-idioma { + display: flex; + justify-content: end; + + margin: 0 auto; + margin-top: 2em; + width: var(--max-width); + max-width: var(--max-width); +} + +#selector-idioma { + display: flex; + justify-items: center; + justify-content: center; + + gap: 0.5rem; + padding: 0.5em 2em; + + font-size: 0.8em; + color: var(--texto); +} + +#selector-idioma a { + font-weight: bolder; + color: var(--amarillo); + text-decoration: none; + padding: 0.25rem 1rem; + border: 2px solid var(--amarillo); + border-radius: .25rem; +} + +#selector-idioma a[aria-selected=true], #selector-idioma a.link-grey-hover-yellow:hover { + color: #000; + background-color: var(--amarillo); + text-decoration: underline; +} + /* GENERAL */ .lucide { diff --git a/templates/marco.html b/templates/marco.html index 4fb68b3..a54d753 100644 --- a/templates/marco.html +++ b/templates/marco.html @@ -1,7 +1,7 @@ - {% load static %} + {% load static i18n %} @@ -33,6 +33,20 @@ {% endif %} + +
{% for message in messages %}
{{ message }}
From d8f71345b7b1afe5628a2e1bc39490108cc69cb9 Mon Sep 17 00:00:00 2001 From: Appuchia Date: Fri, 28 Nov 2025 16:29:37 +0100 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20Traducci=C3=B3n=20del=20texto=20de?= =?UTF-8?q?=20alrededor=20del=20formulario=20de=20registro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestion/views.py | 6 ++--- locale/en/LC_MESSAGES/django.mo | Bin 1111 -> 1662 bytes locale/en/LC_MESSAGES/django.po | 45 +++++++++++++++++++++++++++++--- locale/gl/LC_MESSAGES/django.mo | Bin 1115 -> 1676 bytes locale/gl/LC_MESSAGES/django.po | 45 +++++++++++++++++++++++++++++--- templates/registro.html | 13 ++++++--- 6 files changed, 95 insertions(+), 14 deletions(-) diff --git a/gestion/views.py b/gestion/views.py index 83f06d5..1b4318a 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -23,8 +23,8 @@ ParticipanteForm, PaseForm, Registro, - RevisarParticipanteForm, RevisarMentorForm, + RevisarParticipanteForm, ) from gestion.models import ( Mentor, @@ -55,7 +55,7 @@ def registro(request: HttpRequest): logger.debug("Intento de acceso con el registro cerrado") return render(request, "registro_cerrado.html") - titulo = "Regístrate en" + titulo = _("Regístrate en") url = reverse("registro") if request.method == "GET": @@ -130,7 +130,7 @@ def registro_mentores(request: HttpRequest): logger.debug("Intento de acceso con el registro cerrado") return render(request, "registro_cerrado.html") - titulo = "Registro de mentores" + titulo = _("Registro de mentores") url = reverse("registro-mentores") if request.method == "GET": diff --git a/locale/en/LC_MESSAGES/django.mo b/locale/en/LC_MESSAGES/django.mo index 9cec58582f7104d391b8f25433d2676aa3ae082d..9e540cb53954a6a91b372cd5b85357030fd82377 100644 GIT binary patch delta 811 zcmYk2J#W-N5QgVMAb|t|0SO^d3`N=#LQ0EtIOGGU@>Mg~8)wDduI2TeaCLtm5)Cwn zhBCzop;Q!9mMCfI5Q2(dKnJ|z+@XxLes*WpJMTMR=l?8@zAewbCd5^&+gNY0ZtA{+ z58?&53fAB&@ICklT$>@f1il1sfN#L-TA$>b$@vS|Mg9jk2VOgO%3I(Sq7mJ}MjPIp za1)%x`6;-8W(K^6^BBn^@H_Yz?4KuE1V4f*{4=NmeuCQQH@F1;1y{hO3qA1oaHP?K>(?<1&^`N&{L5&$a?+ zCFA15r{&J5mztsq>_ViTW8;TbN)}B@WGB=s2ELNAZ&-L!(&u|?2_+IM4L%#Bm7LAl%!aPJAN&?;w2UCBLITTpIaC|)1DLM0WdHyG delta 250 zcmeyzbDg99o)F7a1|VPuVi_O~0b*_-?g3&D*a5_*K)e%(rvUMLAoc>{7DfgJE+Bm# zNQ3m=g3^zGv^x;L0%9YexDhkNtW+TF4dj0U(jfJAEDQ`B3=C!rZa@Y|z#m8h^)LYC z!F)C#4FaqX3QPi(Fff5wn@bs`7^R#Oi%U{-auW0M8Qc?da#GXt89ejSa}KX8-kic5 a$|M5*&nA5U diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po index 926cf89..9694d47 100644 --- a/locale/en/LC_MESSAGES/django.po +++ b/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Hackackathon VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-11-24 19:05+0100\n" +"POT-Creation-Date: 2025-11-28 16:16+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -43,14 +43,51 @@ msgid_plural "%d participantes aceptados." msgstr[0] "%d participant accepted." msgstr[1] "%d participants accepted." -#: hackackathon/settings.py:254 +#: hackackathon/settings.py:253 msgid "Castellano" msgstr "Spanish" -#: hackackathon/settings.py:255 +#: hackackathon/settings.py:254 msgid "Gallego" msgstr "Galician" -#: hackackathon/settings.py:256 +#: hackackathon/settings.py:255 msgid "Inglés" msgstr "English" + +#: hackackathon/views.py:21 +msgid "Código de idioma no válido. Los posibles son" +msgstr "Invalid language code. Valid ones are" + +#: templates/registro.html:10 +msgid "Regístrate en" +msgstr "Register at" + +#. Translators: Etiqueta para la casilla de términos y condiciones +#: templates/registro.html:22 +msgid "Acepto los" +msgstr "I accept the" + +#: templates/registro.html:23 +msgid "Términos y Condiciones" +msgstr "Terms and Conditions" + +#: templates/registro.html:24 +msgid "y el" +msgstr "and the" + +#: templates/registro.html:25 +msgid "Código de conducta" +msgstr "Code of conduct" + +#: templates/registro.html:31 +msgid "Apuntarme a HackUDC" +msgstr "Sign up for HackUDC" + +#: templates/registro.html:36 +msgid "Al enviar aceptas la" +msgstr "By signing up you accept the" + +#: templates/registro.html:36 +msgid "política de privacidad" +msgstr "privacy policy" diff --git a/locale/gl/LC_MESSAGES/django.mo b/locale/gl/LC_MESSAGES/django.mo index 0e5b10e55a89b8ced46636004176c57e4150e25d..349ed58841c1544a5486e2a8037bb719900b7852 100644 GIT binary patch literal 1676 zcma)*O>Y}T7{>=F6b$91AORAGrw61~XiZxQsd5_B#dZ>d9Y>B+sXZ~-eY%-4o>|R| zt@s;of(u*_mmYhF5bBxJ9=P!ZkT}2x;LMHxBz|d=wCTv>-_FZE|7V_^|6do+{V34h zM*j%?XY}{u^9%Sx+Xp`br{E9ZFW{G8>qQ}I;P>Er;7{PYaeX#l&BlL#b4+bKZ(@82jCxmR+yKvE{57}^Ee50h0Vcl#{{f@Eds&Frz~8{A`}>T4&gTD}jsF9q z{)JbBz)#%7U(BNkM*XkAnEzey1JHty6yJi77q6m6owv~E?R7lF9On&3JFH(E$9H4g zH{t;80(z`dY)IuWho~<;&Z(3xs7#g81SXkr8Dwtj$5;Gf$)8vwV<{*$Ospxh&atHl zJ9STG2u0Jl?wR%^l{QzHIZ|;a0{KNGb5nQ*1eVpR{&y%+k@>+ zf3r5=(z=lJe4+B>i*ezTp>0rYtDg*bqT-853yC!7PCFeWy?)Y4X`|ohbw0V<-)z^q zs6;Y!(s(U{bq!kE>2_%|?X~GmIWt6mZJuB)6MmrbRGM; z-CJ7Ktt*y$kU_80YcF%ZR=--q;R74UO-tkxct3nvYN^Z$WqZL8@P$Ck{Kre46uU|9RZ9*fbB6+ofBgS?qDMJj*N9 n1M|2oo@o`c^h*DvRi1Rp{u54NH-b%gZj;Pg@Al?bYQ-JtA5PJb}3nK#q7mz*= zq(ORbLFq?8+8u~r0WnCQ5i*U}IpgWbgqpKn4T@X`mhk zpgfollmr7-C=H^3N*I`+{K;!rJSQJyJSXLxSX`2tlarX2&)}YzlardB&)}Jto^yC* V@#YlfNG3^${NaUpAZa971^~Z>Darr< diff --git a/locale/gl/LC_MESSAGES/django.po b/locale/gl/LC_MESSAGES/django.po index 8a8bbf2..de3bdf7 100644 --- a/locale/gl/LC_MESSAGES/django.po +++ b/locale/gl/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Hackackathon VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-11-24 19:05+0100\n" +"POT-Creation-Date: 2025-11-28 16:16+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -42,14 +42,51 @@ msgid_plural "%d participantes aceptados." msgstr[0] "%d participante aceptado." msgstr[1] "%d participantes aceptados." -#: hackackathon/settings.py:254 +#: hackackathon/settings.py:253 msgid "Castellano" msgstr "Castelán" -#: hackackathon/settings.py:255 +#: hackackathon/settings.py:254 msgid "Gallego" msgstr "Galego" -#: hackackathon/settings.py:256 +#: hackackathon/settings.py:255 msgid "Inglés" msgstr "Inglés" + +#: hackackathon/views.py:21 +msgid "Código de idioma no válido. Los posibles son" +msgstr "Código de idioma non válido. Os posibles son" + +#: templates/registro.html:10 +msgid "Regístrate en" +msgstr "Rexístrate en" + +#. Translators: Etiqueta para la casilla de términos y condiciones +#: templates/registro.html:22 +msgid "Acepto los" +msgstr "Acepto os" + +#: templates/registro.html:23 +msgid "Términos y Condiciones" +msgstr "Termos e Condicións" + +#: templates/registro.html:24 +msgid "y el" +msgstr "e o" + +#: templates/registro.html:25 +msgid "Código de conducta" +msgstr "Código de conducta" + +#: templates/registro.html:31 +msgid "Apuntarme a HackUDC" +msgstr "Apuntarme a HackUDC" + +#: templates/registro.html:36 +msgid "Al enviar aceptas la" +msgstr "Ao enviar aceptas a" + +#: templates/registro.html:36 +msgid "política de privacidad" +msgstr "política de privacidade" diff --git a/templates/registro.html b/templates/registro.html index ca0af38..f06f047 100644 --- a/templates/registro.html +++ b/templates/registro.html @@ -1,4 +1,5 @@ {% extends "marco.html" %} +{% load i18n %} {% block title %}Registro{% endblock %} @@ -15,17 +16,23 @@ {{ form }}
- +
-

Al enviar aceptas la política de privacidad

+

{% translate 'Al enviar aceptas la' %} {% translate 'política de privacidad' %}

{% if persona %} From e8bb61adcbdb4e21ad7e4e9ea3842ab63c72bcc7 Mon Sep 17 00:00:00 2001 From: Appuchia Date: Mon, 1 Dec 2025 19:18:47 +0100 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20A=C3=B1adir=20gu=C3=ADa=20de=20trad?= =?UTF-8?q?ucci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/traducciones.md | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 doc/traducciones.md diff --git a/doc/traducciones.md b/doc/traducciones.md new file mode 100644 index 0000000..99377e9 --- /dev/null +++ b/doc/traducciones.md @@ -0,0 +1,68 @@ +# Guía rápida sobre traducciones + +> [!IMPORTANT]\ +> La documentación oficial está disponible [aquí](https://docs.djangoproject.com/en/5.2/topics/i18n/translation/).\ +> Personalmente recomiendo leer al menos hasta la sección de `Lazy Translation` (incluida). + +> [!IMPORTANT]\ +> No queremos traducciones hechas por IA. +> Valoramos el trabajo humano y preferimos no disponer de las traducciones de un idioma antes que servir traducciones +> hechas por IA.\ +> **Por favor, abstente de realizar contribuciones que no sean de autoría humana.** + +## Procedimiento de traducción + +### Modificación del código o las plantillas para integrar las traducciones + +(Solo necesario la primera vez que se traduce un archivo) + +#### En Python + +Se introduce el texto a traducir en la llamada a la función `_()`, definida de forma distinta en función de qué archivo +se trate: + +- En archivos habituales,\ + `from django.utils.translation import gettext as _`.\ +- En archivos ejecutados en el arranque de Django (`admin.py`, `settings.py`, etc.) + https://docs.djangoproject.com/en/5.2/topics/i18n/translation/#lazy-translation \ + `from django.utils.translation import gettext_lazy as _` +- En casos en los que el texto a traducir requiera contexto (aparece en varias situaciones con traducciones distintas), + emplear las variantes:\ + https://docs.djangoproject.com/en/5.2/topics/i18n/translation/#contextual-markers \ + `from django.utils.translation import pgettext as _` y\ + `from django.utils.translation import pgettext_lazy as _`\ + como `_("", "")` +- En traducciones que requieran plurales, usar las variantes:\ + https://docs.djangoproject.com/en/5.2/topics/i18n/translation/#pluralization \ + `from django.utils.translation import ngettext` y\ + `from django.utils.translation import ngettext`. + Para más detalles de su uso ver la documentación oficial. + +Para aportar contexto adicional a los traductores, se debe añadir un comentario en la línea previa a la llamada con la +estructura siguiente: +`# Translators: ` + +#### En plantillas + +Se introduce el texto a traducir entre las comillas de `{% translate '' %}`. + +Para aportar contexto adicional a los traductores, se debe añadir un comentario en la línea previa a la llamada con la +estructura siguiente: +`{# Translators: #}` + +### Creación del archivo de traducción + +`python manage.py makemessages --all` + +### Traducción de los archivos generados + +Se deberán traducir los archivos presentes en `locale/*/*.po`. + +### Compilación de las traducciones para su uso + +`python manage.py compilemessages` + +> Esto es solo un resumen rápido. +> Para información detallada *recomiendo muy encarecidamente* leer la documentación oficial. +> Hay muchos matices que no están recogidos en este documento, bien por desconocimiento, bien por no extenderse en +> exceso. From 873c7d1a2d6f8714ea7b9d713daf996d3d9c4caa Mon Sep 17 00:00:00 2001 From: Appuchia Date: Wed, 3 Dec 2025 16:44:39 +0100 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20A=C3=B1adir=20ejemplos=20a=20la=20g?= =?UTF-8?q?u=C3=ADa=20de=20traducci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/traducciones.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/traducciones.md b/doc/traducciones.md index 99377e9..c32d1fc 100644 --- a/doc/traducciones.md +++ b/doc/traducciones.md @@ -23,7 +23,7 @@ se trate: - En archivos habituales,\ `from django.utils.translation import gettext as _`.\ -- En archivos ejecutados en el arranque de Django (`admin.py`, `settings.py`, etc.) +- En archivos ejecutados en el arranque de Django (`admin.py`, `settings.py`, `models.py`, etc.) https://docs.djangoproject.com/en/5.2/topics/i18n/translation/#lazy-translation \ `from django.utils.translation import gettext_lazy as _` - En casos en los que el texto a traducir requiera contexto (aparece en varias situaciones con traducciones distintas), @@ -42,6 +42,8 @@ Para aportar contexto adicional a los traductores, se debe añadir un comentario estructura siguiente: `# Translators: ` +Un ejemplo del uso está disponible en el archivo [settings.py](hackackathon/settings.py) en la definición de la variable `LANGUAGES`. + #### En plantillas Se introduce el texto a traducir entre las comillas de `{% translate '' %}`. @@ -50,6 +52,8 @@ Para aportar contexto adicional a los traductores, se debe añadir un comentario estructura siguiente: `{# Translators: #}` +Un ejemplo del uso está disponible en el archivo [registro.html](templates/registro.html), en todos los textos presentes. + ### Creación del archivo de traducción `python manage.py makemessages --all`