all groups > dotnet internationalization > july 2006 >
You're in the

dotnet internationalization

group:

Resource Files in .Net 2005


Resource Files in .Net 2005 Eniac0 NO[at]SPAM gmail.com
7/6/2006 9:24:27 AM
dotnet internationalization: Hello guys, I have a (small?) problem with resource files ever since I
switched to .net 2005.

in vs.net 2003, generally, i would handle resource files like so :

in the page_load event, I detect the selected language in session, then
I do a small if-then-else to select the appropriate resource file. then
I finally create a new ResourceManager based on the assembly name, file
name and language.

In vs.net 2005, I cannot load myself the resource files because I dont
know how to set the project's assembly name. so i create my
ResourceManager with something like :
objRM = New ResourceManager("myassembly.languages",
Assembly.GetExecutingAssembly())

The reason why I do it like this is that generally, in our apps, we
have a "French" or "English" button at the top of our pages, to let the
user switch languages at will. So i need a way to detect that change
and instruct .net to load a different resource file.

How would I be able to do this in Visual Studio.net 2005 ?

----------------------------
in vs.net 2003 it would look somewhat like this :
(note that this is all typed on the top of my head, there could be a
few mistakes)

private sub page_load
dim strQuerystringLang as string = Request.Querystring("lang")
dim intLang as integer = 1
dim objRM as ResourceManager

if Not (strQuerystringLang is nothing) andalso
isnumeric(strQuerystringLang) then
intLang = ctype(strQuerystringLang, integer)
else
intLang = Ctype(Session("Language"), integer)
end if

if intLang = 2 then
Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-CA")
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture("en-CA")
else
intLang = 1
Thread.CurrentThread.CurrentUICulture = New CultureInfo("fr-CA")
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture("fr-CA")
end sub

Session("Language") = intLang
objRM = New ResourceManager("myassembly.languages",
Assembly.GetExecutingAssembly())

SetLabels() 'Uses objRM to manually set all labels on the page
Re: Resource Files in .Net 2005 Michael Klingensmith
8/11/2006 12:04:07 AM
I've approached this problem differently. I've added two resource files (1
for English, 1 for French) with the Build Action set to Embedded Resource.
This becomes a strongly type resource class (in this case a class called
StringTable.. actually StringTable.fr.resx and StringTable.resx). Now you
just need to do this. Set you culture then make a call like this to get the
title in the current culture.
MyAssembly.StringTable.MyTitle

Hope this helps,
Michael Klingensmith
http://www.seeknsnatch.com

[quoted text, click to view]

AddThis Social Bookmark Button