joydip_kanjilal
Contributor

How to internationalize your application in .Net

opinion
Feb 25, 20164 mins
Software Development

Learn how to build multilingual applications in .Net by leveraging the framework's built-in support for globalization

Globalization and localization are two important concepts in .Net that help you to internationalize your applications. While globalization is the process that is used to build applications targeted at various cultures, localization is the process that is used to customize your application to provide support for a particular culture and locale.

The steps to internationalize your application in .Net include the following:

  1. Identify the localizable resources
  2. Create resource files for each locale your application needs to provide support for
  3. Read the resource data in your application wherever applicable
  4. Compile the resource files to create satellite assemblies (one for each locale your application supports)
  5. Deploy your application

To implement localization in your applications, you should take advantage of the following namespaces:

  • System.Globalization — types that are used to culture-specific information
  • System.Resources — types that are used for creating, manipulating, and using resources
  • System.Text — types that are used to represent ASCII, Unicode and ANSI character encodings
  • System.Threading — types that are used to work with multi-threading

Resource files

A resource is a piece of non-executable data that your application takes advantage of often. Typical examples of resources include locale specific strings, bitmaps, icons, cursors, etc. Such resources are stored in files known as resource files. To internationalize your application using .Net, you would need to take advantage of resource files. Resource files are used to store data specific to a particular locale. Note that resource files are XML files that can store binary information as well — the binary resources are actually base64 encoded.

Ideally, you would have a separate resource file for each locale, i.e., one resource file per locale. Typically, your application can then read data from the resource files based on the locale your application is using and then display information pertaining to that locale to the user.

Resources used for globalization in .Net can be of two types. These include the following:

  • Local resources — used by a particular Web page, i.e., such resources are Web page specific
  • Global resources — used by the entire application — all the Web pages of your application can leverage such resources

Creating resource files

You can create resource files using the Visual Studio IDE or even programmatically. To create a resource file in the Visual Studio IDE follow these steps.

  1. Open Visual Studio IDE in your system
  2. Click on File -> New -> Project to create a new web project
  3. In the Solution Explorer window, select your project and then right click on it
  4. Click Add -> New Item
  5. Select General from the list of the installed templates displayed in the window that pops up
  6. Select “Resources File” to create a file for storing the resources you need. The name of the file should indicate the locale it is targeted at
  7. Lastly, specify a name for your resource file and click OK

A new resource file would now be created and added to your project in the name you specified – the extension of this file would be .resx. When naming your resource file, you can follow any one of the following conversions:

resourcefilename.language.resx

resourcefilename.language-locale.resx

If you are creating global resources, i.e., resources that would be used by the entire application, you can place them inside the App_GlobalResources – if there isn’t one available you can just create one for you. Once your resource file has been created, you can add data in your resource file using the Resource Designer window.

To access the culture specific resources, you can leverage the System.Resources.ResourceManager class.

After you are done adding the necessary data to one or more resource files for your project, you can build your solution to generate the satellite assemblies for your project. A satellite assembly is a special type of an assembly in .Net that comprise of resources like, locale specific strings, bitmaps, icons, etc. You can also create a satellite assembly using the assembly linker command line tool Al.exe by running the Developer Command Prompt window in administrator mode. You can refer to this link for more information on this tool.

joydip_kanjilal
Contributor

Joydip Kanjilal is a Microsoft Most Valuable Professional (MVP) in ASP.NET, as well as a speaker and the author of several books and articles. He received the prestigious MVP award for 2007, 2008, 2009, 2010, 2011, and 2012.

He has more than 20 years of experience in IT, with more than 16 years in Microsoft .Net and related technologies. He has been selected as MSDN Featured Developer of the Fortnight (MSDN) and as Community Credit Winner several times.

He is the author of eight books and more than 500 articles. Many of his articles have been featured at Microsoft’s Official Site on ASP.Net.

He was a speaker at the Spark IT 2010 event and at the Dr. Dobb’s Conference 2014 in Bangalore. He has also worked as a judge for the Jolt Awards at Dr. Dobb's Journal. He is a regular speaker at the SSWUG Virtual Conference, which is held twice each year.

More from this author