Topic on Project:Village Pump

Looking for a better language switching solution for MediaWiki (was "Two language bars‬")

24
Shirayuki (talkcontribs)

Two language bars are displayed on the Main Page.

TheDJ (talkcontribs)

Yeah seems far from ideal. This is a main-page, not some random page in the project and it totally breaks the aesthetic design.

Want (talkcontribs)

Yes! But it's problem template 'Main page'. I'm looking for the code that generates the bar. And I would say that the practical point of view takes precedence over the aesthetic point of view in this regard. Problem first must be analyzed. I am not motor-mouse.

P858snake (talkcontribs)
Matěj Suchánek (talkcontribs)

I discussed this with Want intensively in the last days. The problem he is trying to solve is the fact that for anonymous users it is quite difficult to discover the way to switch the language. He believes there are many MediaWiki admins around the world who would benefit of having mediawiki.org as the place-to-go for documentation, yet there is a language barrier. Ideally, the user needs to do the switch only once (i.e, on the main page), then all links become language-relative and surfing the web is smooth. Special treatment for the main page is in my opinion acceptable, the wiki's main page will always be "special".

Note that I do not like having two language bars either. The original language bar (placed at the bottom which is even less accessible) links to "Template:Main page/...", this is somewhat weird.

Tacsipacsi (talkcontribs)

Ideally, the user needs to do the switch only once (i.e, on the main page), then all links become language-relative and surfing the web is smooth.

I agree this would be ideal. Unfortunately, mediawiki.org is quite far from this, because it uses the user interface language a lot – which defaults to English and cannot be changed by logged-out users:

  • Main Page itself loads the main page translation in the UI language.
  • Special:MyLanguage is used much (often through {{Ll }}), which redirects the user to the translation in the UI language (if that exists).

Those language-relative links are implemented by {{Pll }}, but that template is hardly used (353 transclusions vs 65k transclusions for {{Ll }}). For the main page, there are two possibilities:

  • The current setup: Main Page itself is not translatable, transcludes a template in UI language. This makes language change and linking to translated main pages relatively difficult, but makes a reasonable guess for the user’s preferred language (at least for that of the logged-in user, since logged-out users always get English).
  • What Meta does: the main page itself is translatable. This displays m:Main Page appear in English even for those who have set their UI language, but makes language switching and linking to translated main pages easier. (The languages bar is at the bottom there as well, but nothing would prevent moving it higher above.)

I prefer the latter because it doesn’t discriminate casual readers, but recognize that the former also has its advantages.

Want (talkcontribs)

Solution used on Meta is optimal, because anonymous user can do switch into language prefered. If let be here as well, it be ok for all users.

But for now.

I looked at the {{Pll }} template. This alone makes 14 calls to demanding functions, and the template {{Ll }} 37. I use a similar template on my wiki which was inspired by the {{Ll }} template.

That linked page has 20 calls because it uses the trascluded man page as documentation, where it is used, including many other templates. But after commenting out the code that embeds the documentation, it has zero calls by itself and doesn't call any other template.

When I do the same thing on the {{Pll }} page, I still have one call to the heavy function and in addition the {{Page language link }}, {{Pagelang }}, {{Translatable }} templates are called , Lua Module:Template translation and call Special:MyLanguage page.

But that's still ok. I wanted to see how many calls the {{Ll }} template would have after the documentation was removed, and I was honestly horrified by them. I didn't expect that the number of calls would rise to 100 and the code would take 1.5 sec to process.

The {{Ll }} template is forgivably stupid. My version of the ll template automatically displays the translated page title if it exists, supports anchors, and also translatable alt descriptions. But it is not applicable to MediaWiki because it uses the Extension:Variables extension.

Okay. There is another solution. The {{Ll }} template does nothing but display the translated page title if it exists, right?

The parameterized template {{Mt }} works with it – for example using this template goto my test subpage languagebar. I want do alternative for {{Ll }} in pure wikicode? Not problem!

I know where the page name is if it is translated. Want an example?

Page name the Template:Main page for czech language is Translations:Template:Main_page/Page_display_title/cs

Just test if it exists and then insert it. As here: Šablona:Main page

But the main page doesn't translate like the other pages. Its name is translated via the system message MediaWiki:mainpage ok. If I know this, I can make a very simple template for the main page:

{{#ifexist:{{ns:1198}}:{{{2}}}/Page_display_title/{{{1}}}
  |[[{{{2}}}/{{{1}}}{{!}}{{:{{ns:1198}}:{{{2}}}/Page_display_title/{{{1}}}}}]]
  |[[Special:MyLanguage/{{{2}}}{{!}}{{{2}}}]]
}}

This example code interpretation, for link to czech translation of the Template:Main_page whereis as second parametrem "cs" [[Template:Main_page/cs|Šablona:Main page]] (Translation name of this template is not allow for translation.)

Sorry I won't be able to respond until Monday - I have to run to the train.

Jdforrester (WMF) (talkcontribs)
BDavis (WMF) (talkcontribs)

I prefer the latter because it doesn’t discriminate casual readers, but recognize that the former also has its advantages.

