Django-cms language_chooser in this language

A typical language_chooser from the multilingual Django-CMS framework displays the following languages:

<a href="{% page_language_url language.0 %}">{% trans language.1 %}</a> English German Dutch 

How to change this fragment to translate each language into its own native form so that the output is

 English Deutsch Nederlands 

Make it easier for people to find on the page?

+4
source share
3 answers

While @mongoose_za's answer is comprehensive and helpful, it answers a different question, not a different one.

The real answer is simply to change the list of languages ​​in the settings to include these own forms as such:

 LANGUAGES = ( ('de', u'Deutsch'), ('en', u'English'), ('nl', u'Nederlands'), ('es', u'Español'), ('fr', u'français'), ('jp', u'日本語'), ) 

I added a couple to make it more obvious what we are doing.

Since you always want to display languages ​​in your own way, there is no need to translate them, so there is no need for ugettext () wrappers. You want to make sure that the first line in your settings file:

 # -*- coding: utf-8 -*- 

So that everything is correctly interpreted by Python.

A great source for this exercise: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

+10
source

I think this is just a list of languages ​​to translate. Then your above snippet should be in order as it is. In your settings, where you specify your language, it should look something like this:

 ugettext = lambda s: s LANGUAGES = ( ('de', ugettext('German')), ('en', ugettext('English')), ('nl', ugettext('Dutch')), ) 

Because then you must configure the translated strings in your locale files, which must be translated into the template with the code that you have.

My change language looks like this:

 {% load i18n %} {% trans 'Change language' %} <form action="/i18n/setlang/" method="post" style="display: inline;">{% csrf_token %} <div style="display: inline;"> <select name="language" onchange="javascript:form.submit()"> {% for lang in LANGUAGES %} <option value="{{ lang.0 }}"{% ifequal LANGUAGE_CODE lang.0 %} selected="selected"{% endifequal %}>{{ lang.1 }}</option> {% endfor %} </select> </div> </form> 
+5
source

Mkoistinen's answer is a pleasant and easy solution. However, this does not allow you to use these language names in any other language if you ever need to.

Another solution would be to correct the mongoose_za answer using the language template tag ( https://docs.djangoproject.com/en/1.8/topics/i18n/translation/#switching-language-in-templates ) to switch to each language for each <a> .

0
source

Source: https://habr.com/ru/post/1392847/


All Articles