2016-07-02 68 views
0

我正在使用Symfony翻譯我的Twig-模板。一切工作正常,但我需要在用戶更改語言時設置其他圖像。我如何用Symfony和Twig做到這一點?如何用Symfony和Twig翻譯圖像

謝謝

回答

0

您可以從細枝使用app.request.getLocale()訪問locale變量和使用它像:

# template 
{% locale = app.request.getLocale(); %} 
{% image '@AppBundle/Resources/public/images/' ~ locale ~ '/example.jpg' %} 
    <img src="{{ asset_url }}" alt="Example" /> 
{% endimage %} 

或者你可以嘗試保存到你的圖片像普通的翻譯資源路徑:

# messages.en.yml 
image.example: @AppBundle/Resources/public/images/en/example.jpg 

# template 
{% image 'image.example'|trans %} 
    <img src="{{ asset_url }}" alt="Example" /> 
{% endimage %} 
+0

如果我嘗試存儲像常規翻譯一樣的路徑,我得到這個錯誤: 值「」的意外標記「標點符號」。 我使用xlf進行翻譯。 – Joris

+0

這工作正常: example 謝謝 – Joris