XliffParser
XliffParser copied to clipboard
XLIFF (XML Localization Interchange File Format) Parser Library
XliffParser
This library is intended as a thin layer above the original markup to help access the contents of XLIFF (XML Localization Interchange File Format) files.
Its main purposes are:
- reading values from a XLIFF file
- changing values inside a XLIFF file
- exporting translation data to C# resource files (resx)
- updating XLIFF file from C# resource files (resx)
More information on XLIFF can be found here:
- OASIS XLIFF v1.1
- OASIS XLIFF v1.2
- OASIS XLIFF v2.0 (Not yet supported!)
Available on nuget.org
To install XliffParser, run the following command in the Package Manager Console
Install-Package fmdev.XliffParser
Examples
Reading values from a XLIFF file
var doc = new XliffParser.XlfDocument(fileName);
var xlfFile = doc.Files.Single();
foreach (var u in xlfFile.TransUnits)
{
// id | source | target | target state
Console.WriteLine("{0}|{1}|{2}", u.Id, u.Source, u.Target, u.Optional.TargetState);
}
Changing values inside a XLIFF file
var unit = xlfFile.AddTransUnit("MyResourceId", "some resouce string", "my awesome translation");
unit.Optional.TargetState = "translated";
unit.Optional.AddNote("No comment!", "XliffParser");
doc.Save();
Exporting translation data to C# resource files (resx)
doc.SaveAsResX();
Updating XLIFF file from C# resource files (resx)
var result = doc.UpdateFromSource();
Console.WriteLine("updated: {0}, added: {1}, removed: {2}",
result.UpdatedItems.Count(), result.AddedItems.Count(), result.RemovedItems.Count());