views:

2403

answers:

2

Hello,

I have added multi-language using the short article below.

When you add for example German language you will have these files: formMain.resx formMain.de-DE.resx formMain.Designer.cs formMain.cs

In first file you will have resources for neutral language, like strings, images, ..

So now you need to add also resources for strings used in code. Add a new resource file and name it formMain.Strings.resx Then i will enter name, value pair for every string that should be translated. When you add resource file then it is automatically typed because another file with name formMain.Strings.Designer.cs is automatically regenerated on every close of resx designer.

Add another resource with name formMain.Strings.de-DE.resx. Add the same Name key's from previous resource, and just change the Value with coresponding german words. Now to access created resource from the source it will be like this.

MessageBox.Show(formMain_Strings.SameStringName);

However, I have changed my to Thai language. Everything works fine when I run my app in VS.

However, as soon as I add a setup project and install on the clients machine it won't change the language to Thai and just keeps to the default language.

So I have added the resource files and the th-TH dll to the project setup. And I still get the same problem.

Packaging file 'Lang.Strings.resx'...
Packaging file 'MultiLanguage.resources.dll'...
Packaging file 'MultiLanguage.exe'...
Packaging file 'Lang.Strings.th-TH.resx'...

As everything works fine when running in visual studio. Is there something I need to do to get it to run once its been installed. All the properties for each of the file I have keep the default.

Many thanks,

=========

static void Main()
    {
        System.Threading.Thread.CurrentThread.CurrentUICulture = 
new System.Globalization.CultureInfo("th-TH");

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
+1  A: 

Try adding in this at the app's startup (if it's not there):

Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentCulture;

Here is a short article discussing some of the options of how to make this work, and options for selecting the locale at runtime.


Edit after comments:

Make sure your satellite assembly is in the appropriate place, and built correctly. From that article I referenced:

"When .NET runtime starts an application it looks for a possible satellite assembly file. A satellite assembly file is a resource only assembly file that has .resources.dll extension instead of .exe ir .dll (if the main assembly is a library). Satellite assembly files always locate on a language specific sub directory of the applciation's main directory. If application file is Converter.exe then the Japanese satellite assembly file is ja\Converter.resources.dll."

There are a few things that you should check here. Check the name of the assembly. Also, make sure it's in the proper location. In your case, it should be in a th-TH subdirectory with the appropriate name under your executable. If it's there, it should be found and used properly.

Here is another good source of information about this topic.

Reed Copsey
Hello. I have this already added to my forms load event. Everything works ok in visual studio. Only when I install on the client's computer.public Form1() { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("th-TH"); InitializeComponent(); }
robUK
Try moving it to your Main() routine, before you load your form. I believe having it at form_load is too late... at that point, the assemblies have already been loaded and chosen.
Reed Copsey
Hello. I have removed it from the form_load and put it in my main. However, it works in visual studio. But as soon as I install on the clients computer it just displays the default language and not the Thai. In my first post I added my resource files and resource.dll. Should I be doing that?
robUK
I have updated my first post with my most recent changes.
robUK
You say it works in VS - does it work on your system, in release mode, if run outside of VS?
Reed Copsey
Yes, I have installed on my machine and also the clients. I have compiled in both debug and release mode. I have also installed both on my and the client's computer. However, it always displays in default language.
robUK
Do I need to add something to the setup? Or do I need to change some of the properties for my resource files or dll?
robUK
Edited my answer with more details for you
Reed Copsey
+1  A: 

Hello,

I found the answer

Click the Setup Project in Solution Explorer and then click Add\Project Output\ . From dialog select the project for which you want to include localization (satelite) assemblies and then select Localized resources.

After the installation in the folder that I install to, I have the th-TH folder which includes the satellite assembly.

Thanks,

robUK
If I may, you're better off ditching Setup Project as soon as humanly possible and switching to Windows Installer XML (WiX). I shipped a product using a setup project once. Never again. Never, ever again.
Promit