2014-04-17 200 views
0

出現的情況是這樣的:嫩枝:設置默認翻譯語言

example.twig.html

<P>{%trans%}Example Message 1{%endtrans%}</P> 
<P>{%trans%}Example Message 2{%endtrans%}</P> 
<P>{%trans%}Example Message 3{%endtrans%}</P> 

這不是模板,通過Web瀏覽器訪問者顯示,但對郵件

發送
[email protected] 

作者:Swift_Message。

我想強制更改默認laguage到Trollish,但我不希望使用此:

{%trans into 'trollish' %}...{% endtrans %} 
每次

。它完美的工作,但它在沼澤中洗後像巨魔一樣醜陋。

在控制器我想是這樣的渲染之前( 'example.twig.html'):

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

然後

{{ app.request.locale }} 

返回 「trollish」

,但使用的語言{%trans%} ... {%trans%}仍然不是trollish :(

我該如何解決這個問題?

回答

0

在你的控制器中添加:

$this->get('translator')->setLocale('trollish'); 
+0

工作得很好:) – user3383675