tags:

views:

117

answers:

3

i know the {% trans %} is for translation,

and how can i translate {% trans "This is the title." %} to chinese.

thanks


D:\zjm_code\register2>python D:\Python25\Lib\site-packages\django\bin\django-adm
in.py compilemessages
processing file django.po in D:\zjm_code\register2\locale\cn\LC_MESSAGES
msgfmt: iconv failure
+1  A: 

I18n in Django

Ignacio Vazquez-Abrams
no,i can't understand the api.
zjm1126
Ask a real question, get a real answer.
Ignacio Vazquez-Abrams
+3  A: 

You don't follow the documentation?

3 steps:

  1. Add {% load i18n %} in the template (as Michał Ludwiński says). Put the {% trans %} in your templates, or _ in python code, etc.

  2. Build a translation dictionary:

    • Run django-admin.py makemessages -l cn (cn = China language code) in your Django project root.

    • Edit locale/cn/LC_MESSAGES/django.po. Just under msgid "Hello!" change msgstr "" to to msgstr "nihao". Don't change msgid. You can use unicode, but I'd use pinyin until you are sure everything else works.

    • Run django-admin.py compilemessages

  3. Setup language translation. You might need to enable some middle-ware.

wisty
hi,wisty,i usd your way to do it,1 and 2 are ok,and 3,i change 'LANGUAGE_CODE' in settings.py from 'en-us' to 'cn',when i fresh my 127.0.0.1:8000 ,it also be english,
zjm1126
#: .\views.py:16 .\django_authopenid\views.py:232msgid "E-mail"msgstr "邮箱"
zjm1126
+3  A: 

before you will try to use {% trans %} blocktag you need to type

{% load i18n %}

then you can use the tag to type in the text you want to be translated (one thing is important - the text ought to be in main project language which is set in settings)

if you have already some text you want to translate type in your projects main dir:

./manage.py makemessages -l pl

where "pl" can by country code of the language of choice. this command will make django scripts generate a right localization file located in the ./locale/(language-code)/LC_MESSAGES/django.po.

after doing the translation stuff you simply type

./manage.py compilemessages 

and that should do the trick.

Michał Ludwiński