HomePhabricator

pywikibot/i18n.py: Rewrite _altlang to use dicts

Tags
None
Referenced Files
None
Subscribers
None

Description

pywikibot/i18n.py: Rewrite _altlang to use dicts

Use two dictionaries to convert input lang to output list. One dict is used
to normalize the language name to a group name, another is used to obtain
the alternatives (fallbacks) for that language group.

It is also possible to use a single dictionary, but that would require
duplicate list values in the dict; which makes maintainance harder and is not
desirable.

This change will help with test coverage (since we are not testing _altlang
for every possible lang group and there is not much benefit in doing so).
It also should improve the runtime performance of the function a little bit.

The dictionaries were generated automatically using the code in P7116.[1]

During the rewrite, two nonsensical cases were eliminated:

'zh-classical' and 'lzh' were used in two different input groups and obviously
only the first one was being used.

[1]: https://phabricator.wikimedia.org/P7116

Change-Id: Idd7fe007b0b5651989f5970aade879a95a44c834

Details

Provenance
DalbaAuthored on May 11 2018, 6:48 AM
Parents
R3347:9d8a208ff087: Remove httpbin and Flask-Common from dev-requirements.txt
Branches
Unknown
Tags
Unknown
ChangeId
Idd7fe007b0b5651989f5970aade879a95a44c834

Event Timeline