【发布时间】:2016-05-03 22:59:48
【问题描述】:
我们如何在 layout.phtml 或 Zend Framework 2 中的视图中获取本地值(即:'en' 或 'en_US'、'de' 等)?
我的本地设置和explained here一模一样
<?php
namespace FileManager;
use Zend\Mvc\ModuleRouteListener;
class Module
{
public function onBootstrap($e)
{
$translator = $e->getApplication()->getServiceManager()->get('translator');
$translator
->setLocale(\Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']))
->setFallbackLocale('en_US');
}
//...
}
我想获得类似这样的本地价值:
$locale = $this->translate()->getLocale(); // <-- It's not working anyway
我需要在调用 google map api url 时使用 '$locale' 来获取匹配的区域设置/语言。我在 layout.phtml 中的整个应用程序中调用它
$this->headScript()->appendFile('http://maps.googleapis.com/maps/api/js?language=' . $locale);
所以我想在调用 api 时使语言选项动态化。
PS:我没有任何查询字符串参数,例如“语言”,这是一个 google api 的东西,我需要在脚本 url 中设置(如果你不知道)请不要混淆。 未回复here
【问题讨论】:
-
一个简单的选择available here
-
Solution:
$this->plugin('translate')->getTranslator()->getLocale();
标签: localization zend-framework2