Saturday, December 3, 2011

Localization Resource Files in ASP.NET

I have been working on a project requiring localizations for several languages. Content localization was implemented using a third party vendor and content submission and fetching is done through web services.
However, we also needed to localize several HTML templates generated by the system upon request. Since the templates text and layout is pretty much fixed, we decided to go with ASP.NET resource files.
aspnet
Now the basic concept is that you create a default resource file containing all your localized resources and then you create copies of the default resource file for the required cultures and locales. You can create resource files for general languages or specific country locales.
Most of the languages were created without issues. Later I needed to add a new resource file for a new locale, but when after adding the required resource file, I was getting the following error:
Compiler Error Message: CS0101: The namespace 'Resources' already contains a definition for ‘Templates’
This was really annoying because I was sure the resource file name was unique and the file was not duplicated. Refreshing the page sometime gave me variations of the same error, but nothing helpful.
Looking around online for answers, I found almost everybody saying that the problem was for sure that two entries in the same resource folder had the key of ‘Templates’. However, after checking several times, and deleting and re-adding the file, I got the same error message.
Suddenly I realised the true cause of the problem: the culture info suffix I was using for the new resource file was not recognized by ASP.NET and therefor the file was being seen as a duplicate.  When you add a new resource file, I was using the same ‘Template’ naming convention, followed by the culture info (in this case en-HK) and the ‘.resx’ extension. The correct culture info was actually ‘zh-HK’. Once I changed the problematic culture info, the error was gone and the app was working as expected.
Hope it helps if you get into the same annoying situation with ASP.NET resource files !
Cheers!
-arbbot

No comments:

Post a Comment