Documentation
¶
Overview ¶
Package language resolves a language name, alias, or ISO 639-1 or ISO 639-2 code to an ISO 639-3 code. The list lives in languages.tsv and the lookup tables are generated from it; README.md explains how and why.
Index ¶
- Variables
- type Code
- func (lc Code) IsZero() bool
- func (lc Code) MarshalJSON() ([]byte, error)
- func (lc Code) MarshalText() ([]byte, error)
- func (lc *Code) Scan(src any) error
- func (lc Code) ShortCode() ShortCode
- func (lc Code) String() string
- func (lc Code) TypescriptType() any
- func (lc *Code) UnmarshalJSON(b []byte) error
- func (lc *Code) UnmarshalText(b []byte) error
- func (lc Code) Value() (driver.Value, error)
- type LanguageCode
- type ShortCode
Constants ¶
This section is empty.
Variables ¶
var SupportedLanguages = map[Code]string{}/* 244 elements not displayed */
SupportedLanguages maps the ISO 639-3 code to the Dutch language name. Only the languages in the supported set are in here. To parse a name or a code, use Parse.
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code uint16
Code is an ISO 639-3 language code, held as its three letters packed into a base 26 number. Only Parse and CodeOf produce one, so a non-zero Code always spells a code.
func CodeOf ¶
CodeOf returns the Code for a literal ISO 639-3 code, and the zero Code for anything that is not three letters. It checks the shape only: use Parse to also check that a language by that code exists.
func Parse ¶
Parse returns the Code for the given language name, ISO 639-1 2-letter, or ISO 639-2/639-3 3-letter code. The lookup is case-insensitive and normalizes the input.
func (Code) MarshalJSON ¶
func (Code) MarshalText ¶
MarshalText is what encoding/json uses for a map key, where MarshalJSON is not consulted. SupportedLanguages is keyed on Code and is meant to be served as JSON.
func (*Code) Scan ¶
Scan converts rows still holding an ISO 639-1 code to ISO 639-3. Unlike UnmarshalJSON it fails on a code it cannot resolve, since that is a broken row and not user input.
func (Code) ShortCode ¶
ShortCode returns the ISO 639-1 code of this language, or the zero ShortCode for the vast majority of ISO 639-3 languages that have none.
func (Code) TypescriptType ¶
TypescriptType tells a TypeScript type generator that a Code goes over the wire as its ISO 639-3 code, not as the number the Go type is.
func (*Code) UnmarshalJSON ¶
UnmarshalJSON reads a code it cannot resolve as the zero value rather than as an error, so one unknown language does not reject an otherwise valid payload.
func (*Code) UnmarshalText ¶
UnmarshalText mirrors MarshalText, and like UnmarshalJSON reads an unknown code as no language rather than as an error.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
gen
command
Command gen regenerates tables_gen.go from languages.tsv.
|
Command gen regenerates tables_gen.go from languages.tsv. |
|
langcode
Package langcode holds the encoding the generated language table is written in.
|
Package langcode holds the encoding the generated language table is written in. |
|
langtable
Package langtable turns languages.tsv into the lookup tables the language package compiles in.
|
Package langtable turns languages.tsv into the lookup tables the language package compiles in. |