コード例 #1
0
        /// <summary>
        /// Initialize Languaging Process for a form
        /// </summary>
        /// <param name="f"></param>
        public static void InitFormLanguage(FinOrgForm f)
        {
            try
            {
                f.ControlDefaultValues = new Dictionary <string, string>();

                foreach (Control c in f.GetAllControlChildren())
                {
                    if (c.IsTranslatableControl() && !string.IsNullOrEmpty(c.Name))
                    {
                        f.ControlDefaultValues.Add(c.Name, c.Text.Simplified(true));
                        // c.AutoSize = false;
                    }

                    // if Control is a type of ToolStrip, iterate for ToolStripItem
                    if (c.GetType().IsSubclassOf(typeof(ToolStrip)) || c.GetType() == typeof(ToolStrip))
                    {
                        foreach (ToolStripItem toolStripItem in ((ToolStrip)c).GetAllToolStripItems())
                        {
                            if (!string.IsNullOrEmpty(toolStripItem.Name))
                            {
                                f.ControlDefaultValues.Add(toolStripItem.Name, toolStripItem.Text.Simplified(true));
                            }
                        }
                    }

                    // if Control is a type of DataGridView, iterate for DataGridViewColumn
                    if (c.GetType() == typeof(DataGridView))
                    {
                        foreach (DataGridViewColumn col in ((DataGridView)c).Columns)
                        {
                            if (!string.IsNullOrEmpty(col.Name))
                            {
                                f.ControlDefaultValues.Add(col.Name, col.HeaderText.Simplified(true));
                            }
                        }
                    }

                    // if Control is TabControl
                    if (c.GetType() == typeof(TabControl))
                    {
                        foreach (TabPage p in ((TabControl)c).TabPages)
                        {
                            if (!string.IsNullOrEmpty(p.Name))
                            {
                                f.ControlDefaultValues.Add(p.Name, p.Text.Simplified(true));
                            }
                        }
                    }
                }

                // ControlDefaultValues loaded
                // LazyLoad these in Languages
                Languages.LazyLoadTranslations(f);
            }
            catch (Exception ex)
            {
            }
        }
コード例 #2
0
        public static void ApplyTranslation(FinOrgForm f)
        {
            f.RightToLeftLayout = currentLanguage == "arabic";
            f.RightToLeft       = currentLanguage == "arabic" ? RightToLeft.Yes : RightToLeft.No;
            foreach (Control c in f.GetAllControlChildren())
            {
                try
                {
                    if (c.IsTranslatableControl())
                    {
                        c.Text = Translations[f.ControlDefaultValues[c.Name]];
                    }

                    // Apply on ToolStrips
                    if (c.GetType().IsSubclassOf(typeof(ToolStrip)) || c.GetType() == typeof(ToolStrip))
                    {
                        foreach (ToolStripItem toolStripItem in ((ToolStrip)c).GetAllToolStripItems())
                        {
                            if (!string.IsNullOrEmpty(toolStripItem.Name))
                            {
                                toolStripItem.Text = Translations[f.ControlDefaultValues[toolStripItem.Name]];
                            }
                        }
                    }

                    // if Control is a type of DataGridView, iterate for DataGridViewColumn
                    if (c.GetType() == typeof(DataGridView))
                    {
                        foreach (DataGridViewColumn col in ((DataGridView)c).Columns)
                        {
                            if (!string.IsNullOrEmpty(col.Name))
                            {
                                if (!f.ControlDefaultValues.ContainsKey(col.Name))
                                {
                                    continue;
                                }
                                col.HeaderText = Translations[f.ControlDefaultValues[col.Name]];
                                if (col.GetType() == typeof(DataGridViewButtonColumn))
                                {
                                    ((DataGridViewButtonColumn)col).Text = col.HeaderText;
                                }
                            }
                        }
                    }

                    // if Control is TabControl
                    if (c.GetType() == typeof(TabControl))
                    {
                        foreach (TabPage p in ((TabControl)c).TabPages)
                        {
                            if (!string.IsNullOrEmpty(p.Name))
                            {
                                p.Text = Translations[f.ControlDefaultValues[p.Name]];
                            }
                        }
                    }

                    // Apply RTL on the following Controls
                    if (c.GetType() == typeof(Panel) || c.GetType() == typeof(GroupBox))
                    {
                        if (c.Tag == null || string.IsNullOrWhiteSpace(c.Tag.ToString()))
                        {
                            c.Tag = "english";
                        }
                        if (!c.Tag.ToString().Equals(currentLanguage))
                        {
                            // panel type, rearrage children
                            foreach (Control panel_child in c.Controls)
                            {
                                panel_child.Location = new System.Drawing.Point(c.Size.Width - panel_child.Size.Width - panel_child.Location.X, panel_child.Location.Y);
                            }
                        }
                        c.Tag = currentLanguage;
                    }
                } catch (Exception e)
                {
                    MessageBox.Show(string.Format("{0}({4}) : {1} ({2})\nKey: {5}\nMessage: {3}", f.Name, c.Name, c.GetType(), e.Message, f.GetType(), "f.ControlDefaultValues[c.Name]"), "FinOrg Langauges ApplyTranslation");
                }
            }
        }