easy internationalization support for PHP
Easy internationalization support for PHP
It aims to be a drop-in replacement for
It can be installed with composer
composer require crodas/intl:dev-master
crodas/intl at run time provides a few functions (
_ 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 needs to be copied in order to create new
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).
Whenever you update your locale files you would need to compile it in order to load efficiently from your PHP app.
TODO: add demos
In order to use
crodas/intl, it needs to be initialized as follows:
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.
It is possible to switch to another locale at any time by doing:
Then you can call to
__("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