jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1094463?usp=email )
Change subject: [IMPR] use page.autoFormat instead of date.getAutoFormat in
titletranslate.py
......................................................................
[IMPR] use page.autoFormat instead of date.getAutoFormat in titletranslate.py
- use page.autoFormat() instead of date.getAutoFormat() in
titletranslate.translate()
- rename local variable x with link for better readability
- use site.getSite() method to get a site with other code
- raise RuntimeError instead of AssertionError if neither page nor site
parameter is given
- hint is usually given as list of literals
Change-Id: I731c667fb74364da65cd9618b57036e951e7bc14
---
M pywikibot/titletranslate.py
1 file changed, 33 insertions(+), 23 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/titletranslate.py b/pywikibot/titletranslate.py
index e349c74..019c73b 100644
--- a/pywikibot/titletranslate.py
+++ b/pywikibot/titletranslate.py
@@ -12,25 +12,37 @@
def translate(
page=None,
- hints=(),
+ hints: list[str] | None = None,
auto: bool = True,
removebrackets: bool = False,
site=None
) -> list[pywikibot.Link]:
"""Return a list of links to pages on other sites based on hints.
- Entries for single page titles list those pages. Page titles for entries
- such as "all:" or "xyz:" or "20:" are first built from the page title of
- 'page' and then listed. When 'removebrackets' is True, a trailing pair of
- brackets and the text between them is removed from the page title.
- If 'auto' is true, known year and date page titles are autotranslated
- to all known target languages and inserted into the list.
- """
- result = set()
+ Entries for single page titles list those pages. Page titles for
+ entries such as "all:" or "xyz:" or "20:" are first built from the
+ page title of 'page' and then listed.
- assert page or site
+ .. versionchanged:: 9.6
+ Raise ``RuntimeError`` instead of ``AssertionError`` if neither
+ *page* nor *site* parameter is given.
+
+ :param auto: If true, known year and date page titles are
+ autotranslated to all known target languages and inserted into
+ the list.
+ :param removebrackets: If True, a trailing pair of brackets and the
+ text between them is removed from the page title.
+ :raises RuntimeError: Either page or site parameter must be given.
+ """
+ if not page and not site:
+ raise RuntimeError(
+ 'Either page or site parameter must be given with translate()')
site = site or page.site
+ result = set()
+
+ if hints is None:
+ hints = []
for h in hints:
# argument may be given as -hint:xy where xy is a language code
@@ -54,10 +66,10 @@
if newcode in site.languages():
if newcode != site.code:
ns = page.namespace() if page else 0
- x = pywikibot.Link(newname,
- site.getSite(code=newcode),
- default_namespace=ns)
- result.add(x)
+ link = pywikibot.Link(newname,
+ site.getSite(code=newcode),
+ default_namespace=ns)
+ result.add(link)
elif config.verbose_output:
pywikibot.info(f'Ignoring unknown language code {newcode}')
@@ -65,19 +77,17 @@
# existing interwiki links.
if auto and page:
# search inside all dictionaries for this link
- sitelang = page.site.lang
- dict_name, value = date.getAutoFormat(sitelang, page.title())
+ dict_name, value = page.autoFormat()
if dict_name:
pywikibot.info(f'TitleTranslate: {page.title()} was recognized as '
f'{dict_name} with value {value}')
for entry_lang, entry in date.formats[dict_name].items():
if entry_lang not in site.languages():
continue
- if entry_lang != sitelang:
- newname = entry(value)
- x = pywikibot.Link(
- newname,
- pywikibot.Site(code=entry_lang,
- fam=site.family))
- result.add(x)
+
+ if entry_lang != page.site.lang:
+ link = pywikibot.Link(entry(value),
+ site.getSite(entry_lang))
+ result.add(link)
+
return list(result)
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1094463?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I731c667fb74364da65cd9618b57036e951e7bc14
Gerrit-Change-Number: 1094463
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]