Y
Y
Yura Khlyan2015-11-05 18:02:43
Django
Yura Khlyan, 2015-11-05 18:02:43

How to translate a few words?

Good day.
How can I make the expression "165.39 € for 5 (saving 8.71 €)" translated depending on the locale? That is, if I choose Russian, then this phrase should look something like this: "165.39 € for 5 (saving 8.71 €)".
I am developing a store on Django-Oscar. To translate it, you need to do the following:
At the beginning of the template, add the line {% load i18n %}. And in the template itself, highlight what needs to be translated like this: {% trans "Product Information" %}.
But if I write something like this: {% trans "for" %}, it doesn't even translate "for". I understand Django does not know such a word for translation. How can I deal with this?
I will be very grateful for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Sklyar, 2015-11-05
@MAGistr_MTM

Okay. You need to enable all settings. Then connect {% load i18n %}. Then select the desired text {% trans "Product Information" %}. The next command in the terminal is ./manage.py makemessages makemessages -l ru. Then you look for a folder in the root of the project locale/ru/LC_MESSAGES. It has a django.po file. When you open it you will see this text

............
#: minisite/apps/info/forms.py:21
msgid "Product Information"
msgstr ""
..............

Enter the translation here -----> msgstr "LINE FEED".
Next, you need to compile the translation ./manage.py compilemessages.
Well, you also need to have a switch for languages ​​\u200b\u200bon the site.
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as languages %}

<html lang="{{LANGUAGE_CODE}}">
{% for lang_code, lang_name in languages %}
    {% language lang_code %}
      {%if LANGUAGE_CODE != lang_code%}
       <a class="navbar-brand" href="#">{% trans 'Change language' %}</a>
      {%endif%}
    {% endlanguage %}
{% endfor %}
</html>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question