Exemple #1
0
        public static List <TranslateUnit3RD> ParseTranslateUnits(string xmlunits)
        {
            List <TranslateUnit3RD> result = new List <TranslateUnit3RD>();

            if (xmlunits == null || !xmlunits.Contains("<GlobalSightPE "))
            {
                return(result);
            }

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlunits);

            XmlNodeList nodes = doc.GetElementsByTagName("TranslateUnit");

            if (nodes != null && nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    int    lineNumber = Int32.Parse(node.Attributes["lineNumber"].Value);
                    string category   = node.Attributes["category"].Value;
                    string content    = node.InnerText;

                    TranslateUnit3RD u = new TranslateUnit3RD(lineNumber, category, content, content);
                    result.Add(u);
                }
            }

            return(result);
        }
Exemple #2
0
        private void DoExtract(List <TranslateUnit3RD> result, string[] lines, TranslateUnitType type, List <TranslateUnit> resultSelf)
        {
            if (lines == null || lines.Length == 0)
            {
                return;
            }

            for (int i = 0; i < lines.Length; i++)
            {
                string line       = lines[i];
                int    lineNumber = i + 1;
                string lineTrimed = line.Trim();

                switch (type)
                {
                case TranslateUnitType.MenuType:
                    if (lineTrimed.StartsWith("POPUP") || lineTrimed.StartsWith("MENUITEM"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null && si.content != null && si.content.Length > 0 && si.content.Trim().Length > 0)
                        {
                            TranslateUnit3RD tu = new TranslateUnit3RD(lineNumber, "menu", si.content, si.content);

                            result.Add(tu);
                        }
                    }
                    break;

                case TranslateUnitType.StringType:
                    if (lineTrimed.Contains(startChar) && lineTrimed.Contains(endChar))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null && si.content != null && si.content.Length > 0 && si.content.Trim().Length > 0)
                        {
                            TranslateUnit3RD tu = new TranslateUnit3RD(lineNumber, "string", si.content, si.content);

                            result.Add(tu);
                        }
                    }
                    break;

                case TranslateUnitType.DialogType:
                    if (lineTrimed.StartsWith("CAPTION") || lineTrimed.StartsWith("CONTROL"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null && si.content != null && si.content.Length > 0 && si.content.Trim().Length > 0)
                        {
                            TranslateUnit3RD tu = new TranslateUnit3RD(lineNumber, "dialog", si.content, si.content);

                            result.Add(tu);
                        }
                    }
                    break;

                case TranslateUnitType.VersionType:
                    if (lineTrimed.StartsWith("VALUE"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 3);

                        if (si != null && si.content != null && si.content.Length > 0 && si.content.Trim().Length > 0)
                        {
                            TranslateUnit3RD tu = new TranslateUnit3RD(lineNumber, "version", si.content, si.content);

                            // set id for version
                            StringIndex siID = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);
                            if (siID != null && siID.content != null && siID.content.Length > 0)
                            {
                                tu.Id = siID.content;

                                TranslateUnit tuSelf = TranslateUnitUtil.GetTranslateUnit(resultSelf, "RT_VERSION", tu.Id);
                                if (tuSelf != null)
                                {
                                    tu.SourceContent = tuSelf.SourceContent;
                                    tu.TargetContent = tuSelf.SourceContent;
                                }
                            }

                            result.Add(tu);
                        }
                    }
                    break;
                }
            }
        }
Exemple #3
0
        private void DoMerge(string[] lines, List <TranslateUnit3RD> units, TranslateUnitType type, bool addChar, string specialChar)
        {
            if (lines == null || lines.Length == 0 || units == null || units.Count == 0)
            {
                return;
            }

            for (int i = 0; i < lines.Length; i++)
            {
                string line       = lines[i];
                int    lineNumber = i + 1;
                string lineTrimed = line.Trim();

                switch (type)
                {
                case TranslateUnitType.MenuType:
                    if (lineTrimed.StartsWith("POPUP") || lineTrimed.StartsWith("MENUITEM"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null)
                        {
                            TranslateUnit3RD tu = TranslateUnitUtil3RD.GetTranslateUnit(units, "menu", lineNumber);

                            if (tu != null)
                            {
                                string line_new = line.Substring(0, si.startIndex) + tu.TargetContent + (addChar ? specialChar : "") + line.Substring(si.endIndex);
                                lines[i] = line_new;
                            }
                        }
                    }
                    break;

                case TranslateUnitType.StringType:
                    if (lineTrimed.Contains(startChar) && lineTrimed.Contains(endChar))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null)
                        {
                            TranslateUnit3RD tu = TranslateUnitUtil3RD.GetTranslateUnit(units, "string", lineNumber);

                            if (tu != null)
                            {
                                string line_new = line.Substring(0, si.startIndex) + tu.TargetContent + (addChar ? specialChar : "") + line.Substring(si.endIndex);
                                lines[i] = line_new;
                            }
                        }
                    }
                    break;

                case TranslateUnitType.DialogType:
                    if (lineTrimed.StartsWith("CAPTION") || lineTrimed.StartsWith("CONTROL"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 1);

                        if (si != null)
                        {
                            TranslateUnit3RD tu = TranslateUnitUtil3RD.GetTranslateUnit(units, "dialog", lineNumber);

                            if (tu != null)
                            {
                                string line_new = line.Substring(0, si.startIndex) + tu.TargetContent + (addChar ? specialChar : "") + line.Substring(si.endIndex);
                                lines[i] = line_new;
                            }
                        }
                    }
                    break;

                case TranslateUnitType.VersionType:
                    if (lineTrimed.StartsWith("VALUE"))
                    {
                        StringIndex si = StringUtil.GetBetween(line, startChar, endChar, true, 0, 3);

                        if (si != null)
                        {
                            TranslateUnit3RD tu = TranslateUnitUtil3RD.GetTranslateUnit(units, "version", lineNumber);

                            if (tu != null)
                            {
                                string line_new = line.Substring(0, si.startIndex) + tu.TargetContent + (addChar ? specialChar : "") + line.Substring(si.endIndex);
                                lines[i] = line_new;
                            }
                        }
                    }
                    break;
                }
            }
        }