From 07474c6976d00fffcb11f5b44eaafc7fd89ce8c9 Mon Sep 17 00:00:00 2001 From: Tobias Kunze Date: Sun, 21 Nov 2021 13:07:19 +0100 Subject: [PATCH] Add i18n support --- pretalx_lower_thirds/forms.py | 16 +++++++--------- pretalx_lower_thirds/signals.py | 13 ++++++++++++- pretalx_lower_thirds/views.py | 1 + 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pretalx_lower_thirds/forms.py b/pretalx_lower_thirds/forms.py index a08e180..012eb79 100644 --- a/pretalx_lower_thirds/forms.py +++ b/pretalx_lower_thirds/forms.py @@ -1,23 +1,21 @@ -from django import forms from django.utils.translation import gettext_lazy as _ from hierarkey.forms import HierarkeyForm +from i18nfield.forms import I18nFormField, I18nFormMixin, I18nTextInput -class LowerThirdsSettingsForm(HierarkeyForm): - lower_thirds_no_talk_info = forms.CharField( +class LowerThirdsSettingsForm(I18nFormMixin, HierarkeyForm): + lower_thirds_no_talk_info = I18nFormField( help_text=_( "Will be shown as talk title if there's currently no talk " "running." ), - initial="Sorry, there's currently no talk running", label=_('"no talk running" information'), + widget=I18nTextInput, required=True, ) - lower_thirds_info_string = forms.CharField( - help_text=_( - "Will only be shown if there's a talk running." - ), - initial="", + lower_thirds_info_string = I18nFormField( + help_text=_("Will only be shown if there's a talk running."), label=_("info line"), required=False, + widget=I18nTextInput, ) diff --git a/pretalx_lower_thirds/signals.py b/pretalx_lower_thirds/signals.py index ebc2a45..c38e7f5 100644 --- a/pretalx_lower_thirds/signals.py +++ b/pretalx_lower_thirds/signals.py @@ -1,8 +1,19 @@ from django.dispatch import receiver from django.urls import resolve, reverse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_noop, ugettext_lazy as _ +from i18nfield.strings import LazyI18nString +from pretalx.common.models.settings import hierarkey from pretalx.orga.signals import nav_event_settings +hierarkey.add_default( + "lower_thirds_no_talk_info", + LazyI18nString.from_gettext( + gettext_noop("Sorry, there's currently no talk running") + ), + LazyI18nString, +) +hierarkey.add_default("lower_thirds_info_string", "", LazyI18nString) + @receiver(nav_event_settings) def navbar_info(sender, request, **kwargs): diff --git a/pretalx_lower_thirds/views.py b/pretalx_lower_thirds/views.py index 8d679f9..2edbc6f 100644 --- a/pretalx_lower_thirds/views.py +++ b/pretalx_lower_thirds/views.py @@ -37,6 +37,7 @@ class LowerThirdsOrgaView(PermissionRequired, FormView): return { "obj": self.request.event, "attribute_name": "settings", + "locales": self.request.event.locales, **kwargs, }