Why internationalize? You can attract a larger market by making content available in additional languages. When offering international content, you need to translate both the fixed and dynamic content in the database. In CakePHP you can facilitate translation with
__n(). In addition content stored in the database can be translated with TranslateBehavior. Multibyte characters exist in many languages, characters outside the traditional latin character set are represented with multibyte characters. This allows for the creation of additional characters and idiomatic expresssion. There is a PHP extentsion for using multibyte strings, it provides the mb_ functions. CakePHP also provides a MultiByte class which provides all the mb_ functions for PHP4 or PHP5 installations lacking them.
Using translation in CakePHP
By using __() we can create translatable strings in our applications. You can use placeholders as well in your translation strings. It is important to use place holders as parameters such as a name can move around in a sentance based on the language. Once you have added all the __() calls, you can use
cake i18n extract -output app/locale. The generated file will be placed in app/locale/default.pot
Mariano then gave an example and quick walkthrough of translation and i18n. He added translated elements to the views. Then extracted the strings with the shell and created translated values with poEdit.
Translating database content
Translate behavior helps to translate any database content. All translations in CakePHP are stored in one table. Translate behavior takes a number of fields when included on a model. This indicates which fields are going to be translated. Translated fields are not needed on the table schema. The translate behavior also allows you to specify a number of languages and language specific values or you can simply add one language. Later on another language can be added. The rest of Translate Behavior works seamlessly on find() and save().
When using elements with caching. You can use a key parameter when calling element() to ensure that different languages are cached separately.
Mariano's talk brought the third day of CakeFest to an end. This has been an excellent conference so far and the last day promises to be great as well.