Allows to mark the language names as translation strings (#6572)

* Force __str__ of Locale to be a string

* Put some translation proxies in to test settings

* Fixed import in wrong place

* Added test for gettext in LANGUAGES to the Locale model

Co-authored-by: Andreas M <am@zauberberg-medien.de>
pull/7887/head
Andreas Morgenstern 2020-12-09 16:59:01 +01:00 zatwierdzone przez Matt Westcott
rodzic e45f188f6c
commit 85423cb100
4 zmienionych plików z 24 dodań i 4 usunięć

Wyświetl plik

@ -400,7 +400,7 @@ class Locale(models.Model):
return get_content_languages().get(self.language_code)
def __str__(self):
return self.get_display_name() or self.language_code
return force_str(self.get_display_name() or self.language_code)
class TranslatableMixin(models.Model):

Wyświetl plik

@ -1,6 +1,7 @@
from django.conf import settings
from django.test import TestCase, override_settings
from django.utils import translation
from django.utils.translation import gettext_lazy as _
from wagtail.core.models import Locale, Page
from wagtail.tests.i18n.models import TestPage
@ -52,3 +53,8 @@ class TestLocaleModel(TestCase):
# This language is not in LANGUAGES so it should just return the language code
locale = Locale.objects.create(language_code="foo")
self.assertEqual(str(locale), "foo")
@override_settings(LANGUAGES=[("en", _("English")), ("fr", _("French"))])
def test_str_when_languages_uses_gettext(self):
locale = Locale.objects.get(language_code="en")
self.assertIsInstance(locale.__str__(), str)

Wyświetl plik

@ -3,6 +3,7 @@ from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, override_settings
from django.utils.text import slugify
from django.utils.translation import _trans
from django.utils.translation import gettext_lazy as _
from wagtail.core.models import Page
from wagtail.core.utils import (
@ -187,6 +188,18 @@ class TestGetContentLanguages(TestCase):
'en': 'English',
})
@override_settings(
WAGTAIL_CONTENT_LANGUAGES=[
('en', _('English')),
('de', _('German')),
],
)
def test_can_be_a_translation_proxy(self):
self.assertEqual(get_content_languages(), {
'de': 'German',
'en': 'English',
})
@override_settings(
WAGTAIL_CONTENT_LANGUAGES=[
('en', 'English'),

Wyświetl plik

@ -1,5 +1,7 @@
import os
from django.utils.translation import gettext_lazy as _
DEBUG = False
WAGTAIL_ROOT = os.path.dirname(os.path.dirname(__file__))
@ -229,10 +231,9 @@ WAGTAILADMIN_RICH_TEXT_EDITORS = {
},
}
WAGTAIL_CONTENT_LANGUAGES = [
("en", "English"),
("fr", "French"),
("en", _("English")),
("fr", _("French")),
]