开发者

How does localization work in Django?

开发者 https://www.devze.com 2023-02-19 10:13 出处:网络
I have reading some topics of http://docs.djangoproject.com/en/1.3/topics/i18n/localization/ But have not understand what I need to do.

I have reading some topics of http://docs.djangoproject.com/en/1.3/topics/i18n/localization/

But have not understand what I need to do.

First what I intend to do...

I have created a new App, called "directorio", and now I need to have the capability of translate the data inside some database columns.

my models.py

PS: I have asked for a way of doing this and I have obtained some help from the user "Tommaso Barbugli"

from django.utils.translation import ugettext as _

GENDERS = (('male', _('MALE')), ('female', _('FEMALE')))

class Genders(models.Model):
    n_gender = models.CharField(max_length= 60, choices= GENDERS)

After doing this I think I need to do the *.po an *.mo files inside my App directory... I have tried to do:

django-admin.py m开发者_如何学运维akemessages -l pt

But is not working, I got this error:

Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\djan
odule>
    from django.core import management
ImportError: No module named django.core

C:\xampp\htdocs\djangodir\directorio>djang
Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\djan
odule>
    from django.core import management
ImportError: No module named django.core

What I need to do to create the dir "locale\pt\LC_MESSAGES" and the *.po and *.mo files for my App?

Another question I'm developing on windows. I must to install gettext?

Give me some clues, I'm kind of lost.

Best Regards,


you need to install gettext. out of the docs:

This is only needed for people who either want to extract message IDs or compile message files (.po). Translation work itself just involves editing existing files of this type, but if you want to create your own message files, or want to test or compile a changed message file, you will need the gettext utilities:

Download the following zip files from the GNOME servers http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/ or from one of its mirrors

gettext-runtime-X.zip gettext-tools-X.zip X is the version number, we are requiring 0.15 or higher.

Extract the contents of the bin\ directories in both files to the same folder on your system (i.e. C:\Program Files\gettext-utils)

Update the system PATH:

Control Panel > System > Advanced > Environment Variables. In the System variables list, click Path, click Edit. Add ;C:\Program Files\gettext-utils\bin at the end of the Variable value field. You may also use gettext binaries you have obtained elsewhere, so long as the xgettext --version command works properly. Do not attempt to use Django translation utilities with a gettext package if the command xgettext --version entered at a Windows command prompt causes a popup window saying "xgettext.exe has generated errors and will be closed by Windows".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号