Localization in C# using Resource (.resx) file

Foridul Islam
3 min readSep 29, 2020

--

Localization is all about developing our software application so that anyone in any region of the world can use the application in their native language. Localization makes our software open for all people of any or specified languages. To make it possible, sometimes we need to localize from the backend. If you are a C# developer, and if you need to implement your localization in C# code, then this will be helpful for you.

Localization in C# is not difficult but sometimes it takes time to implement. Because there are several ways to implement it, you need to use a suitable way to do it. In this article, I will try to show an easy way to implement it in C# code.

There are several steps to implement localization in C# using resource files.

  1. Create a new .NET standard project with the name i18N (or any name you prefer).
  2. Right-click on your project and add a new Resource file (.resx) by doing the following: Select Add > New Item, then pick Resource file and name it resources.resx

3. Double-click on resources.resx file and click Add Resource and add your keys with values. You can also make Access Modifier as Public if you want to make it global. Finally, save your resource.resx file.

4. The resource.resx file is the default resource file. Now you need to add a language-specific resource file with language code. Then add another Resource file with the name resource.de.resx for German language support and add Keys with Values. In this way, you can add your all Resource files with these naming conventions like resource.fr.resx, resource.it.resx, and so on.

5. Now, to get access to any value for a key in a specific language: The following code will print the LANGUAGE value for the “de-DE” language.

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(“de-DE”);

var LANGUAGE = resource.LANGUAGES;

Console.WriteLine(LANGUAGE);

This will show because it automatically generates the resource for the culture and gives it to you. If you need more language support then you need to create more Resource files with naming like other Resource files.

Summary

If you face any problem in generating resources, then you can find help here. Access Modifier should be Public to generate resource class. There you don’t need to create any class because it automatically generates a class like resource.Designer.cs

Leave a comment if you enjoy the read.

--

--

Foridul Islam
Foridul Islam

Written by Foridul Islam

Sr. Software Engineer at SELISE Digital Platforms

No responses yet