Hello all,<br><br>After my last mail, you have of course set up a working rewrite development environment and were wondering how to spread TW integration like a virus through the scripts/ directory. So, how to do it:<br><br>

As you will notice, there is now a i18n/ directory inside the scripts/ directory. This directory contains all files exported from TranslateWiki. The script name defines which TW keys are defined in the file, so i18n/category.py contains category-* (<a href="http://translatewiki.net/wiki/Pywikipedia:Category-was-moved/en">category-was-moved</a>, category-also-in, etc). These are the translations that before were in scripts/category.py.<br>

<br>Adapting scripts to translatewiki consists of four parts:<br>  * Defining TW keys for translations<br>  * Reading in translations and outputting them into the TW format<br>  * Removing translations from script file<br>

  * Adding &#39;from pywikibot import i18n&#39; and adapting all/most pywikibot.translate entries with i18n.twtranslate().<br><br><div><br></div><div><b><u>(1) Defining TW keys</u></b><br>To use isbn.py as an example. There is only one message (only showing german and english):<br>

<blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">msg = {<br></font><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">   &#39;de&#39;: &#39;Bot: Formatiere ISBN&#39;,<div>

   &#39;en&#39;: &#39;Robot: Formatting ISBN&#39;,</div></font><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">}</font></blockquote><div><br></div>For TW, we define this message as <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">isbn-formatting.</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">Sometimes pywikibot.translate is used for site- or language-specific configuration. Don&#39;t move those to translatewiki files (yet).</font><br>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><b><u><font class="Apple-style-span" face="arial, helvetica, sans-serif">(2) Reading in translations and outputting them into the TW format</font></u></b></div>

</div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">Although it is possible to do the isbn example by hand, I&#39;ll use a script that can easily be adapted for a larger number of messages. Don&#39;t forget to </font><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">source bin/activate</font><font class="Apple-style-span" face="arial, helvetica, sans-serif"> your virtualenv!</font></div>

<div><div style="font-family: arial, helvetica, sans-serif; ">The script is available at <span class="Apple-style-span" style="font-family: arial; "><a href="http://pastebin.com/u2XrKt5b">http://pastebin.com/u2XrKt5b</a> (too long to paste in this e-mail)</span></div>

<div style="font-family: arial, helvetica, sans-serif; "><span class="Apple-style-span" style="font-family: arial; "><br></span></div><div>For other scripts, you have to adapt at least lines 2, 6 and 12. Line 12 has a list of tuples (old dict, translatewiki key).</div>

</div><div>If the messages have (one or more) parameters, you should change them to <i>named parameters</i>, so translators can move them around in the message. See lines 15 and 16 for an example of how to do this.</div>
<div>
<br></div><div>Running this script gives you a new file, i18n/isbn.py</div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><b>Test</b> the translation:</font></div>

<div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">(pwbde)/rewrite/scripts$ python</font></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">&gt;&gt;&gt; from pywikibot import i18n</span></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">&gt;&gt;&gt; i18n.twtranslate(&quot;de&quot;, &quot;isbn-formatting&quot;)</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">u&#39;Bot: Formatiere ISBN&#39;</font></div>

<div style="font-family: arial, helvetica, sans-serif; "><br></div></div><div style="font-family: arial, helvetica, sans-serif; ">hurrah!</div><div style="font-family: arial, helvetica, sans-serif; "><br></div><div style="font-family: arial, helvetica, sans-serif; ">

<b><u>(3) Removing translations from the script file</u></b></div><div style="font-family: arial, helvetica, sans-serif; ">Use a sledgehammer, jackhammer or scalpel. Whatever works for you. In the case of isbn.py, lines 49 to 61.</div>

<div style="font-family: arial, helvetica, sans-serif; "><br></div><div style="font-family: arial, helvetica, sans-serif; "><b><u>(4a) Add from pywikibot import i18n</u></b></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">-from pywikibot import pagegenerators</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">+from pywikibot import pagegenerators, i18n</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div>

<div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><b><u>(4b) Adapting all/most pywikibot.translate entries</u></b></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">Search for pywikibot.translate. Change the following:</font></div>

</div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">pywikibot.translate(site, msg) % (param_1, param_2)</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">to</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">i18n.twtranslate(site, &quot;tw-key-for-msg&quot;, {&#39;param_1&#39;: param_1, &#39;param_2&#39;: param_2})</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">With <i>&#39;tw-key-for-msg&#39;</i> referring to the tw key you thought up for <i>msg</i>, and <i>&#39;param_1&#39;</i> and <i>&#39;param_2&#39;</i> (the dictionary keys) referring to the <i>named parameters</i> you introduced in step 2.</font></div>

