From b8f93fc11ca312147cfe7ca70dd94a28a4c15827 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 26 Oct 2026 21:23:52 +0100 Subject: [PATCH] feat(i18n): make UI translatable and add German translation Wraps all user-visible strings (navigation, model fields, template, job and validation messages) in gettext and ships a German catalogue. A test keeps the documented NetBox range in line with min_version/max_version. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 + COMPATIBILITY.md | 2 + README.md | 9 +- netbox_vmware_importer/crypto.py | 3 +- netbox_vmware_importer/jobs.py | 12 +- .../locale/de/LC_MESSAGES/django.mo | Bin 0 -> 8745 bytes .../locale/de/LC_MESSAGES/django.po | 476 ++++++++++++++++++ netbox_vmware_importer/models.py | 36 ++ netbox_vmware_importer/navigation.py | 9 +- netbox_vmware_importer/sync.py | 5 +- .../vcenterendpoint.html | 67 +-- pyproject.toml | 6 +- tests/test_compatibility.py | 52 ++ 13 files changed, 635 insertions(+), 47 deletions(-) create mode 100644 netbox_vmware_importer/locale/de/LC_MESSAGES/django.mo create mode 100644 netbox_vmware_importer/locale/de/LC_MESSAGES/django.po create mode 100644 tests/test_compatibility.py diff --git a/CHANGELOG.md b/CHANGELOG.md index fd5cf1f..a1117ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +- The UI, choices, validation and sync messages are translatable; German translation added. +- Added a test that keeps the NetBox version range in `README.md` and `COMPATIBILITY.md` in line with `min_version`/`max_version`. + ## 0.3.3 - Fixed `DuplicateColumn` (`column "provider" ... already exists`) when running migrations on diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 4cfeab0..66659f2 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -20,3 +20,5 @@ | 0.2.6 | 4.4.0 | 4.6.x | | 0.3.0 | 4.4.0 | 4.6.x | | 0.3.1 | 4.6.5 | 4.6.8 | +| 0.3.2 | 4.6.5 | 4.7.x | +| 0.3.3 | 4.6.5 | 4.7.x | diff --git a/README.md b/README.md index 9dd71c6..23c7260 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ guest data is incomplete. ## Compatibility -- NetBox `4.6.5` – `4.7.x` (verified with 4.7.2) +- NetBox `4.6.5` – `4.7.x` (verified with 4.7.2 and 4.7.3) - Python `>=3.12` - Dependencies installed automatically: `pyvmomi`, `cryptography` @@ -145,6 +145,13 @@ Proxmox support has been removed. Old Proxmox endpoints from earlier versions remain visible in the list and detail view so they can be deleted; they can no longer be edited, created or synchronised. +### Language + +The plugin is available in English and German. Switch the display language +as usual in the user profile (**Preferences → Language**). Translations live in +`netbox_vmware_importer/locale/de/LC_MESSAGES/`. Status messages stored on an +endpoint keep the language that was active when the sync ran. + ## Security The endpoint password is stored encrypted in the plugin table. The key is diff --git a/netbox_vmware_importer/crypto.py b/netbox_vmware_importer/crypto.py index e12108a..4c6c3a5 100644 --- a/netbox_vmware_importer/crypto.py +++ b/netbox_vmware_importer/crypto.py @@ -3,6 +3,7 @@ import hashlib from cryptography.fernet import Fernet, InvalidToken from django.conf import settings +from django.utils.translation import gettext as _ def _fernet(): @@ -22,4 +23,4 @@ def decrypt_secret(value): try: return _fernet().decrypt(value.encode("ascii")).decode("utf-8") except InvalidToken as exc: - raise ValueError("Stored endpoint password cannot be decrypted. Re-enter it on the endpoint.") from exc + raise ValueError(_("Stored endpoint password cannot be decrypted. Re-enter it on the endpoint.")) from exc diff --git a/netbox_vmware_importer/jobs.py b/netbox_vmware_importer/jobs.py index 3daacb5..9bd654a 100644 --- a/netbox_vmware_importer/jobs.py +++ b/netbox_vmware_importer/jobs.py @@ -1,6 +1,7 @@ from core.choices import JobStatusChoices from core.exceptions import JobFailed from django.utils import timezone +from django.utils.translation import gettext as _ from netbox.jobs import JobRunner, system_job from .choices import EndpointProviderChoices, SyncStatusChoices @@ -46,11 +47,12 @@ class SyncVCenterEndpointJob(JobRunner): endpoint = VCenterEndpoint.objects.get(pk=endpoint_pk) if not endpoint.enabled: - endpoint.mark_failure("Endpoint is disabled.") - raise JobFailed("Endpoint is disabled.") + message = _("Endpoint is disabled.") + endpoint.mark_failure(message) + raise JobFailed(message) if endpoint.provider != EndpointProviderChoices.PROVIDER_VMWARE: - message = "Legacy Proxmox endpoints are no longer supported. Delete this endpoint." + message = _("Legacy Proxmox endpoints are no longer supported. Delete this endpoint.") clear_endpoint_sync_schedule(endpoint) endpoint.mark_failure(message) raise JobFailed(message) @@ -72,7 +74,7 @@ class SyncVCenterEndpointJob(JobRunner): endpoint.last_updated_count = result.updated endpoint.last_error_count = result.errors endpoint.last_status = SyncStatusChoices.STATUS_FAILED - endpoint.last_message = f"Finished with {result.errors} VM error(s). Check the job log." + endpoint.last_message = _("Finished with %(errors)s VM error(s). Check the job log.") % {"errors": result.errors} endpoint.set_next_sync(endpoint.last_sync_at) endpoint.save( update_fields=( @@ -120,7 +122,7 @@ class ScheduleDueVCenterSyncsJob(JobRunner): legacy_endpoints = VCenterEndpoint.objects.exclude(provider=EndpointProviderChoices.PROVIDER_VMWARE) cleared = 0 for endpoint in legacy_endpoints: - deleted_count, _ = clear_endpoint_sync_schedule(endpoint) + deleted_count, __ = clear_endpoint_sync_schedule(endpoint) cleared += deleted_count enabled_endpoints = VCenterEndpoint.objects.filter( diff --git a/netbox_vmware_importer/locale/de/LC_MESSAGES/django.mo b/netbox_vmware_importer/locale/de/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..abf7a98a43822bffd5da39652ae94f4cf9ca1878 GIT binary patch literal 8745 zcmai&dyFMnUB}NNi|mN7yP&YT>X~5|y4ksRdWPL)=wX1K?w*<6?VjzO?&;lGK)3F_ zr|+%px>c8|y8Q}9G{#6|2_~4V2ILPXKvdLd9Ali|;}R7TNen6`5~9f(Fpy|Me8fcX z^F38{Up=msKKEPaQRn>5@BQnq-TU%iGCT?Ge%i;r#~2N~>U;U&dG;=2R>1(A1%C^? z7yNsWrRJO94}kv)9s}>>N1xsez7l)`cprEi_Nl^QJ6nr)K zt7ZSQW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SdfYr9=tqZWFux%AjoC-&9WvUb?2UFf&7+Ga9ukF7sZyXtmB1)16s zl+W8Ub7vl{ot~?mdDNacJ^$9ZhvrVt%^g$XP}@v{IEw;&2VbrRal21aP}_7tcivud zDSmi3I*}Z`% z#O2kN<7U#rLC)K=jW9p99`(~8s$ERdZpM`{2)fz%Gv{O*yq=$l?eX*W^eq2y9HroG zmj&H?G6#okxr-t{TBa@7a(g+h^*?UxxoBBQvuP^9-b&)8O%C96k9h??zC z&$!I)%^JaLtfbmns}-`GiDzxlDAp&0tXTeZaBG_g7-aUbqyeK6YN;fOibTJrOux43 zGE~3h^u+PQRG+&VrTjrW&H+^9wj5Z-KTL37quGhWJooC!UA5cvP&_r_D}ifqdvGht zLuI$V8W`M2d4MR=)(+!oRur1mLF0zTPS6=)J}y3K$!{e91k-aE5Q^tUrqyua zVP9DVW)$PIOM_xXk+|aFcw2U7@n=BELmm z9yR`@)I<(T7U3;w%<}g_hr8({nv@=oT|2cni(#oTxB=nV!{CNkz^V9C%8klbGceAJ zE0Cldn^TL@BZwS(kDp~KWso(Ol|${B&_&hzVv!h}l%RaJ{GTh@HpGI`L@7xKOLgbEQAkB?kuSkI`G!T(~(-d*_^;%PMtaU-Mv zoh)hao@JP+tYW0Y(AZLSS?+;W<%9#`00G0kv@Wj1_9=>q!oi|w9KN0UMBr%L@e2+7FIW@ICiG;+p}hMaHGFnM3uJN8{FuioVHXPY@#!`NeOe+Pg0kcO&N{BP_z?*}uLO~jC;X-`yfvZk~6 zk6dndsGLflK!zj14sJmP{}wC!McrNs8&YMbYB&Wt6>&!(`4_zKNE8gq*9=^gr3f=VfqEIi{_&_@4WYVxFa^qzS>(ev)5 zGU>y9+mRqsuv8{uE;# - This is a legacy Proxmox endpoint from an older plugin version. Proxmox sync is no longer supported; this endpoint can be deleted. + {% trans "This is a legacy Proxmox endpoint from an older plugin version. Proxmox sync is no longer supported; this endpoint can be deleted." %} {% endif %}
-
Endpoint
+
{% trans "Endpoint" %}
- + - + - + - + - - + + - - + +
Name{% trans "Name" %} {{ object.name }}
Provider{% trans "Provider" %} {{ object.get_provider_display }}
Host{% trans "Host" %} {{ object.host }}:{{ object.port }}
Username{% trans "Username" %} {{ object.username }}
Enabled{{ object.enabled|yesno:"Yes,No" }}{% trans "Enabled" %}{% if object.enabled %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}
Validate SSL{{ object.validate_ssl|yesno:"Yes,No" }}{% trans "Validate SSL" %}{% if object.validate_ssl %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}
-
NetBox Target
+
{% trans "NetBox Target" %}
- + - + - + - - + + - +
Tenant{% trans "Tenant" %} {{ object.tenant|default:"-" }}
Site{% trans "Site" %} {{ object.site|default:"-" }}
Cluster{% trans "Cluster" %} {{ object.cluster }}
Sync interval{{ object.sync_interval_minutes|default:"Manual only" }}{% trans "Sync interval" %}{% if object.sync_interval_minutes %}{{ object.sync_interval_minutes }}{% else %}{% trans "Manual only" %}{% endif %}
Next sync{% trans "Next sync" %} {{ object.next_sync_at|default:"-" }}
@@ -71,26 +72,26 @@
-
Sync
+
{% trans "Sync" %}
- + - + - + - - + + - +
Last status{% trans "Last status" %} {{ object.get_last_status_display }}
Last sync{% trans "Last sync" %} {{ object.last_sync_at|default:"-" }}
Last success{% trans "Last success" %} {{ object.last_success_at|default:"-" }}
VMs{{ object.last_vm_count }} total, {{ object.last_created_count }} created, {{ object.last_updated_count }} updated, {{ object.last_error_count }} errors{% trans "VMs" %}{% blocktrans with total=object.last_vm_count created=object.last_created_count updated=object.last_updated_count errors=object.last_error_count %}{{ total }} total, {{ created }} created, {{ updated }} updated, {{ errors }} errors{% endblocktrans %}
Message{% trans "Message" %} {{ object.last_message|default:"-" }}
@@ -100,7 +101,7 @@
{% csrf_token %}
@@ -110,23 +111,23 @@
-
Filters
+
{% trans "Filters" %}
- + - + - - + + - - + +
Include regex{% trans "Include regex" %} {{ object.include_name_regex|default:"-" }}
Exclude regex{% trans "Exclude regex" %} {{ object.exclude_name_regex|default:"-" }}
Powered off VMs{{ object.sync_powered_off|yesno:"Synced,Skipped" }}{% trans "Powered off VMs" %}{% if object.sync_powered_off %}{% trans "Synced" %}{% else %}{% trans "Skipped" %}{% endif %}
Interfaces/IPs{{ object.sync_interfaces|yesno:"Interfaces on,Interfaces off" }} / {{ object.sync_ip_addresses|yesno:"IPs on,IPs off" }}{% trans "Interfaces/IPs" %}{% if object.sync_interfaces %}{% trans "Interfaces on" %}{% else %}{% trans "Interfaces off" %}{% endif %} / {% if object.sync_ip_addresses %}{% trans "IPs on" %}{% else %}{% trans "IPs off" %}{% endif %}
@@ -137,7 +138,7 @@
-
Comments
+
{% trans "Comments" %}
{{ object.comments|linebreaksbr }}
diff --git a/pyproject.toml b/pyproject.toml index fe7e673..f4477c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,4 +28,8 @@ dependencies = [ include = ["netbox_vmware_importer*"] [tool.setuptools.package-data] -netbox_vmware_importer = ["templates/**/*.html"] +netbox_vmware_importer = [ + "templates/**/*.html", + "locale/*/LC_MESSAGES/*.po", + "locale/*/LC_MESSAGES/*.mo", +] diff --git a/tests/test_compatibility.py b/tests/test_compatibility.py new file mode 100644 index 0000000..2c8912c --- /dev/null +++ b/tests/test_compatibility.py @@ -0,0 +1,52 @@ +"""Keeps the documented NetBox range in line with the PluginConfig.""" + +import ast +import re +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parent.parent + + +def plugin_config(): + tree = ast.parse((ROOT / "netbox_vmware_importer" / "__init__.py").read_text()) + values = {} + for node in ast.walk(tree): + if isinstance(node, ast.Assign) and isinstance(node.value, ast.Constant): + for target in node.targets: + if isinstance(target, ast.Name): + values[target.id] = node.value.value + return values + + +def documented(version): + # "4.7.99" is the conventional upper bound for "any 4.7 release" + return re.sub(r"\.99$", ".x", version) + + +class CompatibilityTest(unittest.TestCase): + def setUp(self): + config = plugin_config() + self.version = config["version"] + self.min_version = documented(config["min_version"]) + self.max_version = documented(config["max_version"]) + + def test_readme_matches_plugin_config(self): + readme = (ROOT / "README.md").read_text() + expected = f"`{self.min_version}` – `{self.max_version}`" + self.assertIn(f"| **NetBox** | {expected} |", readme) + self.assertIn(f"- NetBox {expected}", readme) + + def test_compatibility_matrix_lists_current_release(self): + matrix = (ROOT / "COMPATIBILITY.md").read_text() + row = re.search(rf"^\|\s*{re.escape(self.version)}\s*\|\s*(\S+)\s*\|\s*(\S+)\s*\|$", matrix, re.M) + self.assertIsNotNone(row, f"COMPATIBILITY.md has no row for {self.version}") + self.assertEqual(row.groups(), (self.min_version, self.max_version)) + + def test_pyproject_version_matches_plugin_config(self): + pyproject = (ROOT / "pyproject.toml").read_text() + self.assertIn(f'version = "{self.version}"', pyproject) + + +if __name__ == "__main__": + unittest.main()