Multilingual project, does not work after installation

sn_race

Member
Joined
Feb 27, 2022
Messages
11
Programming Experience
5-10
Hello,
I developed this sample test to create a Setup project for a Multilingual WinForm application.

I used Visual Studio 2022 and .resx files to translate into three languages.

The test project has only Form1 as a user interface, so the .resx files are:

Form1.resx = Italian (default)
Form1.en.resx = English
Form1.ro.resx = Romanian

I managed the language change with:

CultureInfo ("it");
CultureInfo ("en");
CultureInfo ("ro");

And I update the components with:

this.Controls.Clear ();
InitializeComponent ();

When I start the project from Visual Studio everything works ok.
I create the Setup and only the Italian language works (default), when you change the language you see the components refresh, then the update but it does not load the selected language.

I think the default resx incorporates it into the setup project and the others don't, it's just a theory.

What could I try to solve?

Here 2 pictures to better understand:

 
Don't clear the controls. Reapply the new resources. See this StackOverflow response:

 
Don't clear the controls. Reapply the new resources. See this StackOverflow response:
Ok, many thanks,
i did as it says on StackOverflow,
if I run from Visual Studio it loads me the text of the Button and the Label but it doesn't load me all the rest, so the Text of Form1, the contents of the ComboBox and the languages for the MessageBox, after the installation on win it continues not to load anything , only the default language
 
Please post your updated code. Don't post a screenshot. Post it as text in code tags (</>).
 
You mentioned that the problem also only occurs after installation. What did you use to install your app? Did it also install all the satellite assemblies?

Anyway, have you looked at this guy's alternative approach to changing cultures on the fly?
 
Please post your updated code. Don't post a screenshot. Post it as text in code tags (</>).
Multilingual Setup Project:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Threading;
using System.Windows.Forms;

namespace Multilingual_Setup_Project
{
    public partial class Form1 : Form
    {
        private ResourceManager rm = new ResourceManager("Multilingual_Setup_Project.Form1", Assembly.GetExecutingAssembly());


        public Form1()
        {
            InitializeComponent();
        }

        private void CmbLang_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (CmbLang.SelectedIndex)
            {
                case 0:
                    SetCulture("it");
                    break;
                case 1:
                    SetCulture("en");
                    break;
                case 2:
                    SetCulture("ro");
                    break;
            }
        }

        private void BtmMessage_Click(object sender, EventArgs e)
        {
            string MsgBoxTit = rm.GetString("MsgBoxTit", CultureInfo.CurrentCulture);
            string MsgBoxText = rm.GetString("MsgBoxText", CultureInfo.CurrentCulture);

            MessageBox.Show(MsgBoxText, MsgBoxTit, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public void SetCulture(string cultureName)
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(cultureName);

            var resources = new ComponentResourceManager(this.GetType());

            GetChildren(this).ToList().ForEach(c => {
                resources.ApplyResources(c, c.Name);
            });
        }
        public IEnumerable<Control> GetChildren(Control control)
        {
            var controls = control.Controls.Cast<Control>();

            return controls.SelectMany(ctrl => GetChildren(ctrl)).Concat(controls);
        }
    }
}

I have attached the project I am testing
 

Attachments

  • Multilingual Setup Project.zip
    571.6 KB · Views: 60

Latest posts

Back
Top Bottom