Свежайшие Пирожки от CakePHP по-русски

Полнейшее руководство CakePHP 1.2 на русском языке, горячие новости и полезные статьи

Localizing Your Application

Any Controller that uses localized content should include the use of the L10n CakePHP utility class.

Простой текст
  1. //Include the L10n class:
  2. App::import('Core', 'l10n');
  3. class RecipesController extends AppController { //... }

Next, you’ll need to create language files that manage the localized strings. Each language contains a set of strings and their IDs. Creating these files sets up a way for content to be organized and translated. Each language should contain a default.po file in a folder named after the language of the strings it contains.

Простой текст
  1. /app/locale/eng/LC_MESSAGES/default.po (English)
  2. /app/locale/fre/LC_MESSAGES/default.po (French)
  3. /app/locale/por/LC_MESSAGES/default.po (Portuguese)

The locale folder is located inside the app folder of your CakePHP installation. The three-character locale codes confirm to the ISO 639-2 standard (examples can be found at the Library of Congress Website, http://www.loc.gov/standards/iso639-2/php/code_list.php).

Once you’ve created the files, populate them with the string key and value data used for the localization process. Each string key must be unique and contain a corresponding value. Here’s a basic example of what might be inside of an English language .po file:

Простой текст
  1. msgid "purchase"
  2. msgstr "Please purchase a pastry by selecting its name and pressing BUY NOW."
  3. msgid "search"
  4. msgstr "Click here to search our recipe database."

.po files should be encoded using UTF-8, and there is a 1014-character limit for each msgstr value. If you are using a Macintosh, be careful to ensure you use Unix linebreaks (LF), otherwise the file may not be parsed correctly. You can avoid worrying about the details by using Poedit, a free tool for editing po files.

Once you’ve created the .po files correctly, your application has been localized.