Globalizing the carpool app

I had a question about how to internationalize the carpool app.  I ran through the exercise to try out the Globalization and Localization features of the .NET framework.  

I 1st I added a couple of resource files:


Next, I added a simple string to test:


Next, I added a reference in the markup on the site.master:

<div id="title"> <h1> <asp:Label ID="LabelMainTitle" runat="server" Text="<%$ Resources:LocalizedText, SiteTitle %>"></asp:Label> </h1> </div>

Next, I updated the web.config file:

<globalization enableClientBasedCulture="true" uiCulture="auto" />

Finally, I changed the browser settings:


And Boom goes the dynamite:


So the next step is adding the strings to the resource file…

I am using this site for translations.

A couple of random thoughts about the process:

1) ActionLink – need to refer to the class explicitly:

<ul id="menu"> <li><%: Html.ActionLink(Resources.LocalizedText.HomeTab, "Index", "Home")%></li> <li><%: Html.ActionLink(Resources.LocalizedText.PracticeTab , "Index", "Practice")%></li> <li><%: Html.ActionLink(Resources.LocalizedText.AboutTab, "About", "Home")%></li> </ul>

And I don’t know why no inteliisense from the namespace to class, but there is intliisense from the class to the property name.

2) I appreciate the split screen feature of VS2010:


3) I ran into a problem with a new HTML Helper Controls in MVC:

<%: Html.LabelFor(model => model.Date) %>

This is how it renders:


Apparently, the LabelFor does not support globalization in the view. That means I would need to add the LocalizedDisplayName attribute to each of the POCOs as recommend here OR remove the LabelFor and hand code  labels. Since I am not interested in creating something outside of the base MVC API, I split out the labels like so:

From This:

<%: Html.LabelFor(model => model.Date) %>


To This:

<%: Html.Label(Resources.LocalizedText.DateHeader)%>

After spending a couple of hours associating text to the resource files, I was done

Here is the login screen:


And the main page:



One Response to Globalizing the carpool app

  1. Rob Seder says:

    Seems like you could also create an extension method for Html called LocalizedLabelFor() which would give you the same feel, but where you could implement it the way you want. Just a thought..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: