Page MenuHomePhabricator

zh falls back to zh-hans, why?
Closed, ResolvedPublic

Description

Recently I'm working on a MediaWiki site with ULS and Translate extensions installed. The default content language of the site is en. I created a page in English, let's say, with the title Project:About. Then I translated the page into zh, with the hope that the language variant converter will do its own job. It works out well.

However, there is one thing that still bugs me. If I use MyLanguage redirect in the wikilink, i.e. Special:MyLanguage/Project:About, it will take me either to en or zh subpage, depending on my UI language. My current language setting is zh-cn, so I guess it would ultimately fallback to zh (esp. when I've taken a look at T50292). But I was kept taken to the English page.

After an investigation on File:MediaWiki_fallback_chains.svg, I surprisingly found that zh falls back to zh-hans, instead of the other way around, and the fallback chain is

  • zh-CN -> zh-Hans -> en
  • zh -> zh-Hans -> en

I'm not sure, but I guess that the reason why MW takes zh -> zh-hans fallback chain is that the translations of the MediaWiki software are either zh-hans, zh-hant (or zh-xxxx), but never zh alone. By taking this fallback, those who choose zh as their UI language will effectively see the UI in zh-hans. However, zh is a macro language, and IMO it should never be an option of UI language (I'm not talking about content language, which supports variant conversions).

So back to my problem, I'm just wondering if there is something I can do to fix this. Do I need to patch my MediaWiki code locally? And out of curiosity, why should zh falls back to zh-hans?

Event Timeline

My guess is because in CLDR, the Simplified content are just using zh instead of zh_hans

My guess is because in CLDR, the Simplified content are just using zh instead of zh_hans

Thanks for your explanation. But while CLDR distinguishes between zh_hans and zh_hant, there seems no dedicated zh localized data. see the file tree here https://github.com/wikimedia/mediawiki-extensions-cldr/tree/master/CldrNames

I ended up simply changed the fallback order, i.e. the values of $fallback variables

  • In /languages/messages/MessagesZh_cn.php from "zh-hans" to "zh-hans, zh"
  • In /languages/messages/MessagesZh_tw.php from "zh-hant, zh-hans" to "zh-hant, zh-hans, zh"
  • and so on

And I've removed the $fallback variable in /languages/messages/MessagesZh.php, so that it would directly falls back to en

Now the Special:MyLanguage redirect works the same as my expectation. There is only one side effect, though, that users whose UILanguage is exactly zh will see English UI, but I think it's okay for me. Perhaps I will need to keep on patching the files each time after a version update now.

Winston_Sung changed the task status from Open to In Progress.Dec 25 2021, 9:50 AM
Winston_Sung claimed this task.

Change 703560 had a related patch set uploaded (by Winston Sung; author: Winston Sung):

[mediawiki/core@master] Rearrange zh/zh-* fallbacks, translations, aliases in mediawiki/core

https://gerrit.wikimedia.org/r/703560

Change 788416 had a related patch set uploaded (by Winston Sung; author: Winston Sung):

[mediawiki/core@wmf/1.39.0-wmf.10] Rearrange zh-related fallbacks and zh/zh-* translations, aliases in mediawiki/core

https://gerrit.wikimedia.org/r/788416

Change 788606 had a related patch set uploaded (by Winston Sung; author: Winston Sung):

[mediawiki/core@wmf/1.39.0-wmf.9] Rearrange zh-related fallbacks and zh/zh-* translations, aliases in mediawiki/core

https://gerrit.wikimedia.org/r/788606

Change 788606 abandoned by Winston Sung:

[mediawiki/core@wmf/1.39.0-wmf.9] Rearrange zh-related fallbacks and zh/zh-* translations, aliases in mediawiki/core

Reason:

https://gerrit.wikimedia.org/r/788606

Change 788416 abandoned by Winston Sung:

[mediawiki/core@wmf/1.39.0-wmf.10] Rearrange zh-related fallbacks and zh/zh-* translations, aliases in mediawiki/core

Reason:

https://gerrit.wikimedia.org/r/788416

Change 788416 restored by Winston Sung:

[mediawiki/core@wmf/1.39.0-wmf.10] Rearrange zh-related fallbacks and zh/zh-* translations, aliases in mediawiki/core

https://gerrit.wikimedia.org/r/788416

Change 788606 restored by Winston Sung:

[mediawiki/core@wmf/1.39.0-wmf.9] Rearrange zh-related fallbacks and zh/zh-* translations, aliases in mediawiki/core

https://gerrit.wikimedia.org/r/788606

Winston_Sung removed a project: Patch-For-Review.

Fixed within:

[mediawiki/core@master] Rearrange zh-related language fallback chain

https://gerrit.wikimedia.org/r/703560