Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pyramid.pdf
Скачиваний:
11
Добавлен:
24.03.2015
Размер:
3.82 Mб
Скачать

21. INTERNATIONALIZATION AND LOCALIZATION

9width = 80

10

11[init_catalog]

12domain = MyProject

13input_file = myproject/locale/MyProject.pot

14output_dir = myproject/locale

15

16[update_catalog]

17domain = MyProject

18input_file = myproject/locale/MyProject.pot

19output_dir = myproject/locale

20previous = true

In the above example, the project name is MyProject. To indicate that you’d like the domain of your translations to be mydomain instead, change the setup.cfg file stanzas to look like so:

1[compile_catalog]

2 directory = myproject/locale

3 domain = mydomain

4statistics = true

5

6[extract_messages]

7add_comments = TRANSLATORS:

8 output_file = myproject/locale/mydomain.pot

9width = 80

10

11[init_catalog]

12domain = mydomain

13input_file = myproject/locale/mydomain.pot

14output_dir = myproject/locale

15

16[update_catalog]

17domain = mydomain

18input_file = myproject/locale/mydomain.pot

19output_dir = myproject/locale

20previous = true

21.2.3 Initializing a Message Catalog File

Once you’ve extracted messages into a .pot file (see Extracting Messages from Code and Templates), to begin localizing the messages present in the .pot file, you need to generate at least one .po file. A

.po file represents translations of a particular set of messages to a particular locale. Initialize a .po file

236

21.2. WORKING WITH GETTEXT TRANSLATION FILES

for a specific locale from a pre-generated .pot template by using the setup.py init_catalog command:

$ cd /place/where/myapplication/setup.py/lives

$ $myvenv/bin/python setup.py init_catalog -l es

By default, the message catalog .po file will end up in:

myapplication/locale/es/LC_MESSAGES/myapplication.po.

Once the file is there, it can be worked on by a human translator. One tool which may help with this is Poedit.

Note that Pyramid itself ignores the existence of all .po files. For a running application to have translations available, a .mo file must exist. See Compiling a Message Catalog File.

21.2.4 Updating a Catalog File

If more translation strings are added to your application, or translation strings change, you will need to update existing .po files based on changes to the .pot file, so that the new and changed messages can also be translated or re-translated.

First, regenerate the .pot file as per Extracting Messages from Code and Templates. Then use the setup.py update_catalog command.

$ cd /place/where/myapplication/setup.py/lives $ $myvenv/bin/python setup.py update_catalog

21.2.5 Compiling a Message Catalog File

Finally, to prepare an application for performing actual runtime translations, compile .po files to .mo files:

$ cd /place/where/myapplication/setup.py/lives $ $myvenv/bin/python setup.py compile_catalog

This will create a .mo file for each .po file in your application. As long as the translation directory in which the .mo file ends up in is configured into your application, these translations will be available to Pyramid.

237

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]