django translation template {% trans “something” %}

前端 未结 4 1571
你的背包
你的背包 2021-01-05 00:29

Ok I have been searching like crazy for this I think simple problem.

I use Django 1.4

The problem is that django won\'t translate a simple {% trans \"work\"

4条回答
  •  一整个雨季
    2021-01-05 00:51

    I had the same situation. Part of phrases were translation but most of them just showed the key. We have two main languages en and fa. Both had the same problem. I reviewed all the same problems and every single document online about the django translations. I can say I tried almost everything. The only difference was we were testing on the production server. And I didn't reload the server! So this one-line command took me out of my misery:

    sudo /etc/init.d/uwsgi reload
    

    what I was doing wrong was I restarted wsgi instead of uwsgi!

    If you like to do what I did, here it is: I do the steps in this order on server:

    django-admin makemessages -l en
    django-admin makemessages -l fa
    

    add Persian phrases and some english text to test.

    django-admin compilemessages
    python manage.py clear_cache
    python manage.py runserver
    

    Server runs with no errors. But non of the changes in en or fa take place. It looks that django is loading from old cache. So, I deleted the whole cache, and even deleted all the files from server and installed the whole project again. Yet the same issue.

    I made messages from my django on my laptop and sent it to server. Also, I tried different text editors and translation tools such as poedit to generate po and mo files. Yet the problem keeps showing.

    I used and replaced trans tags to see if it works in any of them:

    {% trans ' ' %}
    {% trans " " %}
    {% blocktrans %} {% endblocktrans %}
    {% trans "xyz" az XYZ %} {{ XYZ }}
    {{ _() }}
    

    none of them worked!

    But reloading the server put everything in order. I hope it might be helpful for some one.

提交回复
热议问题