<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GL.IB.LY &#187; moodle 1.9</title>
	<atom:link href="http://gl.ib.ly/tag/moodle-1-9/feed/" rel="self" type="application/rss+xml" />
	<link>http://gl.ib.ly</link>
	<description>Thoughts on security, computing, business and stuff!</description>
	<lastBuildDate>Sun, 18 May 2014 11:51:56 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>Common translation errors in Moodle language packs</title>
		<link>http://gl.ib.ly/stuff/2009/02/06/common-translation-errors-moodle-language-packs/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=common-translation-errors-moodle-language-packs</link>
		<comments>http://gl.ib.ly/stuff/2009/02/06/common-translation-errors-moodle-language-packs/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 06:34:33 +0000</pubDate>
		<dc:creator><![CDATA[tariq]]></dc:creator>
				<category><![CDATA[Stuff]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[language pack]]></category>
		<category><![CDATA[moodle]]></category>
		<category><![CDATA[moodle 1.9]]></category>
		<category><![CDATA[one liners]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://gl.ib.ly/?p=83</guid>
		<description><![CDATA[<p>If you have ever had to deal with language packs you will know how much of a pain they can be. I regularly interact with 9 Moodle language packs and I don&#8217;t like doing that much. For some reason, can&#8217;t<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://gl.ib.ly/stuff/2009/02/06/common-translation-errors-moodle-language-packs/">Read more &#8250;</a></div><!-- end of .read-more --></p><p>The post <a href="http://gl.ib.ly/stuff/2009/02/06/common-translation-errors-moodle-language-packs/">Common translation errors in Moodle language packs</a> appeared first on <a href="http://gl.ib.ly">GL.IB.LY</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><span style="color: #545454;">If you have ever had to deal with language packs you will know how much of a pain they can be. I regularly interact with 9 Moodle language packs and I don&#8217;t like doing that much. For some reason, can&#8217;t remember why now, we gave people the raw language string files (PHP code files) to translate and they translated these files and sent them back. Only these people are not PHP coders and they make mistakes. Here is my list of what goes wrong and how to solve.</span></p>
<div class="serendipity_entry_extended" style="color: #545454;"><a id="extended"></a><br />
*Incorrect syntax*<br />
They edit the files and send them back to us, but they delete a semicolon or something. Check all language pack files with the following shell script.</p>
<div class="geshi"><span style="font-style: italic; color: #666666;">#!/bin/bash</span><br />
<span style="font-weight: bold; color: #000000;">for</span> i <span style="font-weight: bold; color: #000000;">in</span> $<span style="font-weight: bold; color: #7a0874;">(</span> <span style="font-weight: bold; color: #c20cb9;">ls</span> *.php<span style="font-weight: bold; color: #7a0874;">)</span>; <span style="font-weight: bold; color: #000000;">do</span><br />
php -l $i<br />
<span style="font-weight: bold; color: #000000;">done</span></div>
<p>On windows try:</p>
<div class="geshi">@<span style="font-weight: bold; color: #7a0874;">echo</span> off<br />
FOR %%A IN <span style="font-weight: bold; color: #7a0874;">(</span>*.php<span style="font-weight: bold; color: #7a0874;">)</span> DO php -l %%A</div>
<p>*UTF8 Header*<br />
This is prepended to the start of some files by certain editors. As the header comes before the<code>&lt;?PHP</code> tag the header gets output and this will do all sorts of nasty things like corrupting user sessions. The solution is to strip utf headers from all files.</p>
<p>I use a script to add and <a style="color: #7da939;" href="http://gl.ib.ly/uploads/moodle/check.php.txt">strip UTF8 headers</a> from entire directories.</p>
<p>*Translated variable names*<br />
When the translators see something like <code>$a-&gt;name</code> they sometimes translate name. Again this isn&#8217;t easy to find but I use the following line to get malformed variable names.</p>
<div class="geshi"><span style="font-weight: bold; color: #c20cb9;">grep</span> -nroe <span style="color: #ff0000;">&#8220;\$a-&gt;[^ .\&lt;&gt;/';:\!,\?)(]*&#8221;</span> PATH_TO_DIR | <span style="font-weight: bold; color: #c20cb9;">grep</span> -v <span style="color: #ff0000;">&#8220;\$a-&gt;[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*&#8221;</span></div>
<blockquote style="color: #76767a;">
<pre>PATH_TO_DIR/block_class_list.php:14:$a-&gt;
PATH_TO_DIR/block_task_list.php:30:$a-&gt;
PATH_TO_DIR/block_task_list.php:34:$a-&gt;
PATH_TO_DIR/block_task_list.php:34:$a-&gt;ì ëª©</pre>
</blockquote>
<p>This has caught all issues of this kind to date (for me), but it does rely on illegal variable names. A better approach would be to keep a whitelist of variables extracted from a known good language pack. If we find anything that looks like a variable in a another language pack and doesn&#8217;t appear on this list we can throw an error.</p>
<p>*Converting files to UTF-8 format*<br />
Sometimes countries (especially those using accented languages) tend to send us ASCII encoded files, these files will have to be converted to UTF-8 format so that accented characters are display correctly.</p>
<p>Here is a one liner to convert all files in the current directory to UTF-8 format:</p>
<div class="geshi"><span style="font-weight: bold; color: #000000;">for</span> f <span style="font-weight: bold; color: #000000;">in</span> ./*; <span style="font-weight: bold; color: #000000;">do</span> `<span style="font-weight: bold; color: #c20cb9;">mv</span> $f $f<span style="color: #ff0000;">&#8220;.bak&#8221;</span>; iconv &#8211;from-code iso-<span style="color: #000000;">8859</span>-<span style="color: #000000;">1</span> &#8211;to-code UTF-<span style="color: #000000;">8</span> $f<span style="color: #ff0000;">&#8220;.bak&#8221;</span> &gt; $f`;<span style="font-weight: bold; color: #000000;">done</span></div>
<p>If you are happy with changes do a</p>
<div class="geshi"><span style="font-weight: bold; color: #c20cb9;">rm</span> *.bak</div>
<p>See also: <a style="color: #7da939;" title="http://en.wikipedia.org/wiki/ISO_8859-1" href="http://web.archive.org/web/20110212133444/http://gl.ib.ly/exit.php?url_id=78&amp;entry_id=23">ISO 8859-1</a> and <a style="color: #7da939;" title="http://docs.moodle.org/en/Converting_files_to_UTF-8" href="http://web.archive.org/web/20110212133444/http://gl.ib.ly/exit.php?url_id=79&amp;entry_id=23">Converting files to UTF-8</a>.</p>
<p>*Other things which go wrong*<br />
Translators might change <code>$string['mystring'] = 'Hello $a!';</code> to <code>$string['mystring'] = "Hello $a!";</code>. Subtly $a will just not appear in the output as the double quoted string will be evaluated before Moodle can swap $a with some dynamic data. The following one liner catches most errors for me even though it isn&#8217;t complete.</p>
<div class="geshi"><span style="font-weight: bold; color: #c20cb9;">grep</span> -nro <span style="color: #ff0000;">&#8220;= \&#8221;</span><span style="color: #ff0000;">&#8221; PATH_TO_DIR</span></div>
<p>I guess you could lump all that together in one nice big shell script. If you do send me a copy <img class="emoticon" src="http://web.archive.org/web/20110212133444im_/http://gl.ib.ly/templates/default/img/emoticons/wink.png" alt=";-)" /></p>
</div>
<p>The post <a href="http://gl.ib.ly/stuff/2009/02/06/common-translation-errors-moodle-language-packs/">Common translation errors in Moodle language packs</a> appeared first on <a href="http://gl.ib.ly">GL.IB.LY</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gl.ib.ly/stuff/2009/02/06/common-translation-errors-moodle-language-packs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
