Last post Nov 07, 2007 02:58 PM by Escovado
Nov 06, 2007 08:08 PM|Escovado|LINK
OK, I have a beginner question regarding the globalization of my string resources.
I created a resource file in VS 2005 that has a bunch of my UI message strings. The file is located in App_GlobalResources\Resources.resx. The only apparent way I can access these resource strings is using hard-coded C#. For example:
Resources.Resources.ErrNonExistentAccount will retrieve the string resource named "ErrNonExistentAccount" in the Resource.resx file. The compiler apparently uses the .resx file to generate a namespace called "Resources" with a class named after
the resource file containing a bunch of static string variables named after the resource names in my Resources.resx file. That is not what I want.
I have combed through my ASP .Net and C# books and also searched the web, but everything I have found either dosen't work or does not do what I need: I would like to programatically open a specific resource file depending on what language (CultureInfo)
the site (or thread) is running and get the resource string message for that language. Can anyone here give this confused noob a clue how to do this? [*-)]
Nov 06, 2007 08:23 PM|juneof44|LINK
You will end up calling the same class and properties in your code, but if you set everything up propertly, the call may not always fetch from the same resource file.
Read this QuickStart about
Internationalization and see if it doesn't answer your questions.
Nov 07, 2007 02:58 PM|Escovado|LINK
That tutorial led me to the information I needed.
The global resource files go in the "App_GlobalResources" folder. If my default resource file is called "resources.resx," then the culture-specific files have the culture string inserted before the extension. For example:
If the name of my default resource file is the same and, for example, I want to get a string from the resource file named "ErrorMessage" then the system call used is like so:
string result = (string)HttpContext.GetGlobalResourceObject("resources", "ErrorMessage", Thread.CurrentThread.CurrentCulture);
The string resource will be retrieved from the file with the matching CultureInfo value from "Thread.CurrentThread.CurrentCulture." If no resource file matches the given CultureInfo, then the string from the default "resources.resx" file will be used.
I was spinning my wheels most of the afternoon yesterday looking at all these sattlelite assemblies and such. When you're new to a programming language and framework, 3/4 of the battle is just finding the right information source. Thanks. [Yes]