Question

How can I compare the content of two (or more) large .resx files? With hundreds of Name/Value pairs in each file, it'd be very helpful to view a combined version. I'm especially interested in Name/Value pairs which are present in the neutral culture but are not also specified in a culture-specific version.

Was it helpful?

Solution

There is a great freeware tool to edit resx files where you can see multiple languages at once and clearly see what is missing or extra - Zeta Resource Editor

OTHER TIPS

Although it's not a diff tool per se, RESX Synchronizer may help you out here. Its main use is to update the localized .resx files with new entries from the neutral language one, and remove any deleted items.

Possibly, the output generated by using it with the /v command line switch will be what you need. Otherwise, it does come with full C# source code, so possibly you can adapt it for your needs.

For newer versions of Visual Studio (2010+) there is now a Visual Studio Extension called ResXManager (created by tomenglert) which is amazing for this.

It allows you to view each resource in each language side by side and highlights missing resources. (The below example is from the extension download page.)

Example From Extension Download Page

Using a simple diff on XML files can be totally useless, if the matching elements do not appear in the same order in both files. I have been looking for an XML-specific diff tool too, so far without success.

In the meantime, the workaround I have been using is this:

  • Open the .resx files in Visual Studio.
  • Select all [Ctrl + A] and cut [Ctrl + X] (this may take a while for large files - be patient)
  • Paste [Ctrl + V] and save (this will re-create the .resx files sorted by keys)

When both files are thus re-ordered, normal diff'ing becomes so much easier. You can quickly locate the missing keys by skimming through the diff now.

I've tried several XMl diff tools. Here's the summary (the requirement that drove me to evaluate it was to diff the Visual Studio generated .resx resource files, which I think is a big fault that Microsoft made - the order of the elements is random, and Windows Forms always re-write the ImageStream if you just change a button's location and do nothing with the imageList).

  1. XmlDiff
  2. Araxis
  3. Altova DiffDog
  4. XML Notepad
  5. ExamXML
  6. Liquid XML Studio 2009 (there's an XML diff menu, but only a license version can use it. So I have no chance to give it a try)

First of all, all the normal diff tools should not be considered because they know nothing of XML, they treat text files as just lines of text.

  1. XmlDiff is the first tool I tried. It looks that it can do want I need, but after downloading the source code (Visual Studio 2003) and compiled with Visual Studio 2005 (with a successful auto upgrade) I can compile the small project smoothly. But when I compare two real .resx files (1295 lines) it crashed. Debuging into the code does not give me a clue about what happened because I have no source code of the xmldiffpatch.dll XmlDiffPatch.View.dll.

    And the reason did I not try to dig more into this tool was the output format, or GUI design. It outputs an HTML file with differences highlighted in a Internet Explorer-hosted window. For a large XML file diff, it's not easy to use.

  2. XML Notepad has a simple built-in XML diff. According to the output window I think it internally uses XmlDiff's component. And the output is same as XmlDiff. I'll uninstall it.

  3. Araxis is much more a traditional text diff tool, it can also compares binary file, image file, folder, and word files. I like it very much for any diff task except XML, because it has not XML-aware diff options support.

  4. Altova DiffDog looks like a complicated commercial product, and it did contain an option to ignore the element order, which is the key feature for me.

    But after trying it with the same real .resx file (1295 lines, not a big one in my experience), I found that the "ignore element order" just does not work well if the two elements are located at very different places in the two files.

  5. ExamXML looks like a commercial product, but it is a small product. But after trying it, I found it's the most ideal tool at present for my expectations.

There's also a disappointing side: it crashed when I pressed F10 to navigate to the next difference. The ignore order of elements option works well. There's one pitty that the customization of ignored element is not so much flexible.

label1.Size
label1.Location
label1.Width

I want to ignore all the differences on these elements whose name contains ".Size" or ".Location" or ".Width", but it's not possible to define such a condition at the same time. The customization does not support regular expressions.

Anyway, I'll use ExamXML (with careful) to compare XML files.

UPDATE 1: years passed, now I use VS2017 and winform did not change since my initial answer of this question. When work need to break down to different people, this issue popped again and again, boring me.

Actually I forgotten this answer, google brought me here.

I started a new investigate session, and have some good findings: https://www.codeproject.com/Articles/37022/Solving-the-resx-Merge-Problem shows that how eaisly we can sort the resx file by data/@name attribute by LINQ. It's amazing. The core code is only one statement composed of several LINQ.

Then I also found that ResXResourceManager, which is pointed out by another answer in this thread, the author replied to the above code project article and add the feature to ResXResourceManager, in ResxResourceManager, you can config the plugin to automatically sort the resx file when(before) you save it in the configuration tab. There's even a sorting option you can choose: CurrentCulture, Ordinal or IgnoreCase etc.

Unfortunately the code-project solution and the ResXResourceManager solution produce different result, source is available, I found out that the code-project solution treat the ">>" attribute value as normal text so semantically related widgets are separated. This can be easily fixed by adding a TrimStart('>') to the LINQ.

However, after fixing this the two tool still produce different result. The culprint is the LINQ by default using CurrentCulture to sort string, and I totally ignore the revelant sort option in resXResourceManager, for this problem, I think the best sort option is "Ordinal". After adding the sort option to the code project solution, and setting the same sort option in ResXResourceManager, finally they produce exactly same result!

Although resxResourceManager is great to centrally manage the resource and fix the resx element order issue, the code-project tool is still invaluable to me, since it's standalone so it can be used in a broader cases; plus, the code is very terse and elegant.

I would add another note at the end of my update, I use tortoise git, I use Araxis to compare different versions, it's almost non-sense to compare two resx file revision, however, Araxis support to custom a filter to transform the input file before the compare engine seeing it. For compare, Araxis calls the filter by the following command: sortresx.exe -f C:\Users\ADMINI~1\AppData\Local\Temp\mrg.8032.3.resx C:\Users\ADMINI~1\AppData\Local\Temp\mrg.8032.2 C:\Users\ADMINI~1\AppData\Local\Temp\mrg.8032.4

-f means foward, the first file name is the input file, the second file name is the output file the filter should written, the third one can be safely ignored. After making a little change to the code-project code, I can now compile a filter program, configed it in Araxis, and do a reasonable resx revision comparison even on old, messed up resx files.

You could code something up using XML Diff. See Using the XML Diff and Patch Tool in Your Applications.

You can use a tool like TortoiseSVN's diff (if you're using Windows). Just select both files, right click and then select "diff" from the TortoiseSVN submenu.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top