Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Validate strings in Resx files for all languages

0.00/5 (No votes)
23 Sep 2008 1  
A tool to validate localization strings in Resx files supporting multiple languages.

Introduction

The .NET framework provides support for language localization using resx files. This tool helps to cross check the resx files for various languages, in a GridView. The code is based on .NET 3.5.

Background

For localization using satellite assemblies, please refer to: .NET - Localization using Resource file.

Using the code

With this utility, the user can select multiple resx files and validate if keys exist in all languages. It highlights the errors visibly in red so that a developer can quickly fix the resx files. The utility itself is a couple of lines of code.. thanks to LINQ and .NET 3.5.

void ParseFiles(string[] fileNames)
{
    int marker = 1;
    
    foreach (string file in fileNames)
    {

        XElement xElement = XElement.Load(file);

        IEnumerable<XElement> data = 
            from text in xElement.Elements("data")
            select text;

        foreach (XElement node in data)
        {
            string key = node.FirstAttribute.Value;

            int value = dictionary.ContainsKey(key)? dictionary[key]:0;

            dictionary[key] = value | marker;
        }

        marker = marker << 1;
    }
}

Points of interest

The code uses LINQ, and really looks neat and clean for the purpose.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here