Imtiaz Ahmed
Imtiaz Ahmed

Reputation: 323

How to localize settings in Wagtail

I am trying to implement localization in Wagtail's settings. I know that Snippets can be localized by inheriting from the TranslatableMixin class. And it works perfectly.

However, when I try to localize settings by inheriting from this class in a model that also inherits from BaseGenericSetting to add the model to Wagtail's settings, it does not provide an interface to change the language in the admin panel so that I can create settings for different languages.

How can I add an interface for changing the language in the settings, similar to what we do with snippets?

For instance, I want to create instances of the below-mentioned model for three different languages (which are added in the LANGUAGES setting in base.py). This means there will be three instances of CompanySettings for three different languages.

@register_setting(icon="doc-full")
class CompanySettings(TranslatableMixin ,BaseGenericSetting):
    top_services = models.CharField(
        _("Top Services"), max_length=250, blank=True, null=True, help_text="add top services separated by comma")
    
    copyright_text = models.CharField(_("Copyright Text"), max_length=100, blank=True, null=True)

    panels = [
        FieldPanel('top_services'),
        FieldPanel('copyright_text')
    ]

I have checked the CompanySettings model by querying its instance to verify whether the locale and translation_key fields are available or not, as these are provided by TranslatableMixin. However, even though they are available, it doesn't seem to work for Wagtail's settings.

Can somebody help me to solve this? I just want to add settings for the LANGUAGES set in the base.py

Or suggest me a way to localize the rendered settings in the template.

Upvotes: 4

Views: 334

Answers (1)

nigel239
nigel239

Reputation: 1755

After doing some research I found out that there is an active PR for it on their github.
But, the author of the PR is no longer picking it back up - their work for their respective client was completed.
People just don't have that much free time if it's not in their interest.

I think a good portion of the work has been done though - you could easily implement further with your own custom templatetag implementation.
Yes, a bit tedious - but it'll probably work.

I'd still love for someone to work up an actual solution though. ;)

Upvotes: 1

Related Questions