WireGuard instance form translation

This commit is contained in:
Eduardo Silva 2025-04-15 13:20:58 -03:00
parent 77ed501cfc
commit 52e0f19708
6 changed files with 150 additions and 46 deletions

View File

@ -19,8 +19,8 @@ class DNSSettingsForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(DNSSettingsForm, self).__init__(*args, **kwargs) super(DNSSettingsForm, self).__init__(*args, **kwargs)
self.helper = FormHelper() self.helper = FormHelper()
self.fields['dns_primary'].label = _('Primary Resolver') self.fields['dns_primary'].label = _('Primary DNS')
self.fields['dns_secondary'].label = _('Secondary Resolver') self.fields['dns_secondary'].label = _('Secondary DNS')
self.fields['dns_primary'].required = True self.fields['dns_primary'].required = True
back_label = _('Back') back_label = _('Back')
self.helper.form_method = 'post' self.helper.form_method = 'post'

Binary file not shown.

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-04-15 12:13-0300\n" "POT-Creation-Date: 2025-04-15 13:18-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -58,13 +58,13 @@ msgstr "Destino inválido"
msgid "Enhanced filter is enabled. This command is not available." msgid "Enhanced filter is enabled. This command is not available."
msgstr "Filtro aprimorado está habilitado. Este comando não está disponível." msgstr "Filtro aprimorado está habilitado. Este comando não está disponível."
#: dns/forms.py:22 #: dns/forms.py:22 wireguard/forms.py:19
msgid "Primary Resolver" msgid "Primary DNS"
msgstr "Servidor Primário" msgstr "DNS Primário"
#: dns/forms.py:23 #: dns/forms.py:23 wireguard/forms.py:20
msgid "Secondary Resolver" msgid "Secondary DNS"
msgstr "Servidor Secundário" msgstr "DNS Secundário"
#: dns/forms.py:25 dns/forms.py:67 dns/forms.py:109 #: dns/forms.py:25 dns/forms.py:67 dns/forms.py:109
#: templates/wireguard/wireguard_peer_list.html:166 user_manager/forms.py:49 #: templates/wireguard/wireguard_peer_list.html:166 user_manager/forms.py:49
@ -76,8 +76,9 @@ msgstr "Voltar"
msgid "Resolver Settings" msgid "Resolver Settings"
msgstr "Resolução de DNS" msgstr "Resolução de DNS"
#: dns/forms.py:37 dns/forms.py:83 dns/forms.py:134 user_manager/forms.py:98 #: dns/forms.py:37 dns/forms.py:83 dns/forms.py:134
#: user_manager/forms.py:205 #: templates/wireguard/wireguard_manage_server.html:130
#: user_manager/forms.py:98 user_manager/forms.py:205
msgid "Save" msgid "Save"
msgstr "Salvar" msgstr "Salvar"
@ -140,9 +141,8 @@ msgid ""
"All DNS queries will be forwarded to the primary resolver. If the primary " "All DNS queries will be forwarded to the primary resolver. If the primary "
"resolver is not available, the secondary resolver will be used." "resolver is not available, the secondary resolver will be used."
msgstr "" msgstr ""
"Todas as consultas DNS serão encaminhadas para o resolvedor primário. Se o " "Todas as consultas DNS serão encaminhadas para o DNS primário. Se ele não "
"resolvedor primário não estiver disponível, o resolvedor secundário será " "estiver disponível, o DNS secundário será usado."
"usado."
#: dns/views.py:118 #: dns/views.py:118
msgid "Static DNS deleted successfully" msgid "Static DNS deleted successfully"
@ -400,6 +400,14 @@ msgstr "Instância do WireGuard"
msgid "Users" msgid "Users"
msgstr "Usuários" msgstr "Usuários"
#: templates/wireguard/wireguard_manage_server.html:18
msgid "Create Instance"
msgstr "Criar Instância"
#: templates/wireguard/wireguard_manage_server.html:132
msgid "Delete Configuration"
msgstr "Excluir Configuração"
#: templates/wireguard/wireguard_peer_list.html:75 #: templates/wireguard/wireguard_peer_list.html:75
#: templates/wireguard/wireguard_peer_list.html:125 #: templates/wireguard/wireguard_peer_list.html:125
msgid "Throughput" msgid "Throughput"
@ -603,7 +611,7 @@ msgstr "Recarregar o serviço Wireguard"
msgid "Instance Traffic" msgid "Instance Traffic"
msgstr "Tráfego da Instância" msgstr "Tráfego da Instância"
#: templates/wireguard/wireguard_status.html:46 #: templates/wireguard/wireguard_status.html:46 wireguard/forms.py:12
msgid "Public Address" msgid "Public Address"
msgstr "Endereço Público" msgstr "Endereço Público"
@ -819,10 +827,100 @@ msgstr ""
msgid "Please type the username to proceed." msgid "Please type the username to proceed."
msgstr "Por favor, digite o nome de usuário para prosseguir." msgstr "Por favor, digite o nome de usuário para prosseguir."
#: wireguard/views.py:96 #: wireguard/forms.py:8
msgid "Display Name"
msgstr "Nome de Exibição"
#: wireguard/forms.py:9
msgid "Instance ID"
msgstr "Instância"
#: wireguard/forms.py:10
msgid "Private Key"
msgstr "Chave Privada"
#: wireguard/forms.py:11
msgid "Public Key"
msgstr "Chave Pública"
#: wireguard/forms.py:13
msgid "Listen Port"
msgstr "Porta"
#: wireguard/forms.py:14
msgid "Internal IP Address"
msgstr "Endereço IP Interno"
#: wireguard/forms.py:15
msgid "Netmask"
msgstr "Máscara de Rede"
#: wireguard/forms.py:16
msgid "Post Up"
msgstr "Post Up"
#: wireguard/forms.py:17
msgid "Post Down"
msgstr "Post Down"
#: wireguard/forms.py:18
msgid "Web Refresh Interval"
msgstr "Intervalo de Atualização Web"
#: wireguard/forms.py:39
msgid "Peer List Refresh Interval must be at least 5 seconds"
msgstr "Intervalo de Atualização da Lista de Peers deve ser de pelo menos 5 segundos"
#: wireguard/forms.py:42
msgid "Invalid hostname or IP Address"
msgstr "Endereço ou IP inválido"
#: wireguard/forms.py:51
msgid "The selected network range overlaps with another instance."
msgstr "A faixa de rede selecionada se sobrepõe a outra instância."
#: wireguard/views.py:97
msgid "WireGuard Status" msgid "WireGuard Status"
msgstr "Estado do WireGuard" msgstr "Estado do WireGuard"
#: wireguard/views.py:129
msgid "Update WireGuard Instance"
msgstr "Atualizar Instância do WireGuard"
#: wireguard/views.py:133
msgid "Delete WireGuard Instance"
msgstr "Excluir Instância do WireGuard"
#: wireguard/views.py:136
msgid "Error removing instance: wg"
msgstr "Erro ao remover a instância: wg"
#: wireguard/views.py:136
msgid ""
"|Cannot delete the requested WireGuard instance. There are still peers "
"associated with this instance."
msgstr ""
"|Não é possível excluir a instância do WireGuard solicitada. Existem peers "
"associados a esta instância."
#: wireguard/views.py:139
msgid "|WireGuard instance deleted: wg"
msgstr "|Instância do WireGuard excluída: wg"
#: wireguard/views.py:142
msgid "Invalid confirmation|Please confirm deletion of WireGuard instance: wg"
msgstr ""
"Confirmação inválida|Por favor, confirme a exclusão da instância do "
"WireGuard: wg"
#: wireguard/views.py:146
msgid "Create a new WireGuard Instance"
msgstr "Adicionar uma nova Instância do WireGuard"
#: wireguard/views.py:147
msgid "New WireGuard Instance"
msgstr "Nova Instância do WireGuard"
#: wireguard_peer/views.py:50 #: wireguard_peer/views.py:50
msgid "WireGuard Peer List" msgid "WireGuard Peer List"
msgstr "Lista de Peers do WireGuard" msgstr "Lista de Peers do WireGuard"

