A. Nurb
A. Nurb

Reputation: 536

setting LANGUAGE_CODE in template based on page setting

In Django / Wagtail I can set the language of a single page. With my custom instance method {{ page.get_language }} this language is available in the template.

But I want all dates and hard-coded texts translated in the set language. So I would like to to set LANGUAGE_CODE with page.get_language.

Any ideas what the best practice is?

Upvotes: 0

Views: 141

Answers (2)

HP Bruna
HP Bruna

Reputation: 623

<html class="no-js" lang="{{ page.get_language }}">

and in your template {% load i18n %}

Upvotes: 1

gasman
gasman

Reputation: 25292

The django.utils.translation.activate function selects the language to be used by Django's translation framework, in preference to the default one in LANGUAGE_CODE - so, in this case you would use activate(page.get_language).

Upvotes: 0

Related Questions