Developers
Translating the widget into the user's language
Netvibes is a website used by millions of people from several countries, and many of our users do not regularly use English, yet would probably benefit from your widget.
Therefore, it would certainly benefit from being multilingual. This is called internationalization (or i18n, the fact of making the widget's string translatable) and localization (l10n, the fact of translating the internationalized, or i18n'd, strings).
Depending of the complexity of your widget, there are two ways of turning your monolingual widget into a multilingual one.
Using Netvibes' default strings
All Netvibes' official widgets (that is, the ones you can find directly in Netvibes' sidebar) are i18n'd. These translations are made volunteers, through the Translation tool. Once a string is translated, this translatio can apply to your widget if you use the exact same original English string.
This method is not the best, since you can't use custom messages, but it's the easiest to set up, as long as you can live with the available strings. Such strings are 'Yes', 'No', 'Monday' and other weekdays, 'January' and other months, 'Username', 'Password', 'Search', 'Results', 'Loading…', 'About', …
Their use is pretty simple: you just need to enclose the string within the _() JavaScript method, and the translation will automatically apply according to the user's language setting.
widget.setBody('<p>' + _('Loading...') + '</p>);
or
var html = ''; html += '<p>'; html += _('Username'); html += ': ' + YourWidgetName.getUsername(userid); html += '</p>'; widget.setBody(html);
If your language is not translated, you can request to become a translator…
Using your own custom strings
Once you have custom strings to translate, you need to set up your own translation file, and call it using an ajax method. But you'd have to know the user's language to properly set the translation.
widget.lang and widget.locale
UWA provides with two dedicated widget properties: locale and lang. They can be used to retrieve the user's country (locale), and his language/dialect (lang).
var lang = widget.lang; var loc = widget.locale;
In standalone mode, widget.locale is set to 'us', and widget.lang to 'en_US'. As soon as the widget is previewed or included within Netvibes or another supported environment, widget.locale would change the user's country ISO code, and widget.lang to a combination of the user's language, and the regional dialect.
Therefore, for English you have en_US and en_UK, but also en_PH (Philippines). Spanish has many, with es_ES (Spain), es_AR (Argentina), es_CL (Chile), es_CO (Colombia), es_MX (Mexico) and es_VE (Venezuela).
Internationalization and localization
Once you have the proper lang and locale, there is no one true way of retrieving the needed strings - it's really up to you to set up the code that will handle localization.
The main point is to retrieve the translated strings using an Ajax GET request that features the widget.locale or widget.lang value. Here's how you could set it up on the client side.
var YourWidgetName = {}; YourWidgetName.l10n = new Array(); YourWidgetName.getl10n = function () { UWA.Data.request( 'http://api.example.org/l10n.php?lang=' + widget.lang, { method: 'get', proxy: 'ajax', type: 'json', cache: 1, onComplete: YourWidgetName.processl10n } ); } YourWidgetName.processl10n = function(loc) { YourWidgetName.l10n = loc; widget.setTitle(YourWidgetName.l10n.widgetTitle); }
Leveraging Netvibes' translators network
It's not quite ready yet, but we plan to release a way for widget developers to make their widget strings available to translator worldwide, which will free you from having to rely on a server-side script.
- Send to a friend
- Add to favorites
- Last modified: 2008/04/24 23:27

