From d1107e79f5e395903eb14b4f2ccea10d19997522 Mon Sep 17 00:00:00 2001 From: lukaszett <4248383+lukaszett@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:11:31 +0100 Subject: [PATCH 1/2] add missing i18n lookups --- src/rest_framework_api_key/apps.py | 3 ++- src/rest_framework_api_key/models.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/rest_framework_api_key/apps.py b/src/rest_framework_api_key/apps.py index 11f2be1..dafa093 100644 --- a/src/rest_framework_api_key/apps.py +++ b/src/rest_framework_api_key/apps.py @@ -1,6 +1,7 @@ from django.apps import AppConfig +from django.utils.translation import gettext_lazy as _ class RestFrameworkApiKeyConfig(AppConfig): name = "rest_framework_api_key" - verbose_name = "API Key Permissions" + verbose_name = _("API Key Permissions") diff --git a/src/rest_framework_api_key/models.py b/src/rest_framework_api_key/models.py index 034ea6d..0e40537 100644 --- a/src/rest_framework_api_key/models.py +++ b/src/rest_framework_api_key/models.py @@ -110,8 +110,8 @@ class AbstractAPIKey(models.Model): class Meta: # noqa abstract = True ordering = ("-created",) - verbose_name = "API key" - verbose_name_plural = "API keys" + verbose_name = _("API key") + verbose_name_plural = _("API keys") def __init__(self, *args: typing.Any, **kwargs: typing.Any): super().__init__(*args, **kwargs) @@ -123,7 +123,7 @@ def _has_expired(self) -> bool: return False return self.expiry_date < timezone.now() - _has_expired.short_description = "Has expired" # type: ignore + _has_expired.short_description = _("Has expired") # type: ignore _has_expired.boolean = True # type: ignore has_expired = property(_has_expired) From 45715b5fe9456c5e1c39ed37b3d9ecd7d3ac0161 Mon Sep 17 00:00:00 2001 From: lukaszett <4248383+lukaszett@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:17:22 +0100 Subject: [PATCH 2/2] add translation lookups for fields without verbose name --- src/rest_framework_api_key/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rest_framework_api_key/models.py b/src/rest_framework_api_key/models.py index 0e40537..484d959 100644 --- a/src/rest_framework_api_key/models.py +++ b/src/rest_framework_api_key/models.py @@ -75,9 +75,9 @@ class AbstractAPIKey(models.Model): objects = APIKeyManager() id = models.CharField(max_length=150, unique=True, primary_key=True, editable=False) - prefix = models.CharField(max_length=8, unique=True, editable=False) + prefix = models.CharField(max_length=8, unique=True, editable=False, verbose_name=_("Prefix")) hashed_key = models.CharField(max_length=150, editable=False) - created = models.DateTimeField(auto_now_add=True, db_index=True) + created = models.DateTimeField(auto_now_add=True, db_index=True, verbose_name=_("Created")) name = models.CharField( max_length=50, blank=False, @@ -93,6 +93,7 @@ class AbstractAPIKey(models.Model): revoked = models.BooleanField( blank=True, default=False, + verbose_name=_("Revoked"), help_text=( _( "If the API key is revoked, clients cannot use it anymore. "