globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 602 forks source link

Support for string interpolation #100

Closed jzaefferer closed 12 years ago

jzaefferer commented 12 years ago

As if localization isn't fun enough already, we should consider venturing into the minefield of string interpolation. This ticket should host some discussion around that, gathering resources and the like.

From #72, an example how string interpolation, printf-style, could be used:

Globalize.addCultureInfo("en", {
    messages: {
        "characterLeft": "%0n characters left"
    }
});
Globalize.addCultureInfo("de", {
    messages: {
        "characterLeft": "verbliebene Zeichen: %0n"
    }
});

Resulting in:

var localized = Globalize.localize("charactersLeft", [23]);
// en: "23 character left"
// de: "verbliebene Zeichen: 23"

An interesting reference implementation is Alex Sexton's messageformat.js: https://github.com/SlexAxton/messageformat.js

scottgonzalez commented 12 years ago

There are issues with printf style messages. Just ask Alex :-)

jzaefferer commented 12 years ago

This ticket was supposed to not be specific to printf-style message, not sure though what a better title could be.

jzaefferer commented 12 years ago

This is out of scope of Globalize, at least until we get a grip on all the issues we have within our existing scope. There's other projects working on this, like Jed: https://github.com/SlexAxton/Jed