<?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>Silverlight &#38; WCF RIA Services &#187; Localization</title>
	<atom:link href="http://bachelorthesis.zdechovan.com/tag/localization/feed/" rel="self" type="application/rss+xml" />
	<link>http://bachelorthesis.zdechovan.com</link>
	<description>Bachelor Thesis About RIA Enterprise Applications (written by Lukáš Zdechovan, led by Ondrej Svačina)</description>
	<lastBuildDate>Sat, 29 May 2010 17:57:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Localization of Silverlight Business Application (sample)</title>
		<link>http://bachelorthesis.zdechovan.com/localization-of-silverlight-business-application/</link>
		<comments>http://bachelorthesis.zdechovan.com/localization-of-silverlight-business-application/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 16:55:03 +0000</pubDate>
		<dc:creator>Lukáš Zdechovan</dc:creator>
				<category><![CDATA[Samples]]></category>
		<category><![CDATA[.NET RIA Services]]></category>
		<category><![CDATA[Localization]]></category>

		<guid isPermaLink="false">http://bachelorthesis.zdechovan.com/?p=99</guid>
		<description><![CDATA[
Although it looks that localization of Silverlight Business Applications is not worth of writing a post, there are some really inconspicuous problems which you have to resolve.
If you want to localize the application by creating resource files of strings for a particual language (AppStrings.sk-SK.resx, AppString.de-DE.resx) you should definitely read this post (with sample source-code) to [...]]]></description>
			<content:encoded><![CDATA[<div class="mceTemp" style="text-align: left;">
<div id="attachment_102" class="wp-caption alignleft" style="width: 150px"><img class="size-full wp-image-102" title="Illustration - flags" src="http://bachelorthesis.zdechovan.com/wp-content/uploads/2010/01/100-countries1.png" alt="Illustration" width="140" height="114" /><p class="wp-caption-text">Illustration</p></div>
<p>Although it looks that localization of S<strong>ilverlight Business Applications</strong> is not worth of writing a post, there are some really inconspicuous problems which you have to resolve.</div>
<p>If you want to localize the application by creating resource files of strings for a particual language (AppStrings.sk-SK.resx, AppString.de-DE.resx) you should definitely read this post (with sample source-code) to not get into trouble.</p>
<p><span id="more-99"></span></p>
<p>At first I create a New project with Business Application Template.<br />
<img class="size-full wp-image-111" style="margin: 10px;" title="Business Application Template" src="http://bachelorthesis.zdechovan.com/wp-content/uploads/2010/01/1-template.png" alt="Business Application Template" width="584" height="70" /><br />
The strings resource files are in the template located in both Client and Server (Web) projects.<br />
<img class="alignleft size-full wp-image-112" style="margin: 10px;" title="Resource files" src="http://bachelorthesis.zdechovan.com/wp-content/uploads/2010/01/2-resourcefiles.png" alt="Resource files" width="263" height="530" /></p>
<p>The most important resource is the ApplicationStrings.resx file, in which almost all the strings from the client side are stored.</p>
<p>Strings which are used in the login and registration form are stored on the server side in RegistrationDataResources.resx.</p>
<p>To localize the strings you have to create copies of desired resource file with an appropriate sufix according to the culture, so slovak copy of AppStrings will be ApplicationStrings.<strong>sk-SK</strong>.resx. Do the same to all resource files in the project and translate them to your language.</p>
<p style="text-align: left;">Don&#8217;t add resource files to the Web\Resources directory in the client project, because in this folder should be placed just links to files in Resources folder in Web project. Link to a file si added by adding Existing item to client side Web\Resources and choosing &#8220;Add as link&#8221; option.<a href="http://bachelorthesis.zdechovan.com/wp-content/uploads/2010/01/3-add-links.png"><img class="aligncenter size-thumbnail wp-image-113" style="margin-top: 6px; margin-bottom: 6px;" title="Add as a link" src="http://bachelorthesis.zdechovan.com/wp-content/uploads/2010/01/3-add-links-150x150.png" alt="Add as a link" width="150" height="150" /></a> Till now, we did similar work we do in ASP.NET applications when localizing them.</p>
<p>To test whether it works add following line to App.xaml.cs</p>
<pre name="code" class="c-sharp">
...
using System.Threading;
using System.Globalization;
...
private void Application_Startup(object sender, StartupEventArgs e)
{
    // This will enable you to bind controls in XAML files to WebContext.Current
    // properties
    this.Resources.Add("WebContext", WebContext.Current);

    // This will automatically authenticate a user when using windows authentication
    // or when the user chose "Keep me signed in" on a previous login attempt
    WebContext.Current.Authentication.LoadUser(this.Application_UserLoaded, null);

    //Change current culture to slovak, just for the test
    Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo("sk-SK");</strong>

    // Show some UI to the user while LoadUser is in progress
    this.InitializeRootVisual();
}
</pre>
<p>Run the project and you&#8217;ll not see any localized string there.</p>
<p>Now, you&#8217;ll have to do a bit of manual work to make your localization working. At first, unload your client side project by right-click on a project and select &#8220;Unload Project&#8221;.<br />
Navigate to the project folder in your filesystem and open the .csproj file in notepad or similar text editor.<br />
Locate &lt;SupportedCultures&gt; element a place there all the culture that you want to have in your app separated by comma (&lt;SupportedCultures&gt;en-US,sk-SK&lt;/SupportedCultures&gt;).</p>
<p>Reload the project back, build it and run. Localization should work.</p>
<div id="attachment_117" class="wp-caption aligncenter" style="width: 310px"><a href="http://bachelorthesis.zdechovan.com/wp-content/uploads/2010/01/4-localized-page1.png"><img class="size-medium wp-image-117" title="Localized page" src="http://bachelorthesis.zdechovan.com/wp-content/uploads/2010/01/4-localized-page1-300x167.png" alt="Localized page" width="300" height="167" /></a><p class="wp-caption-text">Localized page</p></div>
<p>Now, let&#8217;s look on how to localize new strings, which are not stored as resources. In this template, not localized are &#8220;Home page content&#8221; and &#8220;About page content&#8221; strings.</p>
<p>I created new resourcefiles HomeView.resx and AboutView.resx plus sk-SK localized equivalents and rebuild the project. In those I will store my strings for each view. To enable use of these resoruces in these views, add some piece of code to the ResourceWrapper.cs Helper class, which holds as a StaticResource in the XAMLs.<br />
<em>Note: Your resources are in Assets.Resources namespace in this case.</em></p>
<pre name="code" class="c-sharp">
using Assets.Resources;
...
public sealed class ResourceWrapper
{
private static SecurityQuestions securityQuestions = new SecurityQuestions();
private static HomeView homeView = new HomeView();
private static AboutView aboutView = new AboutView();
...
public HomeView HomeViewStrings
{ get { return homeView; } }

public AboutView AboutViewStrings
{ get { return aboutView; } }
</pre>
<p><span style="font-style: normal;">Then in our XAMLs we may use our ResourceWrapper properties HomeViewStrings and AboutViewStrings to bind to desired string.</span></p>
<pre name="code" class="xml">
&lt;TextBlock ... Text="{Binding Path=HomeViewStrings.HomeContent, Source={StaticResource ResourceWrapper}}" /&gt;
</pre>
<div id="attachment_119" class="wp-caption aligncenter" style="width: 394px"><img class="size-full wp-image-119" title="Localized content" src="http://bachelorthesis.zdechovan.com/wp-content/uploads/2010/01/5-localized-content.png" alt="Localized content" width="384" height="167" /><p class="wp-caption-text">Localized content</p></div>
<p><span style="font-style: normal;">You can localize the whole application this way, so I hope this article was helpful.</span></p>
<p><span style="font-style: normal;"><strong>Remember what is the most important:</strong></span></p>
<ol>
<li><span style="font-style: normal;">Change the project file in text editor to allow the client to support different cultures (via SupportedCultures XML node).</span></li>
<li><span style="font-style: normal;">Login and registration resources are stored in the Web project.</span></li>
<li><span style="font-style: normal;">Add your own resourcefiles also to ResourceWrapper.cs Helper class to allow binding to it in XAML file.</span></li>
<li><span style="font-style: normal;">I recommend to set the Access Modifier in default resource files to &#8220;Public&#8221; (default is internal) and for culture-specific resource files to &#8220;No-code generation&#8221;, because we don&#8217;t need it in these.</span></li>
</ol>
<p><a href="http://bachelorthesis.zdechovan.com/wp-content/uploads/2010/01/LocalizedSilverlightApp.zip">Download source code</a> of the sample. (Silverlight 4, .NET 4.0, VS 2010)</p>
<p>If you find some errors in my sample or you would like to share your knowledge about localization, some new ideas, etc, please leave comment below.</p>
]]></content:encoded>
			<wfw:commentRss>http://bachelorthesis.zdechovan.com/localization-of-silverlight-business-application/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

