Documentation ¶
Overview ¶
Based on language-subtag-registry updated 2023-08-02, generated 2023-10-02
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsKnownCombination ¶
IsKnownCombination checks a language code against known language region pairs. Returns true if the language is valid and no region is specified or the language-region combination is known.
Types ¶
type LanguageInformation ¶
type LanguageInformation struct { // Code in the canonical xx[-YY] format. Code string // Language (ISO 639-1) code. Language string // LanguageName as defined by IANA. LanguageName string // HasRegion is true if a region was specified for the language. HasRegion bool // Region is the uppercase ISO 3166-1 alpha-2 code. Region string // RegionName as defined by IANA. RegionName string }
LanguageInformation contains information about a language code.
func GetLanguage ¶
func GetLanguage(code string) (LanguageInformation, error)
GetLanguage validates a language (ISO 639-1) region (ISO 3166-1 alpha-2) combination in the format "language[-region]" and returns basic information about the language.
Example ¶
package main import ( "fmt" "github.com/ttab/langos" ) func main() { info, err := langos.GetLanguage("en-gb") if err != nil { panic(err) } knownCombo := langos.IsKnownCombination(info.Code) fmt.Printf("code: %s\n", info.Code) fmt.Printf("language: %s - %s\n", info.Language, info.LanguageName) fmt.Printf("region: %s - %s\n", info.Region, info.RegionName) fmt.Printf("is known combination: %v", knownCombo) }
Output: code: en-GB language: en - English region: GB - United Kingdom is known combination: true
Click to show internal directories.
Click to hide internal directories.