internal static void SaveToCsvSingle(StreamWriter writer,
                                      XmlNodeWithValue winNode,
                                      XmlNodeWithValue englishNode,
                                      XmlNodeWithValue japanNode)
 {
     writer.WriteLine($"{winNode.Name};"
                      + $"'{winNode.Value.Replace(";", "|").Replace(Environment.NewLine, string.Empty)}';"
                      + $"{englishNode.Name};"
                      + $"'{englishNode.Value.Replace(";", "|").Replace(Environment.NewLine, string.Empty)}';"
                      + $"{japanNode?.Name ?? englishNode.Name};"
                      + $"{(japanNode?.Value ?? englishNode.Value).Replace(";", " | ").Replace(Environment.NewLine, string.Empty)}");
 }
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                return;
            }

            var directory = new DirectoryInfo(args[0]);

            args[1] = Path.Combine(args[0], args[1]);
            args[2] = Path.Combine(args[0], args[2]);

            if (!File.Exists(args[1]) || !File.Exists(args[2]))
            {
                return;
            }


            Dictionary <string, MappedItem> readContents = new Dictionary <string, MappedItem>();

            using (StreamReader streamReader = new StreamReader(args[2], Encoding.UTF8))
            {
                while (!streamReader.EndOfStream)
                {
                    var line     = streamReader.ReadLine();
                    var splitted = line?.Split(';');
                    if (splitted == null || splitted.Length < 2)
                    {
                        continue;
                    }

                    readContents.Add(
                        splitted[1],
                        new MappedItem
                    {
                        IsBadSamlpe            = splitted[0] == "1",
                        WinResourceName        = splitted[1],
                        WinResourceValue       = splitted[2],
                        AndroidEnResourceName  = splitted[3],
                        AndroidEnResourceValue = splitted[4],
                        AndroidJaResourceName  = splitted[5],
                        AndroidJaResourceValue = splitted[6]
                    });
                }
            }


            var windowsResource = new XmlDocument();

            windowsResource.Load(args[1]);
            var output = Path.Combine(args[1]) + "_japan.resx";

            foreach (XmlNode rootNode in windowsResource.ChildNodes)
            {
                if (rootNode.Name != "root")
                {
                    continue;
                }

                foreach (XmlNode node in rootNode.ChildNodes)
                {
                    if (node == null)
                    {
                        continue;
                    }

                    if (node.Name != "data")
                    {
                        continue;
                    }

                    if (node.Attributes["type"] != null)
                    {
                        continue;
                    }

                    var winNode = new XmlNodeWithValue(node, false);
                    if (readContents.ContainsKey(winNode.Name) && !readContents[winNode.Name].IsBadSamlpe)
                    {
                        winNode.SetWinValue(readContents[winNode.Name].AndroidJaResourceValue);
                    }
                }
            }

            windowsResource.Save(output);
        }
        public static void SaveTo(XmlNode enXml,
                                  XmlNode jaXml,
                                  XmlDocument windowsResource,
                                  StreamWriter writer,
                                  Action <StreamWriter, XmlNodeWithValue, XmlNodeWithValue, XmlNodeWithValue> saveToAction)
        {
            foreach (XmlNode rootNode in windowsResource.ChildNodes)
            {
                if (rootNode.Name != "root")
                {
                    continue;
                }

                foreach (XmlNode node in rootNode.ChildNodes)
                {
                    if (node == null)
                    {
                        continue;
                    }

                    if (node.Name != "data")
                    {
                        continue;
                    }

                    if (node.Attributes["type"] != null)
                    {
                        continue;
                    }

                    //var winName = node.Attributes["name"];
                    //var winValue = node.ChildNodes.OfType<XmlNode>().FirstOrDefault(x => x.Name == "value").InnerText;
                    //{ Node = node, Value = winValue, Name = winName.Value }
                    var winNode = new XmlNodeWithValue(node, false);
                    if (winNode.Node.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }

                    var englishNodeWithTanimoto = enXml.ChildNodes
                                                  .OfType <XmlNode>()
                                                  .Where(x => x.NodeType != XmlNodeType.Comment)
                                                  .Select(x => new XmlNodeWithValue(x, true)
                    {
                        Tanimoto = TanimotoStringComparer.Tanimoto(x.InnerText, winNode.Value, 1.2)
                    }).Where(x => x.Tanimoto > 0.7);

                    if (englishNodeWithTanimoto.Count() == 0)
                    {
                        continue;
                    }

                    var maxTanimoto = englishNodeWithTanimoto.Max(x => x.Tanimoto);
                    var englishNode = englishNodeWithTanimoto.FirstOrDefault(x => x.Tanimoto == maxTanimoto);

                    var japanNode = jaXml.ChildNodes.OfType <XmlNode>().FirstOrDefault(x => x.NodeType != XmlNodeType.Comment &&
                                                                                       x.Attributes["name"].Value == englishNode.Node.Attributes["name"].Value);

                    var ourJapanXmlNode = new XmlNodeWithValue(japanNode, true);
                    saveToAction(writer, winNode, englishNode, ourJapanXmlNode);
                }
            }
        }