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
- Introduction (this post)
- Part 1: Basics
- Part 2: Detect Browser Settings
- Part 3: Custom Language Choice
- Part 4: CSS Styles
- Part 5: Imperative View Localization
- Part 6: Using .NET Resources
- Part 7: Model Attributes
- Part 8: Data Validation
- Part 9: 3rd Party Controls
- Part 10: Finish
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:
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
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
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
Thanks a lot!
Comment by kingphosphor — June 10, 2016 @ 9:35 am