language

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound           = errors.New("locale not found")
	ErrUnknownLocales     = errors.New("unknown locale(s)")
	ErrUnknownLanguages   = errors.New("unknown language(s)")
	ErrConflictingLocales = errors.New("locales should not have same language and different region")
)

Functions

func CountApplicability

func CountApplicability(cfg *setting.Configuration, ld *data.LocaleData, str string, stripTimezone bool) (int, int)

func DetectLanguage

func DetectLanguage(cfg *setting.Configuration, str string, languages []string,
	uniqueCharsets map[string][]rune, detectLanguagesFunction func(string) []string) (string, error)

func GetLanguages

func GetLanguages(locales []string, languages []string, useGivenOrder bool) ([]string, error)

func GetLocale

func GetLocale(code string) (*data.LocaleData, error)

GetLocale returns a single locale instance based on the specified locale `code`, e.g. 'fr-PF', 'qu-EC', 'af-NA'.

func GetLocales

func GetLocales(locales []string, languages []string, region string, useGivenOrder bool, allowConflictingLocales bool) ([]*data.LocaleData, error)

GetLocales returns list of locale data based on the specified `locales`, `languages` and `region`.

Parameter `locales` is a list of codes of locales which are to be loaded e.g. ['fr-PF', 'qu-EC', 'af-NA'], `languages` is a list of language codes e.g. ['en', 'es', 'zh-Hant'], and `region` is a region code, e.g. 'IN', '001', 'NE'. If `locales` are empty, languages and region are used to construct locales to load.

If `useGivenOrder` is true, the returned list is ordered in the order locales are given. If set to false, the list will be sorted by how common the locale is used in the world.

If `allowConflictingLocales` is set to true, locales with same language and different region can be loaded.

func GetUniqueCharsets

func GetUniqueCharsets(languages []string) map[string][]rune

func IsApplicable

func IsApplicable(cfg *setting.Configuration, ld *data.LocaleData, str string, stripTimezone bool) bool

IsApplicable checks the specified locale data is applicable to translate the date string `str`. The `str` parameter is a string representing date and/or time in a recognizably valid format. If `stripTimezone` set to true, timezone will be stripped and ignored.

func Simplify

func Simplify(ld *data.LocaleData, str string) string

func Split

func Split(ld *data.LocaleData, str string, keepFormatting bool, skippedTokens strutil.Dict) []string

Split splits the date string `str` using translations in locale data. If `keepFormatting` is set to true, it will retaing the formatting of date string.

func SplitSentence

func SplitSentence(ld *data.LocaleData, str string) []string

func Translate

func Translate(cfg *setting.Configuration, ld *data.LocaleData, str string, keepFormatting bool) []string

Translate the date string `str` to its English equivalent using information from the locale data. If `keepFormatting` is set to true, retain formatting of the date string after translation.

func TranslateSearch

func TranslateSearch(cfg *setting.Configuration, ld *data.LocaleData, str string) ([]string, []string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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