nam
nam

Reputation: 3632

How to detect language with tag in Django CMS

I'm designing the home page but there is some words that depend on the language of the actual home page. I want to do something like this {% if english %} Hello {% elif french %} Bonjour {% else %} Blabla {% endif %}

Is there any template tag in django-cms that do the job? Thanks

Upvotes: 1

Views: 363

Answers (1)

Steve K
Steve K

Reputation: 11399

Actually, you're thinking it wrong. Django supports translation, in Python code and in the templates. The Django Translation documentation gives advice on how to do this.

You create a template with

{% load i18n %}
{% trans "Hello" %}

"Hello" will be translated to bonjour once you set it up.

You will need to activate I18N in your project settings, then call

manage.py makemessages

to create a .po file for your project. Once you create the translations for the .po file, type something like

manage.py compilemessages

The actual way of doing things is a bit more difficult than this but is described properly in the docs.

Upvotes: 2

Related Questions