Documentation ¶
Index ¶
Constants ¶
const ( // LocaleCodeUndefined is undefined locale code LocaleCodeUndefined = "UNDEFINED" // LocaleCodeEnUS is locale code LocaleCodeEnUS = "en-US" // LocaleCodeEnUK is locale code LocaleCodeEnUK = "en-UK" LocaleCodeUzUZ = "uz-UZ" // LocaleCodeUaUA is locale code LocaleCodeUaUA = "ua-UA" // LocaleCodeRuRU is locale code LocaleCodeRuRU = "ru-RU" // LocaleCodeFaIR is locale code LocaleCodeFaIR = "fa-IR" // LocaleCodeItIT is locale code LocaleCodeItIT = "it-IT" LocaleCodeIdID = "id-ID" // LocaleCodeDeDE is locale code LocaleCodeDeDE = "de-DE" // LocaleCodeEsES is locale code LocaleCodeEsES = "es-ES" // LocaleCodeFrFR is locale code LocaleCodeFrFR = "fr-FR" // LocaleCodePlPL is locale code LocaleCodePlPL = "pl-PL" // LocaleCodePtPT is locale code LocaleCodePtPT = "pt-PT" // LocaleCodePtBR is locale code LocaleCodePtBR = "pt-BR" LocaleCodeTrTR = "tr-TR" // LocaleCodeKoKO is locale code LocaleCodeKoKO = "ko-KO" // LocaleCodeJaJP is locale code LocaleCodeJaJP = "ja-JP" // LocaleCodeZhCN is locale code LocaleCodeZhCN = "zh-CN" )
Variables ¶
var ( // LocaleUndefined is an undefined locale LocaleUndefined = Locale{Code5: LocaleCodeUndefined, NativeTitle: "Undefined", EnglishTitle: "Undefined"} // LocaleEnUS is en-US locale LocaleEnUS = Locale{Code5: LocaleCodeEnUS, NativeTitle: "English", EnglishTitle: "English", FlagIcon: "🇺🇸"} // LocaleEnUK is en-UK locale LocaleEnUK = Locale{Code5: LocaleCodeEnUK, NativeTitle: "English", EnglishTitle: "English", FlagIcon: "🇬🇧"} // LocaleUaUa is locale LocaleUaUa = Locale{Code5: LocaleCodeUaUA, NativeTitle: "Українська", EnglishTitle: "Ukrainian", FlagIcon: "🇺🇦"} // LocaleRuRu is locale LocaleRuRu = Locale{Code5: LocaleCodeRuRU, NativeTitle: "Русский", EnglishTitle: "Russian", FlagIcon: "🇷🇺"} // LocaleDeDe is locale LocaleDeDe = Locale{Code5: LocaleCodeDeDE, NativeTitle: "Deutsch", EnglishTitle: "German", FlagIcon: "🇩🇪"} // LocaleEsEs is locale LocaleEsEs = Locale{Code5: LocaleCodeEsES, NativeTitle: "Español", EnglishTitle: "Spanish", FlagIcon: "🇪🇸"} // LocaleFrFr is locale LocaleFrFr = Locale{Code5: LocaleCodeFrFR, NativeTitle: "Français", EnglishTitle: "French", FlagIcon: "🇫🇷"} // LocaleItIt is locale LocaleItIt = Locale{Code5: LocaleCodeItIT, NativeTitle: "Italiano", EnglishTitle: "Italian", FlagIcon: "🇮🇹"} LocaleIdID = Locale{Code5: LocaleCodeIdID, NativeTitle: "Bahasa Indonesia", EnglishTitle: "Indonesian", FlagIcon: "🇮🇩"} // LocalePlPl is locale LocalePlPl = Locale{Code5: LocaleCodePlPL, NativeTitle: "Polszczyzna", EnglishTitle: "Polish", FlagIcon: "🇵🇱"} // LocalePtPt is locale LocalePtPt = Locale{Code5: LocaleCodePtPT, NativeTitle: "Português (PT)", EnglishTitle: "Portuguese (PT)", FlagIcon: "🇵🇹"} // LocalePtBr is locale LocalePtBr = Locale{Code5: LocaleCodePtBR, NativeTitle: "Português (BR)", EnglishTitle: "Portuguese (BR)", FlagIcon: "🇧🇷"} // LocaleFaIr is locale LocaleFaIr = Locale{Code5: LocaleCodeFaIR, IsRtl: true, NativeTitle: "فارسی", EnglishTitle: "Farsi", FlagIcon: "🇮🇷"} LocaleTrTr = Locale{Code5: LocaleCodeTrTR, NativeTitle: "Türkçe", EnglishTitle: "Turkish", FlagIcon: "🇹🇷"} // LocaleKoKo is locale LocaleKoKo = Locale{Code5: LocaleCodeKoKO, NativeTitle: "한국어", EnglishTitle: "Korean", FlagIcon: "🇰🇷"} // LocaleJaJp is locale LocaleJaJp = Locale{Code5: LocaleCodeJaJP, NativeTitle: "日本語", EnglishTitle: "Japanese", FlagIcon: "🇯🇵"} LocaleUzUz = Locale{Code5: LocaleCodeUzUZ, NativeTitle: "Oʻzbek tili", EnglishTitle: "Uzbek", FlagIcon: "🇨🇳"} // LocaleZhCn is locale LocaleZhCn = Locale{Code5: LocaleCodeZhCN, NativeTitle: "中文", EnglishTitle: "Chinese", FlagIcon: "🇨🇳"} )
var LocalesByCode5 = map[string]Locale{ LocaleCodeEnUS: LocaleEnUS, LocaleCodeEnUK: LocaleEnUK, LocaleCodeUaUA: LocaleUaUa, LocaleCodeRuRU: LocaleRuRu, LocaleCodeDeDE: LocaleDeDe, LocaleCodeEsES: LocaleEsEs, LocaleCodeFrFR: LocaleFrFr, LocaleCodeItIT: LocaleItIt, LocaleCodeIdID: LocaleIdID, LocaleCodePlPL: LocalePlPl, LocaleCodePtPT: LocalePtPt, LocaleCodePtBR: LocalePtBr, LocaleCodeFaIR: LocaleFaIr, LocaleCodeKoKO: LocaleKoKo, LocaleCodeJaJP: LocaleJaJp, LocaleCodeUzUZ: LocaleUzUz, LocaleCodeZhCN: LocaleZhCn, LocaleCodeTrTR: LocaleTrTr, }
LocalesByCode5 map of locales by 5-character code
Functions ¶
This section is empty.
Types ¶
type Locale ¶
type Locale struct { Code5 string NativeTitle string EnglishTitle string FlagIcon string IsRtl bool }
Locale describes language
func GetLocaleByCode5 ¶ added in v0.0.2
GetLocaleByCode5 returns locale by 5-character code
func (Locale) TitleWithIcon ¶
TitleWithIcon returns name of the language and flag emoji
func (Locale) TitleWithIconAndNumber ¶
TitleWithIconAndNumber returns name, flag emoji and a number // TODO: should bot be here
type LocalesProvider ¶
type LocalesProvider interface { SupportedLocales() []Locale GetLocaleByCode5(code5 string) (Locale, error) }
LocalesProvider provides locale by code
func NewSupportedLocales ¶ added in v0.0.4
func NewSupportedLocales(code5s []string) LocalesProvider
type SingleLocaleTranslator ¶
type SingleLocaleTranslator interface { Locale() Locale Translate(key string, args ...interface{}) string TranslateNoWarning(key string, args ...interface{}) string }
SingleLocaleTranslator should be implemente by translators to a single language
func NewSingleMapTranslator ¶
func NewSingleMapTranslator(locale Locale, translator Translator) SingleLocaleTranslator
NewSingleMapTranslator creates new single map translator
type SingleLocaleTranslatorWithBackup ¶
type SingleLocaleTranslatorWithBackup struct { PrimaryTranslator SingleLocaleTranslator BackupTranslator SingleLocaleTranslator }
SingleLocaleTranslatorWithBackup should be implemente by translators to a single language with backup to another one.
func NewSingleLocaleTranslatorWithBackup ¶
func NewSingleLocaleTranslatorWithBackup(primary, backup SingleLocaleTranslator) SingleLocaleTranslatorWithBackup
NewSingleLocaleTranslatorWithBackup creates SingleLocaleTranslatorWithBackup
func (SingleLocaleTranslatorWithBackup) Locale ¶
func (t SingleLocaleTranslatorWithBackup) Locale() Locale
Locale returns local of the translator
func (SingleLocaleTranslatorWithBackup) Translate ¶
func (t SingleLocaleTranslatorWithBackup) Translate(key string, args ...interface{}) string
Translate translates
func (SingleLocaleTranslatorWithBackup) TranslateNoWarning ¶
func (t SingleLocaleTranslatorWithBackup) TranslateNoWarning(key string, args ...interface{}) string
TranslateNoWarning translates and does not log warning if translation not found
type TranslationContext ¶ added in v0.0.3
type TranslationContext interface { LocalesProvider GetTranslator(c context.Context) Translator SetLocale(code5 string) error }
TranslationContext is an i18n context (internationalization)
func NewContext ¶ added in v0.0.3
func NewContext(c context.Context, supportedLocales LocalesProvider) TranslationContext
type Translator ¶
type Translator interface { Translate(key, locale string, args ...interface{}) string TranslateNoWarning(key, locale string, args ...interface{}) string }
Translator provides translations by key and locale
func NewMapTranslator ¶
func NewMapTranslator(c context.Context, defaultLocale string, translations map[string]map[string]string) Translator
NewMapTranslator creates new map translator
type TranslatorProvider ¶ added in v0.0.3
type TranslatorProvider = func(locale string) Translator