New Script for Translating Wikipedia Links

translatepyWikipedia is treasure trove of free knowledge shared by volunteers. While English Wikipedia is the most known and has the largest number of articles, you may find information in more than 200 different languages. Obviously some topics are covered better in specific languages. For instance, geography of Germany is way better described in German Wikipedia than in English.

Thus, it is often much easier to translate an article from Wikipedia in one language to another than create it from scratch. It can be pretty tedious task nevertheless, because formatting of the wiki code of text may be quite different in different Wikipedias. Under formatting I mean all those templates, categories and conventions for names of files and community-specific rules.

Yet another problem is that nearly any Wikipedia article has plenty of internal links to other articles in the same “source” Wikipedia and when you translate it, you have to replace those links to corresponding internal links in your “target” Wikipedia. For instance, if you want to translate all text in article Density functional theory then you’ll have to find correspondence of 127 internal links.

Sure you do not want to do that by hand. Hence, so-called Content translation function was introduced recently to facilitate this task. Nevertheless, it is still in beta-stage and those who worked with it feel that it still lacks important features. For instance, sometimes you want to translate just a small portion or just want to copy wiki code.

For that purpose I have written a script called translate.py that allows to find automatically corresponding internal links in your target Wikipedia given a file with wiki code from another Wikipedia or given specific arguments to specify what articles you want to translate. It does not do any translations of text beyond internal links.

The script uses tools from Pywikibot project, so you’ll have to install that first to use translate.py. You’ll also have to download another module (generalmodule.py) written by me to re-use its parts in my scripts.

How to use (in the directory, where you installed Pywikibot):

python pwb.py translate [options]

See full help for the first time by using option -help.

The script returns for the first paragraph of the Density functional theory article (from English to Ukrainian using options -fromfile -lang:en -tolang:uk -iwuk):

================================================================================


>>> Text from translate.dat processed <<<
[[en:computational chemistry]] --> [[uk:Обчислювальна хімія]]
[[en:computational physics]] --> {{iw|computational physics||en|computational physics}}
[[en:electronic density]] --> {{iw|electronic density|electron density|en|electronic density}}
[[en:Function (mathematics)]] --> [[uk:Функція (математика)]]
[[en:Functional (mathematics)]] --> [[uk:Функціонал]]
[[en:condensed phase]] --> [[uk:Фізика конденсованих середовищ]]
[[en:Many-body problem]] --> {{iw|Many-body problem|many-body systems|en|Many-body problem}}
[[en:ground state]] --> [[uk:Основний стан квантовомеханічної системи]]
[[en:electronic structure]] --> {{iw|electronic structure||en|electronic structure}}
[[en:materials science]] --> [[uk:Матеріалознавство]]
[[en:chemistry]] --> [[uk:Хімія]]
[[en:physics]] --> [[uk:Фізика]]
[[en:quantum mechanics]] --> [[uk:Квантова механіка]]


--------------------------------------------------------------------------------
'''Density functional theory''' ('''DFT''') is a computational [[Квантова механіка|quantum mechanical]] modelling method used in [[Фізика]], [[Хімія]] and [[Матеріалознавство]] to investigate the {{iw|electronic structure||en|electronic structure}} (principally the [[Основний стан квантовомеханічної системи]]) of {{iw|Many-body problem|many-body systems|en|Many-body problem}}, in particular atoms, molecules, and the [[Фізика конденсованих середовищ]]s. Using  this theory, the properties of a many-electron system can be determined by using [[Функціонал|functionals]], i.e. functions of another [[Функція (математика)|function]], which in this case is the spatially dependent {{iw|electronic density|electron density|en|electronic density}}. Hence the name density functional theory comes from the use of functionals of the electron density. DFT is among the most popular and versatile methods available in condensed-matter physics, {{iw|computational physics||en|computational physics}}, and [[Обчислювальна хімія]].


================================================================================

Now you just have to translate everything else 🙂

If you have any comments or find a bug drop a message here.

Tagged with: , ,

Leave a Reply

Your email address will not be published.