http://translate.usotools.co.cc/ Internationalization Service
I you are after translating strings on demand, with the ability to define strings on-the-fly, then see here: http://userscripts.org/scripts/show/56630
If you find i18n ( Internationalization ) hard, join the club. Luckily for you, I have made a service that makes it easy!
To get started, get as many accurate translations as possible. If you can only manage one language, do not worry, as the service falls back on Google Translate if you do not specify a particular language.
When you have your translations ready, put them into JSON format like so:
{
"en": {
"string": "This is my script",
"string2": "I want this to be translated",
"string3": "Please listen to me!"
},
"fr": {
"string": "Ceci est mon script",
"string2": "Je veux que cela soit traduit",
"string3": "S'il vous plaît écoutez-moi!"
}
}Make sure your language labels, e.g. "en", "fr", follow the ISO 639-1 Code naming convention. See http://en.wikipedia.org/wiki/List_of_ISO_639-1_...
Once done, visit http://translate.usotools.co.cc/ and paste it into the text box. It will try set a default language for you, otherwise you can specify one manually. Then click "Submit".
USO Translate will then generate a URL for you to copy like the following:
http://translate.usotools.co.cc/2.jsonpThis URL links by default to a JSONP document of all your translations in the language of the browser it is viewed in!
Here is some extra URL syntax:
http://translate.usotools.co.cc/2.json?lang=esThe file extension either accepts "json", "jsonp" or "xml", depending if you want it to return JSON or XML.
lang can be used to force it into the specified language, which is un-recommended if you want to make use of the auto-translation. The above would convert it into Spanish.
Usage:
Here is the easiest and fastest method of them all, .jsonp which is also the default. Note you store this one as a @require, as it stores the translation in a variable ready to go. You can specify the variable name by prefixing var=variable_name to the USO Translate URL. Otherwise it defaults to USO.translate:
// ==UserScript== // @name Test USO Translate // @namespace http://userscripts.org/users/tim // @include http* // @require http://translate.usotools.co.cc/2.jsonp?var=variable // ==/UserScript== alert( variable['string'] ); // Alerts "This is my script" in a english browser
Here is a example of using http://translate.usotools.co.cc/ with
.xml inside a script:
// ==UserScript==
// @name Test USO Translate
// @namespace http://userscripts.org/users/tim
// @include http*
// @resource translation http://translate.usotools.co.cc/2.xml
// ==/UserScript==
var translation = new DOMParser().parseFromString( GM_getResourceText('translation'), "text/xml" );
function get_string(id) {
return translation.evaluate( ".//string[@id='" + id + "']", translation, null, 9, null ).singleNodeValue.textContent;
};
alert( get_string( 'string' ) ); // Alerts "This is my script" in a english browserHere is an example using
.json:
// ==UserScript==
// @name Test USO Translate
// @namespace http://userscripts.org/users/tim
// @include http*
// @resource translation http://translate.usotools.co.cc/2.json
// ==/UserScript==
function json_decode( json ) {
if ( typeof JSON !== "undefined" && typeof JSON.parse === "function" )
json = JSON.parse( json );
else
json = eval( "(" + json + ")" );
return json;
};
var translation = json_decode( GM_getResourceText('translation') );
alert( translation['string'] ); // Alerts "This is my script" in a english browserHope this service makes i18n easier for you!

login to vote
Kewl... will need to give this a whirl when I get more time.