Search code examples
djangointernationalizationdjango-i18n

how to display list of LANGUAGES in django template


i'm trying to show languages label list in my template , but it only shows the original name of the language my settings.py

LANGUAGES = (      
   ('en', _('english uk')),
   ('ar', _('arabic uae')),
   ('fa', _('Persian')),

)

my template

        <li class="nav-item dropdown">
          <a class="nav-link" data-toggle="dropdown" href="#">
            <i class="fas fa-globe"></i>
          </a>
          <div class="text-center dropdown-menu dropdown-menu-lg dropdown-menu-right">
            {% get_current_language as LANGUAGE_CODE %}
            {% get_available_languages as LANGUAGES %}
            {% get_language_info_list for LANGUAGES  as languages %}
            {% for lang in languages %}
                <a class="dropdown-item" href="/{{lang.code}}/"> {{lang.name_local}}</a>
            {% endfor %}    
                      
          </div>
        </li> 
i need to show _('english uk'), values instead of the original name is it possible please ? thank you for helping ..


Solution

  • for those who looks for iterate through tuples from template

    <div class="text-center dropdown-menu dropdown-menu-lg dropdown-menu-right">
         {% get_current_language as LANGUAGE_CODE %}
         {% get_available_languages as LANGUAGES %}
         {% for lang in LANGUAGES %}
              <a class="dropdown-item" href="/{{lang.0}}/"> {{lang.1}}</a>
          {% endfor %}    
    </div>