dev-master
9999999-deveasy internationalization support for PHP
BSD-4-Clause
The Requires
by César D. Rodas
Wallogit.com
2017 © Pedro Peláez
easy internationalization support for PHP
Easy internationalization support for PHP, (*1)
It aims to be a drop-in replacement for gettext., (*2)
It can be installed with composer, (*3)
composer require crodas/intl:dev-master
crodas/intl at run time provides a few functions (__, _e and _ if gettext in not installed) to translate text. It also provides a generator that walks throughtout the project and extract all texts it can find and generates a template file., (*4)
That template needs to be copied in order to create new locales or languages. You can run this process as many time as you'd like, the template file and all locale files are going to be updated (but we never override its content)., (*5)
Whenever you update your locale files you would need to compile it in order to load efficiently from your PHP app., (*6)
TODO: add demos, (*7)
In order to use crodas/intl, it needs to be initialized as follows:, (*8)
require "vendor/autoload.php";
crodas\Intl::init("/tmp/language.php", $locale);
It takes two arguments, the first is the compiled locale and the second is the language to use., (*9)
It is possible to switch to another locale at any time by doing:, (*10)
crodas\Intl::setLanguage($locale);
Then you can call to __("Hello") and __("Hello %s, welcome"), they will be replaced with the correct locale or the default content will be print if we can't the locale file or the sentence to translate, pretty much like gettext works., (*11)
easy internationalization support for PHP
BSD-4-Clause