Template strings and templates

Norbert Lindenberg ecmascript at lindenbergsoftware.com
Fri Mar 7 00:31:45 PST 2014

On Mar 6, 2014, at 23:40 , Axel Rauschmayer <axel at rauschma.de> wrote:

>>> // Localization and formatting
>>> l10n`Hello ${name}; you are visitor number ${visitor}:n! You have ${money}:c in your account!`
>> A correct German translation of this would have to take the gender of the visitor into consideration:
>> Male: l10n`Hallo, Herr ${name}; Sie sind Besucher Nummer ${visitor}:n. Sie haben ${money}:c auf Ihrem Konto.`
>> Female: l10n`Hallo, Frau ${name}; Sie sind Besucherin Nummer ${visitor}:n. Sie haben ${money}:c auf Ihrem Konto.`
>> How would you do that with template strings?
> The English version could be used as a key to look up the international version. You could also reorder the pieces. A bit of work for a library, but template strings would help, a little.

If by "used as a key" you mean something like the last part of
then I don't see what value the template strings provide here over just using a simple substitution function. And it appears you lose the ability to use meaningful variable names in the resource bundles.

You haven't addressed how to solve the gender problem.

Has anybody actually implemented a complete msg/l10n function for template strings that provides the functionality of, say, MessageFormat and ResourceBundle in ICU, and used it in a real internationalization and localization project?


More information about the es-discuss mailing list