|Todo||Language files, file structure, loading entries|
|Todo||Language codes, expand on extra arguments for lang()|
Internationalization files can be found in the i18n directories. These directories can be found in system, application or modules directories. Kohana's own internationalization files can be found in the system directory.
In the i18n directories the directories with the language files can be found. English files are in en_US, Dutch in nl_NL, German in de_DE etc.
The configuration file
locale.php sets which locale will be used. The file can be found in the application/config directory, if it's not there copy the one from the system/config directory.
The file will look somewhat like this
$config['language'] = array('en_US', 'English_United States'); $config['timezone'] = '';
$config['language'] sets the language that should be used. It maps to the directories in the i18n directory.
$config['timezone'] sets the timezone, see for more information http://php.net/timezones
root +- application | +- i18n | +- en_US | | +- coffee.php | | | +- de_DE | | +- coffee.php | | | +- zh_CN | | +- coffee.php | +- system | +- i18n | +- en_US | | +- cache.php | | | +- de_DE | | +- cache.php | | | +- zh_CN | | +- cache.php
Using Kohana::lang() languages strings can be retrieved. Example
echo Kohana::lang('cache.resources'); //outputs is locale is set to en_US // Caching of resources is impossible, because resources cannot be serialized. //If locale is set to de_DE // Das Cachen von Ressourcen ist nicht möglich, da diese nicht serialisiert werden können.
In the case of
Kohana::lang('cache.resources') maps to i18n/en_US/cache.php and within this file to
Kohana also allows to give extra arguments to
Kohana::lang() passing them to translated text via PHP function
It is possible to have your own language strings in your application/module. Simply add a directory
i18n, add the directory of the locale and add the file with the language strings. For example, you want to have language strings for coffee and stuff related to coffee. Name the file
coffee.php and place it in
Format of the file
$lang = array ( 'cup' => 'Coffee goes in here', 'beans' => 'Coffee is created from beans.', 'java' => 'Place where coffee comes from, not the programming language', );
These language strings can now be called from your application