Create() public static method

public static Create ( string languageFilename ) : LanguageEntity
languageFilename string
return LanguageEntity
Example #1
0
        private void LanguageEditorMain_Load(object sender, EventArgs e)
        {
            if (LanguageEntity.DefaultLanguage == null)
            {
                MessageBox.Show("Default language not found!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }

            DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);

            foreach (FileInfo languageFile in di.GetFiles("language.??.php"))
            {
                if (!LanguageEntity.IsValidLanguageFilename(languageFile.Name))
                {
                    continue;
                }

                try
                {
                    LanguageEntity languageEntity = LanguageEntity.Create(languageFile.Name);
                    languageEntities.Add(languageEntity);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        string.Format("Cannot parse language file {0}. Error: {1}", languageFile.Name, ex.Message),
                        "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            cmbEditLanguage.Items.AddRange(languageEntities.ToArray());
            cmbEditLanguage.SelectedIndex = 0;
        }
Example #2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string lanquageName = tbNewLanguageName.Text.Trim();
            string languageId   = tbNewLanguageId.Text.ToLower().Trim();

            if (lanquageName.Length == 0)
            {
                MessageBox.Show(string.Format("Invalid language name \"{0}\".", lanquageName),
                                "Create", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                tbNewLanguageName.Focus();
                return;
            }

            if (languageId.Length != 2 || !Regex.IsMatch(languageId, "^[a-z]{2}$"))
            {
                MessageBox.Show(string.Format("Invalid language ID \"{0}\". Two characrets (a-z) expected.", languageId),
                                "Create", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                tbNewLanguageId.Focus();
                return;
            }

            if (languageEntities.Count(o => o.Id == languageId) > 0)
            {
                MessageBox.Show(string.Format("Language with a language ID \"{0}\" already exists.", languageId),
                                "Create", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                tbNewLanguageId.Focus();
                return;
            }

            string languageFilename = string.Format("language.{0}.php", languageId);

            using (StreamWriter sr = new StreamWriter(languageFilename, false, Encoding.UTF8))
            {
                string emptyLanguage = LanguageEntity.EmptyLanguagePhp.Replace("%LANGNAME%", lanquageName);
                emptyLanguage = emptyLanguage.Replace("%LANGPACKROWS%", string.Empty);
                sr.Write(emptyLanguage);
            }

            LanguageEntity languageEntity = LanguageEntity.Create(languageFilename);

            languageEntities.Add(languageEntity);
            cmbEditLanguage.SelectedIndex = cmbEditLanguage.Items.Add(languageEntity);

            MessageBox.Show("Language file successfully created.", "Create", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

            tbNewLanguageName.Text = string.Empty;
            tbNewLanguageId.Text   = string.Empty;
        }