Hi,

Is there any recommeded approach for i18n problem with javascript? I
haven't done a long research, but bibedit doesn't seem to be localized
(and doesn't need to be, right). Because there wasn't much of js
interface for people, I guess other parts of inspire didn't address
that issue yet (?)

While I am writing the new interface for the special editing mode, it
occured to me, that I will have to localise it one day, so why not
start from the beginning...

I have done a quick on the i18n and jquery, and none of the solutions
I found so far, seems satisfactory to me -- they either require usage
of a weird formatting (like '{my localised text}'), or js. variables,
or loading and parsing of a dictionary.

Could you please provide some guidance, or feedback on the solution
below, if i18n wasn't decided yet?


In Drupal world, the solution is similar (the same?) as gettext:
The global namespace contains '_' function -- and every localised
string is wrapped with it, example: _('Please, click here or there')
- English is used as a default language
- there are some basic formatting conventions, example: _('We have
found %s hits in %s seconds')
- the translation is loaded _on demand_ and cached (but only what is
needed throughout the execution), could be of course pre-cached...
- If there is no localisation implemented, the basic language remains
english, also the _ function is used to keep track of untranslated
modules, it can contain pluggable components, but it just doesn't
interfere

Now, with those pieces, I think it could be nice, and minimally
invasive technique also for the js. The central point would allow to
change language by one click, it could be loaded on the fly (ajax), it
could be very complete, or very fast - depending on situation -
managed centrally, or loaded locally. We could ignore it completely,
if we wanted -- and we certainly want during the development

Pseudo code/solution looks like this.

# the global namespace
function _(str):
   if global_dict[current_locale][str] === null:
      # we don't know translation yet
      # get it from somewhere (js file, other module, AJAX call...)
      # return the string itself if nothing is found
      global_dict[current_locale][str] = translate(current_locale, str)
   return global_dict[current_locale][str]


# usange in the modules
alert(_("You seem to be doing something funny and our administrators
were alerted..."))


UPDATE [after i wrote the pieces above, i have don more searching]

I found one implementation that looks like it:
http://svn.recurser.com/misc/jquery/i18n/jquery.i18n.js

The discussion here seems to confirm that the _ approach is good:
http://stackoverflow.com/questions/1553549/how-to-internationalize-string-used-in-javascript-code

And this looks like the direct hit!
http://24ways.org/2007/javascript-internationalisation
http://plugins.jquery.com/project/gettext



I guess, I really dislike the way how i18n is done in jquery plugins
which i saw until now (if..else, locale[something], translation on
serves sides, using .property files, js variables...)

Do you think gettext? Or something else?

Thank you,

  roman

Reply via email to