Documentation
¶
Overview ¶
Package lang is the family's language table: every language a model in an app's catalogue may speak or understand, as embedded data. It covers OmniVoice's 646 languages and Whisper's 100 (99 + Cantonese), 652 in all, with English, native and Simplified Chinese names, the usual script, an RTL flag, the likely region and its flag.
Codes are BCP-47 primary language subtags: ISO 639-1 when one exists, else ISO 639-3 (OmniVoice's convention). Lookup also accepts full tags ("zh-Hans-CN"), ISO 639-3 and 639-2/B codes ("cmn", "fre") and legacy codes ("iw", Whisper's "jw").
Data: languages.tsv and aliases.tsv, generated by gen/main.go from the OmniVoice and Whisper lists and Unicode CLDR 48.2.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Canonical ¶
Canonical returns the table code for a tag or alias ("zh-Hans-CN" → "zh", "cmn" → "zh", "iw" → "he", "jw" → "jv"), or "" when unknown.
func Fold ¶
Fold is the search form of s: NFD, combining marks removed, lower-case, white space collapsed. "Français" and "francais" fold alike.
func Match ¶
Match reports whether a model whose language parameter accepts the codes in supported (any spelling Lookup understands, e.g. a catalogue's "en-US") can speak code, and which of its codes to pass. An exact language wins over a macrolanguage relation ("arb" matches a model that lists "ar", and the other way round).
func OmniVoiceCodes ¶
func OmniVoiceCodes() []string
OmniVoiceCodes and WhisperCodes are the codes each model takes, in the model's own spelling (Whisper: "jw", "tl").
func WhisperCodes ¶
func WhisperCodes() []string
Types ¶
type Language ¶
type Language struct {
Code string // "zh", "en", "arb"
ISO639_3 string // "cmn", "eng", "arb"
Name string // English name: "Chinese"
Native string // the name in the language itself ("中文"); "" when unknown
Script string // ISO 15924 code of the usual script: "Hans", "Latn", "Arab"
RTL bool // the usual script is written right to left
Region string // likely region: ISO 3166-1 alpha-2, or a UN M49 number ("001")
Macro string // the macrolanguage it belongs to, if any ("arb" → "ar")
OmniVoice bool // in OmniVoice's list
Whisper bool // in Whisper's list
WhisperCode string // Whisper's code when it differs from Code ("jw" for "jv")
// contains filtered or unexported fields
}
Language is one row of the table.
func All ¶
func All() []Language
All returns every language, sorted by English name. The slice is a copy.
func Search ¶
Search returns the languages matching query by code, alias or any name (English, native, Chinese), case- and diacritic-insensitively, best first: exact code, exact name, name prefix, word prefix, substring. An empty query returns All().
type Option ¶
type Option struct {
Language
Supported bool // the model can speak it
ModelCode string // what to pass to the model (see Match); "" when unsupported
}
Option is a language in a picker for one model.
type Tag ¶
type Tag struct {
Tag string // as given, canonicalised by x/text ("zh-Hant-TW")
Code string // the table's code ("zh")
Name string // English name ("Chinese")
Native string // endonym ("中文"), may be ""
Script string // explicit or usual script ("Hant")
Region string // explicit region ("TW"), "" when none
RTL bool
}
Tag is a parsed BCP-47 tag: the table's language plus the script and region the tag names, as translation targets and prompts use it.
func Parse ¶
Parse parses a BCP-47 tag ("zh-TW", "pt_BR", "cmn"); ok is false for languages the table does not know. The script is the tag's when it names one, else the language's usual script; zh-TW, zh-HK and zh-MO are Traditional Chinese.
func (Tag) Describe ¶
Describe is the language as written for prompts: "Spanish (Mexico)", "Chinese (Traditional, Taiwan)", "Japanese".