<?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>meier-online &#187; Programming</title>
	<atom:link href="http://meier-online.com/en/category/develop/feed/" rel="self" type="application/rss+xml" />
	<link>http://meier-online.com</link>
	<description>Der Blog von Karsten Meier</description>
	<lastBuildDate>Thu, 19 Aug 2010 23:37:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Multilingual Websites with Ruby on Rails (3)</title>
		<link>http://meier-online.com/en/2010/01/mehrsprachige-webseiten-mit-ruby-on-rails-3/</link>
		<comments>http://meier-online.com/en/2010/01/mehrsprachige-webseiten-mit-ruby-on-rails-3/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 10:02:16 +0000</pubDate>
		<dc:creator>meier</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[multilingualism]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://meier-online.com/?p=656</guid>
		<description><![CDATA[Part 3 &#8211; Quality Assurence
Texte gehören zu den Teilen einer Anwendung, die häufig geändert werden. Wenn dann noch externe Übersetzer im Spiel sind, kann es leicht zu fehlenden Übersetzungen kommen
Wir möchten deshalb automatisch testen, dass es zu allen Texten in Sprache A auch Übersetzungen in Sprache B vorhanden sind. Ein solcher Test allein hilft schon [...]]]></description>
			<content:encoded><![CDATA[<p>Part 3 &#8211; Quality Assurence</p>
<p>Texte gehören zu den Teilen einer Anwendung, die häufig geändert werden. Wenn dann noch externe Übersetzer im Spiel sind, kann es leicht zu fehlenden Übersetzungen kommen</p>
<p>Wir möchten deshalb automatisch testen, dass es zu allen Texten in Sprache A auch Übersetzungen in Sprache B vorhanden sind. Ein solcher Test allein hilft schon sehr, und sollte ja nicht so schwierig sein.</p>
<p>Leider gibt es dabei eine Überraschung: in der Internationalisierung-API findet sich zur Zeit (Rails 2.3.5) keine Möglichkeit, alle Schlüssel aufzuzählen (sprich iterieren). Man muss also offenbar die Yaml-Dateien selbst einlesen, um an alle Schlüssel zu kommen. Unserer Test ist dabei leider abhängig von der konkreten Art der Datenhaltung.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">texts_hash = <span style="color:#CC00FF; font-weight:bold;">YAML</span>::<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'config/locales/de.yml'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Wie haben nun einen rekursiven Hash. Um alle Schlüssel zu überprüfen, extrahieren wie sie mit einer gesonderten Funktion. Diese Funktion ist einfach rekursiv aufgebaut.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> deep_hash_key<span style="color:#006600; font-weight:bold;">&#40;</span>hash, prefix<span style="color:#006600; font-weight:bold;">&#41;</span>
  hash.<span style="color:#9900CC;">keys</span>.<span style="color:#9900CC;">sort</span>.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>key2<span style="color:#006600; font-weight:bold;">|</span>
    val = hash<span style="color:#006600; font-weight:bold;">&#91;</span>key2<span style="color:#006600; font-weight:bold;">&#93;</span>
    newprefix = prefix.<span style="color:#0000FF; font-weight:bold;">nil</span>? ? key2 : <span style="color:#996600;">&quot;#{prefix}.#{key2}&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> val.<span style="color:#9900CC;">is_a</span>? <span style="color:#CC00FF; font-weight:bold;">Hash</span>
     deep_hash_key<span style="color:#006600; font-weight:bold;">&#40;</span>val, newprefix<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      newprefix
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Wollen wir jetzt die Übersetzungen für alle Schlüssel prüfen lauert die Zweite Falle: Wenn die Übersetzung eine Variableninterpolation enthält, erhalten wir einen Fehler beim Aufrufen der translate() Methode ohne den passenden Hash. Offenbar liefert uns die API auch keinen Zugriff auf den String ohne Interpolierung. Da uns in diesen Test nur die Existenz einer Übersetzung interessiert, und nicht ihr konkreter Wert, fangen wir die Exception &#8220;MissingInterpolationArgument&#8221; einfach auf.</p>
<p>Für eine deutsche Anwendung mit Übersetzungen in Englisch und Französisch sieht dann der Test so aus:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> test_all_texts_should_exists
  texts_hash = <span style="color:#CC00FF; font-weight:bold;">YAML</span>::<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'config/locales/de.yml'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  de_keys = deep_hash_key<span style="color:#006600; font-weight:bold;">&#40;</span>texts_hash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'de'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">flatten</span>
  <span style="color:#9966CC; font-weight:bold;">for</span> lang <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'de'</span>, <span style="color:#996600;">'fr'</span>, <span style="color:#996600;">'en'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    I18n::locale = lang
    <span style="color:#9966CC; font-weight:bold;">for</span> key <span style="color:#9966CC; font-weight:bold;">in</span> de_keys
      <span style="color:#9966CC; font-weight:bold;">begin</span>
        val = I18n.<span style="color:#9900CC;">translate</span><span style="color:#006600; font-weight:bold;">&#40;</span>key, <span style="color:#ff3333; font-weight:bold;">:default</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#ff3333; font-weight:bold;">:raise</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">I18n::MissingTranslationData</span>
        val = <span style="color:#0000FF; font-weight:bold;">nil</span>
      <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">I18n::MissingInterpolationArgument</span>
        val = <span style="color:#0000FF; font-weight:bold;">true</span>  <span style="color:#008000; font-style:italic;"># there was a value, only an argument is missing</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      assert_not_nil<span style="color:#006600; font-weight:bold;">&#40;</span>val, <span style="color:#996600;">&quot;key missing for locale #{lang}: #{key}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Wenn jetzt eine Übersetzung fehlt, liefert der Test eine Fehlermeldung der Art:</p>
<pre>
test_all_texts_should_exists(LocalisationTest): key missing for locale en: users.edit.title</pre>
<p>Die fehlende Übersetzung können wir dann ergänzen, bevor wir eine neue Version der Anwendung veröffentlichen.</p>
]]></content:encoded>
			<wfw:commentRss>http://meier-online.com/en/2010/01/mehrsprachige-webseiten-mit-ruby-on-rails-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Deutsch) Classics reloaded: Das Assert-Makro von C</title>
		<link>http://meier-online.com/en/2009/09/assert/</link>
		<comments>http://meier-online.com/en/2009/09/assert/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 14:41:43 +0000</pubDate>
		<dc:creator>meier</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Assert]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[quality assurance]]></category>

		<guid isPermaLink="false">http://meier-online.com/?p=618</guid>
		<description><![CDATA[Sorry, this entry is only available in Deutsch.
]]></description>
			<content:encoded><![CDATA[<p>Sorry, this entry is only available in <a href="http://meier-online.com/category/develop/feed/">Deutsch</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://meier-online.com/en/2009/09/assert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Deutsch) Rotierende Reklametafel mit jQuery</title>
		<link>http://meier-online.com/en/2009/08/rolling-billboard-jquery/</link>
		<comments>http://meier-online.com/en/2009/08/rolling-billboard-jquery/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 17:15:05 +0000</pubDate>
		<dc:creator>meier</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Reklametafel]]></category>

		<guid isPermaLink="false">http://meier-online.com/?p=584</guid>
		<description><![CDATA[Sorry, this entry is only available in Deutsch.
]]></description>
			<content:encoded><![CDATA[<p>Sorry, this entry is only available in <a href="http://meier-online.com/category/develop/feed/">Deutsch</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://meier-online.com/en/2009/08/rolling-billboard-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multilingual Websites with Ruby on Rails (2)</title>
		<link>http://meier-online.com/en/2009/05/localize-ruby-on-rails-p2/</link>
		<comments>http://meier-online.com/en/2009/05/localize-ruby-on-rails-p2/#comments</comments>
		<pubDate>Tue, 12 May 2009 13:51:47 +0000</pubDate>
		<dc:creator>meier</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[multilingualism]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Validations]]></category>

		<guid isPermaLink="false">http://meier-online.com/?p=422</guid>
		<description><![CDATA[Part 2 &#8211; Variables, Validations, Model Classes
Web pages often contains sentences in which a single word is changing. For example, &#8220;You are logged in as xxxx.&#8221; For the translation, we can obviously assemble the sentence from the components. There is often a problem, because the word order is different in different languages .
Better is the [...]]]></description>
			<content:encoded><![CDATA[<h3>Part 2 &#8211; Variables, Validations, Model Classes</h3>
<p>Web pages often contains sentences in which a single word is changing. For example, &#8220;You are logged in as xxxx.&#8221; For the translation, we can obviously assemble the sentence from the components. There is often a problem, because the word order is different in different languages .</p>
<p>Better is the so-called interpolation, as Ruby itself also offers. The string contains a marked variable, which will be replaced at run time. The Yaml file specification does not use the Ruby syntax. Instead, you mark the variable with double curly brackets.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Definition</span>
  logmsg: <span style="color:#996600;">&quot;You are logged in as {{name}}.&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># call</span>
I18n.<span style="color:#9900CC;">translate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:logmsg</span>, <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Administrator'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;"># or short form</span>
t <span style="color:#ff3333; font-weight:bold;">:logmsg</span>, <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Administrator'</span></pre></div></div>

<p><span id="more-422"></span>We need to make sure that the parameters of the definition and the call are matching. The translate ()-method is relatively tolerant: Superfluous parameters are ignored.</p>
<p> <img src='http://meier-online.com/blog/wp-includes/images/smilies/icon_exclaim.gif' alt=':!:' class='wp-smiley' />  Attention: the person who translates must know that the variable names in the brackets must not be translated.</p>
<p>Another small trap lurks in the variable names: They may not have the names one of the other parameters of the translate () method. Not allowed are therefore &#8220;default&#8221; and &#8220;scope&#8221;.</p>
<h3>Texts of Validations</h3>
<p>Even if our application is monolingual in another language than English, we get surprised in one area: The automatically generated error messages from the validation of the model classes. Very convenient, but unfortunately only in English.</p>
<p>Also, the messages contains the class name and attribute name from the ruby code directly. Classes and attribute names are chosen to serve the needs of the programmers. For users, other words are sometimes more appropriate.</p>
<p>You see the composition of such an error message in this picture:</p>
<p><img class="alignnone size-full wp-image-444" title="Composion of the translation of an error message from the model validation in Rails" src="http://meier-online.com/blog/uploads/rails-fehlermeldungen-ersetzung400.png" alt="Composion of the translation of an error message from the model validation in Rails" width="420" height="212" /></p>
<p>To display the validation message with texts in our local language, we need only the translations with the right keys in our translation Yaml file. The template sentences are defined in the area (scope) activerecord.messages. Since these are are equal for all applications, there exists already standard translations for many languages.</p>
<h3>Model Translation</h3>
<p>We define the names of the fields and objects in the Yaml file with the key activerecord.models.classname or activerecord.attributs.classname.attributname. Rails recognizes these keys and uses the translations correctly in the automatic validation notifications.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">activerecord:
  models:
    term: &quot;Begriff&quot;
  attributes:
    term:
      name: &quot;Name&quot;
      topic: &quot;Sachgebiet&quot;</pre></div></div>

<p>The central translation of class names and field names is also useful for the views. So we don&#8217; t need to translate the the labels of input fields a second or third time.</p>
<p>For the view this does not always make sense. The user interface should not stick too narrow to the model. The important thing is the user.</p>
<h3>Validations with own Messages</h3>
<p>A typical use for a specific message is to check of a phone number. The methods for the specification of the validations have a parameter &#8220;message&#8221;.</p>
<p>So the translation should be no problem: we should just call t ()-method, right? Unfortunately it is not that easy:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># funktioniert so nicht! Does not work!</span>
validates_format_of<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:fax</span>,<span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:with</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>\A<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span> \<span style="color:#006600; font-weight:bold;">+</span>\<span style="color:#006600; font-weight:bold;">-</span>\<span style="color:#006600; font-weight:bold;">/</span>\<span style="color:#006600; font-weight:bold;">&#40;</span>\<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span>\Z<span style="color:#006600; font-weight:bold;">/</span>i,
    <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'activerecord.errors.messages.bad_phone'</span><span style="color:#006600; font-weight:bold;">&#41;</span>,
    <span style="color:#ff3333; font-weight:bold;">:allow_blank</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Depending on the version and the deployment, Rails either did not even start or it does not delivers the required translation. What&#8217;s wrong?</p>
<p>The language is set for each request of the web user. But the declarative validations are defined as part of the model class, there is no request at this time! It therefore makes no sense to call a translate method in this stage.</p>
<p>But how do we solve this problem? Typical of Rails, the solution is already built in. But if you don&#8217;t  know, you can go in round circles.</p>
<p>We can put a symbol rather than a string as the message parameter. Now the symbol will be evaluated at the time when the error message will be displayed.</p>
<p>The symbol gets evaluated in these specific contexts (scope) one after another:</p>
<ul>
<li>activerecord.errors.models.[model_name].attributes.[attribute_name]</li>
<li>activerecord.errors.models.[model_name]</li>
<li>activerecord.errors.messages</li>
</ul>
<p>Therefore we can simply write our validation like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">validates_format_of<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:fax</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>
     <span style="color:#ff3333; font-weight:bold;">:with</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>\A<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span>\<span style="color:#006600; font-weight:bold;">+</span>\<span style="color:#006600; font-weight:bold;">-</span>\<span style="color:#006600; font-weight:bold;">/</span>\<span style="color:#006600; font-weight:bold;">&#40;</span>\<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span>\Z<span style="color:#006600; font-weight:bold;">/</span>i,
     <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:bad_phone</span>,
     <span style="color:#ff3333; font-weight:bold;">:allow_blank</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<h4>Sources:</h4>
<p>Description (Guide) of the Internationalization API: <a title="Official guide of the ruby on rails internationalization api" href="guides.rubyonrails.org/i18n.html" target="_blank">guides.rubyonrails.org/i18n.html</a></p>
<p>Language files for standard translations: <a title="default translation file for many languages" href="http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale" target="_self">github.com/svenfuchs/rails-i18n/rails/locale</a></p>
]]></content:encoded>
			<wfw:commentRss>http://meier-online.com/en/2009/05/localize-ruby-on-rails-p2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL: Set a Field from a linked Table</title>
		<link>http://meier-online.com/en/2009/05/sql-update-join/</link>
		<comments>http://meier-online.com/en/2009/05/sql-update-join/#comments</comments>
		<pubDate>Mon, 04 May 2009 13:01:28 +0000</pubDate>
		<dc:creator>meier</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[join]]></category>
		<category><![CDATA[Joomla]]></category>
		<category><![CDATA[Sql]]></category>

		<guid isPermaLink="false">http://meier-online.com/?p=400</guid>
		<description><![CDATA[A little hack for the Joomla Community Builder
Recently, I received a job request. An existing web application will be greatly expanded, and therfore converted to use the CMS &#8220;Joomla&#8221;. For the management of  members  the extension &#8220;Community Builder&#8221; will be used.
Previously, users had a number as login name. This number should now be available [...]]]></description>
			<content:encoded><![CDATA[<h3>A little hack for the Joomla Community Builder</h3>
<p>Recently, I received a job request. An existing web application will be greatly expanded, and therfore converted to use the CMS &#8220;Joomla&#8221;. For the management of  members  the extension &#8220;Community Builder&#8221; will be used.<br />
Previously, users had a number as login name. This number should now be available in a field &#8220;member number&#8221; (german: mitgliedsnummer), and the numbers from existing users should be transferred. So much for the request from a customer perspective. <span id="more-400"></span></p>
<h3>Analysis</h3>
<p>Joomla manages the users in a table jos_user. The &#8220;community builder&#8221; allows to add additonal fields to the user record. The fields are placed in the separate table &#8220;jos_profiler&#8221;. These records are linked with the ID of the user. In this way, the Community Builder does not need to change the table of the Joomla core. However, fiddling with the two tables is technically more complex and error-prone.</p>
<p><img class="alignnone size-full wp-image-406" title="Description of the problem: the content of a field should be copied from one table to another table" src="http://meier-online.com/blog/uploads/update-joined-table.png" alt="Description of the problem: the content of a field should be copied from one table to another table" width="380" height="200" /></p>
<p>The requirement is therefore: For all <em>jos_user</em> records with a number in the field <em>username</em> , put this number in the field member_number of the corresponding member record in the table jos_profiler.</p>
<h3>Is it possible with SQL?</h3>
<p>You can surely make a small PHP program to solve the problem . But if we can do it just with a SQL command, it is much easier. This was the reason for me to  inspect the documentation for MySQL.</p>
<p>Fortunately, the MySQL database can use regular expressions. So you can retrieve all user names that consist only of digits with this statement:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> username <span style="color: #993333; font-weight: bold;">FROM</span> jos_users <span style="color: #993333; font-weight: bold;">WHERE</span> username <span style="color: #993333; font-weight: bold;">REGEXP</span> <span style="color: #ff0000;">'^[0-9]+$'</span></pre></div></div>

<h3>Linking two tables</h3>
<p style="margin-bottom: 0cm;">The link between two database tables is also called a &#8220;join&#8221;, in our case a &#8220;inner equijoin&#8221;.<br />
To show the username field and the membership number at the same time, we use:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> jos_users<span style="color: #66cc66;">.</span>username<span style="color: #66cc66;">,</span> jos_comprofiler<span style="color: #66cc66;">.</span>cb_mitgliedsnummer
<span style="color: #993333; font-weight: bold;">FROM</span> jos_comprofiler<span style="color: #66cc66;">,</span> jos_users
<span style="color: #993333; font-weight: bold;">WHERE</span> jos_comprofiler<span style="color: #66cc66;">.</span>user_id <span style="color: #66cc66;">=</span> jos_users<span style="color: #66cc66;">.</span>id</pre></div></div>

<p>This statement will also helps us to check whether everything is set correctly</p>
<h3>Setting data</h3>
<p>As a final step remains: set  the field of one record with the contents of  the connected record of the other table. Fortunately, the above two techniques are also working in the SQL UPDATE command.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> jos_comprofiler<span style="color: #66cc66;">,</span> jos_users
<span style="color: #993333; font-weight: bold;">SET</span> jos_comprofiler<span style="color: #66cc66;">.</span>cb_mitgliedsnummer <span style="color: #66cc66;">=</span> jos_users<span style="color: #66cc66;">.</span>username
<span style="color: #993333; font-weight: bold;">WHERE</span> jos_comprofiler<span style="color: #66cc66;">.</span>user_id <span style="color: #66cc66;">=</span> jos_users<span style="color: #66cc66;">.</span>id
  <span style="color: #993333; font-weight: bold;">AND</span> jos_users<span style="color: #66cc66;">.</span>username <span style="color: #993333; font-weight: bold;">REGEXP</span> <span style="color: #ff0000;">'^[0-9]+$'</span></pre></div></div>

<p>With a single SQL command, the customer problem is solved. The magic that makes this possible is the mathematical foundation of SQL, the relational algebra.</p>
]]></content:encoded>
			<wfw:commentRss>http://meier-online.com/en/2009/05/sql-update-join/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Multilingual Websites with Ruby on Rails</title>
		<link>http://meier-online.com/en/2009/04/localize-ruby-on-rails/</link>
		<comments>http://meier-online.com/en/2009/04/localize-ruby-on-rails/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 21:09:44 +0000</pubDate>
		<dc:creator>meier</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[multilingualism]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Translation]]></category>

		<guid isPermaLink="false">http://meier-online.com/?p=370</guid>
		<description><![CDATA[Part 1 &#8211; Overview
Writing software for several languages is an ever recurrent challenge. Ruby on Rails provides  solutions to most of the standard problems in web development. But it needed time until the version 2.2. for the &#8220;Internationalization API &#8221; to become an official part of Ruby on Rails. .


Structure of the framework
The framework [...]]]></description>
			<content:encoded><![CDATA[<h3>Part 1 &#8211; Overview</h3>
<p>Writing software for several languages is an ever recurrent challenge. Ruby on Rails provides  solutions to most of the standard problems in web development. But it needed time until the version 2.2. for the &#8220;Internationalization API &#8221; to become an official part of Ruby on Rails. .</p>
<p><img class="alignnone size-full wp-image-374" title="The Ruby-On-Rails Internationalization module" src="http://meier-online.com/blog/uploads/rails-i18n.png" alt="The Ruby-On-Rails Internationalization module" width="480" height="300" /></p>
<p><span id="more-370"></span></p>
<h3>Structure of the framework</h3>
<p>The framework consists of a &#8220;public&#8221; and a &#8220;private&#8221; part. The I18N module forms the public part with the methods that we call in our code. The private backend is interchangeable. The standard implementation reads the texts from files in Yaml format or from normal ruby files.</p>
<h3>Calling</h3>
<p>In our code, we replace all the text to be translated with the <em>I18N.translate()</em> method. Thanks to an alias definition, we can simply write <em>t()</em>. We give a key as parameter, and the backend uses this key to look up the correct translation.</p>
<p>The key is a string or a symbol. Normally, look up by symbol is slightly more efficient. But since the key gets decomposed into its components during the processing, I expect that this advantage disappears.</p>
<p>In a typical web application, many of the texts to be translated are found in the views, ie. Erb templates. As an abbreviation for pure HTML text, there is the following tag:</p>
<pre>&lt;%=t 'key' %&gt;</pre>
<h3>Organization of keys</h3>
<p>The keys have a hierarchical structure. The suggested organization is:</p>
<p>&#8220;Controllername.viewname.key&#8221;, for example &#8216;companies.show.header&#8217;</p>
<h3>The language files</h3>
<p>The language files can either be Ruby code files or text files in Yaml format.  The person who translates is often a person without Ruby knowledge. That is why the Yaml file format is recommended.</p>
<p>The format looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">de:
  users:
    show:
      header: &quot;Company Data&quot;
      intro: &quot;For this company, we have stored the following data:&quot;</pre></div></div>

<p>The first key part the language code. This has the disadvantage that it separates the text entries of different languages. To help the translators, you can insert comments by marking a line with a beginning &#8216;#&#8217; character . And of course, you should name the keys as clear as possible.</p>
<p>But even then, when developer and translator are not the same person, I think the Yaml file format is not optimal.</p>
<p>Part 2 of this article will soon be translated to English.</p>
]]></content:encoded>
			<wfw:commentRss>http://meier-online.com/en/2009/04/localize-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Deutsch) Turing Award für Barbara Liskov</title>
		<link>http://meier-online.com/en/2009/03/turing-award-fur-barbara-liskov/</link>
		<comments>http://meier-online.com/en/2009/03/turing-award-fur-barbara-liskov/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 18:52:17 +0000</pubDate>
		<dc:creator>meier</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Abstraction]]></category>
		<category><![CDATA[CLU]]></category>
		<category><![CDATA[Liskov]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[yield]]></category>

		<guid isPermaLink="false">http://meier-online.com/?p=272</guid>
		<description><![CDATA[

]]></description>
			<content:encoded><![CDATA[</p>
<p><span id="more-272"></span></p></p>
]]></content:encoded>
			<wfw:commentRss>http://meier-online.com/en/2009/03/turing-award-fur-barbara-liskov/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
