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 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?
To start with, you need to create a web application. Here, I am using Visual Studio 2012 and C# as the language. Once you created the application, you need to create a RESX file by clicking the “New Item”. Now you can see a new file in your solution explorer named Resource1.
A . resx file contains a standard set of header information that describes the format of the resource entries, and specifies the versioning information for the XML code that parses the data. These files contain all the strings, labels, captions, and titles for all text in the three IBM Cognos Office components.
The . resx resource file format consists of XML entries. These XML entries specify objects and strings inside XML tags. It can be easily manipulated.
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)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With