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
looks cool.
Although maybe think a bit more about scalability. ie calling a php script from toolserver on every page load won't scale. Better would be an api hit with public expire: ( ie letting the result be cached in the shared squid cache for a few hours ) http://commons.wikimedia.org/w/api.php?action=query&meta=siteinfo&si...
or just hard code the list of languages into the script.
Also the script itself should ideally be hosted as a commons mediawiki page instead of imported from toolserver ( this is so hot fixes can be done by any admin )
Minor fixme ( that I would add if it was a mediawiki page )
return language = language.replace(/(-.*)+/, '').toLowerCase();// convert 'AA-BB' to 'aa' etc.
Should check if the lang key already exists ie 'zh-classical' at least in firefox we get en-US so i look for lower case keys in "getBrowserLang" I don't know if it works the same in other browsers.
Also you can test anonymous usage withJS param: http://commons.wikimedia.org/wiki/Main_Page?withJS=MediaWiki:AnonymousI18N.j...
I imagine you saw the recent persistantUseLang that got turned on that does some similar stuff: http://commons.wikimedia.org/wiki/Commons:Village_pump#Localization_for_anon...
Adding a select language + cookie sounds like a great idea to me :)
peace, --michael
On 12/07/2010 05:06 AM, Krinkle wrote:
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
Commons-l mailing list Commons-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/commons-l
Op 7 dec 2010, om 09:01 heeft Michael Dale het volgende geschreven:
looks cool.
Although maybe think a bit more about scalability. ie calling a php script from toolserver on every page load won't scale. Better would be an api hit with public expire: ( ie letting the result be cached in the shared squid cache for a few hours ) http://commons.wikimedia.org/w/api.php?action=query&meta=siteinfo&si...
Obviously it won't stay on the toolserver quering an object of languages that rarely ever changes. From my initial post:
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).
The PHP list uses the MediaWiki API to get all the languages, it then changes it from [0] => array( 'en' => 'English'); to ['en'] => 'English' (more compact and allows to easily do a check like <code>if( typeof mylist[code] == 'string' )</code>. If it is in a numerical array with objects it requires a loop.. ). The output of this php-file can simply be copied hardcoded into, say, wpAvailableLanguages so that other scripts can use it as well and be updated whenever needed (almost never)
The script will then end up as a Wiki-hosted single-file script. The JS was on Toolserver so I could very easily edit the page in my FTP Editor and edit, save, refresh etc. I'll move it on-wiki tonight as basic stuff is done now.
return language = language.replace(/(-.*)+/, '').toLowerCase();// convert 'AA-BB' to 'aa' etc.
Should check if the lang key already exists ie 'zh-classical' at least in firefox we get en-US so i look for lower case keys in "getBrowserLang" I don't know if it works the same in other browsers.
Thanks, I forgot for a second that there are in fact valid, dashed, language codes as well. I'll put a check in between to see if the raw output from the browser is a code of an available language.
Also you can test anonymous usage withJS param: http://commons.wikimedia.org/wiki/Main_Page?withJS=MediaWiki:AnonymousI18N.j...
Well, yes the script can be loaded with withJS, but it doesn't stay when navigating to other pages which is the main purpose of the script. But if one just wants to see how it basically looks, sure the withJS is great for that.
I imagine you saw the recent persistantUseLang that got turned on that does some similar stuff: http://commons.wikimedia.org/wiki/Commons:Village_pump#Localization_for_anon...
I'm afraid I missed this one, I'll check it out right away. My first impression is that it's very exact and elaborate on referals but a few points though * It should be watching out for a hash-tag (ie. #some-header? uselang=fr doesn't get the user anywhere) * instead of looping through ALL anchor-tags on the page, just listen for a click on any a-tag and then perform the is-wiki-domain-check. By doing it live() one also catches clicks on dynamically added links such as the GlobalUsage-action by MediaWiki:Extra-tabs.js. * And usage of global wgVariables to avoid the script being/becoming wiki-dependant.
I think these scripts can go great together. A hook in AnonymousI18N could be added to suggest an alternative language (ie. the referal language code) (overriding the browser- language check, but not overriding the cookie-setting).
-- Krinkle
On 12/07/2010 05:06 AM, Krinkle wrote:
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
Commons-l mailing list Commons-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/commons-l
Commons-l mailing list Commons-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/commons-l
Well, yes the script can be loaded with withJS, but it doesn't stay when navigating to other pages which is the main purpose of the script. But if one just wants to see how it basically looks, sure the withJS is great for that.
just add withJS to your uselang append ( for testing ) ( instead of having the user have to add it to their user profile ) one less click for people to test ideally gets more people trying it out in the village pump and what not and can ideally help us catch more errors.
I imagine you saw the recent persistantUseLang that got turned on that does some similar stuff: http://commons.wikimedia.org/wiki/Commons:Village_pump#Localization_for_anon...
I'm afraid I missed this one, I'll check it out right away. My first impression is that it's very exact and elaborate on referals but a few points though
- It should be watching out for a hash-tag (ie. #some-header?
uselang=fr doesn't get the user anywhere)
- instead of looping through ALL anchor-tags on the page, just listen
for a click on any a-tag and then perform the is-wiki-domain-check. By doing it live() one also catches clicks on dynamically added links such as the GlobalUsage-action by MediaWiki:Extra-tabs.js.
- And usage of global wgVariables to avoid the script being/becoming
wiki-dependant.
Sounds reasonable. I think there are some absolute links to commons that we want to rewrite that we don't want to rewrite for other domains.
I think these scripts can go great together. A hook in AnonymousI18N could be added to suggest an alternative language (ie. the referal language code) (overriding the browser- language check, but not overriding the cookie-setting).
-- Krinkle
Sounds good, feel free to run with it. Take whatever is useful and we can port over to your work once its ready ;)
peace, michael