Page 1 of 1

Do backticks break the translation system?

Posted: 20 July 2021, 03:09
by JonChambers
Let's suppose instead of writing:

Code: Select all

dojo.string.substitute( _("You can pick ${p} cards and discard ${d}"), {
    p: pick[player],
    d: discard[player]
} );
I instead wrote

Code: Select all

_(`You can pick ${pick[player]} cards and discard ${discard[player]}`)
Would that still work?

Re: Do backticks break the translation system?

Posted: 20 July 2021, 06:18
by Archduke
That won’t work - the translation system needs to have a fixed string in it. If you substitute variables in directly (using backticks and ${}), you are effectively asking to translate different strings depending on the values of pick[player] and discard[player].

In the first case, the translation system would literally contain ${p} and ${d}. The translators would keep those tags in the translated strings, so the substitution still works.

Re: Do backticks break the translation system?

Posted: 20 July 2021, 07:34
by Tisaac
Archduke wrote: 20 July 2021, 06:18 That won’t work - the translation system needs to have a fixed string in it. If you substitute variables in directly (using backticks and ${}), you are effectively asking to translate different strings depending on the values of pick[player] and discard[player].

In the first case, the translation system would literally contain ${p} and ${d}. The translators would keep those tags in the translated strings, so the substitution still works.
Exactly, the translation system always look for perfect match on the string the _() function is receiving.
This is something you should always have on your mind when wondering if what you write will work with translation.

Re: Do backticks break the translation system?

Posted: 21 July 2021, 03:55
by JonChambers
I suspected that was exactly what was going on, but I live in hope.

Thanks for clarifying. I'll get back to work.