I want to use ZF2 i18n module in my custom php project. My composer.json file as bellow
{
"require": {
"zendframework/zend-i18n": "2.3.*@dev"
}
}
My index.php file is
include_once './vendor/autoload.php';
use Zend\I18n\Translator\Translator;
$translator = new Translator();
$translator->setLocale('fr_FR');
echo $translator->translate('All rights reserved.');
My question how to set base dir for language where I store en_US.po, fr_FR.po file for translation and when I set $translator->setLocale('fr_FR'); then french version of 'All rights reserved.' text show.
You need to add a pattern to the translator in order to get it working (you've got two languages supported). Using a pattern allows you to add more locales without changing your code. Use the
addTranslationPatternfunction. The function definition is:Use it like:
Check the reference for more information.