How to sort. resx (resource file) in .NET.

I have a problem with resource files in my project. When I created it in English, I transferred it to the translation team. Somehow, they returned me a resource file with values ​​in a different order, so it was not sorted in alphabetical order.

So first it was:

<data name="a1" xml:space="preserve"> <value>some text2</value> </data> <data name="b1" xml:space="preserve"> <value>some text3</value> </data> <data name="c1" xml:space="preserve"> <value>some text1</value> </data> 

and I got:

 <data name="c1" xml:space="preserve"> <value>some text1</value> </data> <data name="a1" xml:space="preserve"> <value>some text2</value> </data> <data name="b1" xml:space="preserve"> <value>some text3</value> </data> 

So, is there a way to sort these elements in a .resx file with the <data name attribute?

+6
source share
3 answers

I found one software: SortRESX It was created by Tom Clement, and you can find it here: http://www.codeproject.com/KB/cs/ResxMergeUtility.aspx

This is a simple executable file that sorts the resx file alphabetically. It really helped me. I even described it on my blog.

https://tijanavujanac.posterous.com/resxdiff-solving-the-resx-merge-problem :)

+5
source

You can write a quick script for this using LINQ to XML:

 var root = XElement.Load(...); var sortedRoot = new XElement(root.Name, root.Attributes, root.Elements().OrderBy(e => e.Attribute("name").Value) ); 
+3
source

I wrote a very simple VS extension that sorts resx files. Right-click any .resx file and click Sort Resx.

+3
source

Source: https://habr.com/ru/post/886882/


All Articles