{% trans "string"%} does not work on templates, but {% trans variable%}

I am new to Django and I am working on a project with i18n, the fact is that I translated some variables using .manage.py makemessages / compilemessages my template file, but when I use it {% trans "my string" %} , I got the same "my string"for all languages.

What am I doing wrong? Here is the code for views.py and idioma.html


views.py:

# some code here ...

def idioma(request):
    output = _("Mensaje en espanol")
    return render_to_response( 'idioma/idioma.html', { 'idioma' : output }, context_instance = RequestContext(request) )


idioma.html
{% load i18n %}

< form action="/i18n/setlang/" method="post">

        {% csrf_token %}

        < input name="next" type="hidden" value="{{ redirect_to }}" />

        < select name="language" >

        {% get_language_info_list for LANGUAGES as languages %}

        {% for language in languages %}

            < option value="{{ language.code }}">
                {{ language.name_local }} ({{ language.code }})
            < /option>
        {% endfor %}

        </select>

        < input type="submit" value="Go" />

    < /form>

    La cadena es: {% trans idioma  %}

    {% trans "carro" %}


The application translates the idioma variable from .po and .mo files to locale / path / to / language /

But it does not translate the string {% trans "carro"%}.

What's happening?

Thank you for your help!!!!

+3
source share
5

.po?

makemessages "carro" .po, - .po

#: idioma.html:45
msgid "carro"
msgstr ""

.po , , :

#: idioma.html:45
msgid "carro"
msgstr "car"

, .po, compilemessages: .

. , ,fuzzy. - .po

#: idioma.html:45
#, fuzzy
msgid "carro"
msgstr "car"

, django - ( , , ).

#, fuzzy: #, fuzzy .

+10

, LOCALE_PATHS . LOCALE_PATHS - , django .mo .po. :

# settings.py
LOCALE_PATHS = (
    '/path/to/your/project/locale',
)

django LOCALE_PATHS.

+9

.

{% trans "your string " %}

blocktrans trans

blocktrans

{% blocktrans %}  your strnig {% endblocktrans %}
+1

. trans_real.py gettext.py. "".

  • , . uwsgi .
  • Po . gettext.py "mo" ( ). , .
  • "-" "_" . , "zh-CN" "zh_CN". . , , . Linux.
+1

. .

In short, my problem was resolved by rebooting the server using this code:

sudo /etc/init.d/uwsgi reload

Now, every time I change phrases and after compiling the language files, I load the server again to see the changes. Hope this solves one problem.

0
source

All Articles