How to use the @phensley/locale.LanguageResolver.resolve function in @phensley/locale

To help you get started, we’ve selected a few @phensley/locale 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
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 / cldr-core / __tests__ / _helpers / bundle.ts View on Github external
export const languageBundle = (tag: string, config?: SchemaConfig): Bundle => {
  const locale = LanguageResolver.resolve(tag);
  const language = locale.language();
  let spec: PackSpec | undefined;
  let key = tag;
  if (config !== undefined) {
    const raw = JSON.stringify(config);
    const hash = createHash('sha256').update(raw).update(VERSION).digest('hex');
    spec = { hash, config: raw };
    key = `${hash}-${pkg.version}-${tag}`;
  }

  let bundle = bundleCache.get(key);
  if (bundle === undefined) {
    const pack = loadPack(language, spec);
    bundle = pack.get(locale);
    bundleCache.set(key, bundle);
  }
github phensley / cldr-engine / packages / cldr-core / __tests__ / _helpers / bundle.ts View on Github external
export const customPack = (tag: string, config: SchemaConfig): string => {
  const locale = LanguageResolver.resolve(tag);
  const language = locale.language();
  const json = JSON.stringify(config);
  const hash = createHash('sha256').update(json).update(VERSION).digest('hex');
  return buildPack(language, { hash, config: json });
};
github phensley / cldr-engine / packages / cldr-core / src / locale / locales.ts View on Github external
allLocales = availableLocalesRaw.split('|').map(id => {
      const tag = LanguageResolver.resolve(id);
      return { id, tag } as Locale;
    });
  }
github phensley / cldr-engine / packages / locale-matcher / src / matcher.ts View on Github external
paradigmLocaleMap = paradigmLocales.reduce((o: ParadigmMap, k: string, i: number) => {
    const c = LanguageResolver.resolve(k).compact();
    o[c] = i;
    return o;
  }, {});
};

@phensley/locale

Locale subtag resolver

Apache-2.0
Latest version published 17 days ago

Package Health Score

62 / 100
Full package analysis

Popular @phensley/locale functions

Similar packages