diff --git a/README.md b/README.md index e438f67..28ad389 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/netbox_better_ips/forms.py b/netbox_better_ips/forms.py index 8a9bbbc..876df10 100644 --- a/netbox_better_ips/forms.py +++ b/netbox_better_ips/forms.py @@ -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): diff --git a/netbox_better_ips/locale/de/LC_MESSAGES/django.mo b/netbox_better_ips/locale/de/LC_MESSAGES/django.mo new file mode 100644 index 0000000..26c0deb Binary files /dev/null and b/netbox_better_ips/locale/de/LC_MESSAGES/django.mo differ diff --git a/netbox_better_ips/locale/de/LC_MESSAGES/django.po b/netbox_better_ips/locale/de/LC_MESSAGES/django.po new file mode 100644 index 0000000..2e77143 --- /dev/null +++ b/netbox_better_ips/locale/de/LC_MESSAGES/django.po @@ -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." \ No newline at end of file diff --git a/netbox_better_ips/management/commands/reconcile_ip_prefixes.py b/netbox_better_ips/management/commands/reconcile_ip_prefixes.py index 5c26a5b..c335eb5 100644 --- a/netbox_better_ips/management/commands/reconcile_ip_prefixes.py +++ b/netbox_better_ips/management/commands/reconcile_ip_prefixes.py @@ -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)) diff --git a/netbox_better_ips/navigation.py b/netbox_better_ips/navigation.py index 02e7f31..4a3dea3 100644 --- a/netbox_better_ips/navigation.py +++ b/netbox_better_ips/navigation.py @@ -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"], ), ) diff --git a/netbox_better_ips/tables.py b/netbox_better_ips/tables.py index e54b536..2637b26 100644 --- a/netbox_better_ips/tables.py +++ b/netbox_better_ips/tables.py @@ -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=(), ) diff --git a/netbox_better_ips/templates/netbox_better_ips/inc/iprange_list_buttons.html b/netbox_better_ips/templates/netbox_better_ips/inc/iprange_list_buttons.html index bca9897..79601d7 100644 --- a/netbox_better_ips/templates/netbox_better_ips/inc/iprange_list_buttons.html +++ b/netbox_better_ips/templates/netbox_better_ips/inc/iprange_list_buttons.html @@ -1,7 +1,8 @@ +{% load i18n %} {% if perms.ipam.view_prefix %} - Erweiterte Netzübersicht + {% trans "Extended network overview" %} {% endif %} {% if perms.ipam.view_ipaddress and perms.ipam.add_iprange %} @@ -9,7 +10,7 @@ {% csrf_token %} {% endif %} diff --git a/netbox_better_ips/templates/netbox_better_ips/network_overview.html b/netbox_better_ips/templates/netbox_better_ips/network_overview.html index e18a4b6..0569fbd 100644 --- a/netbox_better_ips/templates/netbox_better_ips/network_overview.html +++ b/netbox_better_ips/templates/netbox_better_ips/network_overview.html @@ -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 %}
-

IP-Netzübersicht

-
{{ total_count }} Netze
+

{% trans "IP Network Overview" %}

+
{% blocktrans count counter=total_count %}{{ counter }} network{% plural %}{{ counter }} networks{% endblocktrans %}
{% endblock %} @@ -16,7 +16,7 @@
- + {% for prefix in page_obj %} @@ -28,7 +28,7 @@ {% empty %} - + {% endfor %}
NetzVRFScopeMandantStatusBeschreibung
{% trans "Network" %}{% trans "VRF" %}{% trans "Scope" %}{% trans "Tenant" %}{% trans "Status" %}{% trans "Description" %}
{{ prefix.description|placeholder }}
Keine passenden Netze gefunden.
{% trans "No matching networks found." %}
@@ -36,19 +36,19 @@
{% if page_obj.has_other_pages %} {% endif %}
-

Filter

+

{% trans "Filter" %}

{% for field in filter_form %}
{{ field.label_tag }}{{ field }}
{% endfor %} - +
{% trans "Reset" %}
diff --git a/netbox_better_ips/views.py b/netbox_better_ips/views.py index 104c6b3..4c01389 100644 --- a/netbox_better_ips/views.py +++ b/netbox_better_ips/views.py @@ -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") diff --git a/pyproject.toml b/pyproject.toml index a3de294..3ecbdaa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", +] diff --git a/tests/test_metadata.py b/tests/test_metadata.py new file mode 100644 index 0000000..479ec42 --- /dev/null +++ b/tests/test_metadata.py @@ -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()