<?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>AB-WebLog.com&#187; localization</title>
	<atom:link href="http://www.ab-weblog.com/en/tag/localization/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ab-weblog.com/en</link>
	<description>Andreas Breitschopp</description>
	<lastBuildDate>Wed, 18 Mar 2015 09:47:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MunichJS: Speech About Internationalization of HTML5 Apps and Using Encapsulator</title>
		<link>http://www.ab-weblog.com/en/munichjs-speech-about-internationalization-of-html5-apps-and-using-encapsulator/</link>
		<comments>http://www.ab-weblog.com/en/munichjs-speech-about-internationalization-of-html5-apps-and-using-encapsulator/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 21:00:29 +0000</pubDate>
		<dc:creator>Andreas Breitschopp</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[AppUp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Encapsulator]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[Intel]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[speech]]></category>

		<guid isPermaLink="false">http://www.ab-weblog.com/en/?p=470</guid>
		<description><![CDATA[Today there was a JavaScript meetup of MunichJS in Feldkirchen near Munich (Germany). MunichJS is a user group in Munich for developers that meets monthly to discuss topics on JavaScript and ECMAScript. I was invited to give a speech there &#8230; <a href="http://www.ab-weblog.com/en/munichjs-speech-about-internationalization-of-html5-apps-and-using-encapsulator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today there was a JavaScript meetup of <a title="MunichJS Website" href="http://www.munichjs.org" target="_blank">MunichJS</a> in Feldkirchen near Munich (Germany). MunichJS is a user group in Munich for developers that meets monthly to discuss topics on JavaScript and ECMAScript.</p>
<p>I was invited to give a speech there about the topic &#8220;Run Internationalized HTML5 App as Native Windows Program&#8221;.</p>
<p><a href="http://www.ab-weblog.com/en/files/munichjs-speech-about-internationalization-of-html5-apps-and-using-encapsulator.png"><img class="aligncenter size-medium wp-image-479" title="MunichJS: Speech About Internationalization of HTML5 Apps and Using Encapsulator" src="http://www.ab-weblog.com/en/files/munichjs-speech-about-internationalization-of-html5-apps-and-using-encapsulator-300x179.png" alt="MunichJS: Speech About Internationalization of HTML5 Apps and Using Encapsulator" width="300" height="179" /></a></p>
<p>In the first part of the speech I presented a HTML5 app that uses a JavaScript library to easily localize all strings in the HTML and in the JavaScript part of the application. At the end of the speech I used the Intel AppUp Encapsulator to generate a MSI file for this app. This way the application ran natively on a Windows operating system. <a title="MunichJS: Internationalization of HTML5 Apps and Using Encapsulator (Presentation)" href="http://www.ab-weblog.com/en/files/munichjs-internationalization-of-html5-apps-and-using-encapsulator-presentation.pdf" target="_blank">Download the PowerPoint presentation.</a></p>
<p>The example project used in my presentation can be downloaded in my post <a title="Internationalization: How to Localize HTML5 Projects?" href="http://www.ab-weblog.com/en/internationalization-how-to-localize-html5-projects/">Internationalization: How to Localize HTML5 Projects?</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ab-weblog.com/en/munichjs-speech-about-internationalization-of-html5-apps-and-using-encapsulator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Internationalization: How to Localize HTML5 Projects?</title>
		<link>http://www.ab-weblog.com/en/internationalization-how-to-localize-html5-projects/</link>
		<comments>http://www.ab-weblog.com/en/internationalization-how-to-localize-html5-projects/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 17:59:53 +0000</pubDate>
		<dc:creator>Andreas Breitschopp</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[localization]]></category>

		<guid isPermaLink="false">http://www.ab-weblog.com/en/?p=400</guid>
		<description><![CDATA[While working on a HTML5 project I came across the problem that I needed to localize it to different languages. Therefore obviously strings of HTML tags as well as JavaScript files need to be translated. Although I think internationalization is &#8230; <a href="http://www.ab-weblog.com/en/internationalization-how-to-localize-html5-projects/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While working on a HTML5 project I came across the problem that I needed to localize it to different languages. Therefore obviously strings of HTML tags as well as JavaScript files need to be translated.</p>
<p>Although I think internationalization is something very important in a globally connected world, it looks like as this topic was completely forgotten for HTML5 development. I just found a proposal in the <a title="Common JS Wiki Website" href="http://wiki.commonjs.org/wiki/I18n" target="_blank">Common JS Wiki</a> regarding that with no activity since more than a year!</p>
<p>After searching for while I found this post about <a title="Passive localization in JavaScript" href="http://eligrey.com/blog/post/passive-localization-in-javascript">Passive localization in JavaScript</a>. Of course, I would prefer an officially standardized approach for the localization, but anyway, this JavaScript library is very helpful to use in the meantime until there is an an officially standardized solution.</p>
<p>In the following I will explain how I use this library, not only for JavaScript files, but also for translating the content of HTML tags.</p>
<h2>HTML5 Test Page</h2>
<p>First of all we need a small HTML5 test page like this:</p>
<pre class="brush: html; gutter: true">&lt;!doctype html&gt;
&lt;html class=&quot;no-js&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
	&lt;meta charset=&quot;utf-8&quot;&gt;
	&lt;title&gt;Internationalization Test&lt;/title&gt;

	&lt;link rel=&quot;localization&quot; hreflang=&quot;de&quot; href=&quot;lang/de.json&quot; type=&quot;application/vnd.oftn.l10n+json&quot;/&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;css/style.css&quot;&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;js/i18n.js&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;js/script.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body onload=&quot;loaded()&quot;&gt;
	&lt;h1 id=&quot;headertext&quot;&gt;This is an Internationalization Test!&lt;/h1&gt;
	&lt;h2 id=&quot;subtitletext&quot;&gt;With any subtitle.&lt;/h2&gt;
	&lt;a id=&quot;showinenglish&quot; href=&quot;index.html?lang=en&quot;&gt;Show in English&lt;/a&gt;
	&lt;a id=&quot;showingerman&quot; href=&quot;index.html?lang=de&quot;&gt;Show in German&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>You can see that I assigned IDs to all major HTML tags. We will use them later on for doing the translation.</p>
<h2>JavaScript Helper Functions</h2>
<p>Before starting with the translation itself, we need some JavaScript helper functions first:</p>
<pre class="brush: javascript; gutter: true">var _ = function (string) {
	return string.toLocaleString();
};

function localizeHTMLTag(tagId)
{
	tag = document.getElementById(tagId);
	tag.innerHTML = _(tag.innerHTML);
}

function getParameterValue(parameter)
{
	parameter = parameter.replace(/[\[]/, &quot;\\\[&quot;).replace(/[\]]/, &quot;\\\]&quot;);
	var regexS = &quot;[\\?&amp;]&quot; + parameter + &quot;=([^&amp;#]*)&quot;;
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	if(results == null)
		return &quot;&quot;;
	else
		return results[1];
}</pre>
<p>Here is a short explanation about what these helper functions are doing:</p>
<ul>
<li><code class="brush: javascript; gutter: false">_()</code>: that&#8217;s just a short form of the prototype <code class="brush: javascript; gutter: false">string.toLocaleString()</code>.</li>
<li><code class="brush: javascript; gutter: false">localizeHTMLTag(tagId)</code>: this function gets the appropriate HTML element from the DOM tree based on the passed tag ID and directly does the translation afterwards.</li>
<li><code class="brush: javascript; gutter: false">getParameterValue(parameter)</code>: we&#8217;ll need this function to get a URL parameter value to change the language of the page upon user request.</li>
</ul>
<h2>Doing the Localization</h2>
<p>We have all needed parts to do our localization which is really easy now:</p>
<pre class="brush: javascript; gutter: true">function loaded()
{
	var lang = getParameterValue(&quot;lang&quot;);
	if (lang != &quot;&quot;) String.locale = lang;

	alert(_(&quot;Localizing the document title...&quot;));
	document.title = _(document.title);

	alert(_(&quot;Localizing other HTML tags...&quot;));
	localizeHTMLTag(&quot;headertext&quot;);
	localizeHTMLTag(&quot;subtitletext&quot;);
	localizeHTMLTag(&quot;showinenglish&quot;);
	localizeHTMLTag(&quot;showingerman&quot;);

	alert(_(&quot;Localizing done!&quot;));
}</pre>
<p>There is just one function <code class="brush: javascript; gutter: false">loaded()</code>, which is called after the document is loaded (see the event in body tag of the HTML5 test page above). First we check if there is an URL parameter <em>lang</em> in case the user changed the page language with the links. Otherwise we don&#8217;t need to change the locale (the default browser locale of the user will be used automatically).</p>
<p>Afterwards we can start doing our translation by directly translating a string with the function <code>_()</code> or by using our function <code>localizeHTMLTag(tagId)</code> to translate the content of a HTML tag. That&#8217;s it! <img src='http://www.ab-weblog.com/en/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>What About More Languages?</h2>
<p>If you want to add more or other languages, you just need to add a new localization link in the HTML <em>head</em> section together with a JSON file containing the translations for the new language.</p>
<h2>Why not Using Short Variable Names?</h2>
<p>The author of this JavaScript internationalization library suggests to use short variable strings instead of the default translations. Therefore I want to give an explanation why I&#8217;m not doing this in my example as he is, of course, right that using the default translations adds some overhead to the project. But using short variable names would have at least these two disadvantages, too:</p>
<ul>
<li>your HTML5 page would no longer work without a translation, because otherwise only the short variable names would be displayed. In my example project it would just display the default translation (English) when no internationalization system is available.</li>
<li>I still hope that there will be a standardized way to do internationalization for HTML5 projects. Then probably you will need to have the default translation inside the HTML tags as the de facto standard for doing e. g. translation of PHP projects is to use <em>gettext</em> files (.po). That&#8217;s also the way the mentioned proposal suggests to do it. Therefore when I want to switch to such a way of internationalization somewhen in the future, I don&#8217;t like to copy all default translations back into the HTML tags.</li>
</ul>
<h2>Download Example Project</h2>
<p>If you like, you can <a title="Internationalization HTML5 Example Project" href="http://www.ab-weblog.com/en/files/internationalization-html5-example-project.zip">download the source of my example project</a>.</p>
<h2>Update</h2>
<p>I&#8217;ve updated the example project as there was one comma too much in the JSON file which caused it to only work in Mozilla Firefox (not in Microsoft Internet Explorer and Google Chrome). That&#8217;s fixed now &#8211; thanks Margaret Wong for letting me know about that!</p>
<p>But please keep in mind that you have to upload the files to a webserver for testing as they probably won&#8217;t work in Internet Explorer and Chrome locally due to browser access restrictions. Anyway, the example project will work fine now when you upload it to a webserver.</p>
<p><em>What concept you&#8217;re using for localizing your HTML5 projects?</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ab-weblog.com/en/internationalization-how-to-localize-html5-projects/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->