Beispiel #1
0
        private void ParseLocalizedValues(FileInfo resxFile, CultureInfo ci = null)
        {
            // Prepare LocTable
            if (ci == null)
            {
                LocTable.Columns.Add("ID");
                LocTable.Columns[0].ReadOnly = true;
                LocTable.PrimaryKey          = new DataColumn[] { LocTable.Columns.Add("Key") };
                LocTable.Columns.Add("Default");
            }
            else
            {
                LocTable.Columns.Add(ci.Name);
            }


            MatchCollection matches = null;

            using (StreamReader sr = resxFile.OpenText())
                matches = resxRegex.Matches(sr.ReadToEnd());


            int rowIndex = 0;

            foreach (Match match in matches)
            {
                if (!match.Success)
                {
                    continue;
                }

                string key   = match.Groups["key"].Value;
                string value = match.Groups["value"].Value;

                if (ci == null)
                {
                    DataRow row = LocTable.NewRow();
                    row[0] = rowIndex++;
                    row[1] = key;
                    row[2] = value;
                    LocTable.Rows.Add(row);
                }
                else
                {
                    DataRow row = LocTable.Rows.Find(key);
                    row[ci.Name] = value;
                }
            }
        }
Beispiel #2
0
        public void FindMissingLocalizations()
        {
            IsScanInactive = false;

            try {
                IList <string> keys = ParseLocalizationKeys();

                for (int i = 0; i < keys.Count; i++)
                {
                    string key = keys[i];

                    DataRow row = LocTable.Rows.Find(key);
                    if (row != null)
                    {
                        keys.RemoveAt(i--);
                    }
                }

                string       nl     = Environment.NewLine;
                DialogResult result = MessageBox.Show(
                    "Following keys are not yet localized:" +
                    nl + nl +
                    String.Join(nl, keys) +
                    nl + nl +
                    "Do you want to add them?",
                    "Missing localization keys",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning
                    );

                if (result == DialogResult.Yes)
                {
                    foreach (string missingKey in keys)
                    {
                        DataRow row = LocTable.NewRow();
                        row[0] = missingKey;

                        LocTable.Rows.Add(row);
                    }
                }
            } finally {
                IsScanInactive = true;
            }
        }