<div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">For isbn.py, this is simpler:</font></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">-        self.comment = pywikibot.translate(pywikibot.getSite(), msg)</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">+        self.comment = i18n.twtranslate(pywikibot.getSite(), &#39;isbn-formatting&#39;)</font></div></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>

</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><b>Congratulations! </b>You have adapted a script to use translatewiki translations!</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br>

</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">Of course, before committing, <b>test</b> the script:</font></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">(pwb)/rewrite/scripts$ <b>python isbn.py -page:Gebruiker:Valhallasw -to13 -format</b></font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">(...)</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">Page [[Gebruiker:Valhallasw]] saved</font></div><div>

<font class="Apple-style-span" face="arial, helvetica, sans-serif">yielding:</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span class="Apple-style-span" style="font-family: sans-serif; font-size: 13px; line-height: 19px; "><span class="mw-history-histlinks">(huidig | <a href="http://nl.wikipedia.org/w/index.php?title=Gebruiker:Valhallasw&amp;diff=24011412&amp;oldid=24011399" title="Gebruiker:Valhallasw" style="text-decoration: underline; color: rgb(6, 69, 173); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">vorige</a>) </span><input type="radio" value="24011412" name="oldid" id="mw-oldid-null" style="visibility: hidden; "><input type="radio" value="24011412" checked name="diff" id="mw-diff-24011412"> <a href="http://nl.wikipedia.org/w/index.php?title=Gebruiker:Valhallasw&amp;oldid=24011412" title="Gebruiker:Valhallasw" style="text-decoration: underline; color: rgb(6, 69, 173); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">16 jan 2011 14:29</a> <span class="history-user" style="margin-left: 0.4em; margin-right: 0.2em; "><a href="http://nl.wikipedia.org/wiki/Gebruiker:Valhallasw" title="Gebruiker:Valhallasw" class="mw-userlink" style="text-decoration: underline; color: rgb(6, 69, 173); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Valhallasw</a> <span class="mw-usertoollinks">(<a href="http://nl.wikipedia.org/wiki/Overleg_gebruiker:Valhallasw" title="Overleg gebruiker:Valhallasw" style="text-decoration: underline; color: rgb(6, 69, 173); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Overleg</a> | <a href="http://nl.wikipedia.org/wiki/Speciaal:Bijdragen/Valhallasw" title="Speciaal:Bijdragen/Valhallasw" style="text-decoration: underline; color: rgb(6, 69, 173); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">bijdragen</a>)</span></span> <abbr class="minor" title="Dit is een kleine bewerking" style="border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: black; color: black; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; cursor: help; font-weight: bold; background-position: initial initial; background-repeat: initial initial; ">k</abbr> <span class="history-size">(1.735 bytes)</span> <span class="comment" style="font-style: italic; ">(Bot: ISBN opgemaakt)</span> (<span class="mw-history-undo"><a href="http://nl.wikipedia.org/w/index.php?title=Gebruiker:Valhallasw&amp;action=edit&amp;undoafter=24011399&amp;undo=24011412" title="Met &quot;ongedaan maken&quot; draait u deze bewerking terug en komt in het bewerkingsvenster.
U kunt in de bewerkingssamenvatting een reden opgeven." style="text-decoration: underline; color: rgb(6, 69, 173); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">ongedaan maken</a></span>)</span></font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span class="Apple-style-span" style="font-family: sans-serif; font-size: 13px; line-height: 19px; "><br></span></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span class="Apple-style-span" style="font-family: sans-serif; font-size: 13px; line-height: 19px; ">And, as a last step, <b>commit</b> the script (and the translations!) to the svn repository: </span></font><a href="http://www.mediawiki.org/wiki/Special:Code/pywikipedia/8838">http://www.mediawiki.org/wiki/Special:Code/pywikipedia/8838</a></div>

<div><br></div><div>Good luck adapting scripts!</div><div><br></div><div>Best regards,</div><div>Merlijn &#39;valhallasw&#39; van Deen</div><div style="font-family: arial, helvetica, sans-serif; "><br></div></div><div style="font-family: arial, helvetica, sans-serif; ">

<br></div>