Domanda

Come posso confrontare il contenuto di due (o più) file .resx di grandi dimensioni? Con centinaia di coppie Nome / Valore in ciascun file, sarebbe molto utile visualizzare una versione combinata. Sono particolarmente interessato alle coppie Nome / Valore che sono presenti nella cultura neutrale ma non sono specificate anche in una versione specifica della cultura.

È stato utile?

Soluzione

Esiste un ottimo strumento freeware per modificare i file resx in cui puoi vedere più lingue contemporaneamente e vedere chiaramente cosa manca o extra - Zeta Resource Editor

Altri suggerimenti

Sebbene non sia di per sé uno strumento diff, RESX Synchronizer può aiutarti qui. Il suo uso principale è aggiornare i file .resx localizzati con nuove voci dalla lingua neutra e rimuovere tutti gli elementi eliminati.

Probabilmente, l'output generato usandolo con l'opzione della riga di comando / v sarà quello che ti serve. Altrimenti, viene fornito con il codice sorgente C # completo, quindi possibilmente puoi adattarlo alle tue esigenze.

Per le versioni più recenti di Visual Studio (2010+) ora esiste un'estensione di Visual Studio chiamata ResXManager (creato da tomenglert ) che è sorprendente per questo.

Ti consente di visualizzare fianco a fianco ogni risorsa in ogni lingua e mette in evidenza le risorse mancanti. (L'esempio seguente proviene dalla pagina di download dell'estensione.)

 Esempio dalla pagina di download dell'estensione

L'uso di una semplice diff su file XML può essere totalmente inutile, se gli elementi corrispondenti non compaiono nello stesso ordine in entrambi i file. Ho cercato anche uno strumento diff specifico per XML, finora senza successo.

Nel frattempo, la soluzione alternativa che ho usato è questa:

  • Apri i file .resx in Visual Studio.
  • Seleziona tutto [ Ctrl + A ] e taglia [ Ctrl + X ] (questo può richiedere un mentre per file di grandi dimensioni, sii paziente)
  • Incolla [ Ctrl + V ] e salva (questo creerà nuovamente i file .resx ordinati per chiave)

Quando entrambi i file vengono così riordinati, la differenza normale diventa molto più semplice. È possibile individuare rapidamente i tasti mancanti sfogliando il diff ora.

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top