Hi all,
Over the past weekend I've been looking at a decent solution for the localization towards our anonymous users. Currently there are two solutions being used. * Template:mld :: This template renders all translations, and by means of javascript only shows the desired choosen translation * ?uselang :: Albeit used only a little but it is linked on several Main-pages[1] to show the interface in the correct language
The problem with Template:Mld is that it's use is limited, it can't be used in all ocasions (ie. it would be hard to use for License- templates or for [[Template:Information]]). Also due to ineffeciency (bandwidth wise, it sends everything).
And not to forget that things localized in Messages (ie. translatewiki or MediaWiki-namespace) can't be fetched via javascript inside the page when the wikitext only shows {{int:Message}}.
And lastly, lots of things are localized with {{LangSwitch}}, which is very smart (because of fallbacks etc.) and effecient (only sends the needed translation to the browser) but is currently only usable for registered users.
Which means that anonymous users get talkpage messages in English and see the overal interface in English.
For that reason I've combined bits and pieces of other scripts and re- wrote things and came up with the AnonymousI18N-script. You can check it out by adding the following to your vector.js[2]
importScriptURI( 'MediaWiki:AnonymousI18N.js' );
Keep in mind that this is ofcourse not meant for registered users, in the final version an if()-statement will prevent it from being loaded if the user is logged in, but during development this will work only for logged in users.
The script itself uses the toolserver to fetch a list of available languages and other data (as soon as development is fairly done I will move the script fully on-wiki - as it would not be handy (and not required) to require a toolserver-request on all pageloads for anonymous users, this is purely temporarily hosted on the Toolserver for now. The list of available languages doesn't change often anyway and can be updated manually when needed).
Once the script is loaded it checks if a cookie has been set and as fallback (default for most new users) it checks the browser language. If the language is not set already to this language and it is available in MediaWiki it puts up a (declinable) localized notice[3] on top asking the user to "View Wikimedia Commons in (language)". Clicking that will set a cookie and redirect the user to the current page with ?uselang set to that language.
The page also shows a dropdown menu in the Sidebar for hand-picking a language of choise. This can be used if the suggestion is wrong, or if the user declined the notice and wishes to pick a language later.
When a language other than the default ('en') is choosen, clicking any link linking to the same or another wikimedia-wiki will get the uselang= query string attached.
The script makes the language setting globally available as wgAnonUserLanguage. Other scripts would in the future use this variable whenever something language dependant os needed (for example in the MLD-javascript) to avoid having to write cookie-things up again and again for each script.
Please let me know what you think and if there are any issues. So far it's been tested in Safari 5 and Firefox 3.6 (Mac). Testing on Windows and (older versions of) Internet Explorer is grealty appreciated.
PS: Since it is built for anonymous users it will only work in the Vector-skin.
-- Krinkle
[1] Example: http://commons.wikimedia.org/wiki/Hoofdpagina the link "Herlaad deze pagina met Nederlandstalige menupagina's" [2] http://commons.wikimedia.org/wiki/Special:Mypage/vector.js [3] A screenshot of what it looks like: http://meta.wikimedia.org/wiki/User:Krinkle/Scripts/AnonymousI18N
-- Greetings, Krinkle