ZF2语言系统无法在本地服务器上运行

时间:2013-09-01 11:05:46

标签: php internationalization zend-framework2

我不知道为什么在本地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");
    }
}

1 个答案:

答案 0 :(得分:0)

FIX

在module.config.php的service_manager规则中需要更改:

'service_manager' => array(
    'factories' => array(
        'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
        'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
        'cache' => 'Zend\Cache\Service\StorageCacheFactory',
    ),
),

至:

'service_manager' => array(
    'factories' => array(
        'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
        'cache' => 'Zend\Cache\Service\StorageCacheFactory',
    ),
    'aliases' => array(
        'translator' => 'MvcTranslator',
    ),
),