Localization fails with exe.config file

G

Guest

Hi,
in a Windows form VB.Net project I use localization for all texts.
In App.Config I added:

<appSettings>
<add key="locale" value="de"/>
</appSettings>

In the project I have ressource files strings.resx (English text) and
strings.de.resx for the German texts.

In the Main Module I use the follwowíng code:


Imports System.Configuration
Imports System.Resources
Imports System.Globalization
Imports System.Threading
.......

Friend M_LocRM As ResourceManager
Friend M_Locale As String
......

Sub Main()
M_Locale = ConfigurationSettings.AppSettings.Get("locale")

Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(M_Locale)
Thread.CurrentThread.CurrentUICulture = New CultureInfo(M_Locale)

M_LocRM = New ResourceManager("MyNamespace.Strings",
GetType(MyMainModule).Assembly)
......

For all texts I then use the GetString method of the ResourceManager M_LocRM.

This works fine, as long as I debug the project: changing the value of
'locale' in app.config from 'en' to 'de' (and vice versa) gives all the texts
in German or English like it should be.

When I install MyFunction.exe in a different folder (say c:\program
files\MyFunction) together with the config file MyFunction.exe.config it does
not work any more:

Changing the value of 'locale' in the config file has no effect, as only the
entries of the ressource file 'strings.resx' are used. Changing the locale
from 'en' to 'de' has not the effect that the entries of 'strings.de.resx'
are used.

Why? Can anybody give me some hint, as the above described implementation
works fine in any of my ASP.Net projects but not in my Windows form projects.
 
C

Cor Ligthert

Henry,

I dont, know however is this one not easier
(I dont know how it acts with multithreading for a complete application so
that you have to check)

Threading.Thread.CurrentThread.CurrentCulture = New _
Globalization.CultureInfo("en-US")

And than this one when you need to set it back in the program, what I doubt
that that is needed.
Threading.Thread.CurrentThread.CurrentCulture = _
Globalization.CultureInfo.InstalledUICulture

I hope this helps

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Henry,
When I install MyFunction.exe in a different folder (say c:\program
files\MyFunction) together with the config file MyFunction.exe.config it
does
not work any more:
Do you also remember to install the respective language DLLs to c:\program
files\MyFunction also?

You should be able to copy the folder structure under the bin folder in
VS.NET.

Hope this helps
Jay
 
C

Cor Ligthert

Henry,

I took the wrong one sorry
Threading.Thread.CurrentThread.CurrentUICulture = New
Globalization.CultureInfo("en-US")

And that than direct in the New sub

Cor
 
C

Cor Ligthert

Jay,
Do you also remember to install the respective language DLLs to c:\program
files\MyFunction also?

Edify me?

:)

I know that I can use different framework versions depending on the OS that
is used.

However language dll's?

Cor
 
J

Jay B. Harlow [MVP - Outlook]

C

Cor Ligthert

Jay,

Thanks, I did make an application which is more global, however did not use
the resx for that however an xml. (I still find the RESX a lot of work
although I have now that C# program to edit it).

But now I see what you mean with that dll.

(The links where not needed by the way, your text was enough)

Cor
 
G

Guest

Hi Jay,

that was of course the fault: I forgot to include the 'en' subfolder of the
bin folder in my setup projet ... Thanks a lot

Regards

Henry

Jay B. Harlow said:
Henry,
When I install MyFunction.exe in a different folder (say c:\program
files\MyFunction) together with the config file MyFunction.exe.config it
does
not work any more:
Do you also remember to install the respective language DLLs to c:\program
files\MyFunction also?

You should be able to copy the folder structure under the bin folder in
VS.NET.

Hope this helps
Jay
 
J

Jay B. Harlow [MVP - Outlook]

Henry,
If you are using a Setup Project to deploy your app (as opposed to coping
the files). You should add the localized resources to your setup project (as
opposed to adding the "bin/en" or "bin/de" folders directly. As this will
allow new localized languages to automatically be included in the setup!
(for example "bin/fr" for French support).

Use "Project - Add - Project Output", then select the project with the
localized resources under Project, select "Localized resources" in this list
box, and click OK. I normally include localized resources for all my
projects in a solution, even if those projects are not yet localized...

The setup project will then put create the language folders & deploy the
language dll's for you...

Hope this helps
Jay

Henry said:
Hi Jay,

that was of course the fault: I forgot to include the 'en' subfolder of
the
bin folder in my setup projet ... Thanks a lot

Regards

Henry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top