The address of the page; addresses other than absolute http or https URLs state no language
Optionallanguages: readonly string[]
The tags of the languages the page may be in, matched by base language, so that pt-PT admits
pt; codes and names stating other languages are ignored, as if absent; if omitted, any language is read
The ISO 639-1 tag of the language url states, or its ISO 639-2 code if it has no two-letter tag, stripped
of script and region subtags, or undefined if url states no language, or none admitted by languages
import { inferTag } from "@grafctory/core/language";
inferTag("https://example.org/en/"); // "en"
inferTag("https://example.org/page.php?lang=de"); // "de"
inferTag("https://example.org/home_en.htm"); // "en"
inferTag("https://example.org/id/1234"); // "id"
inferTag("https://example.org/id/1234", ["en", "fr"]); // undefined - Indonesian not admitted
inferTag("https://www.example.de/"); // undefined - hosts never read
identifyTag for reading languages named in words
Infers the language of a web page from its address.
Tells apart the localised versions of a page published on the same site, as
https://example.org/en/andhttps://example.org/pt, which share a host and differ only in the language their address states. The language is read from the first of the following parts of the address that states one, ignoring any later ones:lang,language,locale,lngorhlquery parameter holding a two- or three-letter code, as in?lang=enor?lang=fil, or a language name in any language, as in?lang=Englishor?lang=Inglese/en/,/en-gb/or/courses/EN/home_en.htm,report_eng.pdforGuida – Versione Inglese.pdf, ignoring the file extensionHosts and the words of hyphenated slugs are never read, so
/universite-de-parisisn't taken as German. Codes that identify no language, asundorzxx, are ignored. Path segments and file name words admit fewer codes to keep ordinary words from passing for languages:/iii/,/mal/andnew_report.pdfaren't read as Sichuan Yi, Malayalam or Newari, the languages their three-letter codes would otherwise state.Restrict
languagesto the languages a site is published in to rule out codes such as/id/or/my/, which name records and personal areas far more often than they state Indonesian or Burmese.