User:AT/Langbox

From Guild Wars Wiki
Jump to navigationJump to search

What?[edit]

A tiny tool that adds support for languages other than English.

Why?[edit]

As official wikis in other languages seem unlikely, the next best thing is translating this wiki. It's easy enough to do via google, but this just speeds up the process.

How?[edit]

Add the following to your monobook.js:

function importScript(page, lang) {
     var url = wgScriptPath + '/index.php?title='
                            + encodeURIComponent(page.replace(' ','_'))
                            + '&action=raw&ctype=text/javascript&dontcountme=s';
     if (lang) url = 'http://' + lang + '.wikipedia.org' + url;
     var s = document.createElement('script');
     s.src = url;
     s.type='text/javascript';
     document.getElementsByTagName('head')[0].appendChild(s);
}
importScript('User:AT/langbox.js');

Extra languages[edit]

By default, the tool allows translation into the following languages:

  • French
  • German
  • Spanish
  • Italian
  • Dutch
  • Chinese (Simplified and Traditional)

However, it offers support for many more. You can specify additional languages using the following syntax:

var userLanguages = function() 
{ 
addLangSite('Language', 'code'); 
}

Where 'code' is a language code used by the Google translator. The list of supported languages and corresponding codes are shown below.

Language Code
Arabic ar
Bulgarian bg
Chinese (Simp) zh-CN
Chinese (Trad) zh-TW
Croatian hr
Czech cs
Danish da
Dutch nl
Finnish fi
French fr
German de
Greek el
Hindi hi
Italian it
Japanese ja
Korean ko
Norwegian no
Polish pl
Portugese pt
Romanian ro
Russian ru
Spanish es
Swedish sv

So, for example, if you wanted options to translate into Finnish, Swedish and Norwegian, you'd add the following to your monobook.js:

function importScript(page, lang) {
     var url = wgScriptPath + '/index.php?title='
                            + encodeURIComponent(page.replace(' ','_'))
                            + '&action=raw&ctype=text/javascript&dontcountme=s';
     if (lang) url = 'http://' + lang + '.wikipedia.org' + url;
     var s = document.createElement('script');
     s.src = url;
     s.type='text/javascript';
     document.getElementsByTagName('head')[0].appendChild(s);
}
importScript('User:AT/langbox.js');

var userLanguages = function() 
{ 
addLangSite('Finnish', 'fi'); 
addLangSite('Swedish', 'sv'); 
addLangSite('Finnish', 'no'); 
}

Note: If you already have the importScript function somewhere on the page, no need to add it again.