Beispiel #1
0
        static void DoLangPacks()
        {
            leng_ = new LangPack("english.lang");
            DebugLog(string.Format("Readed engligh.lang - {0} lines\n", leng_.lines_.Count));

            FixLangPack("german.lang", true);
            FixLangPack("french.lang", true);
            FixLangPack("italian.lang", true);
            FixLangPack("spanish.lang", true);
            FixLangPack("russian.lang", false);

            WriteSmartlingOutput("smartling_output.xml");
        }
Beispiel #2
0
        static void FixLangPack(string fname, bool isXML)
        {
            DebugLog(string.Format("{0} - ", fname));
            LangPack lin = new LangPack(fname);

            DebugLog(string.Format("{0} lines\n", lin.lines_.Count));

            LangPack lout = new LangPack();
            //StreamWriter SW = new StreamWriter(fname + "_missing.txt");
            // int missing = 0;


            XmlDocument xmlDoc = new XmlDocument();

            if (isXML)
            {
                string xmlFilename = fname;
                xmlFilename = xmlFilename.Replace(".lang", ".xml");
                xmlDoc.Load(xmlFilename);
            }

            // recreate new langpack
            foreach (LangPack.Entry e in leng_.lines_)
            {
                if (e.value == null)
                {
                    lout.lines_.Add(e);
                    continue;
                }

                LangPack.Entry e2;
                bool           found = false;
                if (isXML)
                {
                    // super slow, but who cares
                    XmlNodeList xmlStrings = xmlDoc.GetElementsByTagName("string");
                    foreach (XmlNode node in xmlStrings)
                    {
                        XmlNodeList keyValueNodes = node.ChildNodes;
                        XmlNode     key           = keyValueNodes.Item(0);
                        XmlNode     value         = keyValueNodes.Item(1);

                        if (key.InnerText == e.name)
                        {
                            string v = value.InnerText;
                            v        = v.Replace("\r\n", "\\n");
                            v        = v.Replace("\u200B", ""); // Unicode Character 'ZERO WIDTH SPACE' (U+200B).
                            e2       = new LangPack.Entry();
                            e2.name  = e.name;
                            e2.value = v;
                            lout.lines_.Add(e2);
                            found = true;
                            break;
                        }
                    }
                }
                else
                {
                    if (lin.map_.TryGetValue(e.name, out e2))
                    {
                        // have translated value
                        lout.lines_.Add(e2);
                        found = true;
                    }
                }

                if (!found)
                {
                    // missing++;
                    // not translated line
                    e2       = new LangPack.Entry();
                    e2.name  = e.name;
                    e2.value = "#" + e.value;
                    lout.lines_.Add(e2);

                    //SW.WriteLine(e.name);
                }
            }

            // SW.Close();
            // if (missing == 0)
            //    File.Delete(fname + "_missing.txt");

            //DebugLog(string.Format("\t{0} missing\n", missing));

            //File.Delete(fname + ".bak");
            //File.Move(fname, fname + ".bak");
            lout.Write(fname);
        }