Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Internationalization / January 2006

Tip: Looking for answers? Try searching our database.

Localizing non object strings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob - 30 Dec 2005 20:33 GMT
Using VS 2005 and Vb.net . If I use the default 'Resources.resx' and
associated resource class located under the My Project folder (as explained
by Garret McGowan in another thread on the subject), that does not seem to
automatically use the current UI culture. Lets say I need a 'Hello world' in
English and a "Bounjour le monde" in French in a message box.

If I extrapolate on the way it works in forms to localize object proeprties,
there I need a file MyFrm.resx for the default locale, a file Myfrm.fr.resx
for the French locale.

Do I not need to create an additional file Resources.fr.resx for the project
for use with the french locale?

If I don't, I think I would have to use a string strHW = 'Hello World' and a
string strBLM = "Bonjour le monde" in the resources.resx file and then write
code in vb to extract either strHW or strBLM from the one resource file
depending on the locale being used.

I tried to add a resouce files resources.fr.resx under the project
folder,doesn't work.

Exactly how can a file with no localization info at all (resources.resx)
help in localizing non-object strings like those used in message boxes and
error messages is unclear to me.

How does one go about localizing these messages. At first glance, it looks
like it's easier to do with a snippet of code hardcoded in the app.

Any ideas would be greatly appreciated.

Bob
Michael Höhne - 09 Jan 2006 16:17 GMT
Hi Bob,

I couldn't get this to work either but you simply create a new resource
file, say Messages.resx and enter the default strings in it. Then just copy
the file and rename it to Messages.fr.resx. Open it and replace the default
value with your french translation. In code, you will then use
Messages.HelloWorld (assuming you used HelloWorld as the name in the
resource file).

Michael

> Using VS 2005 and Vb.net . If I use the default 'Resources.resx' and
> associated resource class located under the My Project folder (as
[quoted text clipped - 28 lines]
>
> Bob
Bob - 09 Jan 2006 18:03 GMT
Thanks Michael,
Excellent idea.
For now what I had been doing was cutting and pasting the following type of
code snippets

If
System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName =
"fr" Then

Me.TblGLAccountsDataGridView.Rows(e.RowIndex).ErrorText = "A summary account
can not be used for chequing."

Else

Me.TblGLAccountsDataGridView.Rows(e.RowIndex).ErrorText = "Un compte
sommaire ne peut être utilisé pour faire des chèques."

End If

It worked OK and its rather simple to do.

I'm not sure if I'll stick to that. Your idea is interesting also.

Bob

> Hi Bob,
>
[quoted text clipped - 39 lines]
>>
>> Bob
Garrett McGowan[MSFT] - 11 Jan 2006 01:52 GMT
Hi Bob. You would need to:

1) Add your default language resource strings to the Resources.resx file
2) Make a copy of the file under the My Project folder (giving it a
culture-relevant name such as Resources.fr.resx)
3) Include the file in the project
4) Translate the strings in the target copy of the RESX file

For example, let's say you have the string:
       Console.WriteLine("Hello world!")

After adding a new name/value pair in the project's Resources.resx file for
this string, you could change the code to:
       Console.WriteLine(My.Resources.strHelloWorld)

The project-level ResourceManager object (created in Resources.Designer.vb)
would then resolve this to the correct RESX file at runtime, based on the
default CultureInfo.CurrentUICulture property value.

For testing purposes, you could create a new CultureInfo object and then
change the thread's CurrentUICulture property to match:

       Dim ci As New System.Globalization.CultureInfo("fr")
       System.Threading.Thread.CurrentThread.CurrentUICulture = ci
       Console.WriteLine(My.Resources.strHelloWorld)

The code should now load the French equivalent at runtime.

Garrett McGowan [MSFT Developer International]

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
>From: "Bob" <bdufour@sgiims.com>
>Subject: Localizing non object strings
[quoted text clipped - 32 lines]
>
>Bob
Michael Höhne - 12 Jan 2006 10:57 GMT
Hi Garrett,

indeed it works. However, it's a bit complicated, because you cannot copy
and paste the resources.resx in the IDE. The Properties folder's context
menu only contains an "Open" menu, so you have to copy it through Windows
Explorer, click the "Show all files" button in the procjet view and manually
include the new resource file. Guess that's the reason why it didn't work
for me, though it's the same concept as for any other resource file.

I will enter a suggestion for this in the Product feedback center.

Thanks
Michael

> Hi Bob. You would need to:
>
[quoted text clipped - 76 lines]
>>
>>Bob
Garrett McGowan[MSFT] - 12 Jan 2006 19:28 GMT
I'm glad to hear that you got it to work Michael. I totally agree about the
workflow - it needs some smoothing-out.

Garrett McGowan [MSFT Developer International]

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
>From: "Michael Höhne" <michael.hoehne@nospam.nospam>
>Subject: Re: Localizing non object strings
[quoted text clipped - 95 lines]
>>>
>>>Bob
Bob - 14 Jan 2006 18:54 GMT
Micheal its been a while, but I would like to share what I came up with for
localizing messages, errors and user prompts.
I created 3 separate resourve files that I simply added under my projects
default folder.
One called errors.resx. one called messages.resx and one called prompts.resx
Now when I need a specific error or message or prompt I can use My.resources
and intellisense brings up a list that contains my three resx files, I can
click on one and intellisense brings up the names of the messages in the
selected resx file. My names are pretty long and descriptive so its easy to
get the message I want. I have not yet created the errors.fr.resx files or
the others but I suppose they will go in the same folder and that I will
just have to translate the message contents leaving the message names in the
resx files as they are. If this works OK in the end its not a bad way to go.
Its just a bit hard to figure out in the first place.

By the way guys or gals, if you need translation from english to french or
vice versa. I can do that, just a bit of advertising, I know, bad boy :-)

Best regards,
Bob

> I'm glad to hear that you got it to work Michael. I totally agree about
> the
[quoted text clipped - 116 lines]
>>>>
>>>>Bob
Michael Höhne - 16 Jan 2006 11:21 GMT
Bob,

your assumption is totally correct. Create copies of the existing resx files
in the same folder and rename them to messages.fr.resx, errors.fr.resx and
prompts.fr.resx. When editing the files in the resource editor, you will
change the values, not the keys, meaning that your code is not affected by
adding new culture specific resource files. If you look at the build output,
you will notice a subdirectory called "fr", containing the compiled resource
assemblies for French. If you subsequently add more languages, there will be
additional directories. These folders must be deployed as well.

Michael

> Micheal its been a while, but I would like to share what I came up with
> for localizing messages, errors and user prompts.
[quoted text clipped - 142 lines]
>>>>>
>>>>>Bob

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.