@grafctory/core - v0.15.0
    Preparing search index...

    Function identifyTag

    • Identifies the language a name refers to.

      Resolves languages named in words rather than in tags, whatever language the name is written in: German, tedesco, Deutsch and allemand all identify de. Names are matched ignoring case, accents and surrounding whitespace. A name that different locales give to different languages, as Akan, identifies none of them: an ambiguous name is never resolved by a guess the caller could mistake for a reliable match.

      Important

      Names are supplied by the JavaScript runtime: the names recognised vary with the platform, and only languages with a two-letter ISO 639-1 code are identified, so that Hawaiian, coded haw alone, identifies nothing.

      Parameters

      • name: string

        The name of the language, written in any language

      Returns Optional<string>

      The ISO 639-1 tag of the language name refers to, or undefined if name refers to no language the runtime knows, or to more than one language in the different locales it is written in

      import { identifyTag } from "@grafctory/core/language";

      identifyTag("German"); // "de"
      identifyTag("Français"); // "fr"
      identifyTag("francais"); // "fr" - accents ignored
      identifyTag("de"); // undefined - a tag, not a name

      nameTag for the converse, naming the language a tag identifies