예제 #1
0
        /// <summary>
        /// Translate tutorial form controls
        /// </summary>
        /// <param name="form">target form to translate</param>
        /// <param name="ressourceFile">resource file adress</param>
        public static void TranslateControls(TutorialForm form, string ressourceFile)
        {
            int languageId = FormOptions.LCID;

            string ressourceContent = ReadString(ressourceFile);

            string[] splitArray = ressourceContent.Split(new string[] { "[End]" }, StringSplitOptions.RemoveEmptyEntries);
            Dictionary <string, string> translateTable = GetTranslateRessources(splitArray, languageId);

            if (null != form.Components)
            {
                foreach (System.ComponentModel.IComponent controlComponent in form.Components.Components)
                {
                    ContextMenuStrip menuStrip = controlComponent as ContextMenuStrip;
                    if (null != menuStrip)
                    {
                        string message = "";
                        translateTable.TryGetValue(menuStrip.Name, out message);
                        if (!string.IsNullOrEmpty(message))
                        {
                            menuStrip.Text = message;
                        }

                        foreach (ToolStripItem unkownItem in menuStrip.Items)
                        {
                            ToolStripMenuItem menuItem = unkownItem as ToolStripMenuItem;
                            if (null != menuItem)
                            {
                                message = "";
                                translateTable.TryGetValue(menuItem.Name, out message);
                                if (!string.IsNullOrEmpty(message))
                                {
                                    menuItem.Text = message;
                                }
                                ForEachItems(menuItem, translateTable);
                            }
                        }
                    }
                }
            }

            string caption = "";

            translateTable.TryGetValue("this", out caption);
            if (!string.IsNullOrEmpty(caption))
            {
                form.Text = caption;
            }

            foreach (Control item in form.Controls)
            {
                string message = "";
                translateTable.TryGetValue(item.Name, out message);
                if (!string.IsNullOrEmpty(message))
                {
                    item.Text = message;
                }
                ForEachSubControls(item, translateTable);
            }
        }
예제 #2
0
        public static void TranslateControls(TutorialForm form, string ressourceFile)
        {
            int languageId = FormOptions.LCID;

            string ressourceContent = ReadString(ressourceFile);
            string[] splitArray = ressourceContent.Split(new string[] { "[End]" }, StringSplitOptions.RemoveEmptyEntries);
            Dictionary<string, string> translateTable = GetTranslateRessources(splitArray, languageId);

            if (null != form.Components)
            {
                foreach (System.ComponentModel.IComponent controlComponent in form.Components.Components)
                {
                    ContextMenuStrip menuStrip = controlComponent as ContextMenuStrip;
                    if (null != menuStrip)
                    {
                        string message = "";
                        translateTable.TryGetValue(menuStrip.Name, out message);
                        if (!string.IsNullOrEmpty(message))
                            menuStrip.Text = message;

                        foreach (ToolStripItem unkownItem in menuStrip.Items)
                        {
                            ToolStripMenuItem menuItem = unkownItem as ToolStripMenuItem;
                            if (null != menuItem)
                            {
                                message = "";
                                translateTable.TryGetValue(menuItem.Name, out message);
                                if (!string.IsNullOrEmpty(message))
                                    menuItem.Text = message;
                                ForEachItems(menuItem, translateTable);
                            }
                        }
                    }
                }
            }

            string caption = "";
            translateTable.TryGetValue("this", out caption);
            if (!string.IsNullOrEmpty(caption))
                form.Text = caption;

            foreach (Control item in form.Controls)
            {
                string message = "";
                translateTable.TryGetValue(item.Name, out message);
                if (!string.IsNullOrEmpty(message))
                    item.Text = message;
                ForEachSubControls(item, translateTable);
            }

        }