Skip to content

robotdance/php-i18n

Repository files navigation

PHP-I18n

Code Climate Test Coverage Issue Count Build Status

PHP-I18n is a simple I18N and L10n library.

Setup

PHP-I18n uses Composer as dependency management tool.

$ composer install

Use

Create a folder called config/locales at your app/module, and put your locale YAML files there. (an example of valid YAML file can found in the source). Then call I18n::t, in one of the ways below.

Simple key/value lookup

$translated = I18n::t('example_message');

Locale override

$translated = I18n::t('example_message', [], 'pt_BR');

Injecting arguments

$translated = I18n::t('hello_message', ['user' => 'Bob']); // 'Hello Bob'

Note about formatting currently the library does not apply formatting to arguments.

Localisation

Create a section 'l10n' on your locale file and follow the source standards.

$value = I18n::l(true);    // 'verdadeiro'
$value = I18n::l(123.45); // '123,45'

Running tests

$ ./bin/phpunit

Contribute

Fork, write tests, code, submit pull request. Coverage must remains at 100%.

References

PHP the right way Fixing PHP errors automatically PHP SPL Exceptions What exception subclasses are buit in