Internationalisation

Usage

Basic usage is made by calling App\Core\I18n\I18n::_m, it works like this:

// Both will return the string 'test string'
_m('test string');
_m('test {thing}', ['thing' => 'string']);

This function also supports ICU format, you can refer to ICU User Guide, for more details on how it works. Below you find some examples:

$apples = [1 => '1 apple', '# apples'];

_m($apples, ['count' => -42]); // -42 apples
_m($apples, ['count' => 0]); // 0 apples
_m($apples, ['count' => 1]); // 1 apple
_m($apples, ['count' => 2]); // 2 apples
_m($apples, ['count' => 42]); // 42 apples

$apples = [0 => 'no apples', 1 => '1 apple', '# apples'];
_m($apples, ['count' => 0]); // no apples
_m($apples, ['count' => 1]); // 1 apple
_m($apples, ['count' => 2]); // 2 apples
_m($apples, ['count' => 42]); // 42 apples

$pronouns = ['she' => 'her apple', 'he' => 'his apple', 'they' => 'their apple', 'someone\'s apple'];
_m($pronouns, ['pronoun' => 'she']); // her apple
_m($pronouns, ['pronoun' => 'he']); // his apple
_m($pronouns, ['pronoun' => 'they']); // their apple
_m($pronouns, ['pronoun' => 'unknown']); // someone's apple

$complex = [
    'she'   => [1 => 'her apple', 'her # apples'],
    'he'    => [1 => 'his apple', 'his # apples'],
    'their' => [1 => 'their apple', 'their # apples'],
];

_m($complex, ['pronoun' => 'she',  'count' => 1]); // her apple
_m($complex, ['pronoun' => 'he',   'count' => 1]); // his apple
_m($complex, ['pronoun' => 'she',  'count' => 2]); // her 2 apples
_m($complex, ['pronoun' => 'he',   'count' => 2]); // his 2 apples
_m($complex, ['pronoun' => 'she',  'count' => 42]); // her 42 apples
_m($complex, ['pronoun' => 'they', 'count' => 1]); // their apple
_m($complex, ['pronoun' => 'they', 'count' => 3]); // their 3 apples

Utilities

Some common needs regarding user internationalisation are to know his language and whether it should be handled Right to left:

$user_lang = $user->getLanguage();
App\Core\I18n\I18n::isRtl($user_lang);