我想在我的自定义php项目中使用ZF2 i18n模块。我的作曲家。Json文件如下
{
"require": {
"zendframework/zend-i18n": "2.3.*@dev"
}
}
我的index.php文件是
include_once './vendor/autoload.php';
use ZendI18nTranslatorTranslator;
$translator = new Translator();
$translator->setLocale('fr_FR');
echo $translator->translate('All rights reserved.');
我的问题是如何为我存储en_US的语言设置基本目录。阿宝,fr_FR。当我设置$translator->setLocale('fr_FR');然后是法语版的"版权所有"。
您需要向翻译器添加一个模式以使其工作(您已经支持两种语言)。使用模式可以在不更改代码的情况下添加更多的区域设置。使用addTranslationPattern
函数。函数定义为:
//$type -> format loader
//$baseDir -> the dir where you place your locale files
//$pattern -> sprintf expression (the locale is parsed through it)
//$textDomain -> category specified for the file. By default is 'default'
public function addTranslationFilePattern($type, $baseDir, $pattern, $textDomain = 'default')
使用方式:
$translator = new Translator();
$translator->addTranslationFilePattern('gettext', '<your_base_dir>', '%s.mo');
参考资料