HighTechTalks DotNet Forums  

Problem Adding and Using Resource Files

Dotnet Internationalization microsoft.public.dotnet.internationalization


Discuss Problem Adding and Using Resource Files in the Dotnet Internationalization forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
TCook
 
Posts: n/a

Default Problem Adding and Using Resource Files - 11-08-2006 , 01:51 PM






Hey All,

I am building a solution which will have many strings that will need to be
localized (i.e. strings for toolbars, strings for different WinForms,
strings for messages and error messages, etc.).

I am having trouble accessing string file resources.

What I want to do is to break out strings into separate files so that they
are easier to manage and such that I don't have to look through hundreds to
find, edit or delete something.

How can I use code similar to that below:

Dim rm As ResourceManager
Dim Message as StringBuilder

rm = New ResourceManager("StringTable", Me.GetType().Assembly)

Message = New StringBuilder()
Message.Append(rm.GetString("String1"))
Message.Append(rm.GetString("String2"))
MessageBox.Show(Message.ToString())

Right now, when I try the above I get an error claiming that such resources
cannot be found. The text file is listed under the resources. What's
wrong?

Am I missing something in regards to the structure of the text file or
perhaps how it is added?

Please advise.

Thanks,

TC



Reply With Quote
  #2  
Old   
Larry Smith
 
Posts: n/a

Default Re: Problem Adding and Using Resource Files - 11-08-2006 , 03:32 PM






Quote:
Am I missing something in regards to the structure of the text file or
perhaps how it is added?
I assume you're using Visual Studio (?). If so then are you aware that it
already has a built-in mechanism to handle strings for you (with relatively
little work on your part)?




Reply With Quote
  #3  
Old   
TCook
 
Posts: n/a

Default Re: Problem Adding and Using Resource Files - 11-08-2006 , 06:42 PM



Hey Larry,

As I mentioned in the original post, I am using the stings available under
"Resources".

What I am asking for is a way to segregate these strings into intelligent
collections probably via separate files.

That said, how can I load and use separate resource files into the list of
resources?

How can I use code similar to that below:

Dim rm As ResourceManager
Dim Message as StringBuilder

rm = New ResourceManager("StringTable", Me.GetType().Assembly)

Message = New StringBuilder()
Message.Append(rm.GetString("String1"))
Message.Append(rm.GetString("String2"))
MessageBox.Show(Message.ToString())

Regards,

TC


"Larry Smith" <no_spam (AT) _nospam (DOT) com> wrote

Quote:
Am I missing something in regards to the structure of the text file or
perhaps how it is added?

I assume you're using Visual Studio (?). If so then are you aware that it
already has a built-in mechanism to handle strings for you (with
relatively little work on your part)?




Reply With Quote
  #4  
Old   
Larry Smith
 
Posts: n/a

Default Re: Problem Adding and Using Resource Files - 11-09-2006 , 11:34 AM



Quote:
Hey Larry,

As I mentioned in the original post, I am using the stings available under
"Resources".

What I am asking for is a way to segregate these strings into intelligent
collections probably via separate files.

That said, how can I load and use separate resource files into the list of
resources?

How can I use code similar to that below:

Dim rm As ResourceManager
Dim Message as StringBuilder

rm = New ResourceManager("StringTable", Me.GetType().Assembly)

Message = New StringBuilder()
Message.Append(rm.GetString("String1"))
Message.Append(rm.GetString("String2"))
MessageBox.Show(Message.ToString())
What I was alluding to is that you don't need to do this (or rather you're
probably making your life more difficult). First, ".resx" files for forms
are handled automatically by VS (referring to all strings that appear on
your forms for instance). If you're not aware of the details please let me
know (it seems that way). For other resources like error messages and so
forth, go to Solution Explorer and right-click your project's node. Select
"Properties" from the context menu and click "Resources" on the left-hand
side. A table now appears where you can enter all (non-form) resources which
are usually strings (you may have to click on the notice in the middle of
the window first if there is one - it will be present if it's the first time
doing this). VS then creates a wrapper class called "Resources" where you
can now access any single resource (string or whatever) via the
<YourProjectNamespace>.Properties.Resources.<Resou rceName> static property
(a "using <YourProjectNamespace>.Properties" statement is required in each
source file of course). For instance, if you add "MyString=Whatever" to the
table and your project's namespace is "YourProjectNamespace", you can do
this:

using YourProjectNamespace.Properties;
// ...
string MyString = Resources.MyString;

You can access all resources this way, not just strings.




Reply With Quote
  #5  
Old   
TCook
 
Posts: n/a

Default Re: Problem Adding and Using Resource Files - 11-09-2006 , 01:13 PM



Hey Larry,

Yes, I am already using the catch-all resources file and I'm also using the
resource files exposed to userforms.

My question is, if I want to, how can I break the strings in the catch-all
resource out into separate files?

Regards,

Todd



"Larry Smith" <no_spam (AT) _nospam (DOT) com> wrote

Quote:
Hey Larry,

As I mentioned in the original post, I am using the stings available
under "Resources".

What I am asking for is a way to segregate these strings into intelligent
collections probably via separate files.

That said, how can I load and use separate resource files into the list
of resources?

How can I use code similar to that below:

Dim rm As ResourceManager
Dim Message as StringBuilder

rm = New ResourceManager("StringTable", Me.GetType().Assembly)

Message = New StringBuilder()
Message.Append(rm.GetString("String1"))
Message.Append(rm.GetString("String2"))
MessageBox.Show(Message.ToString())

What I was alluding to is that you don't need to do this (or rather you're
probably making your life more difficult). First, ".resx" files for forms
are handled automatically by VS (referring to all strings that appear on
your forms for instance). If you're not aware of the details please let me
know (it seems that way). For other resources like error messages and so
forth, go to Solution Explorer and right-click your project's node. Select
"Properties" from the context menu and click "Resources" on the left-hand
side. A table now appears where you can enter all (non-form) resources
which are usually strings (you may have to click on the notice in the
middle of the window first if there is one - it will be present if it's
the first time doing this). VS then creates a wrapper class called
"Resources" where you can now access any single resource (string or
whatever) via the
YourProjectNamespace>.Properties.Resources.<Resour ceName> static property
(a "using <YourProjectNamespace>.Properties" statement is required in each
source file of course). For instance, if you add "MyString=Whatever" to
the table and your project's namespace is "YourProjectNamespace", you can
do this:

using YourProjectNamespace.Properties;
// ...
string MyString = Resources.MyString;

You can access all resources this way, not just strings.




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.