Languages


When dealing with languages, be sure to make all links link to their relevant language page.


At the top of the HTML file include 



{% load static i18n %}{% get_current_language as LANGUAGE_CODE %}


This give you access to a variable called LANGUAGE_CODE.

This variable is usually en or fr.

We then append this variable where applicable to links, since most of our links will be editable by the user, we test to see if it's an external link first and then prepend en/fr to the URL as need be. 




For example to make the nav be dynamic.



{% for link in navs.main_nav.links %}    <li>        <a href="{% if "http" in link.link %}{{link.link}}{% else %}/{{LANGUAGE_CODE}}{{link.link}}{% endif %}">{{link}}</a>    </li>{% endfor %}




For links through out the page we do something very similar, just referencing their link instead.



href="{% if "http" in nav_bottom_btn.link_url %}{{nav_bottom_btn.link_url}}{% else %}/{{LANGUAGE_CODE}}{{nav_bottom_btn.link_url}}{% endif %}"



Translation Tag

Wrap any text you want translated in {% trans "" %}

ex.<li><a href="/{{LANGUAGE_CODE}}/about-us/" role="link" aria-label="about">{% trans "About & Contact" %}</a></li>






Nav Select

Use this for the nav



{% for lang_code, lang_name in languages %}
{% language lang_code %}
 <a href="/{{lang_code}}/{{page.get_url}}"
      class="{% if lang_code == LANGUAGE_CODE %}active{% endif %}">
      {{lang_code}}
</a> {% if not forloop.last %} <span class="language_divider">/</span> {% endif %}{% endlanguage %}
{% endfor %}