From e430580abaa474ecb74b8874638fe44a952e1ab4 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Mon, 14 Apr 2025 15:42:12 -0300 Subject: [PATCH] Add language selection feature and internationalization support --- intl_tools/__init__.py | 0 intl_tools/admin.py | 1 + intl_tools/apps.py | 6 ++ intl_tools/forms.py | 23 +++++++ intl_tools/migrations/__init__.py | 0 intl_tools/models.py | 1 + intl_tools/tests.py | 1 + intl_tools/views.py | 25 +++++++ locale/pt_BR/LC_MESSAGES/django.mo | Bin 0 -> 1489 bytes locale/pt_BR/LC_MESSAGES/django.po | 87 ++++++++++++++++++++++++ templates/accounts/login.html | 102 +++++++++++++---------------- templates/accounts/logout.html | 47 +++++-------- templates/base.html | 33 ++++++---- templates/base_login.html | 4 +- templates/generic_form_guest.html | 17 +++++ update_messages.sh | 3 + wireguard_webadmin/settings.py | 16 +++-- wireguard_webadmin/urls.py | 2 + 18 files changed, 261 insertions(+), 107 deletions(-) create mode 100644 intl_tools/__init__.py create mode 100644 intl_tools/admin.py create mode 100644 intl_tools/apps.py create mode 100644 intl_tools/forms.py create mode 100644 intl_tools/migrations/__init__.py create mode 100644 intl_tools/models.py create mode 100644 intl_tools/tests.py create mode 100644 intl_tools/views.py create mode 100644 locale/pt_BR/LC_MESSAGES/django.mo create mode 100644 locale/pt_BR/LC_MESSAGES/django.po create mode 100644 templates/generic_form_guest.html create mode 100755 update_messages.sh diff --git a/intl_tools/__init__.py b/intl_tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/intl_tools/admin.py b/intl_tools/admin.py new file mode 100644 index 0000000..846f6b4 --- /dev/null +++ b/intl_tools/admin.py @@ -0,0 +1 @@ +# Register your models here. diff --git a/intl_tools/apps.py b/intl_tools/apps.py new file mode 100644 index 0000000..0e508b5 --- /dev/null +++ b/intl_tools/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class IntlToolsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'intl_tools' diff --git a/intl_tools/forms.py b/intl_tools/forms.py new file mode 100644 index 0000000..35d9fc2 --- /dev/null +++ b/intl_tools/forms.py @@ -0,0 +1,23 @@ +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Column, Layout, Row, Submit +from django import forms +from django.conf import settings +from django.utils.translation import gettext_lazy as _ + + +class LanguageForm(forms.Form): + language = forms.ChoiceField( + choices=settings.LANGUAGES, + label=_("Language"), + ) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.form_method = 'post' + self.helper.layout = Layout( + Row( + Column('language', css_class='col-md-6'), + ), + Submit('submit', _("Change Language"), css_class='btn btn-primary') + ) \ No newline at end of file diff --git a/intl_tools/migrations/__init__.py b/intl_tools/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/intl_tools/models.py b/intl_tools/models.py new file mode 100644 index 0000000..6b20219 --- /dev/null +++ b/intl_tools/models.py @@ -0,0 +1 @@ +# Create your models here. diff --git a/intl_tools/tests.py b/intl_tools/tests.py new file mode 100644 index 0000000..a39b155 --- /dev/null +++ b/intl_tools/tests.py @@ -0,0 +1 @@ +# Create your tests here. diff --git a/intl_tools/views.py b/intl_tools/views.py new file mode 100644 index 0000000..6f4e52b --- /dev/null +++ b/intl_tools/views.py @@ -0,0 +1,25 @@ +from django.conf import settings +from django.shortcuts import redirect, render +from django.utils import translation + +from .forms import LanguageForm + + +def view_change_language(request): + if request.method == 'POST': + form = LanguageForm(request.POST) + if form.is_valid(): + language = form.cleaned_data['language'] + translation.activate(language) + request.session['django_language'] = language + next_url = '/' + response = redirect(next_url) + response.set_cookie(settings.LANGUAGE_COOKIE_NAME, language) + return response + else: + form = LanguageForm(initial={'language': translation.get_language()}) + + if request.user.is_authenticated: + return render(request, 'generic_form.html', {'form': form}) + else: + return render(request, 'generic_form_guest.html', {'form': form}) \ No newline at end of file diff --git a/locale/pt_BR/LC_MESSAGES/django.mo b/locale/pt_BR/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..fb309f4ab29dc5296b1ee1e5382aa58e7c5c438a GIT binary patch literal 1489 zcmZ9L%a7bd5XKEGui=eAhzO)YND!2GNOFp1vr){BcQeBC&^#6;w_3Z$(~+m!bhih> z9f_Pcao`9+T7<+6j+_Sm1g_lR%$);#J)W#LwAB7}yQ-_dDwqFwdFQJD<0Z^DFu%im z4fEn7cwl@1z5w0>p8~%I9|yk$p8>z$zW)h)0{dUU7r|daf9`kib?{H{9QZHzEO_qG zI^Mfr3;Rppli)7+4!93~4&DJHocSAk9{Vdh^*s^j{cnO^`v~;9j<@y&=(OBE#kNt`p*BewPvZL(nE*i|-|l^Huh z(TZik$Ax(CVk|zcq!HPJJ*$k2C^Tneg;~k;)U&o&$Hp}#_)wn}#F$`)jpC&Ujz$CO zsg-nC3S*^K!7W|Uf>(l$g-~RxG!@p)tD?9|h0b%4k*-|ZyBYcjdJZc#UV(E`<@U_c zrOxDBimXjjOY~=j1FTuipP`QaL^iyQX3ccZ7#F$gDSV-RClN~8ir%Bl0N6Ki-LFP zRveAP{xIxDbaUA0_b%KX4&qkA)`e5U$`CnL}NoWxDW4adiqh4|&>UPKRWO5y@ z_16xkf|ngiqQT+JE4h{=HwxL-CU1P8px^7qjqJ0wpZM18tVJL#o_t?cSALl-yhP&MUf3 zm*3lM1ySLIVMD!4>LmwTME;|*3AQAqS7;ZA3noG>IEc|)nGPaXaUnnB^~w6armnQ5 zR_h;EqWGU>Abh;_H%9WQ#gIVzrfiJJalfuRb$!xAtv#fYseIT0WvaWx(9Bjotj2G% zT?MfEhNhAY6B>Ne+0Yjp>2&=A&9$UVSacd12T7pkmcGp)P`86g#kT1}gG;4W80>YzlqC2A{+9Bv$U)-R_hZ+m*c1QMH0jh1xCS|0#xEm0h-I&!GD?Q Bq2&Mo literal 0 HcmV?d00001 diff --git a/locale/pt_BR/LC_MESSAGES/django.po b/locale/pt_BR/LC_MESSAGES/django.po new file mode 100644 index 0000000..8c7bbc6 --- /dev/null +++ b/locale/pt_BR/LC_MESSAGES/django.po @@ -0,0 +1,87 @@ +# 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. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-04-14 15:34-0300\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" + +#: intl_tools/forms.py:11 templates/accounts/login.html:36 +msgid "Language" +msgstr "Idioma" + +#: intl_tools/forms.py:22 templates/base.html:80 +msgid "Change Language" +msgstr "Alterar Idioma" + +#: templates/accounts/login.html:14 +msgid "Username" +msgstr "Usuário" + +#: templates/accounts/login.html:23 +msgid "Password" +msgstr "Senha" + +#: templates/accounts/login.html:32 +msgid "Login" +msgstr "Acessar" + +#: templates/accounts/logout.html:11 +msgid "You have been successfully logged out." +msgstr "Você foi desconectado com sucesso." + +#: templates/accounts/logout.html:14 +msgid "Login again" +msgstr "Acessar novamente" + +#: templates/base.html:112 +msgid "Status" +msgstr "Estado" + +#: templates/base.html:158 +msgid "User Manager" +msgstr "Configurar Usuários" + +#: templates/base.html:176 +msgid "VPN Invite" +msgstr "Convite para VPN" + +#: templates/base.html:254 +msgid "Update Required" +msgstr "Atualização Necessária" + +#: templates/base.html:256 +msgid "" +"Your WireGuard settings have been modified. To apply these changes, please " +"update the configuration and reload the WireGuard service." +msgstr "" +"Suas configurações do WireGuard foram modificadas. Para aplicar essas " +"mudanças, atualize a configuração e recarregue o serviço WireGuard." + +#: templates/base.html:265 +msgid "Update and restart service" +msgstr "Atualizar e reiniciar o serviço" + +#: templates/base.html:273 +msgid "Update and reload service" +msgstr "Atualizar e recarregar o serviço" + +#: templates/base.html:286 +msgid "Update Available" +msgstr "Atualização Disponível" + +#: templates/base.html:288 +msgid "Version" +msgstr "Versão" diff --git a/templates/accounts/login.html b/templates/accounts/login.html index 974a5bc..602abe1 100644 --- a/templates/accounts/login.html +++ b/templates/accounts/login.html @@ -1,62 +1,50 @@ {% extends "base_login.html" %} +{% load i18n %} {% block content %} +
+ +
+
+
+ {% csrf_token %} +
+ +
+
+ +
+
+
-
- +
- -
-
-
- {% csrf_token %} -
- -
-
- -
-
-
- -
- -
-
- -
-
-
- - - -
-
-
-
- -
-
-
- - - -
- -
-
- - - - - - - - - {% endblock %} -``` + +{% endblock %} diff --git a/templates/accounts/logout.html b/templates/accounts/logout.html index 55a5d6b..0896bc8 100644 --- a/templates/accounts/logout.html +++ b/templates/accounts/logout.html @@ -1,35 +1,20 @@ {% extends "base_login.html" %} +{% load i18n %} {% block content %} - -
- - -
-
- - - - - -
- -
- Login again +
+ +
+
+ +
-
- - -
- -
-
- - - - - - {% endblock %} -``` +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 2d1d5b7..edfadf0 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,5 +1,7 @@ - +{% load i18n %} +{% get_current_language as CURRENT_LANGUAGE %} + @@ -70,13 +72,16 @@ -