Ejemplo n.º 1
0
        /// <summary>
        /// Set the display words.
        /// </summary>
        /// <param name="lang">The language instance.</param>
        private void SetMenuDisplay(LanguageClass lang)
        {
            if (lang == null)
            {
                return;
            }

            this.Text = lang.Title;
            this.lblTime.Text = lang.GameTime;
            this.txtTime.Left = this.lblTime.Left + this.lblTime.PreferredWidth;
            this.lblFoodCount.Text = lang.FoodEaten;
            this.lblFoodCount.Left = this.txtTime.Left + this.txtTime.Width + 6;
            this.txtFoodCount.Left = this.lblFoodCount.Left + this.lblFoodCount.PreferredWidth;
            this.lblScore.Text = lang.Score;
            this.lblScore.Left = this.txtFoodCount.Left + this.txtFoodCount.Width + 6;
            this.txtScore.Left = this.lblScore.Left + this.lblScore.PreferredWidth;

            this.toolStripMenu_Game.Text = lang.Game;
            this.toolStripMenu_NewGame.Text = lang.NewGame;
            this.toolStripMenu_Pause.Text = this.tmrForward.IsStopped ? lang.Play : lang.Pause;
            this.toolStripMenu_Save.Text = lang.Save;
            this.toolStripMenu_Restore.Text = lang.Restore;
            this.toolStripMenu_Exit.Text = lang.Exit;
            this.toolStripMenu_Set.Text = lang.Settings;
            this.toolStripMenu_Language.Text = lang.Language;
            foreach (ToolStripMenuItem item in this.toolStripMenu_Language.DropDownItems)
            {
                if (item.Name.IndexOf(lang.CultureInfoName) >= 0)
                {
                    item.Checked = true;
                }
                else
                {
                    item.Checked = false;
                }
            }

            this.ToolStripMenu_Help.Text = lang.Help;
            this.toolStripMenu_UpdLog.Text = lang.Log;
            this.toolStripMenu_About.Text = lang.About;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Read language config file into a LanguageClass instance.
        /// </summary>
        /// <param name="lang">The LanguageClass to read into.</param>
        /// <param name="filePath">language config file's full path</param>
        private void ReadInTheLanguageInfo(LanguageClass lang, string filePath)
        {
            if (lang == null || string.IsNullOrEmpty(filePath))
            {
                MessageBox.Show("Language File read error!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                return;
            }

            XmlDocument doc = new XmlDocument();
            doc.Load(filePath);

            XmlNode langNode = doc.SelectSingleNode("language");
            lang.CultureInfoName = ((XmlElement)langNode).GetAttribute("CultureInfo");
            XmlNodeList nodes = langNode.ChildNodes;

            Type t = lang.GetType();
            foreach (XmlNode item in nodes)
            {
                t.GetProperty(item.Name).SetValue(lang, item.InnerText);
            }
        }