C# 多语言应用程序菜单条项

C# Multilingual Application Menu Strip Item

我正在尝试使我的程序支持多语言,我几乎做到了。其余控件运行正常,但我的菜单条项出现问题。

当我在英语和土耳其语之间切换程序语言时,子菜单条项会发生变化,但主菜单项不会以某种方式发生变化。

如您所见,选择土耳其语项时,子菜单项为土耳其语,选择英语项时,子菜单项也为英语。

这是我切换语言的代码:

private void türkçeToolStripMenuItem_Click(object sender, EventArgs e)
    {
        türkçeToolStripMenuItem.Checked = true;
        ingilizceToolStripMenuItem.Checked = false;

        ChangeLanguage(typeof(MainForm), "tr");
    }

    private void ingilizceToolStripMenuItem_Click_1(object sender, EventArgs e)
    {
        ingilizceToolStripMenuItem.Checked = true;
        türkçeToolStripMenuItem.Checked = false;

        ChangeLanguage(typeof(MainForm), "en");
    }

private void ChangeLanguage(Type t, string lang)
    {
        ComponentResourceManager resources = new ComponentResourceManager(t);
        foreach (Control c in this.Controls)
        {
            resources.ApplyResources(c, c.Name, new CultureInfo(lang));
        }

        foreach (ToolStripItem item in metroContextMenu1.Items)
        {
            if (item is ToolStripDropDownItem)
                foreach (ToolStripItem dropDownItem in ((ToolStripDropDownItem)item).DropDownItems)
                {
                    resources.ApplyResources(dropDownItem, dropDownItem.Name, new CultureInfo(lang));
                }
        }
    }

您的 ApplyResources 仅应用于 dropDownItem 而不是主要 item

    foreach (ToolStripItem item in metroContextMenu1.Items)
    {
        if (item is ToolStripDropDownItem)
            foreach (ToolStripItem dropDownItem in ((ToolStripDropDownItem)item).DropDownItems)
            {
                resources.ApplyResources(dropDownItem, dropDownItem.Name, new CultureInfo(lang));
            }
        //Also apply resources to main toolstrip items. 
        resources.ApplyResources(item, item.Name, new CultureInfo(lang));
    }