<?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>mitcho.com &#187; gettext</title>
	<atom:link href="http://mitcho.com/blog/tag/gettext/feed/" rel="self" type="application/rss+xml" />
	<link>http://mitcho.com</link>
	<description></description>
	<lastBuildDate>Fri, 10 Feb 2012 23:24:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>Ubiquity Localization Update</title>
		<link>http://mitcho.com/blog/projects/ubiquity-localization-update/</link>
		<comments>http://mitcho.com/blog/projects/ubiquity-localization-update/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 10:35:23 +0000</pubDate>
		<dc:creator>mitcho</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[l10n]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[Mozilla Planet]]></category>
		<category><![CDATA[ubiquity]]></category>

		<guid isPermaLink="false">http://mitcho.com/blog/?p=2219</guid>
		<description><![CDATA[As we move closer and closer to shipping a Ubiquity with there is still much work to be done, particularly in the area of localization. In a recent Ubiquity meeting we laid out the explicit localization goals and non-goals of as follows: Goals for 0.5 Parser 2 (on by default) underlying support for localization of [...]
Related posts:<ol>
<li><a href='http://mitcho.com/blog/projects/big-issues-and-small-issues-with-parser-2/' rel='bookmark' title='Big Issues and Small Issues with Parser 2'>Big Issues and Small Issues with Parser 2</a></li>
<li><a href='http://mitcho.com/blog/projects/localizing-ubiquity-commands-and-nountypes/' rel='bookmark' title='Localizing Ubiquity: commands and nountypes'>Localizing Ubiquity: commands and nountypes</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-commands-by-the-numbers/' rel='bookmark' title='Ubiquity Commands by The Numbers'>Ubiquity Commands by The Numbers</a></li>
</ol>

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>As we move closer and closer to shipping a Ubiquity with <a href="https://labs.mozilla.com/2009/05/ubiquity-05-call-for-participation/">there is still much work to be done</a>, particularly in the area of localization. <a href="https://wiki.mozilla.org/Labs/Ubiquity/Meetings/2009-05-27_Weekly_Meeting">In a recent Ubiquity meeting</a> we laid out the explicit localization goals and non-goals of as follows:</p>

<ul>
<li>Goals for 0.5

<ul>
<li>Parser 2 (on by default)</li>
<li>underlying support for localization of commands</li>
<li>localization of standard feed commands for a few languages</li>
<li>Parser 2 language files for those same languages</li>
</ul></li>
<li>Nongoals for 0.5

<ul>
<li>distribution/sharing of localizations</li>
<li>localization of nountypes </li>
</ul></li>
</ul>

<p>The overall goal for this release of Ubiquity is to come up with a format and standard for localization. Localizations in Ubiquity 0.5 will only apply to commands bundled with Ubiquity, and the localization files themselves will be distributed with Ubiquity. In a future release we will tackle the problem of localizations for <a href="https://ubiquity.mozilla.com/herd/">commands in the wild</a> and truly croud-source<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> this process.</p>

<p><span id="more-2219"></span></p>

<h3>Localization Architecture</h3>

<p>The localization of Ubiquity commands will use a <a href="http://en.wikipedia.org/wiki/gettext">gettext</a>-style approach where localization files list key-value pairs for different properties and messages of the commands. For Ubiquity 0.5, where we only deal with the standard command feeds bundled Ubiquity, we can simply place all the localization files in <a href="https://ubiquity.mozilla.com/hg/ubiquity-firefox/file/tip/ubiquity/standard-feeds/localization"><code>ubiquity/standard-feeds/localization</code></a>. Localization files are organized by source feed, with one localization file per source feed, per language.</p>

<p>The localizable components of commands will include the <code>names</code>, <code>contributors</code>, and <code>help</code> properties, as well as any localizable strings in the command&#8217;s <code>preview()</code> and <code>execute()</code> methods. To make strings localizable in <code>preview()</code> and <code>execute()</code>, they must be wrapped in the localize function, <code>_()</code>.<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup></p>

<p>Other localizable components, like <code>names</code>, <code>contributors</code>, and <code>help</code> will not need to be wrapped in the <code>_()</code> function. In addition, as the localization files can only hold values of strings, for values such as names and contributors, the delimiter <code>|</code> can be used to delimit multiple values.</p>

<p><pre code='javascript'>zoom.names=ズーム|ズームして|ズームする|ズームしろ</pre></p>

<h3>The Localization Experience</h3>

<p><a href="https://ubiquity.mozilla.com/trac/ticket/739">One tool we have planned</a> to help kickstart the localization process is a tool that will automatically create a template of strings that need localization in a user&#8217;s commands. I took a first stab at this tool today. Clicking on the &#8220;get localization template&#8221; link next to each feed in the <a href="chrome://ubiquity/content/cmdlist.html">Ubiquity command list</a> will give you a template which you can then copy into a text file:</p>

<p><a class='limages' href='http://mitcho.com/blog/wp-content/uploads/2009/06/localization-template.png' rel='lightbox'><img src="http://mitcho.com/blog/wp-content/uploads/2009/06/localization-template-smaller.png" alt="localization-template-smaller.png" border="0" width="600" height="437" /></a></p>

<p>Additionally, instructions will later be added to this page to specify how and where to save localizations to test them or perhaps we can add a button that will automatically save it in the right location.</p>

<h3>Open Questions</h3>

<h4>Localization file formats</h4>

<p>There are two kinds of file formats for localizations we are considering: <a href="https://developer.mozilla.org/En/XUL_Tutorial/Property_Files"><code>.properties</code></a> and <code>.po</code>, the native <a href="http://en.wikipedia.org/wiki/gettext">gettext</a> format. As an example, here is the same key-value pair in the two formats:</p>

<h5><code>.properties</code>:</h5>

<p><pre># This is a comment
welcomeMessage=Hello, world!</pre></p>

<h5><code>.po</code>:</h5>

<p><pre>#. This is a comment (the . is actually optional)
msgid "welcomeMessage"
msgstr "Hello, world!"</pre></p>

<p>The advantage of <code>.properties</code> over <code>.po</code> is that Mozilla natively supports this format with an XUL/XPCOM interface called <a href="https://developer.mozilla.org/En/XUL/Stringbundle">stringbundle</a> and it is what is used to localize JavaScript in Firefox itself. We actually already have the <code>_()</code> localization function working with the properties file format, following <a href="http://www.xuldev.org/blog/?p=45">gomita&#8217;s great instructions</a> (Japanese) on how to load properties files in using Mozilla&#8217;s native <a href="https://developer.mozilla.org/En/XUL/Stringbundle">stringbundle</a> tools via JavaScript.</p>

<p>The advantage of <code>.po</code> over <code>.properties</code> is that it is the de-facto standard in localization, particularly in the UNIX world. Lots of great tools have been written for it. The adoption of <code>.po</code> could make Ubiquity localization more accessible for more people. Another advantage is that <code>.po</code> files can have keys with spaces, as I note below.</p>

<p>If we do opt to work with <code>.po</code> files, the two libraries I see out in the wild for dealing with <code>.po</code> files are <a href="http://code.google.com/p/gettext-js/">gettext-js</a> (MIT) and <a href="http://jsgettext.berlios.de/">jsgettext</a> (LGPL). While I haven&#8217;t looked at the libraries in depth yet, so far jsgettext seems to be the winner, as some sections of gettext-js require the use of the <a href="http://www.prototypejs.org/">prototype.js</a> library.</p>

<h4>A &#8220;key&#8221; question</h4>

<p><img src="http://mitcho.com/blog/wp-content/uploads/2009/06/icanhaskeyplz.jpg" alt="icanhaskeyplz.jpg" border="0" width="650" height="416" /></p>

<p>In either file format, we need a unique way to refer to each localizable string—a key format. As each localization file refers to a command feed, the first collision we must avoid is the command name. With this in mind, we can come up with some trivial keys for the localizable properties: (here, consider the command <code>hello</code>)</p>

<ul>
<li><code>hello.names</code></li>
<li><code>hello.contributors</code></li>
<li><code>hello.help</code></li>
</ul>

<p>However, we run into difficulty when we try to come up with keys for the arbitrary text in <code>preview</code>s and <code>execute</code>s. For example, for a message like &#8220;Hello world!&#8221; in the preview, we could simply make the key <code>hello.preview.Hello world!</code> but this may be unruly and be prone to typos. In addition, in <code>.properties</code> files keys cannot have certain characters in them, like spaces, so we would have to make the key something like <code>hello.preview.Hello_world!</code> or, stripping symbols and standardizing case, <code>hello.preview.HELLO_WORLD</code>.</p>

<p>Keys could also get very long with this type of key format, although here again <code>.po</code> files may have an advantage as they can stay relatively more legible even with long keys. One option to deal with this would be to optionally supply a key argument to <code>_()</code> so that it is used instead of the automatic key. For example, suppose the <code>hello</code> command&#8217;s <code>preview()</code> included this code:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">_<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'This is a really long greeting message. Hello there!'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'longmessage'</span><span style="color: #009900;">&#41;</span></pre></div></div>


<p>then a localizer would only have to refer to <code>hello.preview.longmessage</code>, not <code>hello.preview.THIS_IS_A_REALLY_LONG_GREETING_MESSAGE_HELLO_THERE</code>.</p>

<p><a href="http://twitter.com/m_satyr">satyr</a> points out that some commands use another function to incorporate similar actions and messages in both <code>preview()</code> and <code>execute()</code>. In this case, he argues, it wouldn&#8217;t make sense to have to keep both localizations (<code>hello.preview.</code>&#8230; and <code>hello.execute.</code>&#8230;). He suggests that optional keys (mentioned above) could be used without the <code>preview.</code> or <code>execute.</code> infixes, as in <code>hello.longmessage</code>. By taking out the <code>preview</code> and <code>execute</code> namespacing in the localization keys, though, it becomes the command author&#8217;s responsibility to not accidentally use strings named &#8220;names&#8221;, &#8220;help&#8221;, etc. that will have unintended consequences.</p>

<h3>Conclusion</h3>

<p>I hope that this blog post gives people an idea of the progress we&#8217;ve made in the localization area and gets people thinking about the challenges we still face. <strong>We&#8217;d love to get your feedback on the localization format and process in Ubiquity, as well as the open problems of the file format and keys.</strong></p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>Or &#8220;cloud-source&#8221;&#8230; finally a Japanese accent joke that&#8217;s semantically stable!&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>This function currently also has the ability to do simple <a href="http://en.wikipedia.org/wiki/printf">printf</a>-formatted string replacements:<br/>
<pre code='javascript'>_('This is a %S.',['test'])</pre>
<br/>Whether this format will replace support for <code>CmdUtils.renderTemplate</code> remains to be seen and is definitely worthy of discussion. If we move away from <a href="https://developer.mozilla.org/En/XUL_Tutorial/Property_Files">properties files</a>, in particular, we may keep <code>renderTemplate()</code> in lieu of the <a href="http://en.wikipedia.org/wiki/printf">printf</a> format. Mozilla&#8217;s built-in <a href="https://developer.mozilla.org/En/XUL/Stringbundle">stringbundle handling</a> just gave us a fast and free implementation of <a href="http://en.wikipedia.org/wiki/printf">printf</a>-style replacement.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<p>Related posts:</p><ol>
<li><a href='http://mitcho.com/blog/projects/big-issues-and-small-issues-with-parser-2/' rel='bookmark' title='Big Issues and Small Issues with Parser 2'>Big Issues and Small Issues with Parser 2</a></li>
<li><a href='http://mitcho.com/blog/projects/localizing-ubiquity-commands-and-nountypes/' rel='bookmark' title='Localizing Ubiquity: commands and nountypes'>Localizing Ubiquity: commands and nountypes</a></li>
<li><a href='http://mitcho.com/blog/projects/ubiquity-commands-by-the-numbers/' rel='bookmark' title='Ubiquity Commands by The Numbers'>Ubiquity Commands by The Numbers</a></li>
</ol>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mitcho.com/blog/projects/ubiquity-localization-update/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

