Exemplo n.º 1
0
        /// <summary>
        /// Translate a control and its sub controls based on a language id
        /// </summary>
        /// <param name="control">control to translate</param>
        /// <param name="ressourceFile">used resource file</param>
        /// <param name="languageId">language id</param>
        public static void TranslateControls(Control control, string ressourceFile, int languageId)
        {
            string ressourceContent = ReadString(ressourceFile);

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

            ILocalizationDesign toolBoxControl = control as ILocalizationDesign;

            if ((null != toolBoxControl) && (null != toolBoxControl.Components))
            {
                foreach (System.ComponentModel.IComponent controlComponent in toolBoxControl.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))
            {
                control.Text = caption;
            }

            foreach (Control item in control.Controls)
            {
                string message = "";
                translateTable.TryGetValue(item.Name, out message);
                if (!string.IsNullOrEmpty(message))
                {
                    item.Text = message;
                }
                ForEachSubControls(item, translateTable);
            }
        }
        private void treeGridView1_SelectionChanged(object sender, EventArgs e)
        {
            RaiseSelectionChanged();
            Clear();
            if(null == _owner)
                _owner = FindOwner(this);
            _owner.StopHighLightControl1();
            _lastHightlight = null;
           
            if (treeGridView1.SelectedCells.Count > 0)
            {
                int index = treeGridView1.SelectedCells[0].RowIndex;
                TreeGridNode node = treeGridView1.Rows[index] as TreeGridNode;
                
                LocalizableCompoment component;
                component = node.Tag as LocalizableCompoment;
                if (null == component)
                {
                    if (null != (node.Parent.Tag as LocalizableCompoment))
                    {
                        string ctrlName = (node.Tag as NotifyPropertyChanged).Value;
                        if (!ctrlName.Equals("this", StringComparison.InvariantCulture))
                        { 
                            Control ctrl = Translator.TryGetControl((node.Parent.Tag as LocalizableCompoment).Design, (node.Tag as NotifyPropertyChanged).Value);
                            if (null != ctrl && tabControl1.SelectedIndex == 0)
                            {
                                _owner.StartHighLightControl1(ctrl);
                                _lastHightlight = ctrl;
                            }
                            else
                            {
                                _owner.StopHighLightControl1();
                                _lastHightlight = null;
                            }
                        }
                    }

                    component = node.Parent.Tag as LocalizableCompoment;
                    ShowStringEditor(component, node.Tag as NotifyPropertyChanged);
                }
                else
                    ShowStringEditor(null, node.Tag as NotifyPropertyChanged);

                if (null != component)
                {
                    ILocalizationDesign design = component.Design as ILocalizationDesign;
                    if (null != design)
                    {
                        design.Localize(component.ControlRessources);
                    }

                    tabPage1.Controls.Add(component.Design);
                    component.Design.Dock = DockStyle.Fill;
                    EnableInput(component.Design, false);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Translate a control an its sub controls
        /// </summary>
        /// <param name="control">target control to translate</param>
        /// <param name="strings">language items for translation</param>
        public static void TranslateControls(Control control, ItemCollection strings)
        {
            string caption = "";

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

            ILocalizationDesign toolBoxControl = control as ILocalizationDesign;

            if ((null != toolBoxControl) && (null != toolBoxControl.Components))
            {
                foreach (System.ComponentModel.IComponent controlComponent in toolBoxControl.Components.Components)
                {
                    ContextMenuStrip menuStrip = controlComponent as ContextMenuStrip;
                    if (null != menuStrip)
                    {
                        string message = "";
                        strings.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 = "";
                                strings.TryGetValue(menuItem.Name, out message);
                                if (!string.IsNullOrEmpty(message))
                                {
                                    menuItem.Text = message;
                                }
                                ForEachItems(menuItem, strings);
                            }
                        }
                    }
                }
            }

            foreach (Control item in control.Controls)
            {
                ToolStrip toolStrip = item as ToolStrip;
                if (null != toolStrip)
                {
                    string message = "";
                    strings.TryGetValue(toolStrip.Name, out message);
                    if (!string.IsNullOrEmpty(message))
                    {
                        toolStrip.Text = message;
                    }

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

            foreach (Control item in control.Controls)
            {
                string message = "";
                strings.TryGetValue(item.Name, out message);
                if (!string.IsNullOrEmpty(message))
                {
                    RichTextBox box = item as RichTextBox;
                    if (null != box)
                    {
                        box.Rtf = message;
                    }
                    else
                    {
                        item.Text = message;
                    }
                }
                ForEachSubControls(item, strings);
            }
        }