npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bscotch/xliff

v0.8.1

Published

A library for building simple XLIFF 2.0 and GlossML 1.0 files for hand-off to translators.

Downloads

301

Readme

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.