Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 283
ticky Avatar asked Apr 28 '11 13:04

ticky


People also ask

How do I read a RESX file?

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.

What is a resources RESX file?

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.

What is the use of RESX file in C #?

The . resx resource file format consists of XML entries. These XML entries specify objects and strings inside XML tags. It can be easily manipulated.


2 Answers

SortRESX is a simple executable created by Tom Clement on CodeProject.

It sorts *.resx file alphabetically. I described it on my blog.

like image 131
ticky Avatar answered Oct 04 '22 02:10

ticky


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)
);
like image 45
SLaks Avatar answered Oct 04 '22 03:10

SLaks