angular-translate - 同一个翻译键中的变量和插值
angular-translate - variable and interpolation in the same translation key
我可以在同一个翻译键中有一个变量和一个插值吗?
像这样:
"notice" : "{{subject}} {RES, select, is{is} are{are} other{are}}",
在 Web 浏览器控制台上给我错误:
Object { message: "Expected [ \t\n\r] or [0-9a-zA-Z$_] but \"{\"
found.", expected: (8) […], found: "{", location: {…}, name:
"SyntaxError", stack: "" }
删除 {{subject}} 后,它会起作用。
提前感谢您的帮助。
如果您尝试将 angular-translate 复数插值消息格式与普通变量插值结合使用,则可以采用不同的方法。来自 docs:
The drawback
Actually it's pretty cool that we are able to use MessageFormat as our
interpolation engine. Unfortunately, when replacing MessageFormat
interpolation with angular-translate's default interpolation, there's
a big problem. Take a look at the following code: Do you see any
difference?
{
"DEFAULT_INTERPOLATION": "This is a translation that uses default
interpolation with a dynamic value: {{value}}",
"MF_INTERPOLATION": "This is a translation that uses MessageFormat
interpolation with a dynamic value: {value}"
}
Exactly. MessageFormat uses a different syntax for its interpolation.
This means, when using MessageFormat interpolation, you have to rock
over all of your translations, check if they use any kind of variable
replacement and update them to match the right interpolation syntax.
This isn't a cool thing.
我可以在同一个翻译键中有一个变量和一个插值吗?
像这样:
"notice" : "{{subject}} {RES, select, is{is} are{are} other{are}}",
在 Web 浏览器控制台上给我错误:
Object { message: "Expected [ \t\n\r] or [0-9a-zA-Z$_] but \"{\" found.", expected: (8) […], found: "{", location: {…}, name: "SyntaxError", stack: "" }
删除 {{subject}} 后,它会起作用。
提前感谢您的帮助。
如果您尝试将 angular-translate 复数插值消息格式与普通变量插值结合使用,则可以采用不同的方法。来自 docs:
The drawback
Actually it's pretty cool that we are able to use MessageFormat as our interpolation engine. Unfortunately, when replacing MessageFormat interpolation with angular-translate's default interpolation, there's a big problem. Take a look at the following code: Do you see any difference?
{ "DEFAULT_INTERPOLATION": "This is a translation that uses default interpolation with a dynamic value: {{value}}", "MF_INTERPOLATION": "This is a translation that uses MessageFormat interpolation with a dynamic value: {value}" }
Exactly. MessageFormat uses a different syntax for its interpolation. This means, when using MessageFormat interpolation, you have to rock over all of your translations, check if they use any kind of variable replacement and update them to match the right interpolation syntax. This isn't a cool thing.