How to use @phensley/cldr-core - 10 common examples

To help you get started, we’ve selected a few @phensley/cldr-core 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 / cldr-compiler / src / cli / compiler / pack.ts View on Github external
validateConfig(config);
  } else {
    config = DEFAULT_CONFIG;
  }

  const regions = new Set(argv.regions ? argv.regions.split(',') : []);

  const dest = argv.out;
  if (!fs.existsSync(dest)) {
    fs.mkdirSync(dest);
  }

  // Configure the schema accessor builder
  const builder = new CodeBuilder(config);
  const origin = builder.origin();
  const checksum = checksumIndices(pkg.version, origin.indices);

  const rbnf = new RBNFCollector();
  rbnf.load();

  let path: string;
  const hashes: { [x: string]: string } = {};
  const pkghash = createHash('sha256');
  langs.forEach(lang => {
    console.warn(`processing:  ${lang}`);

    // Get the list of languages that should live together in this bundle.
    let locales = localeMap[lang];

    if (regions.size > 0) {
      locales = locales.filter(l => l.id === lang || regions.has(l.tag.region()));
    }
github phensley / cldr-engine / packages / cldr-compiler / src / rbnf / collector.ts View on Github external
const files = fs.readdirSync(dir).filter(f => RE_FILE.test(f));
    const res: Map = new Map();

    const ids: string[] = [];
    for (const file of files) {
      const p = path.join(dir, file);
      const data = JSON.parse(fs.readFileSync(p, { encoding: 'utf-8' })) as JSONRoot;
      if (!data.SpelloutRules && !data.OrdinalRules) {
        continue;
      }

      const { name } = path.parse(file);
      let id = name;
      if (name !== 'root') {
        // compact each tag to language-script with region if specified
        const tag = parseLanguageTag(name);
        const max = LanguageResolver.resolve(name);
        id = `${max.language()}-${max.script()}`;
        if (tag.hasRegion()) {
          id = `${id}-${max.region()}`;
        }
      }
      res.set(id, data);
      ids.push(id);
    }

    res.forEach((_, id) => this.populate(res, id));

    // Fill in the locales that have no RBNF mapping.
    for (const locale of availableLocales()) {
      const { tag } = locale;
      const id = `${tag.language()}-${tag.script()}`;
github phensley / cldr-engine / packages / cldr-compiler / src / rbnf / collector.ts View on Github external
Object.keys(NumberingSystems).forEach(k => {
      const sys = NumberingSystems[k];
      if (sys._type !== 'algorithmic') {
        return;
      }
      if (sys._rules.indexOf('/SpelloutRules') === -1) {
        return;
      }
      const parts = sys._rules.split('/');
      const tag = LanguageResolver.resolve(parts[0]);
      const id = `${tag.language()}-${tag.script()}`;

      if (!this.core.includes(id)) {
        this.core.push(id);
      }

      // Map numbering systems to a spellout locale id
      const set = this.systems.get(id) || [];
      set.push(k);
      this.systems.set(id, set);
    });
github phensley / cldr-engine / packages / cldr-compiler / src / rbnf / collector.ts View on Github external
populate(groups: Map, id: string): void {
    const group = groups.get(id);
    if (!group) {
      return;
    }
    const tag = parseLanguageTag(id);
    for (const key of KEYS) {
      const parents = ['root'];
      const rulesets = group[key];
      if (rulesets === undefined) {
        if (tag.hasRegion()) {
          parents.unshift(`${tag.language()}-${tag.script()}`);
        }

        // Patch in the rulesets from a parent
        for (const parent of parents) {
          const tmp = groups.get(parent);
          if (tmp && tmp[key]) {
            group[key] = tmp[key];
            break;
          }
        }
github phensley / cldr-engine / packages / cldr-compiler / src / resource / rbnf.ts View on Github external
report(): string {
    let r = '';

    let allids: string[] = [];
    this.collector.locales.forEach((_, id) => allids.push(id));

    const seen: Set = new Set();
    allids = ['root'].concat(allids.filter(i => i !== 'root').sort());
    for (const id of allids) {
      // Same rule are defined for each script and region of a language, so only
      // list rules at the language level.
      const lang = id === 'root' ? 'root' : parseLanguageTag(id).language();
      if (seen.has(lang)) {
        continue;
      }

      seen.add(lang);

      const name = id === 'root' ? 'Global' : lang;
      r += `${name}:\n`;
      const raw = this.collector.locales.get(id)!;
      const names: string[] = [];

      // Only show numbering systems at the root level
      const keys: (keyof JSONRoot)[] = id === 'root' ?
        ['NumberingSystemRules'] : ['OrdinalRules', 'SpelloutRules'];

      for (const key of keys) {
github phensley / cldr-engine / packages / cldr-compiler / src / rbnf / collector.ts View on Github external
if (!this.core.includes(id)) {
        this.core.push(id);
      }

      // Map numbering systems to a spellout locale id
      const set = this.systems.get(id) || [];
      set.push(k);
      this.systems.set(id, set);
    });

    // Map each spellout id to the language bundle that should contain it
    for (const id of ids) {
      this.locales.set(id, res.get(id)!);

      this.locales.set(id, res.get(id)!);
      const lang = id === 'root' || this.core.includes(id) ? 'root' : parseLanguageTag(id).language();
      const map = this.langs.get(lang) || [];
      map.push(id);
      this.langs.set(lang, map);
    }
  }
github phensley / cldr-engine / packages / cldr-compiler / src / rbnf / collector.ts View on Github external
const res: Map = new Map();

    const ids: string[] = [];
    for (const file of files) {
      const p = path.join(dir, file);
      const data = JSON.parse(fs.readFileSync(p, { encoding: 'utf-8' })) as JSONRoot;
      if (!data.SpelloutRules && !data.OrdinalRules) {
        continue;
      }

      const { name } = path.parse(file);
      let id = name;
      if (name !== 'root') {
        // compact each tag to language-script with region if specified
        const tag = parseLanguageTag(name);
        const max = LanguageResolver.resolve(name);
        id = `${max.language()}-${max.script()}`;
        if (tag.hasRegion()) {
          id = `${id}-${max.region()}`;
        }
      }
      res.set(id, data);
      ids.push(id);
    }

    res.forEach((_, id) => this.populate(res, id));

    // Fill in the locales that have no RBNF mapping.
    for (const locale of availableLocales()) {
      const { tag } = locale;
      const id = `${tag.language()}-${tag.script()}`;
      if (res.has(id)) {
github phensley / cldr-engine / packages / cldr / src / index.ts View on Github external
export * from './exports';

// Wire up the default configuration
import { CLDRFramework } from '@phensley/cldr-core';
import { config } from './config';

CLDRFramework.setDefaultConfig(config);
github phensley / cldr-engine / packages / cldr-compiler / src / resource / pack.ts View on Github external
push(locale: Locale): void {
    // ensure default content is initialized
    if (defaultContent.size === 0) {
      loadDefaultContent();
    }

    const { tag } = locale;
    const script = tag.script();
    let layers = this.layers[script];
    if (layers === undefined) {
      layers = [];
      this.layers[script] = layers;
    }

    // Determine the default region / script
    const minimumTag = LanguageResolver.removeLikelySubtags(tag);

    // Determine default layer for this language
    if (minimumTag.compact() === minimumTag.language()) {
      this.defaultLayer = tag;
    }

    const layerIsDefault = defaultContent.has(tag.expanded());
    const layer = new Layer(tag, layerIsDefault);
    this.current = layer;
    layers.push(layer);
  }
github phensley / cldr-engine / packages / cldr-compiler / src / rbnf / collector.ts View on Github external
// compact each tag to language-script with region if specified
        const tag = parseLanguageTag(name);
        const max = LanguageResolver.resolve(name);
        id = `${max.language()}-${max.script()}`;
        if (tag.hasRegion()) {
          id = `${id}-${max.region()}`;
        }
      }
      res.set(id, data);
      ids.push(id);
    }

    res.forEach((_, id) => this.populate(res, id));

    // Fill in the locales that have no RBNF mapping.
    for (const locale of availableLocales()) {
      const { tag } = locale;
      const id = `${tag.language()}-${tag.script()}`;
      if (res.has(id)) {
        continue;
      }
      // Default to 'en-Latn' spellout
      res.set(id, res.get('en-Latn')!);
      ids.push(id);
    }

    this.core.push('root');

    // Identify the rbnf rulesets that are globally-accessible. We need to
    // ensure that each locale that requires one of these has the correct
    // set of rbnf rulesets in its resource bundle.
    const { NumberingSystems } = getSupplemental();