【问题标题】:translate delimited text symfony2翻译分隔文本 symfony2
【发布时间】:2012-03-14 19:31:24
【问题描述】:

我需要翻译部分文本(在树枝中)。

类似的东西:

// page.html.twig

    ...
    {{ text | trans ({}, 'MyprojectMyBundle')}} 

假设变量 'text' 有字符串:“Value is between 5 and 10”

在翻译中我有:

// Project/MyBundle/Resources/Translations/MyprojectMyBundle.pt_BR.yml

...
Value is between and : "Valor está entre e"

如何在翻译中转义数字(5 和 10)? 我需要:

值在 5 到 10 之间 -> Valor está entre 5 e 10

值在 50 到 60 之间 -> Valor está entre 50 e 60

等等……

【问题讨论】:

    标签: symfony translation twig


    【解决方案1】:

    你可以使用占位符,所以在你的翻译文件中你会:

    // Project/MyBundle/Resources/Translations/MyprojectMyBundle.pt_BR.yml
    
    ...
    Value is between %min% and %max%: "Valor está entre %min% e %max%"
    

    然后在您的模板中,您可以使用以下内容:

    {{ text | trans({'%min%': '5', '%max%': '10'}, "MyprojectMyBundle") }}
    

    其中 text = '值在 %min% 和 %max% 之间'

    【讨论】:

    • 但是 min 和 max 每次都会改变
    • 是的,您可以将“5”和“10”替换为包含值的模板变量,例如 {{ text | trans({'%min%': minval, '%max%': maxval}, "MyprojectMyBundle") }}
    • 有效!但是'text'现在是一个带有('text','min','max)的数组。所以我可以打电话给 {{ text.text | trans({'%min%': 'text.min', '%max%': 'text.max'}, "MyprojectMyBundle") }} 谢谢!
    • 太棒了!很高兴能提供帮助
    猜你喜欢
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 2015-10-07
    相关资源
    最近更新 更多