How to use the @phensley/language-tag.parseLanguageTag function in @phensley/language-tag

To help you get started, we’ve selected a few @phensley/language-tag examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phensley / cldr-engine / packages / locale-matcher / src / matcher.ts View on Github external
const parse = (locales: string | string[] = []): Entry[] => {
  let raw: string[];
  if (typeof locales === 'string') {
    raw = locales.split(TAG_SEP);
  } else {
    raw = locales.reduce((a: string[], e: string): string[] => {
      const tmp = e.split(TAG_SEP);
      return a.concat(tmp);
    }, []);
  }

  const result: Entry[] = [];
  const len = raw.length;
  for (let i = 0; i < len; i++) {
    const id = raw[i].trim();
    const tag = parseLanguageTag(id);

    // Preserve 'und' undefined locale. If we resolve it, adding
    // likely subtags will expand it to 'en-Latn-US'.
    if (tag.hasLanguage() || tag.hasScript() || tag.hasRegion()) {
      result.push(new Entry(id, LanguageResolver.resolve(tag)));
    } else {
      // Preserve undefined core fields, but include input's extensions
      result.push(new Entry(id, new LanguageTag(
        undefined, undefined, undefined, undefined, tag.extensions(), tag.privateUse()
      )));
    }
  }
  return result;
};
github phensley / cldr-engine / packages / locale / src / resolver.ts View on Github external
static removeLikelySubtags(real: string | LanguageTag): LanguageTag {
    const tag = typeof real === 'string' ? parseLanguageTag(real) : real;
    const max = fastTag(tag);
    if (max[Tag.LANGUAGE] === Tag.LANGUAGE || max[Tag.SCRIPT] === Tag.SCRIPT || max[Tag.REGION] === Tag.REGION) {
      addLikelySubtags(max);
    }
    const tmp = UNDEFINED.slice(0);

    // Using "en-Latn-US" as an example...
    // 1. Match "en-Zzzz-ZZ"
    tmp[Tag.LANGUAGE] = max[Tag.LANGUAGE];
    let match = tmp.slice(0);
    addLikelySubtags(match);
    if (fastTagEquals(match, max)) {
      return returnTag(tag, tmp);
    }

    // 2. Match "en-Zzzz-US"
github phensley / cldr-engine / packages / locale / src / resolver.ts View on Github external
const parseFastTag = (raw: string): FastTag => fastTag(parseLanguageTag(raw));
github phensley / cldr-engine / packages / locale / src / locale.ts View on Github external
static resolve(id: string): Locale {
    let tag = parseLanguageTag(id);
    if (tag.hasLanguage() || tag.hasScript() || tag.hasRegion()) {
      tag = LanguageResolver.resolve(tag);
    } else {
      tag = UNDEFINED;
    }
    return { id, tag };
  }
}
github phensley / cldr-engine / packages / locale / src / resolver.ts View on Github external
static resolve(real: string | LanguageTag): LanguageTag {
    const tag = typeof real === 'string' ? parseLanguageTag(real) : real;
    const fast = fastTag(tag);
    substituteLanguageAliases(fast);
    substituteRegionAliases(fast);
    addLikelySubtags(fast);
    return returnTag(tag, fast);
  }
github phensley / cldr-engine / packages / locale / src / resolver.ts View on Github external
static addLikelySubtags(real: string | LanguageTag): LanguageTag {
    const tag = typeof real === 'string' ? parseLanguageTag(real) : real;
    const fast = fastTag(tag);
    addLikelySubtags(fast);
    return returnTag(tag, fast);
  }

@phensley/language-tag

Parsing and construction of BCP 47 language tags

Apache-2.0
Latest version published 18 days ago

Package Health Score

62 / 100
Full package analysis

Similar packages