1

Can I have a variable and an interpolation in the same translation key?

Something like this:

"notice" : "{{subject}} {RES, select, is{is} are{are} other{are}}",

gives me the error on the web browser console:

Object { message: "Expected [ \t\n\r] or [0-9a-zA-Z$_] but \"{\" found.", expected: (8) […], found: "{", location: {…}, name: "SyntaxError", stack: "" }

When {{subject}} is removed, it works.

Thank you in advance for help.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
lucius.pl
  • 65
  • 1
  • 7
  • @georgeawg I think this is not a duplication. It is a question on angular-translate usage of special custom interpolation for plural translation. In this case, they state that to use variable, it's a different syntax and should use only one curly bracket. https://angular-translate.github.io/docs/#/guide/14_pluralization – elpddev Jun 11 '19 at 19:52

1 Answers1

2

If you are trying to use angular-translate pluralization interpolation message format in combination with normal variable interpolation, it can be done differently. From the 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.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
elpddev
  • 4,314
  • 4
  • 26
  • 47
  • Thank you for help. I've read only the "Variable replacement" part. Good to know, that this topic is covered in "Pluralization". – lucius.pl Jun 12 '19 at 08:37