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

lang-ietf-opentype

v0.0.1

Published

Map between IETF language tags and OpenType language system tags

Downloads

15

Readme

Mapping IETF language tags to OpenType language system tags

The language of text written in a markup language such as XML or HTML is usually identified by an IETF language tag, conforming to BCP 47. Such text is most often displayed using OpenType fonts. In order to display text optimally with OpenType, it is necessary to use an OpenType language system tag. Unfortunately, for historical reasons, OpenType language system tags have their own specification, and are not the same as IETF language tags. This means that any system that wants to display HTML or XML using OpenType fonts has to convert IETF language tags into OpenType language system tags.

This project is designed to help with this problem, by providing

  • data, in JSON format, declaratively describing the conversion and
  • a node.js module that uses this data to do the conversion.

The OpenType specification associates a number of ISO 639-2 or ISO 639-3 three-letter tags with each OpenType language system. Using ISO 639-2, each such ISO 639 tag can be mapped to an IETF language tag consisting of just a primary language subtag. Although this provides the starting point for the conversion, the following problems still have to be solved:

  • sometimes a particular ISO 639 tag is associated with multiple OpenType tags; these ambiguities can sometimes be resolved by finding an appropriate script, region or variant subtag to add to the primary language subtag;
  • for some OpenType tags, there is no associated ISO 639 tag;
  • sometimes the associated ISO 639 tags are inconsistent with the name of the OpenType language system.

There are extensive notes describing the issues for each OpenType language system tag. The gen directory contains code based on these notes to generate the JSON data file.

Data

The format of the data is a JSON object, which maps an initial subtag to a rule for converting tags that begin with that subtag. The initial subtag is the part of the IETF tag up to the first hyphen, if there is one, or the whole tag, if there is not. The rule is either a string or an array of strings.

If the rule is a string, then the string specifies the OpenType tag.

If the rules is an array of strings, then the array will contain an odd number of strings. The first members of the array is the default OpenType tag. The remaining strings are interpreted in pairs. The first member of each pair specifies a subtag, and the second member specifies the OpenType tag for when the IETF tag contains that subtag. For example, an entry:

"zh": ["ZHS", "latn", "ZHP", "hk", "ZHH", "hant", "ZHT"]

means that an IETF tag that is zh or starts with zh- is handled as follows:

  • if it has a subtag "latn", then it maps to the OpenType tag ZHP;
  • othewise, if it has a subtag "hk", then it maps to the OpenType tag ZHH;
  • otherwise, if it has a subtag "hant", then it maps to the OpenType tag ZHT;
  • otherwise, it maps to the OpenType tag ZHS.

Note that subtags are specified in the data in lower-case but are matched case-insensitively. Subtags that occur in a tag following a singleton subtag (a subtag of length 1) should be ignored when applying a rule.

Module

The module provides a single function.

ietfToOpenType(tag)

This converts an IETF language tag to an OpenType language system tag. The argument must be a string. It returns a string with the OpenType language system tag, or undefined if there is no suitable OpenType language system tag.