Localizing ASP.NET - which is best?

by Mads Kristensen 13. July 2007 06:16

There are different approaches to localizing an ASP.NET application. You can use a global resource file or local ones. The local resource files only applies to a single page or user control, whereas the global can be used from anywhere.

I’ve always used the global resource file located in the App_GlobalResources folder. I like that I can use all the text strings wherever I want. However, I have never used a local resource file for a specific page or user control for that very same reason.

Lately though, I’ve thought that the local resource file might be good for some specific scenarios. For instance if I know that a particular string is only going to be used on one specific page, then I don’t clutter the global resource file with page specific strings. However, then the information is spread over multiple files instead of just the global ones.

It reminds me about HTML style attributes and stylesheets. Is it ok to hardcode styles directly onto a page if the same style is not being implemented anywhere else? In my opinion yes, sometimes it makes sense, but I’m generally against it just like I’ve been against using local resource files.

Do you use local resources and if so, why have you chosen that instead of a global file?

* Only $4.95/month ASP.NET & Windows 2008 + IIS 7 Hosting! FREE SQL Included

Tags:

ASP.NET

Comments

7/13/2007 10:55:14 AM #

Cameron

I don't use local resource files or hard code styles into pages either, I prefer the global approach, makes things easier to maintain in the long run.

Cameron United States |

7/13/2007 3:38:48 PM #

Mads Kristensen

Exactly, but there must be a middle way or a balanced approach to the localization. Is it that black and white?

Mads Kristensen Denmark |

7/13/2007 4:13:02 PM #

Aleksey

I use both local and global resources. The reason, as I wrote you in a personal letter recently, is a difference between languages. All of the typical button texts like "Save changes" or "Next" can surely be localized using global resources. But this way doesn't suit all of the texts. I.e. the word "new" in phrases "new category" and "new site" in Russian is two different words. In such cases using local resources greatly improves maintainability and keeps my global resource file clean and simple.

Aleksey Russia |

7/13/2007 5:04:34 PM #

oVan

I would definitely recommend using both. While using Microsoft's MyWebPagesStarterKit (also on Codeplex), I've noticed that adding your own localised controls or plugins is made difficult because you have to use the global resources. With every new release you have to start merging your resource files again...

oVan Belgium |

7/13/2007 11:50:02 PM #

Mike

I use Global and select the strings thru the properties. Has anyone else noticed that the string names are NOT in alphabetical order. VERY frustrating.

Mike United States |

7/14/2007 12:37:19 AM #

Lars Hundertwasser

I use a mix of both, but mainly local resources actually. First and foremost as, Aleksey say, because there can be some differences in grammatic that makes them different. And (AFAIK) the nifty meta:resourceKey tag only applies to local resources.

But I definitely think it is up to the situation.

Lars Hundertwasser Denmark |

7/15/2007 6:59:29 PM #

NinjaCross

I only use App_GlobalResources creating in it many differently named .resx files, since every web project of mine is built of a set of decoupled modules (folders) where I place specific aspx, ascx, and so on.

In this way the typical folders structure is as follows:
WEBROOT
+- Module1
+- Module2
+- Module3
+- System
+- App_GlobalResources

In App_GlobalResources i create:
Module1.resx -> default fallback
Module1.it-IT.resx -> Italian localized resources
Module2.resx -> default fallback
Module2.it-IT.resx -> Italian localized resources
Module3.resx -> default fallback
Module3.it-IT.resx -> Italian localized resources
System.resx -> default fallback
System.it-IT.resx -> Italian localized resources

This technique is, AFAIK, much less cpu and memory intensive than the App_LocalResources one, cause for every resx file, a new assembly is generated in both cases (as stated here msdn2.microsoft.com/en-us/library/ms227427.aspx) but:
- With App_LocalResources : you have as many assemblies as pages and controls (hundreds, if the site is not absolutely small)
- With App_GlobalResources: you have a new assembly for every module, and every module assembly contains the resources for tents or hundreds pages/controls that works in the same context

NinjaCross Italy |

7/17/2007 8:55:44 PM #

Kristof

I use the same approach as NinjaCross. I also use separate global resource files for different aspects. For example, I have one for all the error message, one for all the confirmation dialogs, ...

Kristof Belgium |

7/3/2008 7:04:40 PM #

Blogging Developer

Great thanks.

Blogging Developer Turkey |

Comments are closed

About the slave

Mads Kristensen Mads Kristensen
Web developer at ZYB and founder of BlogEngine.NET. More...

LinkedIn ZYB Facebook Last.fm Twitter View Mads Kristensen's profile on Technorati

The Lounge

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008