これは私にとってはうまくいきます:
public function onBootstrap(MvcEvent $e)
{
$localeFromHttp = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
if (false === stripos($localeFromHttp, '-')) {
$locale = $localeFromHttp . '_' . strtoupper($localeFromHttp);
$e->getApplication()
->getServiceManager()
->get('MvcTranslator')
->setLocale($locale);
}
else {
$e->getApplication()->getServiceManager()->get('MvcTranslator')->setFallbackLocale('en_US');
}
}
そして私の modal.config.php:
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
),
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
),
),
'translator' => array(
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
'text_domain' => __NAMESPACE__,
),
),
),