A Localization Approach With Json Data for .NET Application

There are two approaches in localization implement in .NET development, the traditional one is using resource file, another one is based on database.

The technique of using resource to solve localization problem is very mature, it can be easily implemented by developer by using resource manager, but its maintainability is weakness, although the resource file is based on xml structure, but it is flat, no more structure meaning, and also can not find a good editor except MS Visual Studio.

For big, frequent update and complicated system, database is  better choice for localization data storage, and it’s necessary to have a powerful administration tool for localization data CRUD operation.

Json data is being more and more populate in vairious project development, and the conversion between Json and object also become convenient, the Newtonsoft.Json is a great solution for using Json data on .NET platform.

Is it possible to use json data for localization in .NET application?

The answer is positive. By using Newtonsoft.Json we can make the localization data more clean and structured, and the localization data can be edited by any text editor easily.

Let’s start with an example which is a simple APS.NET page.

1. Create a new text file with name “en.json” in /resources/ folder.

2. Define the Json data structure and localization content in en.json file.

We can define the Json structure as we want,  even more levels in data organizing  if we like.

3. Use Newtonsoft.Json to parse the Json file into object.

4. Show localization text in front page.


Tagged with: ,
Posted in ASP.NET, C#


Related Posts