1

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

sonlinux
  • 33
  • 5
  • is your select option returned by database query or is it a static python or html value? – Madox Feb 23 '18 at 13:56
  • Hi my select if not from the database as I set up rosetta as as the docs say and also added my translation files and I can switch between them in url and it works so from English to Indonesia I would say 127.0.0.1:8080/en/ to 127.0.0.1:8080/id/ so I think it's a usual select coming from rosetta package. – sonlinux Feb 24 '18 at 14:24

1 Answers1

0

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 %}
sonlinux
  • 33
  • 5
  • Except that once I click a language to switch to I get redirected to the home page of my site. How can I have the site reload and only change the language Id without redirecting me to the home page. – sonlinux Feb 26 '18 at 12:58
  • Can someone help on how I can get javascript to add the current location and only change the language ID from the URL so as I dont get a redirection to home page. Thanks – sonlinux Feb 28 '18 at 12:17