Symfony Bundle为不同的语言提供不同的文本


Symfony Bundle with different texts for different languages

我想创建一个Symfony bundle,它将为不同的语言保存不同的文本/标志等。

是可能的(和正确的)使用Symfony翻译这个功能?还是只有两张桌子?

不确定,如果我理解正确的话。

但是对于不同语言的不同文本,只需使用Translation组件: http://symfony.com/doc/current/translation.html

基本上,您创建了两个文件- mytranslation.en。Yml mytranslation.cs。yml(英语和捷克语)。它们每个都有相同的翻译键,例如:
app.title: My English title
app.description: This is my English translation.
app.counter: You have been here %count% times so far.
然后,在控制器或服务中,像这样使用Translation服务:
$title = $this->get('translator')->trans('app.title', [], 'mytranslation');

或带参数:

$counter = $this->get('translator')->trans('app.counter', ['%counter%' => 2], 'mytranslation');

在一个Twig模板中,你可以这样做:

{% trans_default_domain "mytranslation" %}
{{ 'app.title'|trans }}
{{ 'app.counter'|trans({'%counter%': 2}) }}