Page MenuHomePhabricator

How to translate MediaWiki Magic words with Pywikibot?
Closed, InvalidPublic

Description

I have a simple question: I would like to write a multilingual bot script to localise Magic words like:

{{DEFAULTSORT: => {{AAKKOSTUS: {{CLEDETRI: {{DEFAŬLTORDIGO: {{ORDENA: {{SORTIERUNG: {{SORTUJ: etc.

What algorithm could I use to translate a Magic word in the local language of a Wikipedia?

Event Timeline

You can use Site.getmagicwords() to get magic words for translation:

>>> import pywikibot
>>> site = pywikibot.Site('de')
>>> words = site.getmagicwords('defaultsort')
['SORTIERUNG:', 'DEFAULTSORT:', 'DEFAULTSORTKEY:', 'DEFAULTCATEGORYSORT:']

An example can be found in cosmetic_changes.CosmeticChangesToolkit.translateMagicWords() which replaces magic words inside File links.

@Geertivp: Anything left to do here?