How to use the @phensley/language-tag.LanguageTag 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 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
const returnTag = (real: LanguageTag, fast: FastTag): LanguageTag => {
  const language = fast[Tag.LANGUAGE];
  const script = fast[Tag.SCRIPT];
  const region = fast[Tag.REGION];

  return new LanguageTag(
    typeof language === 'number' ? undefined : language,
    typeof script === 'number' ? undefined : script,
    typeof region === 'number' ? undefined : region,
    real.variant(),
    real.extensions(),
    real.privateUse()
  );
};
github phensley / cldr-engine / packages / locale / src / locale.ts View on Github external
import { parseLanguageTag, LanguageTag } from '@phensley/language-tag';
import { LanguageResolver } from './resolver';

const UNDEFINED = new LanguageTag();

/**
 * Wrapper pairing an application's opaque locale identifier with a
 * parsed and resolved language tag object.
 *
 * @alpha
 */
export interface Locale {

  /**
   * Application's own identifier for the locale, e.g. 'en_US', 'fr-CA', etc.
   * We preserve this since applications may use it as a unique key to
   * resolve translated messages, and may be forced to use a legacy
   * identifier.
   */
  readonly id: string;
github phensley / cldr-engine / packages / locale-matcher / src / matcher.ts View on Github external
}

      for (let j = 0; j < this.count; j++) {
        const supported = this.supported[j];
        const distance = getDistance(desired.tag, supported.tag, threshold);
        if (bestDistance === U || distance < bestDistance) {
          bestDistance = distance;
          bestMatch = supported;
          bestDesired = desired;
        }
      }
    }
    const extensions = bestDesired.tag.extensions();
    const privateUse = bestDesired.tag.privateUse();
    const { id, tag } = bestMatch === U ? this.default : bestMatch;
    const result = new LanguageTag(tag.language(), tag.script(), tag.region(), tag.variant(), extensions, privateUse);
    return {
      locale: { id, tag: result },
      distance: bestMatch === U ? MAX_DISTANCE : bestDistance
    };
  }
}

@phensley/language-tag

Parsing and construction of BCP 47 language tags

Apache-2.0
Latest version published 17 days ago

Package Health Score

62 / 100
Full package analysis

Similar packages