Skip to content
Patryk Gołębiowski edited this page Aug 22, 2016 · 9 revisions

Prerequisites

You need to get a set of CLDR JSON files. These files can be organized in any way - their location and even names don't matter. Given a path to certain directory, Onism will browse all its subdirectories recursively using this logic.

Building a binary file

Building a binary file of subsetted CLDR data is as simple as that:

var inputDirectory = @"/some/directory";
var outputFile = @"/some/file.bin";
var patterns = new PatternCollectionBuilder()
    .Exclude("*")
    .Include("some path")
    .Build();

var builder = new CldrDataBuilder();

var data = builder.Build(inputDirectory, patterns);
data.WriteToFile(outputFile);

The patterns is a list of patterns specifying a subset of JSON data that Onism should exclude. For information on the format, see this section.

The inputDirectory contains CLDR JSON files, as described in the prerequisites section above.

Consuming data

Once the binary file was built, you can load it into memory and consume its contents:

var inputFile = @"/some/file.bin";
var pathToNode = "simple.json.path";
var enGB = new CldrLocale(
    language: "en",
    territory: "GB"
);

var data = CldrData.LoadFromFile(inputFile);
var result = data.Tree.SelectNode(pathToNode).GetValue(locale);

The inputFile is a path to the previously built binary file.

The pathToNode is a simple JSON path leading to a leaf in the CLDR tree. See CLDR tree path for information on the path format. Also, consult CLDR tree page to be aware of the modifications in the tree structure.

The locale is the culture you wish to get the value for.