lang

package
v0.5.0-beta.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lang is the language table: every language a model in the 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

func Canonical(tag string) string

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

func Fold(s string) string

Fold is the search form of s: NFD, combining marks removed, lower-case, white space collapsed. "Français" and "francais" fold alike.

func Len

func Len() int

Len is the number of languages in the table.

func Match

func Match(supported []string, code string) (string, bool)

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 Lookup

func Lookup(tag string) (Language, bool)

Lookup finds a language by code, tag or alias (see Canonical).

func Search(query string) []Language

Search returns the languages matching query by code, alias or any name (English, native, Chinese, Japanese), case- and diacritic-insensitively, best first: exact code, exact name, name prefix, word prefix, substring. An empty query returns All().

func (Language) Flag

func (l Language) Flag() string

Flag is the flag emoji of the likely region, or "" when the region is not a country (Esperanto's "001").

func (Language) NameIn

func (l Language) NameIn(locale string) string

NameIn is the language's name for a UI in locale: the Simplified Chinese name for "zh…" locales and the Japanese one for "ja…" locales when known, else the English name.

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.

func Annotate

func Annotate(langs []Language, supported []string) []Option

Annotate marks each of langs as supported or not by a model, for a picker that shows unsupported languages disabled.

func ForModel

func ForModel(supported []string) []Option

ForModel lists the languages a model supports, one per supported code, in the table's order. Codes the table does not know are skipped.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL