简体   繁体   中英

ZF2 Language system not work on local server

I have no idea why on local wamp server that system not work, and on VPS server that work. I have installed intl extensionsint for php.

That is my translator config:

'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',
        ),
    ),
),

and boostrap on Module.php file of application module

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");
    }
}

FIX

In service_manager rule of module.config.php need change:

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

to:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM