<?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>DucDigital &#187; Localization</title>
	<atom:link href="http://www.ducdigital.com/tag/localization/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ducdigital.com</link>
	<description>for ( $girl = 1; $girl &#60; $required; $girl++ ) { echo "I love DucDigital"; }</description>
	<lastBuildDate>Sat, 07 Aug 2010 09:12:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Noob guide to Globalization in Asp.net MVC</title>
		<link>http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/</link>
		<comments>http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 21:06:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Asp.net MVC]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[culture]]></category>
		<category><![CDATA[globalization]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[Localization]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[noob]]></category>
		<category><![CDATA[translation]]></category>
		<category><![CDATA[uiCulture]]></category>
		<category><![CDATA[web form view engine]]></category>

		<guid isPermaLink="false">http://www.ducdigital.com/?p=209</guid>
		<description><![CDATA[Yea. Finally, I've done the Globalization after google and code for 4 hours, it's a pain because there are really (as of when I search) no specific post for this area. So basically in this post, i will gather everything I've done in my Globalization / Localization / Internationalization (whatever you called it is) and [...]]]></description>
			<content:encoded><![CDATA[<p>Yea. Finally, I've done the Globalization after google and code for 4 hours, it's a pain because there are really (as of when I search) no specific post for this area. So basically in this post, i will gather everything I've done in my Globalization / Localization / Internationalization (whatever you called it is) and post here.</p>
<p>First step, we need to make a folder name: <strong>"App_GlobalResources"</strong>, which you can create by right click your project, <em>Add  -> Add ASP.NET Folder -> App_GlobalResources</em></p>
<p>After you created the folder, we need to create <strong>Resource Files</strong> in this folder for the language. Basically, you can see the picture below have 3 files:</p>
<ol>
<li>Language.resx -> this is the default of the language, all the default translation must be in here.</li>
<li>Language.en.resx -> this is the English file. It will override the default translations</li>
<li>Language.vi.resx -> Vietnamese translation, used UTF-8 in here on an UTF-8 website</li>
</ol>
<p><a href="http://www.ducdigital.com/wp-content/uploads/2010/01/Global1.jpg"><img src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global1.jpg" alt="" title="Global1" width="378" height="428" class="aligncenter size-full wp-image-210" /></a></p>
<p>This is the<strong> Language.resx</strong>, which I just have to put the name because it actually doesn't matter, but if for precaution, you can always duplicate one of your language file and replace the <strong>Language.resx</strong> with it so you don't have to worry.<br />
<a href="http://www.ducdigital.com/wp-content/uploads/2010/01/Global2.jpg"><img src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global2.jpg" alt="" title="Global2" width="478" height="174" class="aligncenter size-full wp-image-211" /></a></p>
<p>And here is the picture showing the file <strong>Language.en.resx</strong>. Which I have the Name and the Value<br />
<a href="http://www.ducdigital.com/wp-content/uploads/2010/01/Global3.jpg"><img src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global3.jpg" alt="" title="Global3" width="681" height="302" class="aligncenter size-full wp-image-212" /></a></p>
<p>As you notice the {0} and {1} above, I will explain in the later part.</p>
<p>2nd, we need now is to create a new folder to contain our <em>HtmlExtension </em>and use this to output text string.<br />
In my case, I created a Folder name Helper in my Project root.</p>
<p>Notice: these files are not mine, they are code from, i have modified a little from this source: http://blog.eworldui.net/post/2008/10/ASPNET-MVC-Simplified-Localization-via-ViewEngines.aspx . If ever you need to explain further about WebFormViewEngine or something, you can always go to their website. In my case, to make it as simple as possible, i will cut down this part.</p>
<p><strong> LocalizationWebFormView.cs </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Project.<span style="color: #0000FF;">Helper</span>.<span style="color: #0000FF;">Localization</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LocalizationWebFormView <span style="color: #008000;">:</span> WebFormView
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">internal</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> ViewPathKey <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;__ViewPath__&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> viewPath<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>viewPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> viewPath, <span style="color: #FF0000;">string</span> masterPath<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>viewPath, masterPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Render<span style="color: #000000;">&#40;</span>ViewContext viewContext, TextWriter writer<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// there seems to be a bug with RenderPartial tainting the page's view data</span>
            <span style="color: #008080; font-style: italic;">// so we should capture the current view path, and revert back after rendering</span>
            <span style="color: #FF0000;">string</span> originalViewPath <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span> viewContext.<span style="color: #0000FF;">ViewData</span><span style="color: #000000;">&#91;</span>ViewPathKey<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            viewContext.<span style="color: #0000FF;">ViewData</span><span style="color: #000000;">&#91;</span>ViewPathKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> ViewPath<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Render</span><span style="color: #000000;">&#40;</span>viewContext, writer<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            viewContext.<span style="color: #0000FF;">ViewData</span><span style="color: #000000;">&#91;</span>ViewPathKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> originalViewPath<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong> LocalizationWebFormViewEngine.cs </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Project.<span style="color: #0000FF;">Helper</span>.<span style="color: #0000FF;">Localization</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LocalizationWebFormViewEngine <span style="color: #008000;">:</span> WebFormViewEngine
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> IView CreateView<span style="color: #000000;">&#40;</span>ControllerContext controllerContext, <span style="color: #FF0000;">string</span> viewPath, <span style="color: #FF0000;">string</span> masterPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span>viewPath, masterPath<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> IView CreatePartialView<span style="color: #000000;">&#40;</span>ControllerContext controllerContext, <span style="color: #FF0000;">string</span> partialPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span>partialPath, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong> LocalizationWebFormViewEngine.cs </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Project.<span style="color: #0000FF;">Helper</span>.<span style="color: #0000FF;">Localization</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LocalizationWebFormViewEngine <span style="color: #008000;">:</span> WebFormViewEngine
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> IView CreateView<span style="color: #000000;">&#40;</span>ControllerContext controllerContext, <span style="color: #FF0000;">string</span> viewPath, <span style="color: #FF0000;">string</span> masterPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span>viewPath, masterPath<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> IView CreatePartialView<span style="color: #000000;">&#40;</span>ControllerContext controllerContext, <span style="color: #FF0000;">string</span> partialPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> LocalizationWebFormView<span style="color: #000000;">&#40;</span>partialPath, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong> ResourceExtensions.cs </strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Globalization</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Compilation</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> P014.<span style="color: #0000FF;">Helper</span>.<span style="color: #0000FF;">Localization</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> ResourceExtensions
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> Resource<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> Controller controller, <span style="color: #FF0000;">string</span> expression, <span style="color: #0600FF;">params</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            ResourceExpressionFields fields <span style="color: #008000;">=</span> GetResourceFields<span style="color: #000000;">&#40;</span>expression, <span style="color: #666666;">&quot;~/&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> GetGlobalResource<span style="color: #000000;">&#40;</span>fields, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> Resource<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> expression, <span style="color: #0600FF;">params</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">string</span> path <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>htmlHelper.<span style="color: #0000FF;">ViewData</span><span style="color: #000000;">&#91;</span>LocalizationWebFormView.<span style="color: #0000FF;">ViewPathKey</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>path<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                path <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;~/&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            ResourceExpressionFields fields <span style="color: #008000;">=</span> GetResourceFields<span style="color: #000000;">&#40;</span>expression, path<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>fields.<span style="color: #0000FF;">ClassKey</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">return</span> GetGlobalResource<span style="color: #000000;">&#40;</span>fields, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> GetLocalResource<span style="color: #000000;">&#40;</span>path, fields, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> Language<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> key, <span style="color: #0600FF;">params</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
		    <span style="color: #008080; font-style: italic;">//Replace Language with a name of your choice, if you have lang.en.resx, you should change the value here to &quot;lang&quot;</span>
            <span style="color: #FF0000;">string</span> expression <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Language, &quot;</span> <span style="color: #008000;">+</span> key<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> Resource<span style="color: #000000;">&#40;</span>htmlHelper, expression, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetLocalResource<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> path, ResourceExpressionFields fields, <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">try</span><span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">GetLocalResourceObject</span><span style="color: #000000;">&#40;</span>path, fields.<span style="color: #0000FF;">ResourceKey</span>, CultureInfo.<span style="color: #0000FF;">CurrentUICulture</span><span style="color: #000000;">&#41;</span>, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">GetLocalResourceObject</span><span style="color: #000000;">&#40;</span>path, fields.<span style="color: #0000FF;">ResourceKey</span>, CultureInfo.<span style="color: #0000FF;">CurrentUICulture</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetGlobalResource<span style="color: #000000;">&#40;</span>ResourceExpressionFields fields, <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">try</span><span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">GetGlobalResourceObject</span><span style="color: #000000;">&#40;</span>fields.<span style="color: #0000FF;">ClassKey</span>, fields.<span style="color: #0000FF;">ResourceKey</span>, CultureInfo.<span style="color: #0000FF;">CurrentUICulture</span><span style="color: #000000;">&#41;</span>, args<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">GetGlobalResourceObject</span><span style="color: #000000;">&#40;</span>fields.<span style="color: #0000FF;">ClassKey</span>, fields.<span style="color: #0000FF;">ResourceKey</span>, CultureInfo.<span style="color: #0000FF;">CurrentUICulture</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">static</span> ResourceExpressionFields GetResourceFields<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> expression, <span style="color: #FF0000;">string</span> virtualPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var context <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ExpressionBuilderContext<span style="color: #000000;">&#40;</span>virtualPath<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            var builder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ResourceExpressionBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>ResourceExpressionFields<span style="color: #000000;">&#41;</span>builder.<span style="color: #0000FF;">ParseExpression</span><span style="color: #000000;">&#40;</span>expression, <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>, context<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>What I've added in this code is in the file ResourceExtensions.cs. Which i add a language helper to make you called out from your view easier. Remember to replace Language with a name of your choice, if you have lang.en.resx, you should change the value here to "lang".</p>
<p>Now for the program to finally fire up the Globalization / Localization for the webpage, we need to declare the culture for the program, either you can declare in web.config or you can write a little code in Global.asax</p>
<p>web.config approach:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system</span> .web<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;globalization</span> <span style="color: #000066;">uiCulture</span>=<span style="color: #ff0000;">&quot;vi&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Global.asax</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Application_BeginRequest<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Application Level language</span>
            <span style="color: #008080; font-style: italic;">// VI here is the language you want to set it on default.</span>
            Thread.<span style="color: #0000FF;">CurrentThread</span>.<span style="color: #0000FF;">CurrentUICulture</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CultureInfo<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;vi&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></div></div>

<p>3rd, Configure.... We need to config the view of WFViewEngine to be able to find the Localization classes.<br />
Open web.config and search for</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
/* Find: */
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;namespaces<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
/* Add this after, where &quot;Project.Helper.Localization&quot; is the class of the files above. */
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;Project.Helper.Localization&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/namespaces<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Finally! We've done most of it. You can now use the tag below to insert the translation text into the program.</p>

<div class="wp_syntax"><div class="code"><pre class="cshrap" style="font-family:monospace;">&lt; %= Html.Language(&quot;name&quot;) %&gt;</pre></div></div>

<p>For the {0} {1} argument I've mention earlier, I will put some example here:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// name: argumenttest</span>
<span style="color: #008080; font-style: italic;">// value: This is first argument {0}, 2nd {1}, 3rd &lt;strong&gt;{3} &lt;/strong&gt;</span>
<span style="color: #008000;">&lt;</span> <span style="color: #008000;">%=</span> Html.<span style="color: #0000FF;">Language</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;argumenttest&quot;</span>, <span style="color: #008000;">new</span> <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> <span style="color: #666666;">&quot;First&quot;</span>, <span style="color: #666666;">&quot;duc&quot;</span>, <span style="color: #666666;">&quot;strong&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: #008000;">%&gt;</span>
<span style="color: #008080; font-style: italic;">// output: This is first argument First, 2nd duc, 3rd strong</span></pre></div></div>

<p>Now you can have a fully functional globalization / localization without a sweat!<br />
I hope you enjoy this post <img src='http://www.ducdigital.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  !<br />

<a href='http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/global1/' title='Global1'><img width="150" height="150" src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global1-150x150.jpg" class="attachment-thumbnail" alt="Global1" title="Global1" /></a>
<a href='http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/global2/' title='Global2'><img width="150" height="150" src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global2-150x150.jpg" class="attachment-thumbnail" alt="Global2" title="Global2" /></a>
<a href='http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/global3/' title='Global3'><img width="150" height="150" src="http://www.ducdigital.com/wp-content/uploads/2010/01/Global3-150x150.jpg" class="attachment-thumbnail" alt="Global3" title="Global3" /></a>
</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ducdigital.com%2F2010%2F01%2F10%2Fnoob-guide-to-globalization-in-asp-net-mvc%2F&amp;linkname=Noob%20guide%20to%20Globalization%20in%20Asp.net%20MVC"><img src="http://www.ducdigital.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ducdigital.com/2010/01/10/noob-guide-to-globalization-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
