langos

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: MIT Imports: 2 Imported by: 3

README

Langos

GoDev Build Status

Langos validates a language (ISO 639-1) region (ISO 3166-1 alpha-2) combinations in the format "language[-region]" and returns basic information about the language and region.

Example:

func ExampleGetLanguage() {
	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
}

Data sources

Langos uses the languages and regions defined in the IANA language subtag registry together with the the list of known language and region codes compiled by Sean Christ.

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

func IsKnownCombination(code string) bool

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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