Translating an Asp.NET site to Another Language Using .resx Files

translating the .resx files to another language does not require any programming knowledge at all

Translating a properly globalized site in is simple and does not require the least bit of development knowledge... which is good, because most developers I know barely have a grasp on their own [non-programming] language. This post should probably come after one on how to globalize your site, but I have an urgent need to explain how to do this first (someone has volunteered to translate my open-source project Slick-Ticket to Spanish; thanks Victor!).

how does it work?

First of all, you should understand how this actually works, it may make it easier. Every page in a site has access to two types of resources (when I say resources here I am referring to strings, words or phrases): Global Resources, and Local Resources - these resources are held in .resx files. Global Resources are commonly used resources that all pages can see, and Local Resources are resources that only a specific page can see. Each language/dialect has a specific code, which you can see here: Language Codes (you can see your default setting in your browser options, for IE, check Tools->Internet Options->Languages). Each page then has place-holders where it will substitute a specific language's resource if it is available. For example, if your browser's settings are set to Mexican Spanish (es-mx) and you are trying to view example.aspx, will look for the file to fill in the text. If that file is not present, it will default back down to the default resx file which is example.aspx.resx.

simple enough, how do I edit them?

.resx files are just xml files, and can be edited in a text editor, but that can be very confusing and error prone as there is no syntax and/or structure checking. I recommend you use a program such as Visual Studio if you have it, or Visual Web Developer (free) if you don't; alternatively, there are a few more options such as Mads Kristensen's .NET resource editor application for .resx files, and Resx Editor on SourceForge.

Once you have your editor, just go through and edit the column to be translated, and *ONLY* that one column, messing with the key/name field will break the translation completely.

folder structure

This is the only part that might be a bit confusing. Each folder that contains .aspx, .ascx, etc. files (files with words to be translated) will have their own App_LocalResources folder, and in this folder, there will be a corresponding *.aspx.resx file for each file. Also, any additional languages will be held in a folder with the language abbreviation, and a corresponding file for each file as well. For example, in the admin folder shown here, you can see that it has it's own App_LocalResources folder, in that folder is each corresponding default (in blue) .resx file and there is a folder for each additional language. Here you see the en-us folder (English - United States) and in that you see the same .resx file, but each is named *.en-us.resx (in red) instead of just *.resx. This is the same for each folder, so you will see many App_LocalResources folders. If you forget to change any of them, it will be pretty apparent when you run the program and a lot of stuff does not match up.

Then there is the App_GlobalResources folder in the root; the same thing applies here, just do the same and translate the value column.

Remember that will first look for your desired language, and use it if it is there, if not, it will drop down to the default.

a couple notes

A couple things to keep in mind, if you see any html markup (not the best practice, but sometimes necessary), remember this:


Also, if you see brackets with a number in them (i.e. {0}, {2}, etc.), be sure to leave those, the developer is using that as a word placeholder.

that's it

Now, as long as it is available, your users will see your site in their preferred language. It is a bit tedious to translate, but much easier than walking through the markup and screwing things up that way. Also, if a resx file is ever missing, it will not error out, it will simply use the default for any parts that are not available.
Comments are closed