dongyu4455 2014-11-22 07:20
浏览 32
已采纳

如何使用Symfony 2.5翻译组件

I use example from documentation 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

}

What do I wrong?

May be a problem with Symfony 2.5 Translation Component?

  • 写回答

1条回答 默认 最新

  • dpfqy5976 2014-11-22 18:29
    关注

    You are overriding the locale in your code.

    Change $this->get('request')->setLocale('fr'); to $this->get('request')->setLocale('fr_FR');

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?