AJ's blog

November 8, 2013

ASP.NET MVC Internationalization

Filed under: ASP.NET MVC, Internationalization — ajdotnet @ 8:13 am

Internationalization and localization of web applications is a regular demand and by no means something exotic or rarely required. Speaking specifically of Line-of-Business (LOB) applications built on ASP.NET MVC there is even plenty of information available, e.g starting here or simply by issuing a bing search.

Actually doing localization in my web application proved to be… . Well, not as simple as some blog posts and tutorials try to sell it.

The problem is not that the information is not there, or that it is overly complex. It’s just rather fragmented, and even the well documented aspects often miss some crucial details. What I could not find is a complete guide to all aspects of localizing my web application.

Well, luckily for you, this is what I’m trying to accomplish here…

To get it out of the way: “Internationalization” (a.k.a. i18n) provides the basic plumbing to be able to support different languages and regions, while “localization” provides the necessary information for a particular language and region. Two sides of the same coin, actually.

Further details can be found here.

Here is what it takes…

TOC

 

Playing field

For this endeavor let’s provide our playing field: I have a simple business contract for maintaining some stock information, and a (simplistic) implementation to maintain the data in a database. Here’s the contract:

[DebuggerDisplay("BusinessContract.Stock: {ID} {Isin} {Name} {Price} {Date}")]
public class Stock
{
    public int ID { get; set; }
    /// <summary>
    /// http://en.wikipedia.org/wiki/International_Securities_Identification_Number  
    /// 12-character alpha-numerical code
    /// </summary>
    public string Isin { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
    public DateTime Date { get; set; }
}

public interface IStockService
{
    Stock[] GetAllStocks();
    Stock GetStock(int id);
    void UpdateStock(Stock stock);
}

With that in mind, creating an MVC4 intranet application, with respective controller actions is quite simple, and offering a simple list view, details view, and an edit view is just point-and-click using the "new controller/view" features in Visual Studio. Add some styling and it looks like this:

Initial Application

Then I realize: I am actually German, and I would like to be greeted as such – and  please not in some halfhearted fashion, I want every aspect to be addressed: Labels, data formats, and so on.

We’ll get there, Next couple of post…

That’s all for now folks,
AJ.NET

Advertisement

3 Comments »

  1. Hi,AJ.Thanks for your series.I am a beginner using the ASP.Net MVC framework. This series is helpful to me. But it’s still too difficult to understand some detail for me. So, would you mind giving me a copy of the code for this series? Thanks very much!
    BTW , sorry for my poor English.

    Comment by kingphosphor — June 9, 2016 @ 11:59 am

  2. Hi,
    thanks for the feedback.
    The code is available on github: https://github.com/ajdotnet/mvc-localization
    HIH,
    AJ.NIT

    Comment by ajdotnet — June 10, 2016 @ 6:34 am

  3. Thanks a lot!

    Comment by kingphosphor — June 10, 2016 @ 9:35 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: