djangodjango-rosetta

Django translation


I am using django rosetta to translate my site in 2 different languages and it is working correctly. So if I want to translate from english to indonesian i type

127.0.0.1:8000/en/ to 127.0.0.1:8000/id/ 

But the problem is when i want to add a select option in template Am just not sure how to pass the selected language to rosetta.

{% get_available_languages as languages %}

{% trans '' %}
{% for lang_code, lang_name in languages %}
    {% language lang_code %}
        <li>
        <i class="icon-wrench"></i>
        <a href="#" target="_blank" data-toggle="modal">
            {{lang_name|slice:'3' }}, {{ lang_code|upper }}
        </a>
        </li>
    {% endlanguage %}
{% endfor %}

How could I pass my selection to rosetta for translation in my case


Solution

  • So I found a fix to my problem by using the template language syntax only, and am going to share my code here in case someone finds a similar challenge.

    {% for lang_code, lang_name in languages %}
        {% language lang_code %}
            <li>
            <i class="icon-wrench"></i>
                <a href="/{{ lang_code }}/"
                     {% if lang_code == LANGUAGE_CODE %}
                     {% endif %}>
                {% if lang_code == 'en' %}
                 <img src="{% static "img/en.png" %}" alt="Eng"
                      style="height: 13pt;
                      margin-bottom: 3pt;">
                    {{ lang_code|upper }}
                {% endif %}
                 {% if lang_code == 'id' %}
                 <img src="{% static "img/id.png" %}" alt="Ind"
                      style="height: 13pt;
                      margin-bottom: 3pt;">
                    {{ lang_code|upper }}
                {% endif %}
    
             </a>
            </li>
        {% endlanguage %}
    {% endfor %}