【发布时间】:2020-06-27 03:59:54
【问题描述】:
我需要在 Symfony 3.4 中翻译可变长度的句子。
示例句:“包括:4 份早餐、1 份早午餐和 3 份晚餐。”
例如,假设以下约束:
- 我必须表示一次旅行在完整行程中可能包含的早餐、早午餐、午餐和晚餐的数量
- 要枚举的“事物”列表是已知且有限的。每个关键词都有单数和复数翻译。
- 并非所有这些都必须出现。如果有 0 个单元,则将省略整个块。
- 列表以逗号分隔。
- 除了最后一个添加了“and”连接器的块。
- 如果只有 1 个块,则没有逗号,也没有“and”连接符。
- 每个都可以是单数/复数。
- 有多种语言,在本例中我将使用英语和西班牙语,但实际上也有加泰罗尼亚语。
English-singular / english-plural / spanish-singular / spanish-plural 中的关键字如下:
breakfast / breakfasts / desayuno / desayunos
brunch / brunches / alumerzo-desayuno / almuerzo-desayunos
lunch / lunches / almuerzo / almuerzos
dinner / dinners / cena / cenas
所以...我可以想象以下测试用例:
[
'language' => 'en-US',
'parameters' => [
'breakfast' => 4,
'dinner' => 1,
],
'expectedOutput' => 'Included: 4 breakfasts and 1 dinner.'
],
[
'language' => 'es-ES',
'parameters' => [
'breakfast' => 2,
'brunch' => 1,
'lunch' => 5,
'dinner' => 2,
],
'expectedOutput' => 'Incluido: 2 desayunos, 1 desayuno-almuerzo, 5 almuerzos y 2 cenas.'
],
[
'language' => 'en-US',
'parameters' => [
'breakfast' => 1,
],
'expectedOutput' => 'Included: 1 breakfast.'
],
[
'language' => 'es-ES',
'parameters' => [
'dinner' => 4,
'lunch' => 3,
],
'expectedOutput' => 'Incluido: 3 almuerzos y 4 cenas.'
],
问题
- Symfony 3.4 中的本地翻译引擎是否支持此功能?
- 如果不支持,Symfony 4 或 5 的本地翻译引擎是否支持?
- 否则,是否有任何已知的模式或策略适合这种情况?
【问题讨论】:
标签: symfony translation symfony-3.4 variable-length-array