<?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>MIKE &#187; Localization</title>
	<atom:link href="http://helios.ca/tag/localization/feed/" rel="self" type="application/rss+xml" />
	<link>http://helios.ca</link>
	<description>Just another developer blog</description>
	<lastBuildDate>Tue, 12 Jul 2011 21:35:29 +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>C#.NET Localization with MasterPage</title>
		<link>http://helios.ca/2008/08/31/cnet-localization-with-masterpage/</link>
		<comments>http://helios.ca/2008/08/31/cnet-localization-with-masterpage/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 17:02:29 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Developement]]></category>
		<category><![CDATA[Globalization]]></category>
		<category><![CDATA[Localization]]></category>

		<guid isPermaLink="false">http://helios.ca/?p=38</guid>
		<description><![CDATA[I recently started programming using C#.NET. The first thing I had to do with it, is make a complete website, kinda cool to learn about the language! At first it was easy, but then I had to localize the website for French and English. After hours of reading, I found a suitable solution written by [...]]]></description>
			<content:encoded><![CDATA[<p>I recently started programming using C#.NET. The first thing I had to do with it, is make a complete website, kinda cool to learn about the language! At first it was easy, but then I had to localize the website for French and English. After hours of reading, I found a suitable solution written by <a href="http://www.smart-soft.ch">Michael Ulmann</a>.</p>
<ol>
<li>Open up your Website in Visual Studio</li>
<li>Open up Global.asax and add these lines
<pre name="code" class="csharp">void Session_Start(object sender, EventArgs e)
{
    /*
     * Set the default language of the website
     * In my case it is en-CA, but you could put anything
     */
    Session["MyCulture"] = "en-CA";
}</pre>
</li>
<li>Create two links in your MasterPage.master
<pre name="code" class="csharp">&lt;asp:linkbutton
    onclick="changeCulture_Click"
    commandargument="fr-CA"
    text="Français"
    runat="server"
    id="btnSetFR"/&gt;
&lt;asp:linkbutton
    onclick="changeCulture_Click"
    commandargument="en-CA"
    text="English"
    runat="server"
    id="btnSetEN"/&gt;</pre>
</li>
<li>Add the Click Event to your MasterPage.master.cs
<pre name="code" class="csharp">    protected void changeCulture_Click(object sender,
       EventArgs e)
    {
        LinkButton senderLink = sender as
            LinkButton;

        Session["userCulture"] =
           senderLink.CommandArgument;

        Server.Transfer(Request.Path);
    }</pre>
</li>
<li>Create a new C# Class in App_Code, name it <strong>BasePage.cs</strong> and copy this code in it.
<pre name="code" class="csharp">
    public class MyPage : Page
    {
        protected override void InitializeCulture()
        {
            /*
             * Get the culture from the Sessions
             */
            string currentCulture =
                Convert.ToString(Session["userCulture"]);

            /*
             * Check if there's in a
             * culture in the Sessions
             * Otherwise, set the Default Culture
             */
            if (!string.IsNullOrEmpty(currentCulture))
                currentCulture = currentCulture;
            else
                currentCulture = "en-CA"; 

            /*
             * Apply the Culture to our thread.
             */
            Thread.CurrentThread.CurrentCulture =
                CultureInfo.CreateSpecificCulture(
                    currentCulture
                );

            Thread.CurrentThread.CurrentUICulture =
                new CultureInfo(currentCulture);

            base.InitializeCulture();
        }
    }</pre>
</li>
<li> Change the inheritance of all your web forms from Page to BasePage</li>
<li> Now all you need to do is create your Resources in GlobalResources and LocalResources Folders</li>
</ol>
<p>As I said, I learned this from an article posted on CodeProject by Michael Ulmann. If you would like to read the original article or download the source code, follow this <a href="http://www.codeproject.com/KB/locale/MasterPage_Localization.aspx">link</a></p>
]]></content:encoded>
			<wfw:commentRss>http://helios.ca/2008/08/31/cnet-localization-with-masterpage/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

