在我的Twig项目中,我使用来自.yaml文件的翻译。我需要翻译的文本可以在.html.twig文件中找到,例如,
“我的翻译文本包含要翻译的{参数}”。
我知道我可以用关键字替换整个字符串,例如- to_translate %参数% to_translate2,我可以像下面这样使用来自.yaml文件的转换
to_translate:“我的翻译文本包含一个”to_translate2:“来翻译”
参数就会被传递。然而,我怎么能做到这一点,而不打破这个句子的许多部分呢?
发布于 2016-12-27 12:32:05
也许我没有理解你的意思,但你可以添加任意多的参数吗?
Yaml档案:
my_translation_key: Hello %firstname%, %lastname%, welcome here !在Twig:
{{ 'my_translation_key' | trans({
'%firstname%': 'John',
'%lastname%': 'Doe'
}) }}如果您想要的是在翻译中获得嵌套块,那么您可能可以尝试这样的方法:
Yaml档案:
my_translation_key: Hello %firstname%, %lastname%, %welcome% !
welcome_block: welcome %where%在Twig:
{% set welcome = 'welcome_block' | trans({'%where%': 'here'}) %}
{{ 'my_translation_key' | trans({
'%firstname%': 'John',
'%lastname%': 'Doe',
'%welcome%': welcome
}) }}发布于 2016-12-27 10:01:46
也许你应该试试这个:
{{ ('My text for translation contains a '~parameter)|trans }}在文档中:
~:将所有操作数转换为字符串并将它们连接起来。{{ "Hello“~ name > "!”}}将返回(假设名称为'John') Hello John!
https://stackoverflow.com/questions/41342758
复制相似问题