Search code examples
c#.netasp.netwpfglobalization

.NET localization


I'm developing an application that supports multiple locales.

This is done through a separate dll that has a resource for each language, each resource stores the translation of a string to the specific language.

This is working just fine on a WPF application, every time a string is needed on the app, a request is made to the dll and it returns the text acording to the language selected on the app. If the language is changed the text return from the language dll reflects the change.

Now I'm creating a website in ASP.Net with MVC that uses the same language dll.

The problem is that resourcemanager on the language dll, for what I can understand, always returns the text for the system culture. I changed the cultureinfo used by the resource manager, but it doesn't work.

Does anyone have a idea on how can I solve this? Thanks

UPDATE: Sorry for the late reply. No access to the internet during the weekend... This is the first time that I have a project that uses the same dll for both web and windows and I expected the behavior to be same, but it isn't. Basically I have a global class that stores user and app settings, one of then is the current cultureinfo, when the user changes it, the language manager update is current cultureinfo variable. When I call the code to get the string the language,

resmgr.GetString(label, ci);

Where resmgr is the ResourceManager object of the language manager, ci is the cultureinfo object and label the string that I want to get, it returns the text for the label/language. I have a resx file for each culture that the project supports and one for the invariant/default In the windows app works fine, but on the web and in some unit tests that I made it doesn't, even thou I change the ci value to a new culture the result is always in the same, the string from the invariant culture. I tried to change the current thread culture and current ui culture but it didn't work

UPDATE 2: Why does the resource manager method GetResourceSet returns the correct resourceset for the culture that passing in a wpf application but the same code in unit testing or web returns the invariant resourceset. I'm missing something just don't know what it is....

UPDATE 3: Because of the us of IOC and because the language porject is not reference but copied to the folder when it finishes compiling, i found that the folders that are created for each resource weren't being copy to the unit test debug folder and to the website bin folder. I correct that and now the file are being copy but the problem persists.


Solution

  • Like i sad on update3 the fact that I wasn't copy the resources dlls for each language made that the website and unit test failed when I tried to get a label, as the resourcemanager didn't find the correct language, it would return always the invariant string associated to the label. At first the copy of the dlls didn't seem to work, but after I run "Clean Solution" and "Rebuild Solution" from visual studio the website and unit testing started to work as expected. Thanks for all the hints, those were of a big help for me, with then I was able to pin down the problem.