bcp47_language

package
v2.0.20 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Language

type Language struct {
	// contains filtered or unexported fields
}

Language represents a BCP49 language entity. It includes the base ISO639 language, the original BCP47 code string, and the corresponding language.Tag from the golang.org/x/text/language package.

func ByStrErr

func ByStrErr(code string) (result Language, err error)

ByStrErr creates a new Language by parsing a BCP47 code string. It returns an error if the BCP47 code is invalid or if the base ISO639 language cannot be parsed.

func (Language) BaseISO639Language

func (l Language) BaseISO639Language() (language.Language, error)

BaseISO639Language returns the base ISO639 language of the BCP47 code. The returned language.Language represents the most significant part of the language identification used in the BCP47 code. For example, for the BCP47 code "en-US", the base ISO639 language would be "en".

This method will return an error if the ISO639 language cannot be determined from the BCP47 code.

func (Language) MarshalJSON added in v2.0.13

func (l Language) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. It marshals the Language into its BCP47 string representation.

func (Language) Raw

func (l Language) Raw() stdLanguage.Tag

Raw returns the parsed BCP47 code as a language.Tag.

func (Language) String

func (l Language) String() string

String returns the original BCP47 code string.

func (*Language) UnmarshalJSON

func (l *Language) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON unmarshals a JSON-encoded BCP47 code into a Language.

func (Language) Validate

func (l Language) Validate() (err error)

Validate checks if the Language is valid by attempting to parse its BCP47 code. It returns an error if the BCP47 code is invalid.

func (*Language) Value

func (l *Language) Value() (value driver.Value, err error)

Value returns the BCP47 code as a driver.Value for use with SQL databases.

Jump to

Keyboard shortcuts

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