I'm just not currently convinced that going with the status quo (baking the equivalent of gettext into everything) is the correct answer.
I like your idea of not making the plugins dependent on an additional i18n library. I also like the idea of not baking gettext into everything. That said, I don't have a better solution at this time.
gettext does several things nicely
1. It lets u mark strings for translation with a function signature _("some string"). This allows command-line tools like xgettext to gather all your strings into a translation template that can be sent to translators or a web-based translation program like
pootle
- $ xgettext -L Python ui.myplugin.js > ui.myplugin.pot
Note: Xgettext parses out strings from various languages but isn't tuned specifically for js. Using the Python setting seems to work fine.
2. You can add internationalize your application later. You don't have to do it up front. Let's face it, i18n is an afterthought for 99% of developers. It certainly was for me.
3. gettext and the larger GNU C localization API cover a broad array of localization requirements
Scott, you bring up that both dialog and datepicker maintain their own closeText values. Once we have 5-6 plugins on a page that store their own closeText string for the same locale, doesn't it make sense to centralize this information?
I didn't make myself clear. closeText should be a special string value, just like Yes/No stored separately from translations, just like formatting information is
I think closeText and yes/no should be stored separately from regular strings. Here is an example:
$.i18n.es.closeText = "Cerrar"
$.i18n.es.yes = "Sí";
$.i18n.es.no = "No";
$.i18n.es.strings = {"Buy ticket": "Compra billete", "Change Time": "Cambia la hora", ....}
Again, I am shamelessly aping how the GNU C Library handles localization for lack of a better idea. The GNU C Library is pretty darn good at covering all the various use cases. Further, rails, django, gnome, KDE, all use some variation on its API.
I definitely want it to be possible to use a full i18n system to work with these plugins, but I don't want it to become a dependency.
Perhaps we could get around this by putting in stubs for the gettext functions into ui.core.js . These stub functions simply return their argument if the i18n plugin isn't loaded. The code size of these stub functions would be negligible
Here is an example stub for the gettext function
- $.ui.i18n.gettext = function(str) { return str;};
If i18n isn't loaded
this._('Hello') returns "Hello"
if i18n is loaded and locale set to 'es'
this._('Hello') returns "Hola"
There are a # of issues I haven't yet touched on that further add complication, particularly "context," where we use the same word in two different contexts with two different meanings. In many languages, there won't be one word that has the same two meanings. Some examples are "commit", "close", "mail" (both noun and verb in English).
I will take a look at the wiki page and see what I can contribute. I have to keep working on i18n anyways for the sake of my own applications