Crater PHP Framework

fast, lightweight and modular

Languages

The 'Languages' helper is used for internationalization.
It is very easy to use. All strings are stored in an array file

How to use

First of all, you need to change language_code line in your config file for default language:

return array(
    'language_code' => 'en',
    [...]
);

In your controller, you must specify what is name of your language. A good option is to write the language loader in constructor:

public function __construct()
{
    parent::__construct();
    $this->language->load('hello', Session::get('language'));

    // Or
    $this->language->load('hello', 'en');
}

Translate your string

In your controller action you can use the following syntax:

$viewVariables = array(
    'title' => $this->language->get('hello_title'),
    'message' => $this->language->get('hello_message'),
);

How looks the language files

All language files would need to stay in /App/Languages/[language_code]/[key].php folder.
For the example above, the url is /App/Language/en/hello.php

The file's contents will be something like:

return array(
    'hello_title' => 'Hello',
    'hello_message' => 'This is hello message!'
);

Sure, for another language will need to have a new file. For example if you want to have french language, you will need to create /App/Language/fr/hello.php

How to change the current language

For a dynamic change, you'll need to use sessions. For example:

public function setLanguageAction()
{
    $code = $this->getParam('code');

    Session::set('language', $code);
    $this->redirect('/');
}