none
If I export this multilingual text resource to file, how to load specific multilingual string for each control's text from file? RRS feed

  • Question

  • Dear All,

    On Windows Form, we could load multilingual for each control text by following way,

                ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
                CultureInfo cult = new CultureInfo(cultureCode);

                foreach (Control ctl in Controls)
                {
                    resourcesss.ApplyResources(ctl, ctl.Name);
                }

    If I export this multilingual text resource to file, how to load each control's multilingual from file?

    Thanks and Best regards,

    E-John

    Project File Key Comment Comment.zh-Hant .zh-Hant
    TestWinFormNeutralResLang Form1 openToolStripMenuItem.Text Open 開啟
    TestWinFormNeutralResLang Form1 saveToolStripMenuItem.Text Save 儲存
    TestWinFormNeutralResLang Form1 exitToolStripMenuItem.Text Exit 離開
    TestWinFormNeutralResLang Form1 toolStripMenuItem1.Text File 檔案
    TestWinFormNeutralResLang Form1 englishToolStripMenuItem.Text English English
    TestWinFormNeutralResLang Form1 chineseTraditionalToolStripMenuItem.Text 中文 中文
    TestWinFormNeutralResLang Form1 languageToolStripMenuItem.Text Language 語言
    TestWinFormNeutralResLang Form1 menuStrip1.Text menuStrip1
    TestWinFormNeutralResLang Form1 button1.Text button1 按鈕1
    TestWinFormNeutralResLang Form1 button2.Text button2 按鈕2
    TestWinFormNeutralResLang Form1 tabPage1.Text tabPage1 頁面1
    TestWinFormNeutralResLang Form1 label6.Text Label6
    TestWinFormNeutralResLang Form1 label5.Text Label5
    TestWinFormNeutralResLang Form1 label4.Text Label4
    TestWinFormNeutralResLang Form1 label3.Text Label3
    TestWinFormNeutralResLang Form1 label2.Text Label2
    TestWinFormNeutralResLang Form1 label1.Text Label1
    TestWinFormNeutralResLang Form1 GroupBox1.Text Culture Information
    TestWinFormNeutralResLang Form1 buttonClearRichTextBox.Text Clear 清除
    TestWinFormNeutralResLang Form1 button3.Text Dump  Langs code 列印
    TestWinFormNeutralResLang Form1 tabPage2.Text tabPage2 頁面2
    TestWinFormNeutralResLang Form1 $this.Text Form1
    TestWinFormNeutralResLang Resources\multilingual\MsgBoxStrings ErrMsg01 error message 01 錯誤訊息 01
    TestWinFormNeutralResLang Resources\multilingual\MsgBoxStrings ErrMsg02 error message 02 錯誤訊息 02


    • Edited by E-John Thursday, September 5, 2019 2:12 AM
    Thursday, September 5, 2019 1:21 AM

All replies

  • Hi E-John,

    Thank you for posting here.

    >>If I export this multilingual text resource to file, how to load each control's multilingual from file?
    First, I want to know how do you generate the file. Could you provide the related code?

    >>On Windows Form, we could load multilingual for each control text by following way,

    Second, It works well, why you load it again from resource file?

    Last but not least, I think your problem is not enough clear,so you could describe it more clearly.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 5, 2019 3:14 AM
    Moderator
  • Hi Jack,


    First, I want to know how do you generate the file. Could you provide the related code?

    >> It is exported from Visual Studio Extensions, ResXManager

    Second, It works well, why you load it again from resource file?

    >> If this is possible, then we could provide the file for User to load external multilingual UI without re-compile the code

    Last but not least, I think your problem is not enough clear,so you could describe it more clearly.

    >> My question is if reflection is possible to get the control string and load the specific language to implement a plug-in multilingual  package.

    The sequence is most like below,

    1. Get "label1" from the excel file.

    2. Get the multilingual, like "ru" from the file

    3. C# parse the string "label1" and assign the label to Russian text.

        label1.Text = "Русский"; 

    Best Regards,

    E-John


    • Edited by E-John Thursday, September 5, 2019 4:04 AM
    Thursday, September 5, 2019 4:03 AM
  • Hi E-John,

    Thanks for the feedback.

    According to your description, I have modified my code. Please check if it is suitable for you.

    Code:

            public  DataTable csvdatatable(string path)
            {
                DataTable dt = new DataTable();
                string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";" + "Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1;MAXSCANROWS=0'";
                    using (OleDbConnection conn = new OleDbConnection(connectionString))
                {
                    using (OleDbCommand comm = new OleDbCommand())
                    {
                        string sheetName = "Sheet1";
                        comm.CommandText = "Select * from [" + sheetName + "$]";
                        comm.Connection = conn;
                        using (OleDbDataAdapter da = new OleDbDataAdapter())
                        {
                            da.SelectCommand = comm;
                            da.Fill(dt);
                            return dt;
                        }
                    }
    
                }
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                comboBox1.Items.Add("chinese");
                comboBox1.Items.Add("english");
    
            }
    
            private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if(comboBox1.Text== "chinese")
                {
                    string filepath = "D:\\Export.xlsx";
                    DataTable table = csvdatatable(filepath);
                    string controlname = string.Empty;
                    foreach (DataRow item in table.Rows)
                    {
                        foreach (Control c in Controls)
                        {
                            if (item["Key"].ToString().Contains(c.Name))
                            {
                                c.Text = item[4].ToString();
                            }
                        }
                    }
                }
                if (comboBox1.Text == "english")
                {
                    string filepath = "D:\\Export.xlsx";
                    DataTable table = csvdatatable(filepath);
                    string controlname = string.Empty;
                    foreach (DataRow item in table.Rows)
                    {
                        foreach (Control c in Controls)
                        {
                            if (item["Key"].ToString().Contains(c.Name))
                            {
                                c.Text = item[3].ToString();
                            }
                        }
                    }
                }
            }

    Excel:

    Result:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by D Avik Thursday, September 5, 2019 6:23 AM
    Thursday, September 5, 2019 6:14 AM
    Moderator
  • Hi

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer. So that it will help other members to find the solution quickly if they face the similar issue.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 12, 2019 8:43 AM
    Moderator
  • Hi Jack,

    Thanks for your helps.

    In this case, there are MenuStrip controls used by Form1,

    there is another foreach loop be added to assign multilingual text to each menuStrip1.Items.

    Is it possible to get the Class type by it instance text, then use cast to assign the multilingual Text to each different instance?

    Pseudo code may be like

    ClassType t = GetFromInstanceText(Label1);

    Label1.Text = (t)item[3].ToString();

    Thanks and Best regards,

    E-John


    • Edited by E-John Thursday, September 19, 2019 3:54 AM
    Thursday, September 19, 2019 3:53 AM
  • Hi E-John,

    Thanks for the feedback.

    I want to what you want to do now if it is related to excel file.

    Do you mean that you want to read text from MenuStrip instead of excel file?

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 19, 2019 5:46 AM
    Moderator