feat: translate UI to English with German locale

Use English source strings wrapped for gettext, ship a German catalogue, and check that README and package metadata match the PluginConfig.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-10-26 21:24:20 +01:00
1 parent 34be43bffb
commit e9d9b59d16
12 files changed
+225 -30

No files matched your search

+24 -1
View File
@@ -30,7 +30,7 @@ IP ranges created automatically from the saved IP addresses:
## Compatibility
- NetBox `4.6.5` – `4.7.x` (verified with 4.7.2)
- NetBox `4.6.5` – `4.7.x` (verified with 4.7.3)
- Python `>=3.12`
## Installation
@@ -169,6 +169,29 @@ NetBox has no separate core model called organisation. The overview maps
organisation to NetBox `Region` and includes child regions and their sites and
locations.
### Language
The plugin is available in English (source) and German. Switch the display
language as usual in the user profile (**Preferences → Language**).
Translations live in `netbox_better_ips/locale/de/LC_MESSAGES/`.
## Development and tests
```bash
python -m unittest discover -s tests
```
The tests check that the NetBox range in this README and the package version
match the `PluginConfig`, and that the translations are shipped.
After changing user-visible strings, update and compile the catalogue from
within `netbox_better_ips/`:
```bash
django-admin makemessages -l de --no-location
msgfmt --check -o locale/de/LC_MESSAGES/django.mo locale/de/LC_MESSAGES/django.po
```
## License
Apache License 2.0 — see [LICENSE](LICENSE).
+8 -7
View File
@@ -1,25 +1,26 @@
from django import forms
from django.utils.translation import gettext_lazy as _
from dcim.models import Location, Region, Site, SiteGroup
from tenancy.models import Tenant, TenantGroup
class NetworkOverviewFilterForm(forms.Form):
q = forms.CharField(required=False, label="Suche")
q = forms.CharField(required=False, label=_("Search"))
organization = forms.ModelChoiceField(
queryset=Region.objects.all(), required=False, label="Organisation / Region"
queryset=Region.objects.all(), required=False, label=_("Organisation / Region")
)
site_group = forms.ModelChoiceField(
queryset=SiteGroup.objects.all(), required=False, label="Standortgruppe"
queryset=SiteGroup.objects.all(), required=False, label=_("Site group")
)
site = forms.ModelChoiceField(queryset=Site.objects.all(), required=False, label="Standort")
site = forms.ModelChoiceField(queryset=Site.objects.all(), required=False, label=_("Site"))
location = forms.ModelChoiceField(
queryset=Location.objects.all(), required=False, label="Lokation"
queryset=Location.objects.all(), required=False, label=_("Location")
)
tenant_group = forms.ModelChoiceField(
queryset=TenantGroup.objects.all(), required=False, label="Mandantengruppe"
queryset=TenantGroup.objects.all(), required=False, label=_("Tenant group")
)
tenant = forms.ModelChoiceField(
queryset=Tenant.objects.all(), required=False, label="Mandant"
queryset=Tenant.objects.all(), required=False, label=_("Tenant")
)
def __init__(self, *args, **kwargs):
Binary file not shown.
@@ -0,0 +1,102 @@
# German translation of NetBox Better IPs.
# This file is distributed under the same license as the netbox-better-ips package.
#
msgid ""
msgstr ""
"Project-Id-Version: netbox-better-ips\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-10-26 21:14+0100\n"
"PO-Revision-Date: 2026-10-26 21:15+0100\n"
"Last-Translator: NetBox Better IPs contributors\n"
"Language-Team: German\n"
"Language: de\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"
msgid "Search"
msgstr "Suche"
msgid "Organisation / Region"
msgstr "Organisation / Region"
msgid "Site group"
msgstr "Standortgruppe"
msgid "Site"
msgstr "Standort"
msgid "Location"
msgstr "Lokation"
msgid "Tenant group"
msgstr "Mandantengruppe"
msgid "Tenant"
msgstr "Mandant"
msgid "IP Network Overview"
msgstr "IP-Netzübersicht"
msgid "Device / VM"
msgstr "Gerät / VM"
msgid "Extended network overview"
msgstr "Erweiterte Netzübersicht"
msgid "Create all missing ranges"
msgstr "Alle fehlenden Bereiche anlegen"
#, python-format
msgid "%(counter)s network"
msgid_plural "%(counter)s networks"
msgstr[0] "%(counter)s Netz"
msgstr[1] "%(counter)s Netze"
msgid "Network"
msgstr "Netz"
msgid "VRF"
msgstr "VRF"
msgid "Scope"
msgstr "Geltungsbereich"
msgid "Status"
msgstr "Status"
msgid "Description"
msgstr "Beschreibung"
msgid "No matching networks found."
msgstr "Keine passenden Netze gefunden."
msgid "Previous"
msgstr "Vorherige"
#, python-format
msgid "Page %(number)s of %(total)s"
msgstr "Seite %(number)s von %(total)s"
msgid "Next"
msgstr "Nächste"
msgid "Filter"
msgstr "Filter"
msgid "Apply"
msgstr "Anwenden"
msgid "Reset"
msgstr "Zurücksetzen"
#, python-brace-format
msgid ""
"{created} ranges were created; {failed} IP addresses could not be processed."
msgstr "{created} Bereiche wurden angelegt; {failed} IP-Adressen konnten nicht verarbeitet werden."
#, python-brace-format
msgid ""
"{created} missing ranges were created. {skipped} host addresses were ignored."
msgstr "{created} fehlende Bereiche wurden angelegt. {skipped} Host-Adressen wurden ignoriert."
@@ -21,7 +21,7 @@ class Command(BaseCommand):
skipped += int(ip_range is None)
except Exception as exc:
failed += 1
self.stderr.write(f"Fehler bei {address}: {exc}")
verb = "würden erstellt" if options["dry_run"] else "erstellt"
message = f"{created} IP-Bereiche {verb}; {skipped} Hostmasken ignoriert; {failed} Fehler."
self.stderr.write(f"Error for {address}: {exc}")
verb = "would be created" if options["dry_run"] else "created"
message = f"{created} IP ranges {verb}; {skipped} host masks ignored; {failed} errors."
self.stdout.write(self.style.SUCCESS(message) if not failed else self.style.WARNING(message))
+2 -1
View File
@@ -1,3 +1,4 @@
from django.utils.translation import gettext_lazy as _
from netbox.navigation import MenuItem
@@ -15,7 +16,7 @@ def register_ipam_menu_item():
*group.items,
MenuItem(
link=link,
link_text="IP-Netzübersicht",
link_text=_("IP Network Overview"),
permissions=["ipam.view_prefix"],
),
)
+2 -1
View File
@@ -1,4 +1,5 @@
import django_tables2 as tables
from django.utils.translation import gettext_lazy as _
from ipam.tables import IPAddressTable
from utilities.tables import register_table_column
@@ -7,7 +8,7 @@ device_or_vm = tables.Column(
accessor="assigned_object__parent_object",
linkify=True,
orderable=False,
verbose_name="Gerät / VM",
verbose_name=_("Device / VM"),
empty_values=(),
)
@@ -1,7 +1,8 @@
{% load i18n %}
{% if perms.ipam.view_prefix %}
<a href="{% url 'plugins:netbox_better_ips:network_overview' %}" class="btn btn-outline-primary">
<i class="mdi mdi-view-list" aria-hidden="true"></i>
Erweiterte Netzübersicht
{% trans "Extended network overview" %}
</a>
{% endif %}
{% if perms.ipam.view_ipaddress and perms.ipam.add_iprange %}
@@ -9,7 +10,7 @@
{% csrf_token %}
<button type="submit" class="btn btn-primary">
<i class="mdi mdi-auto-fix" aria-hidden="true"></i>
Alle fehlenden Bereiche anlegen
{% trans "Create all missing ranges" %}
</button>
</form>
{% endif %}
@@ -1,12 +1,12 @@
{% extends 'base/layout.html' %}
{% load helpers %}
{% load helpers i18n %}
{% block title %}IP-Netzübersicht{% endblock %}
{% block title %}{% trans "IP Network Overview" %}{% endblock %}
{% block header %}
<div class="row align-items-center">
<div class="col"><h1>IP-Netzübersicht</h1></div>
<div class="col-auto text-secondary">{{ total_count }} Netze</div>
<div class="col"><h1>{% trans "IP Network Overview" %}</h1></div>
<div class="col-auto text-secondary">{% blocktrans count counter=total_count %}{{ counter }} network{% plural %}{{ counter }} networks{% endblocktrans %}</div>
</div>
{% endblock %}
@@ -16,7 +16,7 @@
<div class="card">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead><tr><th>Netz</th><th>VRF</th><th>Scope</th><th>Mandant</th><th>Status</th><th>Beschreibung</th></tr></thead>
<thead><tr><th>{% trans "Network" %}</th><th>{% trans "VRF" %}</th><th>{% trans "Scope" %}</th><th>{% trans "Tenant" %}</th><th>{% trans "Status" %}</th><th>{% trans "Description" %}</th></tr></thead>
<tbody>
{% for prefix in page_obj %}
<tr>
@@ -28,7 +28,7 @@
<td>{{ prefix.description|placeholder }}</td>
</tr>
{% empty %}
<tr><td colspan="6" class="text-center text-secondary py-4">Keine passenden Netze gefunden.</td></tr>
<tr><td colspan="6" class="text-center text-secondary py-4">{% trans "No matching networks found." %}</td></tr>
{% endfor %}
</tbody>
</table>
@@ -36,19 +36,19 @@
</div>
{% if page_obj.has_other_pages %}
<nav class="mt-3"><ul class="pagination">
{% if page_obj.has_previous %}<li class="page-item"><a class="page-link" href="?{% querystring request page=page_obj.previous_page_number %}">Zurück</a></li>{% endif %}
<li class="page-item disabled"><span class="page-link">Seite {{ page_obj.number }} / {{ page_obj.paginator.num_pages }}</span></li>
{% if page_obj.has_next %}<li class="page-item"><a class="page-link" href="?{% querystring request page=page_obj.next_page_number %}">Weiter</a></li>{% endif %}
{% if page_obj.has_previous %}<li class="page-item"><a class="page-link" href="?{% querystring request page=page_obj.previous_page_number %}">{% trans "Previous" %}</a></li>{% endif %}
<li class="page-item disabled"><span class="page-link">{% blocktrans with number=page_obj.number total=page_obj.paginator.num_pages %}Page {{ number }} of {{ total }}{% endblocktrans %}</span></li>
{% if page_obj.has_next %}<li class="page-item"><a class="page-link" href="?{% querystring request page=page_obj.next_page_number %}">{% trans "Next" %}</a></li>{% endif %}
</ul></nav>
{% endif %}
</div>
<div class="col-xl-3">
<div class="card">
<h2 class="card-header">Filter</h2>
<h2 class="card-header">{% trans "Filter" %}</h2>
<div class="card-body">
<form method="get">
{% for field in filter_form %}<div class="mb-3">{{ field.label_tag }}{{ field }}</div>{% endfor %}
<div class="d-flex gap-2"><button class="btn btn-primary" type="submit">Filtern</button><a class="btn btn-outline-secondary" href=".">Zurücksetzen</a></div>
<div class="d-flex gap-2"><button class="btn btn-primary" type="submit">{% trans "Apply" %}</button><a class="btn btn-outline-secondary" href=".">{% trans "Reset" %}</a></div>
</form>
</div>
</div>
+7 -2
View File
@@ -5,6 +5,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.paginator import Paginator
from django.db.models import Q
from django.shortcuts import redirect
from django.utils.translation import gettext as _
from django.views.decorators.http import require_POST
from django.views.generic import TemplateView
from dcim.models import Location, Region, Site, SiteGroup
@@ -112,11 +113,15 @@ def reconcile_missing_ranges(request):
if failed:
messages.warning(
request,
f"{created} Bereiche wurden angelegt; {failed} IP-Adressen konnten nicht verarbeitet werden.",
_("{created} ranges were created; {failed} IP addresses could not be processed.").format(
created=created, failed=failed
),
)
else:
messages.success(
request,
f"{created} fehlende Bereiche wurden angelegt. {skipped} Host-Adressen wurden ignoriert.",
_("{created} missing ranges were created. {skipped} host addresses were ignored.").format(
created=created, skipped=skipped
),
)
return redirect("ipam:iprange_list")
+6 -2
View File
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "netbox-better-ips"
version = "1.2.2"
description = "Automatic prefix creation and an organization-aware IP network overview for NetBox 4.6"
description = "Automatic IP ranges from IP addresses and an organisation-aware IP network overview for NetBox"
readme = "README.md"
requires-python = ">=3.12"
license = {text = "Apache-2.0"}
@@ -21,4 +21,8 @@ classifiers = [
include = ["netbox_better_ips*"]
[tool.setuptools.package-data]
netbox_better_ips = ["templates/**/*.html"]
netbox_better_ips = [
"templates/**/*.html",
"locale/*/LC_MESSAGES/*.po",
"locale/*/LC_MESSAGES/*.mo",
]
+57
View File
@@ -0,0 +1,57 @@
"""Keep README and packaging metadata in sync with the PluginConfig.
Runs without NetBox: `python -m unittest discover -s tests`.
"""
import ast
import re
import tomllib
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def plugin_config():
tree = ast.parse((ROOT / "netbox_better_ips" / "__init__.py").read_text())
return {
node.targets[0].id: node.value.value
for node in ast.walk(tree)
if isinstance(node, ast.Assign)
and isinstance(node.targets[0], ast.Name)
and isinstance(node.value, ast.Constant)
}
def readme_range(max_version):
# max_version "4.7.99" is written as "4.7.x" in the README
major_minor, patch = max_version.rsplit(".", 1)
return major_minor + ".x" if patch == "99" else max_version
class MetadataTest(unittest.TestCase):
def setUp(self):
self.config = plugin_config()
self.readme = (ROOT / "README.md").read_text()
def test_readme_netbox_range_matches_plugin_config(self):
expected = f"`{self.config['min_version']}` – `{readme_range(self.config['max_version'])}`"
info_row = re.search(r"^\| \*\*NetBox\*\* \| (.+?) \|$", self.readme, re.M)
self.assertIsNotNone(info_row, "README info table has no NetBox row")
self.assertEqual(info_row.group(1), expected)
compatibility = self.readme.split("## Compatibility", 1)[1].split("\n## ", 1)[0]
self.assertIn(f"NetBox {expected}", compatibility)
def test_package_version_matches_plugin_config(self):
project = tomllib.loads((ROOT / "pyproject.toml").read_text())["project"]
self.assertEqual(project["version"], self.config["__version__"])
def test_translations_are_shipped(self):
package_data = tomllib.loads((ROOT / "pyproject.toml").read_text())["tool"]["setuptools"][
"package-data"
]["netbox_better_ips"]
self.assertIn("locale/*/LC_MESSAGES/*.mo", package_data)
self.assertTrue((ROOT / "netbox_better_ips/locale/de/LC_MESSAGES/django.mo").is_file())
if __name__ == "__main__":
unittest.main()