예제 #1
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switch (LangType)
            {
            case StringsType.DeployTool:
            {
                NameValueCollection translations = new NameValueCollection();

                foreach (DataGridViewRow row in gv.Rows)
                {
                    translations.Add((string)row.Cells[0].Value, (string)row.Cells[1].Value);
                }

                ResxHandler.Save(culture.Name, translations);
            }
            break;

            default:
            {
                DataTable translations = new DataTable();

                DataColumn col0 = new DataColumn("id", Type.GetType("System.String"));
                DataColumn col1 = new DataColumn("Translated", Type.GetType("System.String"));
                DataColumn col2 = new DataColumn("PrefixTranslated", Type.GetType("System.String"));

                translations.Columns.Add(col0);
                translations.Columns.Add(col1);
                translations.Columns.Add(col2);

                foreach (DataGridViewRow row in gv2.Rows)
                {
                    translations.Rows.Add((string)row.Cells["id"].Value, (string)row.Cells["Translated"].Value,
                                          (string)row.Cells["PrefixTranslated"].Value);
                }

                XmlHandler.Save(culture.Name, culture.EnglishName, translations);
            }
            break;
            }

            ToolStripText("Your translations have been saved.");
            //MessageBox.Show("Your translations have been saved.", "MPLanguageTool -- Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
예제 #2
0
        private void openDeployToolToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LangType = StringsType.DeployTool;

            folderBrowserDialog1.Description  = "Please select a path where [MediaPortal.DeployTool.resx] can be found:";
            folderBrowserDialog1.SelectedPath = Application.StartupPath;
            folderBrowserDialog1.RootFolder   = Environment.SpecialFolder.Desktop;

            if (folderBrowserDialog1.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            languagePath = folderBrowserDialog1.SelectedPath;
            // check if selected path contains the default resx file
            defaultTranslations = ResxHandler.Load(null);

            // if not show folderbrowserdlg until user cancels or selects a path that contains it
            while (defaultTranslations == null)
            {
                MessageBox.Show(
                    "The file [MediaPortal.DeployTool.resx] could not be found.\nThe LanguageTool does not work without it.",
                    "MPLanguageTool -- Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (folderBrowserDialog1.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                languagePath        = folderBrowserDialog1.SelectedPath;
                defaultTranslations = ResxHandler.Load(null);
            }

            gv.Dock     = DockStyle.Fill;
            gv2.Dock    = DockStyle.None;
            gv2.Visible = false;

            DisableMenuItems();

            SelectCulture dlg = new SelectCulture();

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            culture = dlg.GetSelectedCulture();
            Text    = "MPLanguageTool -- Current language: " + culture.NativeName + " -- File: MediaPortal.DeployTool." +
                      culture.Name + ".resx";
            ToolStripText("Loading \"MediaPortal.DeployTool." + culture.Name + ".resx\"...");

            Cursor = Cursors.WaitCursor;
            NameValueCollection translations = ResxHandler.Load(culture.Name);
            int untranslated = 0;

            foreach (string key in defaultTranslations.AllKeys)
            {
                gv.Rows.Add(key, translations[key]);
                if (String.IsNullOrEmpty(translations[key]))
                {
                    gv.Rows[gv.RowCount - 1].Cells[0].Style.ForeColor = System.Drawing.Color.Red;
                    gv.Rows[gv.RowCount - 1].Cells[1].Style.ForeColor = System.Drawing.Color.Red;
                    untranslated++;
                }
            }
            ToolStripText(untranslated);
            saveToolStripMenuItem.Enabled = true;
            Cursor = Cursors.Default;
        }