Is it possible to redirect though Special:MyLanguage and get a hybrid of both approaches? By that I mean could we setup a Main Page here that is #REDIRECT [[Special:MyLanguage/MediaWiki]] so that the default index.php entry point, logo, and wordmark all end up using the MyLanguage translation with fallbacks selection process to choose the real page to display?

Matěj Suchánek (talkcontribs)

You may want to test it but I am pretty sure it isn't. Quick search in Phabricator gave me phab:T164357.

BDavis (WMF) (talkcontribs)

Quick search in Phabricator gave me phab:T164357 The blocker is apparently that Wikimedia project wikis set $wgDisableHardRedirects to true.

Tacsipacsi (talkcontribs)

Setting Main Page to #REDIRECT [[Special:MyLanguage/MediaWiki]] probably doesn’t work, but through phab:T345737 I realized that setting MediaWiki:mainpage to Special:MyLanguage/MediaWiki apparently does, and that also gives best of both worlds.

Want (talkcontribs)

It's a good trick, but is not universally solution for this condition, because every language version mainpage use own translation from translatewiki net.

It be functioned only is message used is '''not''' translatable by translatewiki.net

I use redirect trick it on my multilanguage wiki (default wiki language is czech) . In MediaWiki code is default fallback for pages name 'Main Page' (<code>includes/Title.php</code>) I have redirect from 'Main Page/cs' to 'Hlavní strana' - it's czech translation of the 'MediaWiki:mediawiki' included from translatewiki.net If user call 'Main Page', do system (default) redirect to 'Main Page/cs', and it do redirect to 'Hlavní strana'.

If you want use Special:MyLanguage/MediaWiki, it must be included into every language subpage MediaWiki:mediawiki, by my mind.

I just solved it 10 days ago. Because I want use for Special:SpecialPages unify translatable manual, must was solved problem with a tranlationably target. Default use MediaWiki:Specialpages. But it do problem. I solved it by insert code into MediaWiki:Specialpages-doc and not MediaWiki:Specialpages (translationed by translatewiki.net) If you are interested in the effect of this, check out my SpecialPages page and try switching the interface language to a different. The code refers to the translatable how-to use parameterized links to special pages (not yet finished).

Tacsipacsi (talkcontribs)

It's a good trick, but is not universally solution for this condition, because every language version mainpage use own translation from translatewiki net.

