0.8.1 • Published 12 months ago

@bscotch/xliff v0.8.1

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Simple XLIFF & GlossML Builder/Parser

A library for programmatically building and parsing simple XLIFF 2.0 and GlossML 1.0 files, assisted by Typescript.

Usage

XLIFF

The following sample code:

import { createXliffDocument } from '@bscotch/xliff';

const doc = createXliffDocument();
doc
  .addFile({ id: 'file1' })
  .addGroup({ id: 'group1' })
  .addGroup({ id: 'Nested' })
  .addUnit({ id: 'unit1', 'slr:sizeRestriction': 255 }, 'Stuff to translate!')
  .addNote('This is a "note"!');

console.log(doc.toString());

Produces the following XLIFF:

<?xml version="1.0" encoding="UTF-8"?>
<xliff version="2.0" srcLang="en-US" xmlns="urn:oasis:names:tc:xliff:document:2.0" xmlns:slr="urn:oasis:names:tc:xliff:sizerestriction:2.0">
	<file id="file1">
		<group id="group1">
			<group id="Nested">
				<unit id="unit1" slr:sizeRestriction="255">
					<notes>
						<note>This is a &quot;note&quot;!</note>
					</notes>
					<segment>
						<source>Stuff to translate!</source>
					</segment>
				</unit>
			</group>
		</group>
	</file>
</xliff>

This package also provides an XLIFF parser that does some extra work on top of plain XML parsing, to provide a simpler JavaScript object format with meaningful types. Note that it doesn't support all features of XLIFF (e.g. <other/>, <originalData>, and some other tags are skipped).

import { parseXliff } from '@bscotch/xliff';

const asObj = parseXliff(yourXliffString);

GlossML

The following sample code:

import { createGlossMLDocument } from '@bscotch/xliff';

const doc = createGlossMLDocument();
doc.comment = 'A description of the glossary itself';
doc
  .addEntry('term1', 'definition1', 'comment1')
  .addEntry('term2')
  .addEntry('term3', undefined, 'comment3');

Produces the following GlossML file (after formatting):

<?xml version="1.0" encoding="UTF-8"?>
<glossary version="1.0" srcLang="en-US" xmlns="http://www.maxprograms.com/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.maxprograms.com/glossml/GlossML.xsd">
	<glossentry>
		<comment>
			comment1
		</comment>
		<langentry xml:lang="en-US">
			<term>
				term1
			</term>
			<definition>
				definition1
			</definition>
		</langentry>
	</glossentry>
	<glossentry>
		<langentry xml:lang="en-US">
			<term>
				term2
			</term>
		</langentry>
	</glossentry>
	<glossentry>
		<comment>
			comment3
		</comment>
		<langentry xml:lang="en-US">
			<term>
				term3
			</term>
		</langentry>
	</glossentry>
</glossary>

Limitations

This library is intended to be used for simple files, and does not support all features of either format.

0.8.1

12 months ago

0.8.0

12 months ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.1

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago