Groups | Blog | Home
all groups > dotnet internationalization > january 2006 >

dotnet internationalization : Localization using text files in VS2005


Mike Leftwich
1/27/2006 4:59:26 PM
I've created a very simple test app with WinForms to learn how to use
localization in .NET. The app simply has a button that displays a MessageBox
with a message retrieved from ResourceManager.GetString. Here's the code:

private ResourceManager rm =
ProdRegTest.Properties.Resources.ResourceManager;
private void button2_Click(object sender, EventArgs e)
{
string msg = rm.GetString("IDS_MSG");
MessageBox.Show(msg);
}

I added a text file resource to my project in the project properties dialog,
then entered a single line like the following:

IDS_MSG = Hello world

When I run the program, the message box is displayed with a null string
instead of "Hello world".

I have verified that VS creates the .resources file in the obj\debug
directory, and I've looked at the .exe in a hex editor and can see the string
resource embedded in the executable, but for some reason the call to
GetString is returning a null string.

I've tried this now in 2 different projects, with the same result. I'm sure
I must be doing something really dumb, but I can't see what it might be.

Thanks in advance.

Michael Höhne
1/29/2006 1:20:14 AM
If you're not somehow limited to using text files, please see the discussion
"Localizing non object strings" in this newsgroup. It describes how to use
resource files and localize them in VS.NET 2005, and I guarantee that it
works and is much easier to use.

Michael

--
Michael
http://www.stunnware.com/crm
----------------------------------------------------------
"Mike Leftwich" <Mike Leftwich@discussions.microsoft.com> schrieb im
Newsbeitrag news:869849AE-AEA1-4758-AC55-64B534C65F1C@microsoft.com...
[quoted text, click to view]

Mike Leftwich
1/29/2006 5:00:27 PM
I have a strong preference for using text files. Other modules of this
application are written in Java, and the resource file formats are very
similar. We plan to share most of the resources to economize on translation
costs. So I would really like to get the text file method to work if at all
possible.

Thanks for your response!

Mike

[quoted text, click to view]
marinm NO[at]SPAM online.microsoft.com
2/2/2006 8:49:38 PM
You can use and compile the text format in VS2005 using some special steps.
Add a new text file, set the file extension to ".restext". Select the
file in the Solution Explorer, and set the Build Action to Embedded
Resource in the properties window.
Now you can access the string using the ResourceManager, something like
below:
ResourceManager rm2 = new ResourceManager("LocalizationSample.TextFile1",
Assembly.GetExecutingAssembly());
MessageBox.Show(rm2.GetString("mystring"));
Hope this helps,
Marin Millar [MSFT]

Mike Leftwich
2/3/2006 7:55:04 PM
Marin,

Ok, that worked. But I'm a little baffled as to why it worked. I tried
doing all the same steps except for changing the file extension, and it's
clear that changing the file extension is required. It doesn't work if the
extension is .txt. However, all the help topics refer to naming the file
..txt, and the IDE names it with .txt if you create a new text file in the
resource editor. In fact, after changing the file extension to .restext the
IDE shows the file with a generic icon and if you try to open the text file
in the resource editor it displays a dialog box that says, "The Managed
Resource Editor does not support the requested file type. Would you like to
open the default editor for <filename>?"

Am I mistaken in thinking that something is broken here?

Thanks for your help.

Mike

[quoted text, click to view]

AddThis Social Bookmark Button