Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Apress.Pro.Drupal.7.Development.3rd.Edition.Dec.2010.pdf
Скачиваний:
73
Добавлен:
14.03.2016
Размер:
12.64 Mб
Скачать

CHAPTER 19 LOCALIZATION AND TRANSLATION

you want to generate .pot files with the same layout as those available at http://drupal.org/ project/Translations:

$ php potx-cli.php --mode=core

The script always outputs .pot files in the same directory the script is in; for example, modulesaggregator.pot will be created in the root directory of your site, not in modules/aggregator/. The name of the .pot file reflects where it was found. So in the previous example, a sites-all-modules-custom- annotate.pot file would be generated.

Installing a Language Translation

Drupal can be installed in a language other than English or the language translation can be added later. Let’s cover both possibilities.

Setting Up a Translation at Install Time

Drupal’s installer recognizes installer translations with the st() function rather than t(), which isn’t available to the installer at runtime because, well, Drupal isn’t installed yet. Installer translations are offered as a choice during installation and are based on the installer.pot file (see the “Getting .pot Files for Drupal” section).

To view the installer’s translation capabilities in action, let’s download the French translation of Drupal from www.drupal.org/project/translations. This results in the file fr-7.x-1.1.tar.gz. You can tell from the. tar.gz ending that this is a .tar file that has been compressed with GZIP compression. One way to extract the file is by using the Unix tar utility:

$ tar -xzvf fr-7.x-1.1.tar.gz

Caution The file contains a directory structure that mirrors the directory structure of Drupal. When extracting it, be careful to use an extraction method that merges the directory structure in the tarball with your existing Drupal directory structure. The default extractor in Mac OS X will not do it correctly. If you end up with a folder called fr- 7.x-1.1 after extraction, the merge did not take place. See www.lullabot.com/videocast/installing-drupal- translation for a screencast demonstrating the proper way to do the extraction.

After successful extraction of the translation, additional folders called translations should be found in your Drupal directories. For example, the profiles/default folder (where Drupal’s default installation profile lives) now has a translations subfolder containing a fr.po file. That’s the French translation of the installer. When Drupal’s installer runs, you can see the new choice presented, as shown in Figure 19-15.

If you choose French, the installation will proceed in French, and the default language for the site will be set to French.

432

CHAPTER 19 LOCALIZATION AND TRANSLATION

Figure 19-15. When a .po file exists in the installation profile’s translations subdirectory, Drupal’s installer allows you to choose a language for the installer.

Installing a Translation on an Existing Site

To install a language translation on an existing site, you can add the language by navigating to Configuration -> Languages and clicking the “Add language” tab. Next, simply choose the language and click “Add language,” as shown in Figure 19-16. The new language will then be shown in the table at Configuration -> Languages.

Figure 19-16. Installing a language

433

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