i18n

package
v1.60.5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 7 Imported by: 22

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NilCountry = Country("")

NilCountry represents our nil, or unknown country

View Source
var NilLanguage = Language("")

NilLanguage represents our nil, or unknown language

View Source
var NilLocale = Locale("")

Functions

This section is empty.

Types

type BCP47Matcher

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

BCP47Matcher helps find best matching locale from a set of available locales

func NewBCP47Matcher

func NewBCP47Matcher(codes ...string) *BCP47Matcher

NewBCP47Matcher creates a new BCP47 matcher from the set of available locales which must be valid BCP47 tags.

func (*BCP47Matcher) ForLocales

func (m *BCP47Matcher) ForLocales(preferred ...Locale) string

type Country

type Country string

Country is a ISO 3166-1 alpha-2 country code

func DeriveCountryFromTel

func DeriveCountryFromTel(number string) Country

DeriveCountryFromTel attempts to derive a country code (e.g. RW) from a phone number

func (Country) MarshalJSON

func (c Country) MarshalJSON() ([]byte, error)

func (*Country) Scan

func (c *Country) Scan(value any) error

Place nicely with NULLs if persisting to a database or JSON

func (*Country) UnmarshalJSON

func (c *Country) UnmarshalJSON(b []byte) error

func (Country) Value

func (c Country) Value() (driver.Value, error)

type Language

type Language string

Language is holds a an ISO-639-3 language code.

func ParseLanguage

func ParseLanguage(lang string) (Language, error)

ParseLanguage returns a new Language for the passed in language string, or an error if not found

func (Language) ISO639_1

func (l Language) ISO639_1() string

ISO639_1 returns the ISO-639-1 2-letter code for this language if it has one

func (Language) MarshalJSON

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

func (*Language) Scan

func (l *Language) Scan(value any) error

Place nicely with NULLs if persisting to a database or JSON

func (*Language) UnmarshalJSON

func (l *Language) UnmarshalJSON(b []byte) error

func (Language) Value

func (l Language) Value() (driver.Value, error)

type Locale

type Locale string

Locale is the combination of a language and optional country, e.g. US English, Brazilian Portuguese, encoded as the language code followed by the country code, e.g. eng-US, por-BR. Every locale is valid BCP47 language tag, tho not every BCP47 language tag is a valid goflow locale because we only use ISO-639-3 3 letter codes to represent language.

func NewLocale

func NewLocale(l Language, c Country) Locale

NewLocale creates a new locale

func (Locale) MarshalJSON

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

func (*Locale) Scan

func (l *Locale) Scan(value any) error

Place nicely with NULLs if persisting to a database or JSON

func (Locale) Split

func (l Locale) Split() (Language, Country)

func (*Locale) UnmarshalJSON

func (l *Locale) UnmarshalJSON(b []byte) error

func (Locale) Value

func (l Locale) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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