"""Title translate module."""## (C) Pywikibot team, 2003-2024## Distributed under the terms of the MIT license.#from__future__importannotationsimportpywikibotfrompywikibotimportconfig,date
[docs]deftranslate(page=None,hints=(),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()assertpageorsitesite=siteorpage.siteforhinhints:# argument may be given as -hint:xy where xy is a language codecodes,_,newname=h.partition(':')ifnotnewname:# if given as -hint:xy or -hint:xy:, assume that there should# be a page in language xy with the same title as the page# we're currently working on ...ifpageisNone:continuenewname=page.title(with_ns=False,without_brackets=removebrackets)ifcodes.isdigit():codes=site.family.languages_by_size[:int(codes)]elifcodes=='all':codes=list(site.family.codes)else:codes=site.family.language_groups.get(codes,codes.split(','))fornewcodeincodes:ifnewcodeinsite.languages():ifnewcode!=site.code:ns=page.namespace()ifpageelse0x=pywikibot.Link(newname,site.getSite(code=newcode),default_namespace=ns)result.add(x)elifconfig.verbose_output:pywikibot.info(f'Ignoring unknown language code {newcode}')# Autotranslate dates into all other languages, the rest will come from# existing interwiki links.ifautoandpage:# search inside all dictionaries for this linksitelang=page.site.langdict_name,value=date.getAutoFormat(sitelang,page.title())ifdict_name:pywikibot.info('TitleTranslate: {} was recognized as {} with value {}'.format(page.title(),dict_name,value))forentry_lang,entryindate.formats[dict_name].items():ifentry_langnotinsite.languages():continueifentry_lang!=sitelang:newname=entry(value)x=pywikibot.Link(newname,pywikibot.Site(code=entry_lang,fam=site.family))result.add(x)returnlist(result)