【问题标题】:How to use Symfony 2.5 Translation Component如何使用 Symfony 2.5 翻译组件
【发布时间】:2015-01-20 09:48:21
【问题描述】:

我使用文档http://symfony.com/doc/current/components/translation/introduction.html中的示例

public function mytestAction()
{

    $this->get('session')->set('_locale', 'fr_FR');
    $this->get('request')->setLocale('fr');

    $translator = $this->get('translator');

    $translator->addLoader('array', new \Symfony\Component\Translation\Loader\ArrayLoader());

    $translator->addResource('array', array(
        'Hello World!' => 'Bonjour',
    ), 'fr_FR');

    $Bonjour = $translator->trans('Hello World!');

    echo $Bonjour; exit;// I get Hello World

}

我做错了什么?

可能是 Symfony 2.5 翻译组件的问题?

【问题讨论】:

  • 什么是默认语言环境?
  • 默认语言环境英语

标签: php symfony translation translate


【解决方案1】:

您正在覆盖代码中的语言环境。

$this->get('request')->setLocale('fr'); 更改为$this->get('request')->setLocale('fr_FR');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-19
    • 1970-01-01
    • 2017-11-24
    • 2015-11-06
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多