By default, MediaWiki:mainpage is loaded in the content language, because one usually wants to have a single main page, regardless of the current user’s language settings (usually wikis are single-language). This can be overridden using $wgForceUIMsgAsContentMsg, but as far as I see, it’s not overridden on mediawiki.org. (Try clicking on the MediaWiki logo on https://www.mediawiki.org/wiki/Manual:$wgForceUIMsgAsContentMsg/cs?uselang=cs: you get to MediaWiki, not on MediaWiki/cs, which would be set by MediaWiki:Mainpage/cs.)

However, it is overridden for MediaWiki:mw-mainpage-url, which is used in MediaWiki:sidebar. Maybe after the change, the sidebar should be switched to using MediaWiki:mainpage, and MediaWiki:mw-mainpage-url should be removed.

BDavis (WMF) (talkcontribs)

Nice find @Tacsipacsi! I think this means that the pattern used on Meta is what we should try to replicate here.

I think implementing that change might look something like:

  1. Move the current MediaWiki out of the way to something like MediaWiki historic main page. We will want to merge the history of the current main page into the final main page later. Once that is done then I think (please correct me if I'm wrong) we would go ahead and delete the moved current main page.
  2. Move Template:Main page to MediaWiki. Because of the translations involved, there are far too many subpages to move via the UI. We should instead use Help:Extension:Translate/Move translatable page#Moving_a_large_number_of_pages to move via the job queue.
  3. Change MediaWiki:Mainpage to Special:MyLanguage/MediaWiki so that things that target the default main page will link to the version of MediaWiki matching the user's preferred UI language.
  4. Merge the history of MediaWiki historic main page (the moved version of the current [[MediaWiki]]) into the newly moved MediaWiki (the moved version of the current [[:Template:Main page]]) so that browsing the history will start from Special:PermanentLink/2368 (or Special:PermanentLink/1) and proceed until the first edit of Template:Main page.
  5. Delete MediaWiki historic main page to clean things up.

Is my reasoning correct? Is this too weird or scary to try?

Want (talkcontribs)

Is my reasoning correct?

Yes!

Is this too weird or scary to try?

No. The faster the change is made, the less it will hurt. It's my experience. My result: Your proposal it's the only right way. I support it. The current problems (with language bars for example) are caused by the fact that the main page is chasing the {{Zh other }} template, which is created only for Chinese language fallback.

Order points 1. (Move the current MediaWiki out of the way to something like MediaWiki historic main page.) and 2. (Move Template:Main page to MediaWiki) it's right. But watch out!

I have experience with moving translated pages. If a page is translated as before using Extension:Translate, existing language subpages can cause a problem. I made this change in my wiki a long time ago, when weren't that many pages. First, I gradually moved the language subpages to another namespace, and only then did I move the default translated page with translationed subpages to new name.

The point is that the Extension:Translate checks whether the move causes a problem. Maybe today it already allows existing language subpages to be replaced, but I'm not sure.

To point 3 (Change MediaWiki:Mainpage to Special:MyLanguage/MediaWiki)

Thought in links? Or where? In templates? Or in the MediaWiki code?

BDavis (WMF) (talkcontribs)

To point 3 (Change MediaWiki:Mainpage to Special:MyLanguage/MediaWiki)

Thought in links? Or where? In templates? Or in the MediaWiki code?

The change I am proposing is to the MediaWiki:Mainpage message which is used internally by MediaWiki to determine which page to serve when a URL without a page like https://www.mediawiki.org/ is requested and also to set the target page for the site logo and the "Main page" sidebar link. See Manual:Main Page for more information.

The use of Special:MyLanguage in the Mainpage message is what Meta does as @Tacsipacsi reported above.

BDavis (WMF) (talkcontribs)

The point is that the Extension:Translate checks whether the move causes a problem. Maybe today it already allows existing language subpages to be replaced, but I'm not sure.

This is exactly why I suggested using the moveTranslatableBundle.php maintenance script recommended at Help:Extension:Translate/Move translatable page#Moving_a_large_number_of_pages rather than attempting the move via the MediaWiki UI directly. I am almost certain that a normal move will be blocked. If for some reason a normal move is not blocked, I believe it will timeout before actually moving all subpages.

Shirayuki (talkcontribs)

Template:Main page This translatable page consists of over 500 pages. Due to reliability issues, moving translatable pages that consist of more than 500 pages cannot be done through the user interface. Please file a Phabricator task and fill in the fields of the form to request the system administrators to perform the page move on your behalf.

Tacsipacsi (talkcontribs)

The point is that the Extension:Translate checks whether the move causes a problem. Maybe today it already allows existing language subpages to be replaced, but I'm not sure.

This point is about the subpages of the target page. I don’t think Translate got smarter in this regard; if there are pages in the way (and there are about a hundred of them), the move won’t produce the result you want, if succeeds at all. Probably all of these pages have to be moved away (but do make sure not to move non-language subpages like MediaWiki/test) and then merged back. Or not merged: the merge may cause more harm than good; I haven’t checked if the page histories are sufficiently apart. (If histories of two pages are merged that have been edited simultaneously, the result is a huge mess, with irrelevant diffs and IIRC even byte changes in the history not corresponding to the changes shown by the (prev) diff link.)

Want (talkcontribs)

I tryed moving pages on my wiki. Subpages of MediaWiki (Main page) listed by Special:PrefixIndex/MediaWiki/ must be moved by moveBatch.php, because script moveTranslatableBundle.php from Extension:Translate functioned only if the page is translatable.

Must be prepared list for it and the MediaWiki moving realize do as last. I visited all subpages of MediaWiki page with other name then language code:

  • Gallery of extensions - is only redirect
  • Homepage improvements 2018 - is linked from Phabricator and talk pages
  • Homepage redesign - is linked from Phabricator and talk pages
  • intro - redirect from 31.8.2005, which is linked only from two user pages
  • latest - redirect to MediaWiki 1.32 (last edit 14.4.2019)
  • sandbox - invalid link, created October 2023 linked only from two topics

After move pages with languagecode name, can be used script moveTranslatableBundle.php from Extension:Translate which move 'Template:Main page' to 'MediaWiki'.

Count 'Template:Main page' subpages is 1520. It's scary because then translatable page use 22(!) translatable templates:

  1. Template:Main page/admins text
  2. Template:Main page/admins title
  3. Template:Main page/current versions
  4. Template:Main page/devs text
  5. Template:Main page/devs text2
  6. Template:Main page/devs title
  7. Template:Main page/download
  8. Template:Main page/howto contribute link
  9. Template:Main page/include
  10. Template:Main page/intro
  11. Template:Main page/new opportunities
  12. Template:Main page/news title
  13. Template:Main page/old news link
  14. Template:Main page/site news
  15. Template:Main page/sitelink1
  16. Template:Main page/sitelink2
  17. Template:Main page/sitelink3
  18. Template:Main page/sitelink4
  19. Template:Main page/sitelink5
  20. Template:Main page/users text
  21. Template:Main page/users title
  22. Template:Main page/welcome

See Special:PrefixIndex/Template:Main page/ I have only word for it – hegeš. By my mind, is better leaved the Template:Main page and create completly new translatable MediaWiki page.

Want (talkcontribs)

Of course, with the use of existing translatable pages, used as templates now.

Pppery (talkcontribs)

(If this is done, as a monolingual English speaker I'm not qualified to comment on its merits)

The right thing to do with the subpages is probably to use Special:MergeHistory to merge them to the new pages, then delete any edits that don't merge, then do the move. That ensures no harm can be done.

Pppery (talkcontribs)

There are also a bajllion unused templates at Special:PrefixIndex/Template:Main page from an old pre-Translate design of the Main Page. Those should not be moved to mainspace, and probably should just be deleted.

Reply to "Looking for a better language switching solution for MediaWiki (was "Two language bars‬")"