Compare and extract different between tow NopCommerce Language pack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Xml.Linq; | |
namespace Nop.CompareLocaleResource | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var fullLangXmlPath = @"H:\l\language_pack.xml"; | |
var newLangXmlPath = @"H:\l\language_pack_.xml"; | |
var resultLangXmlPath = @"H:\l\language_pack_diff.xml"; | |
var strXmlTag = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"; | |
var LanguageName = "فارسی"; | |
var SupportedVersion = "4.1"; | |
var reader = new System.IO.StreamReader(fullLangXmlPath).ReadToEnd(); | |
XElement fullXml = XElement.Parse(reader); | |
reader = new System.IO.StreamReader(newLangXmlPath).ReadToEnd(); | |
XElement newXml = XElement.Parse(reader); | |
var fullElements = fullXml.Elements(XName.Get("LocaleResource")); | |
var newElements = newXml.Elements(XName.Get("LocaleResource")); | |
var fullDictionary = new Dictionary<string, string>(); | |
foreach (var fItem in fullElements) | |
{ | |
fullDictionary.Add(fItem.Attribute(XName.Get("Name")).Value, fItem.Value); | |
} | |
var newDictionary = new Dictionary<string, string>(); | |
foreach (var fItem in newElements) | |
{ | |
newDictionary.Add(fItem.Attribute(XName.Get("Name")).Value, fItem.Value); | |
} | |
var extractXml = new Dictionary<string, string>(); | |
foreach (var item in fullDictionary) | |
{ | |
if (!newDictionary.ContainsKey(item.Key)) | |
{ | |
extractXml.Add(item.Key, item.Value); | |
} | |
} | |
var writer = new System.IO.StreamWriter(resultLangXmlPath); | |
writer.Write("<?xml version=\"1.0\" encoding=\"utf-16\"?><Language Name=\"" + LanguageName + "\" SupportedVersion=\"" + SupportedVersion + "\">"); | |
foreach (var item in extractXml) | |
{ | |
writer.WriteLine("<LocaleResource Name=\""+item.Key+"\"><Value>"+item.Value+"</Value></LocaleResource>"); | |
} | |
writer.Write("</Language>"); | |
writer.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment