iso6391

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2023 License: MIT Imports: 0 Imported by: 18

README

ISO 639-1

Go Reference CircleCI Go Report Card Chat on Discord

List of all ISO 639-1 language names, native names and two character codes as well as functions for convenient access. The lists of all names and codes (Codes, Names, NativeNames, Languages) are build in the init function for quick read access. For full documentation please read the Godocs.

Installation

go get github.com/emvi/iso-639-1

Example

fmt.Println(iso6391.Codes)          // print all codes
fmt.Println(iso6391.Names)          // print all names
fmt.Println(iso6391.NativeNames)    // print all native names
fmt.Println(iso6391.Languages)      // print all language objects {Code, Name, NativeName}

fmt.Println(iso6391.FromCode("en"))             // prints {Code: "en", Name: "English", NativeName: "English"}
fmt.Println(iso6391.Name("en"))                 // prints "English"
fmt.Println(iso6391.NativeName("zh"))           // prints "中文"
fmt.Println(iso6391.CodeFromName("English"))    // prints "en"
fmt.Println(iso6391.ValidCode("en"))            // prints true
// ... see Godoc for more functions

Contribute

See CONTRIBUTING.md

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Codes is a list of all ISO 639-1 two character codes.
	Codes []string

	// Names is a list of all ISO 639-1 english language names.
	Names []string

	// NativeNames is a list of all ISO 639-1 native language names.
	NativeNames []string
)
View Source
var Languages = map[string]Language{}/* 184 elements not displayed */

Languages is a map of all ISO 639-1 languages using the two character lowercase language code as key.

Functions

func CodeForName

func CodeForName(name string) string

CodeForName returns the language code for given name.

func CodeForNativeName

func CodeForNativeName(name string) string

CodeForNativeName returns the language code for given native name.

func Name

func Name(code string) string

Name returns the language name in english for given code.

func NativeName

func NativeName(code string) string

NativeName returns the language native name for given code.

func ValidCode

func ValidCode(code string) bool

ValidCode returns true if the given code is a valid ISO 639-1 language code. The code must be passed in lowercase.

func ValidName

func ValidName(name string) bool

ValidName returns true if the given name is a valid ISO 639-1 language name. The name must use uppercase characters (e.g. English, Hiri Motu, ...).

func ValidNativeName

func ValidNativeName(name string) bool

ValidNativeName returns true if the given code is a valid ISO 639-1 language native name. The name must be passed in its native form (e.g. English, 中文, ...).

Types

type Language

type Language struct {
	Code       string
	Name       string
	NativeName string
}

Language is an ISO 639-1 language with code, name and native name.

func FromCode

func FromCode(code string) Language

FromCode returns the language for given code.

func FromName

func FromName(name string) Language

FromName returns the language for given name.

func FromNativeName

func FromNativeName(name string) Language

FromNativeName returns the language for given native name.

Jump to

Keyboard shortcuts

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