Django 2 versions of german - django

I'm developing website with 2 versions of german (Default and Austrian).
My problem is that template do not differ them, so in select django displays them both as Deutsch(de).
Languages in settings.py:
('en', _('English')),
('de', _('German')),
('de-at', _('Austrian'))
template code:
<form action="{% url 'set_language' %}" method="post">
{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select style="border:1px dotted black" name="language">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
<input class="btn-primary" type="submit" value="{% trans 'Change' %}" />
</form>
Code is from documentation.
Translation in Austrian language doesn't work, because django in select defines Austrian as default Deutsch select it and do not translate.
So, are there any ways to display sublanguage in template, like (Deutsch(de-at)) or just (Austrian instead of Deutsch), or are there any other ways to solve it?
Tried to change all languages in settings:
('en-us', _('English')),
('de-de', _('German')),
('de-at', _('Austrian'))
Then created .po and .mo files to them. But still template defines them as same languages. Also I thought about changing language name in template, but as far as I understand I can't do it.

I've sold my problem, still don't understand what's the reason...
Django front end form, that I copied from documentation doesn't work as it should.
Form, that I used on front side works correct only with base languages and crashes on sublanguages(all). Now I've rewrite this form:
<form action="/i18n/setlang/" method="post">
{% csrf_token %}
<select style="border:1px solid black" name="language">
{% for lang in LANGUAGES %}
<option value="{{ lang.0 }}"
{% ifequal lang.0 request.LANGUAGE_CODE %}
selected="yes"
{% endifequal %}
>{{ lang.1 }}</option>
{% endfor %}
</select>
<input type="submit" value="{% trans 'Change' %}" />
</form>
Per now it works fine...

Related

How to let user select currency in Django using Django-money?

I am currently working on an online store. I want a user to be able to change their currency option in the header and convert the whole site to the currency choice. I have found app called django-money, which seams to have that functionality, but I cannot find any implementation examples.
I want it to work like localize work in django. Having a form that will redirect to URL and saving choice in session and in cookie. This is the example of the language selection code.
/template.html
<form action="{% url 'set_language' %}" method="post">{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}">
<select name="language" onchange="this.form.submit()">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected{% endif %}>
{{ language.code|upper}}
</option>
{% endfor %}
</select>
</form>
And then whenever I need something to be translated I will use this inside html:
{% trans "Some text to translate" %}
So is there something similar for currency? What would be the action for the form? Please can somebody help if you have ready solution! I will really appreciate.

How can I change the language name of the I18N code?

i need some help with a internationalization (I18N) issue for a website.
In trying to change the value of the language name of the I18N code, I have a select form with the languages so i change it, this is the code of the select:
<form action="/i18n/setlang/" method="post">
{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select name="language" onchange="this.form.submit()">
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
{{ trans 'language.name_local|capfirst' }}
</option>
{% endfor %}
</select>
</form>
This is the languages declaration in setting.py
ugettext = lambda s: s
LANGUAGES = (
('es', ugettext('Spanish')),
('en', ugettext('English')),
('eu', ugettext('Euskera')),
)
Euskera is the local language of the spanish state Basque country.
But in the select it shows the values: "Español","English","Basque" and I want it to show different values depending the current language.
If i want the website in Spanish it should show: "Español", "Ingles", "Euskera".
If i want the website in English it should show: "Spanish", "English", "Basque"
If i want the website in Spanish it should show: "Español", "Ingles", "Euskera"
I have three django.po files for each languaje and they translate other texts correctly.
If you have any idea, please share it.
Thank you.

Django i18n explorer verification failed

I am using the below code in my site wide template...
{% for lang in languages %}
<li>
<form name="setLang{{ lang.1}}" action="/i18n/setlang/" method="POST">{% csrf_token %}
<input name="next" type="hidden" value="/" />
<input type="hidden" name="language" value="{{ lang.0 }}" />
<a class='{% if LANGUAGE_CODE == lang.0 %}selected{% endif %}' href="#" onclick="document.setLang{{ lang.1 }}.submit();return false;">{{ lang.0 }}</a>
</form>
</li>
{% endfor %}
and in urls.py i have
(r'^i18n/', include('django.conf.urls.i18n'))
But on internet explorer i am getting csrf verification failed error... Is the problem about there are two forms on the page?
Well I'm not sure if this will solve your problem, but you should definitely put a space after {{ lang.1 so that it looks like {{ lang.1 }}. It is worth trying that, at least, to see if the semantics is causing a break somewhere.

invalid block-tag when I implement i18n

I'm currently adding i18n in my website but there is something wrong.
When I use code from djangoproject
<form action="{% url 'set_language' %}" method="post">
{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select name="language">
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}">{{ language.name_local }} ({{ language.code }})</option>
{% endfor %}
</select>
<input type="submit" value="Go" />
</form>
I get this error
Invalid block tag: 'get_language_info_list'
I don't understand why get_language_info_list is unknown. Templates_context_processors is ok. HTML form is on my homepage.
Always make sure you load the tag library first before you requests any tags. To use get_language_info_list, you need to make sure {% load i18n %} is in your template.

django-translation: How to translate languages

The officual django doc suggest to write the following in the settings.py
ugettext = lambda s: s
LANGUAGES = (
('de', ugettext('German')),
('en', ugettext('English')),
)
With this arrangement, django-admin.py makemessages will still find and mark these strings for translation, but the translation won't happen at runtime -- so you'll have to remember to wrap the languages in the real ugettext() in any code that uses LANGUAGES at runtime.
But, I fail to understand where to wrap the code with real translation tags?
e.g. my code in template is
<form id="locale_switcher" method="POST" action="{% url localeurl_change_locale %}">
<label><b>{% trans "Language" %}:</b></label>
<select name="locale" onchange="$('#locale_switcher').submit()">
{% for lang in LANGUAGES %}
<option value="{{ lang.0 }}" {% ifequal lang.0 LANGUAGE_CODE %}selected="selected"{% endifequal %}>
{{ lang.1 }}</option>
{% endfor %}
</select>
<noscript>
<input type="submit" value="Set" />
</noscript>
</form>
The solution suggested here: Using settings.LANGUAGES with properly translated names using gettext()
Shows empty select box with no text at all on any laguage
The following code works for me:
// settings.py
ugettext = lambda s:s
LANGUAGES = (
('de', ugettext('German')),
('en', ugettext('English')),
)
// template
{% load i18n %}
{% get_available_languages as LANGUAGES %}
{% for LANGUAGE in LANGUAGES %}
<p>{{ LANGUAGE.0 }} - {{ LANGUAGE.1 }}</p>
{% endfor %}