mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
networks: i18n: Mark various strings for translation
Helps: #1938. - Translate various states passed in by Network Manager: - Device state - Device state reason - Device type - Firewall zone - IPv4/IPv6 connection method - Wireless mode - forms.py: Move zones list to network.py, reuse in views.py. Testing: - Yapf applied. - Flake8 without errors or warnings for changed files. - (Unit) tests run without errors. - Screnshots attached to #1938. Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com> [sunil: Add strings for many more states] [sunil: Don't allow None to be selected as firewall zone] [sunil: Drop forced_literals.py as it reduces modularity of the code] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
67edecb8ab
commit
ff9d0ace31
@ -35,8 +35,7 @@ class ConnectionForm(forms.Form):
|
||||
label=_('Firewall Zone'),
|
||||
help_text=_('The firewall zone will control which services are '
|
||||
'available over this interfaces. Select Internal only '
|
||||
'for trusted networks.'),
|
||||
choices=[('external', _('External')), ('internal', _('Internal'))])
|
||||
'for trusted networks.'), choices=network.ZONES)
|
||||
ipv4_method = forms.ChoiceField(
|
||||
label=_('IPv4 Addressing Method'), help_text=format_lazy(
|
||||
_('"Automatic" method will make {box_name} acquire '
|
||||
|
||||
@ -71,17 +71,17 @@
|
||||
<div class="list-group">
|
||||
<div class="list-group-item">
|
||||
{% trans "State" %}
|
||||
<span class="pull-right">{{ device.state }}</span>
|
||||
<span class="pull-right">{{ device.state_string }}</span>
|
||||
</div>
|
||||
{% if device.state_reason != 'none' %}
|
||||
<div class="list-group-item">
|
||||
{% trans "State reason" %}
|
||||
<span class="pull-right">{{ device.state_reason }}</span>
|
||||
<span class="pull-right">{{ device.state_reason_string }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="list-group-item">
|
||||
{% trans "Type" %}
|
||||
<span class="pull-right">{{ device.type }}</span>
|
||||
<span class="pull-right">{{ device.type_string }}</span>
|
||||
</div>
|
||||
<div class="list-group-item">
|
||||
{% trans "MAC address" %}
|
||||
@ -140,7 +140,7 @@
|
||||
</div>
|
||||
<div class="list-group-item">
|
||||
{% trans "Mode" %}
|
||||
<span class="pull-right">{{ device.wireless.mode }}</span>
|
||||
<span class="pull-right">{{ device.wireless.mode_string }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if access_point.channel %}
|
||||
@ -169,7 +169,7 @@
|
||||
{% if connection.ipv4.method %}
|
||||
<div class="list-group-item">
|
||||
{% trans "Method" %}
|
||||
<span class="pull-right">{{ connection.ipv4.method }}</span>
|
||||
<span class="pull-right">{{ connection.ipv4.method_string }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@ -210,7 +210,7 @@
|
||||
{% if connection.ipv6.method %}
|
||||
<div class="list-group-item">
|
||||
{% trans "Method" %}
|
||||
<span class="pull-right">{{ connection.ipv6.method }}</span>
|
||||
<span class="pull-right">{{ connection.ipv6.method_string }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@ -255,7 +255,7 @@
|
||||
<div class="list-group-item">
|
||||
{% trans "Firewall zone" %}
|
||||
<div class="pull-right">
|
||||
<span class="label label-success">{{ connection.zone }}</span>
|
||||
<span class="label label-success">{{ connection.zone_string }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -275,7 +275,7 @@
|
||||
<div class="list-group-item">
|
||||
{% trans "Firewall zone" %}
|
||||
<div class="pull-right">
|
||||
<span class="label label-warning">{{ connection.zone }}</span>
|
||||
<span class="label label-warning">{{ connection.zone_string }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -294,7 +294,7 @@
|
||||
<div class="list-group-item">
|
||||
{% trans "Firewall zone" %}
|
||||
<div class="pull-right">
|
||||
<span class="label label-warning">external</span>
|
||||
<span class="label label-warning">{% trans "External" %}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -8,6 +8,7 @@ from django.shortcuts import redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.translation import ugettext_lazy
|
||||
from django.views.decorators.http import require_POST
|
||||
from django.views.generic.edit import FormView
|
||||
|
||||
@ -20,6 +21,98 @@ from .forms import (ConnectionTypeSelectForm, EthernetForm, GenericForm,
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# i18n for device.state
|
||||
# https://developer.gnome.org/libnm/1.29/libnm-nm-dbus-interface.html#NMDeviceState
|
||||
CONNECTION_METHOD_STRINGS = {
|
||||
'disabled': ugettext_lazy('disabled'),
|
||||
'auto': ugettext_lazy('automatic'),
|
||||
'manual': ugettext_lazy('manual'),
|
||||
'shared': ugettext_lazy('shared'),
|
||||
'link-local': ugettext_lazy('link-local'),
|
||||
}
|
||||
|
||||
# i18n for device.state
|
||||
# https://developer.gnome.org/libnm/1.29/libnm-nm-dbus-interface.html#NMDeviceState
|
||||
DEVICE_STATE_STRINGS = {
|
||||
'unknown': ugettext_lazy('unknown'),
|
||||
'unmanaged': ugettext_lazy('unmanaged'),
|
||||
'unavailable': ugettext_lazy('unavailable'),
|
||||
'disconnected': ugettext_lazy('disconnected'),
|
||||
'prepare': ugettext_lazy('preparing'),
|
||||
'config': ugettext_lazy('connecting'),
|
||||
'need-auth': ugettext_lazy('needs authentication'),
|
||||
'ip-config': ugettext_lazy('requesting address'),
|
||||
'ip-check': ugettext_lazy('checking'),
|
||||
'secondaries': ugettext_lazy('waiting for secondary'),
|
||||
'activated': ugettext_lazy('activated'),
|
||||
'deactivating': ugettext_lazy('deactivating'),
|
||||
'failed': ugettext_lazy('failed'),
|
||||
}
|
||||
|
||||
# i18n for device.state_reason
|
||||
# https://developer.gnome.org/libnm/1.29/libnm-nm-dbus-interface.html#NMDeviceStateReason
|
||||
DEVICE_STATE_REASON_STRINGS = {
|
||||
'none':
|
||||
ugettext_lazy('no reason'),
|
||||
'unknown':
|
||||
ugettext_lazy('unknown error'),
|
||||
'now-managed':
|
||||
ugettext_lazy('device is now managed'),
|
||||
'now-unmanaged':
|
||||
ugettext_lazy('device is now unmanaged'),
|
||||
'config-failed':
|
||||
ugettext_lazy('configuration failed'),
|
||||
'no-secrets':
|
||||
ugettext_lazy('secrets required'),
|
||||
'dhcp-start-failed':
|
||||
ugettext_lazy('DHCP client failed to start'),
|
||||
'dhcp-error':
|
||||
ugettext_lazy('DHCP client error'),
|
||||
'dhcp-failed':
|
||||
ugettext_lazy('DHCP client failed'),
|
||||
'shared-start-failed':
|
||||
ugettext_lazy('shared connection service failed to start'),
|
||||
'shared-failed':
|
||||
ugettext_lazy('shared connection service failed'),
|
||||
'removed':
|
||||
ugettext_lazy('device was removed'),
|
||||
'user-requested':
|
||||
ugettext_lazy('device disconnected by user'),
|
||||
'dependency-failed':
|
||||
ugettext_lazy('a dependency of the connection failed'),
|
||||
'ssid-not-found':
|
||||
ugettext_lazy('Wi-Fi network not found'),
|
||||
'secondary-connection-failed':
|
||||
ugettext_lazy('a secondary connection failed'),
|
||||
'new-activation':
|
||||
ugettext_lazy('new connection activation was enqueued'),
|
||||
'ip-address-duplicate':
|
||||
ugettext_lazy('a duplicate IP address was detected'),
|
||||
'ip-method-unsupported':
|
||||
ugettext_lazy('selected IP method is not supported'),
|
||||
}
|
||||
|
||||
# i18n for device.type
|
||||
# https://developer.gnome.org/libnm/1.29/libnm-nm-dbus-interface.html#NMDeviceType
|
||||
DEVICE_TYPE_STRINGS = {
|
||||
'unknown': ugettext_lazy('unknown'),
|
||||
'ethernet': ugettext_lazy('Ethernet'),
|
||||
'wifi': ugettext_lazy('Wi-Fi'),
|
||||
'generic': ugettext_lazy('generic'),
|
||||
'tun': ugettext_lazy('TUN or TAP interface'),
|
||||
'wireguard': ugettext_lazy('WireGuard'),
|
||||
}
|
||||
|
||||
# i18n for wireless.mode
|
||||
# https://developer.gnome.org/libnm/1.29/libnm-nm-dbus-interface.html#NM80211Mode
|
||||
WIRELESS_MODE_STRINGS = {
|
||||
'unknown': ugettext_lazy('unknown'),
|
||||
'adhoc': ugettext_lazy('ad-hoc'),
|
||||
'infra': ugettext_lazy('infrastructure'),
|
||||
'ap': ugettext_lazy('access point'),
|
||||
'mesh': ugettext_lazy('mesh point'),
|
||||
}
|
||||
|
||||
|
||||
def index(request):
|
||||
"""Show connection list."""
|
||||
@ -52,6 +145,14 @@ def show(request, uuid):
|
||||
|
||||
# Connection status
|
||||
connection_status = network.get_status_from_connection(connection)
|
||||
connection_status['zone_string'] = dict(network.ZONES).get(
|
||||
connection_status['zone'], connection_status['zone'])
|
||||
connection_status['ipv4']['method_string'] = CONNECTION_METHOD_STRINGS.get(
|
||||
connection_status['ipv4']['method'],
|
||||
connection_status['ipv4']['method'])
|
||||
connection_status['ipv6']['method_string'] = CONNECTION_METHOD_STRINGS.get(
|
||||
connection_status['ipv6']['method'],
|
||||
connection_status['ipv6']['method'])
|
||||
|
||||
# Active connection status
|
||||
try:
|
||||
@ -72,12 +173,21 @@ def show(request, uuid):
|
||||
device = network.get_device_by_interface_name(interface_name)
|
||||
|
||||
device_status = network.get_status_from_device(device)
|
||||
device_status['state_string'] = DEVICE_STATE_STRINGS.get(
|
||||
device_status['state'], device_status['state'])
|
||||
device_status['state_reason_string'] = DEVICE_STATE_REASON_STRINGS.get(
|
||||
device_status['state_reason'], device_status['state_reason'])
|
||||
device_status['type_string'] = DEVICE_TYPE_STRINGS.get(
|
||||
device_status['type'], device_status['type'])
|
||||
|
||||
# Access point status
|
||||
access_point_status = None
|
||||
if connection_status['type'] == '802-11-wireless':
|
||||
access_point_status = network.get_status_from_wifi_access_point(
|
||||
device, connection_status['wireless']['ssid'])
|
||||
connection_status['wireless'][
|
||||
'mode_string'] = WIRELESS_MODE_STRINGS.get(
|
||||
connection['wireless']['mode'], connection['wireless']['mode'])
|
||||
|
||||
return TemplateResponse(
|
||||
request, 'connection_show.html', {
|
||||
|
||||
@ -21,6 +21,8 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
_client = None
|
||||
|
||||
ZONES = [('external', _('External')), ('internal', _('Internal'))]
|
||||
|
||||
CONNECTION_TYPE_NAMES = collections.OrderedDict([
|
||||
('802-3-ethernet', _('Ethernet')),
|
||||
('802-11-wireless', _('Wi-Fi')),
|
||||
@ -51,6 +53,7 @@ def ipv4_int_to_string(address_int):
|
||||
|
||||
def init():
|
||||
"""Create and keep a network manager client instance."""
|
||||
|
||||
def new_callback(source_object, result, user_data):
|
||||
"""Called when new() operation is complete."""
|
||||
global _client
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user