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

21. INTERNATIONALIZATION AND LOCALIZATION

1

2

3

from pyramid.threadlocal import get_current_registry settings = get_current_registry().settings languages = settings[’available_languages’].split()

This is only a suggestion. You can create your own “available languages” configuration scheme as necessary.

21.10 Activating Translation

By default, a Pyramid application performs no translation. To turn translation on, you must:

add at least one translation directory to your application.

ensure that your application sets the locale name correctly.

21.10.1 Adding a Translation Directory

gettext is the underlying machinery behind the Pyramid translation machinery. A translation directory is a directory organized to be useful to gettext. A translation directory usually includes a listing of language directories, each of which itself includes an LC_MESSAGES directory. Each LC_MESSAGES directory should contain one or more .mo files. Each .mo file represents a message catalog, which is used to provide translations to your application.

Adding a translation directory registers all of its constituent message catalog files within your Pyramid application to be available to use for translation services. This includes all of the .mo files found within all LC_MESSAGES directories within each locale directory in the translation directory.

You can add a translation directory imperatively by using the pyramid.config.Configurator.add_translation_dirs() during application startup. For example:

1

2

3

from pyramid.config import Configurator config.add_translation_dirs(’my.application:locale/’,

’another.application:locale/’)

A message catalog in a translation directory added via add_translation_dirs() will be merged into translations from a message catalog added earlier if both translation directories contain translations for the same locale and translation domain.

244

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