How to sort a . resx (resource file) in .NET
I have a problem with resource files in my project. As I created one in English, I gave it to the translation team. Somehow, they returned me resource file with values in different order, so it wasn't sorted alphabetically.
So, at first it was:
<data name="a1" xml:space="preserve">
<value>some text2</value>
</data>
<data开发者_StackOverflow中文版 name="b1" xml:space="preserve">
<value>some text3</value>
</data>
<data name="c1" xml:space="preserve">
<value>some text1</value>
</data>
and I received:
<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 any way to sort those elements in the .resx file by the <data name
attribute?
SortRESX is a simple executable created by Tom Clement on CodeProject.
It sorts *.resx file alphabetically. I described it on my blog.
You could write a quick script to do that using LINQ to XML:
var root = XElement.Load(...);
var sortedRoot = new XElement(root.Name, root.Attributes,
root.Elements().OrderBy(e => e.Attribute("name").Value)
);
I wrote a very simple VS extension that sorts resx files. Right click any .resx file(s), and click "Sort Resx".
精彩评论