我不知道为什么在本地 wamp 服务器上该系统不工作,而在 VPS 服务器上工作。我已经为 php 安装了 intl extensionsint。
那是我的翻译配置:
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../../Donation/language',
'pattern' => '%s.mo',
),
),
),
和应用程序模块的 Module.php 文件的 boostrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$serviceManager = $e->getApplication()->getServiceManager();
$eventManager->attach('dispatch', array($this, 'setLayout'));
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
//LANGUAGE
$validatorTranslator = new \Zend\Mvc\I18n\Translator();
$sessionLang = new SessionContainer('language');
$HelperPluginManager = new HelperPluginManager();
$translator = $serviceManager->get('translator');
$validatorTranslator->addTranslationFile('phparray', __DIR__ . '/language/validator/pl_PL.php', 'default', 'pl_PL');
$validatorTranslator->addTranslationFile('phparray', __DIR__ . '/language/validator/en_US.php', 'default', 'en_US');
AbstractValidator::setDefaultTranslator($validatorTranslator);
AbstractValidator::setMessageLength(500);
$HelperPluginManager->injectTranslator($validatorTranslator);
$http = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : 'en';
$lang = $sessionLang->lang ? $sessionLang->lang : $http;
switch($lang){
case 'pl':
$validatorTranslator->setLocale("pl_PL");
$translator->setLocale("pl_PL");
date_default_timezone_set("Etc/GMT+1");
break;
default:
$validatorTranslator->setLocale("en_US");
$translator->setLocale("en_US");
date_default_timezone_set("Etc/GMT");
}
}