# Website translation between two languages

**URL:** <https://forum.djangoproject.com/t/website-translation-between-two-languages/3350>\
**Category:** Using Django\
**Created:** [July 9, 2020, 8:06am UTC](https://forum.djangoproject.com/t/website-translation-between-two-languages/3350 "2020-07-09T08:06:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![4ka0](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/4ka0/32/669_2.png) [@4ka0](https://forum.djangoproject.com/u/4ka0)\
**Post date:** [July 9, 2020, 8:06am UTC](https://forum.djangoproject.com/t/website-translation-between-two-languages/3350/1 "2020-07-09T08:06:42Z")

</div>

I’m quite new to Django and I have a beginner question that I need some help with if that’s okay. I would like to build a site that is available in two languages, in this case English and Japanese, and I would like to have a single button for switching between languages.

The following code works fine for displaying two buttons, one for each language.

```
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
    <form action="{% url 'set_language' %}" method="post" id="form_{{ language.code }}" >
        {% csrf_token %}
        <input name="next" type="hidden" value="{{ redirect_to }}" />
        <input name="language" type="hidden" value="{{ language.code }}" />
        </form>
    <button class="btn btn-light" type="submit" form="form_{{ language.code }}" value="Submit">{{ language.name_local }}</button>
{% endfor %}

```

I tried to adapt this to use a simple if/else condition in the following way to show just one button that would make it possible to switch to the other language. However, I am getting an error stating:

> Invalid block tag on line 67: ‘LANGUAGE\_CODE’, expected ‘elif’, ‘else’ or ‘endif’. Did you forget to register or load this tag?

which refers to the line stating "{% LANGUAGE\_CODE = ‘ja’ %}.

```
{% get_current_language as LANGUAGE_CODE %}
{% if LANGUAGE_CODE == 'en' %}
    {% LANGUAGE_CODE = 'ja' %}
{% else %}
    {% LANGUAGE_CODE = 'en' %}
{% endif %}

{% get_language_info for LANGUAGE_CODE as language %}
<form action="{% url 'set_language' %}" method="post" id="form_{{ language.code }}" >
    {% csrf_token %}
    <input name="next" type="hidden" value="{{ redirect_to }}" />
    <input name="language" type="hidden" value="{{ language.code }}" />
</form>
<button class="btn btn-light" type="submit" form="form_{{ language.code }}" value="Submit">{{ language.name_local }}</button>

```

Would someone mind giving me some help with this error? And also, is my attempt here a good approach for what I’m trying to do or is there a better approach?

Many thanks in advance

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 9, 2020, 12:27pm UTC](https://forum.djangoproject.com/t/website-translation-between-two-languages/3350/2 "2020-07-09T12:27:34Z")

</div>

> [@4ka0](#):
>
> ```auto
> {% if LANGUAGE_CODE == 'en' %}
> {% LANGUAGE_CODE = 'ja' %}
> {% else %}
> {% LANGUAGE_CODE = 'en' %}
> {% endif %}
> 
> ```

The [templating language](https://docs.djangoproject.com/en/3.0/ref/templates/language/#the-django-template-language) is not designed for performing logic like this. You want to set the LANGUAGE\_CODE in the view, and then take advantage of that setting in your template.  
(See the sidebar marked Philosophy on that page.)

---

<div class="post-metadata">

**Author:** ![4ka0](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/4ka0/32/669_2.png) [@4ka0](https://forum.djangoproject.com/u/4ka0)\
**Post date:** [July 9, 2020, 2:34pm UTC](https://forum.djangoproject.com/t/website-translation-between-two-languages/3350/3 "2020-07-09T14:34:27Z")

</div>

Thank you very much for the reply and the advice. Much appreciated. And thanks for the link as well. That makes more sense.
