Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/639151 )
Change subject: [bugfix] Fix TypeError in i18n.translate ......................................................................
[bugfix] Fix TypeError in i18n.translate
Change-Id: Ia3b68f9fc5e99a19c33c0555a45631a18b0c43d8 --- M pywikibot/i18n.py 1 file changed, 6 insertions(+), 6 deletions(-)
Approvals: jenkins-bot: Verified Xqt: Looks good to me, approved
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py index 682c1d9..359fc96 100644 --- a/pywikibot/i18n.py +++ b/pywikibot/i18n.py @@ -29,7 +29,7 @@ from collections import defaultdict from contextlib import suppress from textwrap import fill -from typing import Optional +from typing import Optional, Union from warnings import warn
import pywikibot @@ -545,7 +545,10 @@ DEFAULT_FALLBACK = ('_default', )
-def translate(code, xdict, parameters=None, fallback=False): +def translate(code, + xdict: Union[dict, str], + parameters: Union[dict, str, int, None] = None, + fallback=False) -> str: """Return the most appropriate localization from a localization dict.
Given a site code and a dictionary, returns the dictionary's value for @@ -569,14 +572,11 @@ dictionary with family names as keys containing code dictionaries or a single string. May contain PLURAL tags as described in twtranslate - @type xdict: dict, string, unicode @param parameters: For passing (plural) parameters - @type parameters: dict, string, unicode, int @param fallback: Try an alternate language code. If it's iterable it'll also try those entries and choose the first match. @type fallback: boolean or iterable @return: the localized string - @rtype: str @raise IndexError: If the language supports and requires more plurals than defined for the given PLURAL pattern. @raise KeyError: No fallback key found if fallback is not False @@ -589,7 +589,7 @@
try: lookup = xdict[code] - except KeyError: + except (KeyError, TypeError): # Check whether xdict has multiple projects if isinstance(xdict, dict) and family in xdict: lookup = xdict[family]
pywikibot-commits@lists.wikimedia.org