intl

package
v0.0.0-...-122f59b Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const BuiltinBaseLanguage = "en"

BuiltinBaseLanguage is the default language. It is english. Default templates and translation are written in english.

Variables

View Source
var AvailableLanguages = []string{
	"en",
	"af",
	"am",
	"ar",
	"hy",
	"az",
	"eu",
	"be",
	"bn",
	"bg",
	"my",
	"ca",
	"zh-HK",
	"zh-CN",
	"zh-TW",
	"hr",
	"cs",
	"da",
	"nl",
	"et",
	"fil",
	"fi",
	"fr",
	"gl",
	"ka",
	"de",
	"el",
	"hi",
	"hu",
	"is",
	"id",
	"it",
	"ja",
	"kn",
	"km",
	"ko",
	"ky",
	"lo",
	"lv",
	"lt",
	"mk",
	"ms",
	"ml",
	"mr",
	"mn",
	"ne",
	"no",
	"fa",
	"pl",
	"pt",
	"pt-PT",
	"ro",
	"ru",
	"sr",
	"si",
	"sk",
	"sl",
	"es-419",
	"es",
	"sw",
	"sv",
	"ta",
	"te",
	"th",
	"tr",
	"uk",
	"vi",
	"zu",
}

AvailableLanguages are the languages we recognize.

View Source
var BuiltinLanguages = []string{
	"en",
	"zh-HK",
	"zh-TW",
}

BuiltinLanguages are the languages we have localization.

View Source
var CldrLanguages = []string{}/* 710 elements not displayed */

Copied from https://github.com/unicode-org/cldr-json/blob/main/cldr-json/cldr-core/availableLocales.json For mapping BCP47 language tag to CLDR language tag.

Functions

func BestMatch

func BestMatch(preferredLanguageTags []string, supportedLanguageTags SupportedLanguages) (int, language.Tag)

matcher.Match will not return tags with higher confidence For example, with supported tags zh-CN, zh-HK matcher.Match("zh-Hant") will return zh-CN, which confidence is Low, but not zh-HK which confidence is High. This function is an implementation of Match trying to return an option with higher confidence.

func GetMatcher

func GetMatcher(supported []language.Tag) language.Matcher

func GetPreferredLanguageTags

func GetPreferredLanguageTags(ctx context.Context) []string

func HTMLDir

func HTMLDir(languageTag string) string

func LocalizeJSONObject

func LocalizeJSONObject(preferredLanguageTags []string, fallbackLanguage FallbackLanguage, jsonObject map[string]interface{}, key string) string

LocalizeJSONObject returns the localized value of key in jsonObject according to preferredLanguageTags.

func LocalizeStringMap

func LocalizeStringMap(preferredLanguageTags []string, fallbackLanguage FallbackLanguage, stringMap map[string]string, key string) string

LocalizeStringMap returns the localized value of key in stringMap according to preferredLanguageTags.

func Match_Deprecated

func Match_Deprecated(preferredLanguageTags []string, supportedLanguageTags SupportedLanguages) (int, language.Tag)

Match matches preferredLanguageTags to supportedLanguageTags using fallbackLanguageTag as fallback. NOTE(tung): Replaced by BestMatch. Use BestMatch instead. This function were keep just for reference and testing

func ParseAcceptLanguage

func ParseAcceptLanguage(header string) []string

func ParseUILocales

func ParseUILocales(uiLocales string) []string

func Resolve

func Resolve(preferred []string, fallback string, supported []string) (int, language.Tag)

Resolve resolved language based on fallback and supportedLanguages config. Return index of supportedLanguages and resolved language tag. Return -1 if not found

func ResolveUnicodeCldr

func ResolveUnicodeCldr(lang language.Tag, fallback language.Tag) string

ResolveUnicodeCldr resolves language tag to Unicode CLDR language tag.

func WithPreferredLanguageTags

func WithPreferredLanguageTags(ctx context.Context, tags []string) context.Context

Types

type FallbackLanguage

type FallbackLanguage string

FallbackLanguage is non-empty. Its purpose is to ensure fallback language is non-empty at compile time. Use Fallback to construct FallbackLanguage. Use string() to convert it back to a string.

func Fallback

func Fallback(fallbackLanguageTag string) FallbackLanguage

Fallback constructs FallbackLanguage.

type SupportedLanguages

type SupportedLanguages []string

SupportedLanguages ensures fallback language is the first element.

func Supported

func Supported(supportedLanguageTags []string, fallbackLanguage FallbackLanguage) SupportedLanguages

Supported constructs SupportedLanguages.

Jump to

Keyboard shortcuts

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