View File

@ -1,4 +1,5 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load i18n %}
{% block content %} {% block content %}
@ -14,7 +15,7 @@
</li> </li>
{% endfor %} {% endfor %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link {%if not current_instance%}active{%endif%}" href="/server/manage/?action=create" role="tab" >Create Instance</a> <a class="nav-link {%if not current_instance%}active{%endif%}" href="/server/manage/?action=create" role="tab" >{% trans 'Create Instance' %}</a>
</li> </li>
</ul> </ul>
@ -125,9 +126,9 @@
</div> </div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button> <button type="submit" class="btn btn-primary">{% trans 'Save' %}</button>
{% if current_instance.uuid %} {% if current_instance.uuid %}
<a href='javascript:void(0)' class='btn btn-outline-danger' data-command='delete' onclick='openCommandDialog(this)'>Delete Configuration</a> <a href='javascript:void(0)' class='btn btn-outline-danger' data-command='delete' onclick='openCommandDialog(this)'>{% trans 'Delete Configuration' %}</a>
{% endif %} {% endif %}
</div> </div>
</form> </form>

View File

@ -1,22 +1,26 @@
from django import forms
from .models import WireGuardInstance, NETMASK_CHOICES
from wgwadmlibrary.tools import is_valid_ip_or_hostname
import ipaddress import ipaddress
from django import forms
from django.utils.translation import gettext_lazy as _
from wgwadmlibrary.tools import is_valid_ip_or_hostname
from .models import NETMASK_CHOICES, WireGuardInstance
class WireGuardInstanceForm(forms.ModelForm): class WireGuardInstanceForm(forms.ModelForm):
name = forms.CharField(label='Display Name', required=False) name = forms.CharField(label=_('Display Name'), required=False)
instance_id = forms.IntegerField(label='Instance ID') instance_id = forms.IntegerField(label=_('Instance ID'))
private_key = forms.CharField(label='Private Key') private_key = forms.CharField(label=_('Private Key'))
public_key = forms.CharField(label='Public Key') public_key = forms.CharField(label=_('Public Key'))
hostname = forms.CharField(label='Public Address') hostname = forms.CharField(label=_('Public Address'))
listen_port = forms.IntegerField(label='Listen Port') listen_port = forms.IntegerField(label=_('Listen Port'))
address = forms.GenericIPAddressField(label='VPN IP Address') address = forms.GenericIPAddressField(label=_('Internal IP Address'))
netmask = forms.ChoiceField(choices=NETMASK_CHOICES, label='Netmask') netmask = forms.ChoiceField(choices=NETMASK_CHOICES, label=_('Netmask'))
post_up = forms.CharField(label='Post Up', required=False) post_up = forms.CharField(label=_('Post Up'), required=False)
post_down = forms.CharField(label='Post Down', required=False) post_down = forms.CharField(label=_('Post Down'), required=False)
peer_list_refresh_interval = forms.IntegerField(label='Web Refresh Interval', initial=20) peer_list_refresh_interval = forms.IntegerField(label=_('Web Refresh Interval'), initial=10)
dns_primary = forms.GenericIPAddressField(label='Primary DNS', initial='1.1.1.1', required=False) dns_primary = forms.GenericIPAddressField(label=_('Primary DNS'), initial='1.1.1.1', required=False)
dns_secondary = forms.GenericIPAddressField(label='Secondary DNS', initial='', required=False) dns_secondary = forms.GenericIPAddressField(label=_('Secondary DNS'), initial='', required=False)
class Meta: class Meta:
model = WireGuardInstance model = WireGuardInstance
@ -35,10 +39,10 @@ class WireGuardInstanceForm(forms.ModelForm):
peer_list_refresh_interval = cleaned_data.get('peer_list_refresh_interval') peer_list_refresh_interval = cleaned_data.get('peer_list_refresh_interval')
if peer_list_refresh_interval < 5: if peer_list_refresh_interval < 5:
raise forms.ValidationError('Peer List Refresh Interval must be at least 5 seconds') raise forms.ValidationError(_('Peer List Refresh Interval must be at least 5 seconds'))
if not is_valid_ip_or_hostname(hostname): if not is_valid_ip_or_hostname(hostname):
raise forms.ValidationError('Invalid hostname or IP Address') raise forms.ValidationError(_('Invalid hostname or IP Address'))
current_network = ipaddress.ip_network(f"{address}/{netmask}", strict=False) current_network = ipaddress.ip_network(f"{address}/{netmask}", strict=False)
all_other_instances = WireGuardInstance.objects.all() all_other_instances = WireGuardInstance.objects.all()
@ -47,7 +51,7 @@ class WireGuardInstanceForm(forms.ModelForm):
for instance in all_other_instances: for instance in all_other_instances:
other_network = ipaddress.ip_network(f"{instance.address}/{instance.netmask}", strict=False) other_network = ipaddress.ip_network(f"{instance.address}/{instance.netmask}", strict=False)
if current_network.overlaps(other_network): if current_network.overlaps(other_network):
raise forms.ValidationError(f"The network range {current_network} overlaps with another instance's network range {other_network}.") raise forms.ValidationError(_('The selected network range overlaps with another instance.'))
#if self.instance: #if self.instance:
# if post_up or post_down: # if post_up or post_down:

View File

@ -4,6 +4,7 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.db import models from django.db import models
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from user_manager.models import UserAcl from user_manager.models import UserAcl
@ -125,25 +126,25 @@ def view_wireguard_manage_instance(request):
current_instance = wireguard_instances.first() current_instance = wireguard_instances.first()
if current_instance: if current_instance:
page_title = f'wg{current_instance.instance_id}' page_title = f'wg{current_instance.instance_id}'
message_title = 'Update WireGuard Instance' message_title = _('Update WireGuard Instance')
if current_instance.name: if current_instance.name:
page_title += f' ({current_instance.name})' page_title += f' ({current_instance.name})'
if request.GET.get('action') == 'delete': if request.GET.get('action') == 'delete':
message_title = 'Delete WireGuard Instance' message_title = _('Delete WireGuard Instance')
if request.GET.get('confirmation') == 'delete wg' + str(current_instance.instance_id): if request.GET.get('confirmation') == 'delete wg' + str(current_instance.instance_id):
if current_instance.peer_set.all().count() > 0: if current_instance.peer_set.all().count() > 0:
messages.warning(request, 'Error removing wg' +str(current_instance.instance_id) + '|Cannot delete WireGuard instance wg' + str(current_instance.instance_id) + '. There are still peers associated with this instance.') messages.warning(request, _('Error removing instance: wg') + str(current_instance.instance_id) + _('|Cannot delete the requested WireGuard instance. There are still peers associated with this instance.'))
return redirect('/server/manage/?uuid=' + str(current_instance.uuid)) return redirect('/server/manage/?uuid=' + str(current_instance.uuid))
current_instance.delete() current_instance.delete()
messages.success(request, message_title + '|WireGuard instance wg' + str(current_instance.instance_id) + ' deleted successfully.') messages.success(request, message_title + _('|WireGuard instance deleted: wg') + str(current_instance.instance_id))
return redirect('/server/manage/') return redirect('/server/manage/')
else: else:
messages.warning(request, 'Invalid confirmation' + '|Please confirm deletion of WireGuard instance wg' + str(current_instance.instance_id)) messages.warning(request, _('Invalid confirmation|Please confirm deletion of WireGuard instance: wg') + str(current_instance.instance_id))
return redirect('/server/manage/?uuid=' + str(current_instance.uuid)) return redirect('/server/manage/?uuid=' + str(current_instance.uuid))
else: else:
page_title = 'Create a new WireGuard Instance' page_title = _('Create a new WireGuard Instance')
message_title = 'New WireGuard Instance' message_title = _('New WireGuard Instance')
if request.method == 'POST': if request.method == 'POST':
form = WireGuardInstanceForm(request.POST, instance=current_instance) form = WireGuardInstanceForm(request.POST, instance=current_instance)
@ -151,7 +152,7 @@ def view_wireguard_manage_instance(request):
this_form = form.save(commit=False) this_form = form.save(commit=False)
this_form.pending_changes = True this_form.pending_changes = True
this_form.save() this_form.save()
messages.success(request, message_title + '|WireGuard instance wg' + str(form.instance.instance_id) + ' saved successfully.') messages.success(request, message_title + '|WireGuard instance updated: wg' + str(form.instance.instance_id))
return redirect('/server/manage/?uuid=' + str(form.instance.uuid)) return redirect('/server/manage/?uuid=' + str(form.instance.uuid))
else: else:
if not current_instance: if not current_instance: