I created the file it_IT.mo and it_IT.po that I placed in the folder
module/application/language/mydomain/
in file module.php I entered
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$eventManager->attach('dispatch.error', array($this,'onDispatchError'), 100);
$translator = $e->getApplication()->getServiceManager()->get('translator');
$translator->addTranslationFile(
'phpArray',
'vendor/zendframework/zendframework/resources/languages/it/Zend_Validate.php',
'default',
'it_IT'
);
$translator->addTranslationFilePattern('Gettext',"module/Application/language/mydomain/","mydomain");
AbstractValidator::setDefaultTranslator($translator);
}
in my view
<?php echo $this->translate("operation_allowed_false","ha","it_IT"); die();?>
operation_allowed_false is the msgid of the file
print the key and not the translated text
this is my file
msgid ""
msgstr ""
"Project-Id-Version: ha\n"
"POT-Creation-Date: 2014-09-17 13:09+0100\n"
"PO-Revision-Date: 2014-09-17 13:14+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: it_IT\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.6.9\n"
"X-Poedit-Basepath: C:\\Users\\DEVELOPMENT\\xamp\\htdocs\\ha\\doc\\phpstring"
"\\contenuti\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SearchPath-0: C:\\Users\\DEVELOPMENT\\xamp\\htdocs\\ha\\doc"
"\\phpstring\\contenuti\n"
#: C:\Users\DEVELOPMENT\xamp\htdocs\ha\doc\phpstring\contenuti/base.php:9
msgid "operation_allowed_false"
msgstr "Operazione non consentita."
In Module.php you register the gettext translationFilePattern with wrong a pattern. The pattern string must contain a "%s" which gets replaced by the locale string.
Example:
So if your locale is it_IT, the translator will load the file module/Application/language/mydomain/it_IT.mo
In your view you want to translate from domain ha (second param):
But you did not register your translationFilePattern with a text domain. Set this parameter to
null
to use the default domain:I would also recommend to move the translator configuration to your module.config.php:
Everything untested