本文整理汇总了PHP中Zend\Validator\AbstractValidator::setDefaultTranslatorTextDomain方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractValidator::setDefaultTranslatorTextDomain方法的具体用法?PHP AbstractValidator::setDefaultTranslatorTextDomain怎么用?PHP AbstractValidator::setDefaultTranslatorTextDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Validator\AbstractValidator
的用法示例。
在下文中一共展示了AbstractValidator::setDefaultTranslatorTextDomain方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$request = $e->getApplication()->getServiceManager()->get('Request');
$moduleRouteListener->attach($eventManager);
$adapter = $e->getApplication()->getServiceManager()->get('Zend\\Db\\Adapter\\Adapter');
$config = $e->getApplication()->getServiceManager()->get('Configuration');
$locale = null;
$eventManager->attach(new UserRegisterListener($adapter));
$eventManager->attach(new LogListener());
// Add ACL information to the Navigation view helper
$authorize = $e->getApplication()->getServiceManager()->get('BjyAuthorize\\Service\\Authorize');
$acl = $authorize->getAcl();
$role = $authorize->getIdentity();
\Zend\View\Helper\Navigation::setDefaultAcl($acl);
\Zend\View\Helper\Navigation::setDefaultRole($role);
// translating system
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config['session']);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();
$session = new Container('base');
// Get the visitor language selection
$translator = $e->getApplication()->getServiceManager()->get('translator');
// get the locale from the cookie
$headCookie = $request->getHeaders()->get('Cookie');
if (!empty($headCookie) && array_key_exists('locale', get_object_vars($headCookie))) {
$locale = $headCookie->locale;
}
if (empty($locale)) {
// if there is not set any cookie
$locale = $session->offsetGet('locale');
// Get the locale from the session
if (empty($locale)) {
// if there is not any session set yet
$headers = $request->getHeaders();
if ($headers->has('Accept-Language')) {
$locales = $headers->get('Accept-Language')->getPrioritized();
$first = array_shift($locales);
$locale = $first->getLanguage();
if (!empty($locale) && 2 == strlen($locale)) {
$locale .= "_" . strtoupper($locale);
}
}
if (empty($locale)) {
// if the browser has no locale set, we have to get the default INTL global locale setting
$locale = \Locale::getPrimaryLanguage(\Locale::getDefault());
// Gets the default locale value from the INTL global 'default_locale'
}
}
} else {
#\Zend\Debug\debug::dump("Cookie set with locale: $locale");
}
$translator->setLocale(\Locale::acceptFromHttp($locale));
$translator->setLocale($locale)->setFallbackLocale('en_US');
\Zend\Validator\AbstractValidator::setDefaultTranslator($translator);
\Zend\Validator\AbstractValidator::setDefaultTranslatorTextDomain();
}
示例2: onBootstrap
/**
* @internal
*/
public function onBootstrap(\Zend\EventManager\EventInterface $e)
{
\Zend\Filter\StaticFilter::getPluginManager()->setInvokableClass('Library\\FixEncodingErrors', 'Library\\Filter\\FixEncodingErrors');
$serviceManager = $e->getApplication()->getServiceManager();
// Register form element view helpers
$formElementHelper = $serviceManager->get('ViewHelperManager')->get('formElement');
$formElementHelper->addClass('Library\\Form\\Element\\SelectSimple', 'formselectsimple');
$formElementHelper->addType('select_untranslated', 'formselectuntranslated');
if (\Locale::getPrimaryLanguage(\Locale::getDefault()) != 'en') {
$mvcTranslator = $serviceManager->get('MvcTranslator');
if (Application::isDevelopment()) {
$translator = $mvcTranslator->getTranslator();
$translator->enableEventManager();
$translator->getEventManager()->attach(\Zend\I18n\Translator\Translator::EVENT_MISSING_TRANSLATION, array($this, 'onMissingTranslation'));
}
// Validators have no translator by default. Attach translator, but
// use a different text domain to avoid warnings if the Zend
// translations are not loaded. For custom messages, the text domain
// must be reset manually to 'default' for individual validators.
\Zend\Validator\AbstractValidator::setDefaultTranslator($mvcTranslator);
\Zend\Validator\AbstractValidator::setDefaultTranslatorTextDomain('Zend');
}
}