Ensure LanguageCode::bcp47() returns a valid BCP 47 language code
authorC. Scott Ananian <cscott@cscott.net>
Tue, 26 Jun 2018 20:39:57 +0000 (16:39 -0400)
committerC. Scott Ananian <cscott@cscott.net>
Thu, 11 Oct 2018 05:53:54 +0000 (01:53 -0400)
commit21ead7a98d1a103b77f1e3ba29a85493782d398b
tree2db794517bc11c71a3c65b5cdf20c5b5b109eca9
parent079a0c4caac91f2ca908a8127b37d377643fc7dc
Ensure LanguageCode::bcp47() returns a valid BCP 47 language code

MediaWiki uses a number of nonstandard codes which do not validate
according to the IANA language subtag registry.  Some of them have
the wrong semantics entirely: MediaWiki's `sr-ec` variant maps to
BCP 47 `sr-EC` which is "Serbian as used in Ethiopia" (!).

Extend LanguageCode::bcp47() to map our nonstandard codes to valid
BCP 47 language codes.  Export the mapping so that it can be used
in JavaScript's corresponding mw.language.bcp47() implementation
as well, and return the standard BCP 47 codes in the siteinfo
API.

Thanks to TheDJ (I10b4473c7e53f027812bbccf26bb47aec15fddfd) and
Fomafix (I93efc190714ba76247d30ba49fc21ae872fc3555) for previous
attempts at this!

Also removed a fixme for the name of 'Twi', dating back to 2004
(f59c3be23b209e178a917cb14ebedcc243c847b6) -- checking
tw.wikipedia.org it certainly appears that the autonym of 'Twi'
is correctly 'Twi'.

Tracking bugs for invalid language codes are T125073 and T145535.
Discussion of zh-XX => zh-HanX-XX mapping is at T198419.

This is a replay of an earlier merged patch,
8380f0173e79b66f0e2afd6c49cd88afb9f4f6f3, which had to be reverted
because it caused regressions in the Babel extension (T199941).

Bug: T34483
Bug: T106367
Bug: T120847
Depends-On: I27a5b8e45b34c6b57c1b612b11548001c88cd483
Change-Id: Iebbc604af21d7f2af9c1f1ab2574cb5f309bf6ed
RELEASE-NOTES-1.32
includes/api/ApiQuerySiteinfo.php
includes/resourceloader/ResourceLoaderLanguageDataModule.php
languages/LanguageCode.php
languages/data/Names.php
languages/i18n/qqq.json
resources/src/mediawiki.language/mediawiki.language.init.js
resources/src/mediawiki.language/mediawiki.language.js
tests/phpunit/includes/api/ApiQuerySiteinfoTest.php
tests/phpunit/languages/LanguageCodeTest.php
tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js