Code 52 - a new coding project every week

Recap: i18n Packages for MVC4

Rather than boring you with the details of how this week went - it was quiet, then chaotic towards the end - I thought I'd run you through the packages you can install today and see the hard work done.

These packages are split up so that users can pull in the features that they want in their applications, but if you want to start with a new application you can get started quickly.

Warning: these packages are not yet available on the official NuGet repository. If you are feeling bold, add this feed to your NuGet Package Source settings: - this contains the latest alpha builds. These packages may drown puppies and kick kittens. Please log any and all feedback you have on the GitHub site.

PM> Install-Package Code52.i18n

The core package contains a helper class for mapping a locale code to a CultureInfo object, with additional helper methods to identify culture-related information.

This also includes a config transform to enable globalization on your website.

PM> Install-Package Code52.i18n.MVC4

PM> Install-Package Code52.i18n.MVC3

These packages extend the core and allow a user to override their current region inside your application. There are two pieces to this:

  • A LanguageController to handle requests from the browser and set a cookie value.
  • A LanguageFilterAttribute set globally to detect the cookie and set the culture for the current user to a different value.

PM> Install-Package Code52.i18n.MVC4.Example.Razor

PM> Install-Package Code52.i18n.MVC3.Example.Razor

These are the sample sites which have controllers, views and resources all ready to go. It is recommended that you install these into a Blank MVC Project as that's the scenarios we've been testing currently.

Cool features:

10 Second Introduction

A very quick walkthrough after installing the example site package. You should see a page resembling this:

Start the application and you'll see the label in the top-left with your current language.

Click on it to slide down a selector with the available languages.

Pick one and the cookie gets set, reloads the page, and displays the new language.

A special shout-out to David Christiansen who has been a great help this week with his tips and tricks like the above.

When will it be ready-ready?

We'll let you know (by pushing the packages to NuGet officially and tweeting) when its stabilised and ready for general use. We're already gathering feedback on this so hopefully later in the week we can start planning for official releases.

Note: Please read the App_Readme before diving straight in - you need to change the _ViewStart.cshtml file to point at the different template:

    Layout = "~/Views/Shared/_Layout.Code52.cshtml";

But wait, there's more?

There's a lot more to this story - we timed it when we thought we'd get a lot of interest (sadly that didn't eventuate), and I know there are people keen to get involved.

  • Pseudoizer - the build has the ability to generate test resources so you can verify the localization of a site, but we haven't got this integrated into a project.
  • DateTimeOffsetModelBinder - this has been started in a fork, but requires some polishing before we can merge it in to master.
  • NuGet - the packages are generated from a build script, and there's some things we'd like to do that require some more Powershell skills and understanding the hooks available in install.ps1. For example, pointing _ViewStart.cshtml to use a custom layout page rather than the default.
  • Support for other versions/view engines/languages.
  • Improved styles for the project templates - unfortunately the blank project templates are a bit plain...

As we had a lot of interest in this idea, and the number of features still available to implment, I hope this is just the beginning.

blog comments powered by Disqus