Last post Sep 15, 2011 06:37 AM by Boddah
Aug 14, 2011 11:57 AM|Boddah|LINK
I have a bit of a weird problem. I'm using a class library to store my different resource files, which I then use in a web application. There are 2 resource files; resources.resx and resources.nl.resx
The language is stored in a database, in a table named 'user'.
Localization locrm = new Localization(user.Language);
lblTest.Text = locrm.GetString("test");
This works perfectly fine, when I change the language in the database table, the website is translated properly.
However, when I try to do the same within the class library (for example to send automated news messages in the user's own language), the language stays English even though the localization is set to Dutch. When debugging, I can see in the quickwatch of
the locrm variable that the culture is correctly set to "nl", but the GetString method returns only English text.
The code to set the localization variable is exactly the same as on the website.
Anyone has an idea what could be the cause?
Aug 15, 2011 05:56 AM|Boddah|LINK
I think it has to do with the location of the resource files. All the files are under the folder 'Properties'. But I think that, for some reason, the Dutch file can't be found so the default language is used instead. I don't understand, however, how it works
for a website (external application) but not within the class library itself.
I must be missing something... or maybe it has to do with initializing the localization variable? Do I have to set the culture as well, besides the language?
Any help or tips would be appreciated
Aug 16, 2011 02:46 AM|Yanping Wang - MSFT|LINK
The resource files should located in App_LocalResources folder, if your change the current culture, the application will automatically find the according region.resx file .
Please refer the MSDN article:
Hope this helps, thanks.
Aug 21, 2011 08:59 AM|Boddah|LINK
Thanks for replying.
The problem is not on the web application level. The translations work fine here. I have embedded the resource files in the class library and my web application is finding the correct language.
My problem is when using the resources files within the class library itself. For example, when I want to send a weekly e-mail notification.
I created an 'Update' class with a method that loops through all users that exist in the database. For each user, I want to send the e-mail in their own language.
But this doesn't work for some reason. In the method I set the Localization variable to the users' language, but it keeps showing English texts. I don't think the folder matters, as the English resource file is in the same folder as the other files.
Sep 12, 2011 05:45 AMfirstname.lastname@example.org|LINK
Did you find a solution for this problem, as I have the same thing.
I have several unit tests which test this behavior. This unit test project contains a folder named Resources, which contains the resources in English, Dutch and French.
However, when I specify the Dutch or French culture, I always get the default English value back.
Sep 12, 2011 07:52 AMemail@example.com|LINK
I solved my problem. Seems that my unit tests did not copy the sattelite assemblies containing the resources for the different languages.
So I used the DeploymentItem attribute and specified the relative location to my sattelite assembly dll's.
Note that the relative location has to be relative to the solution folder. (So the folder containing your solution's .sln file. By default your project's source code and project file are in the same location, but they could be different)
Maybe this sheds some light on your problem?
Sep 15, 2011 06:37 AM|Boddah|LINK
I apparently solved it like this:
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(language);
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
Localization locrm = new Localization(language);