i18n

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: MIT Imports: 5 Imported by: 25

README

i18n

Documentation

Index

Constants

View Source
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"
	// LocalCodeUaUa is locale code
	LocalCodeUaUa = "ua-UA"
	// LocalCodeRuRu is locale code
	LocalCodeRuRu = "ru-RU"

	// LocaleCodeFaIR is locale code
	LocaleCodeFaIR = "fa-IR"
	// LocaleCodeItIT is locale code
	LocaleCodeItIT = "it-IT"

	// 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"

	// LocaleCodeKoKO is locale code
	LocaleCodeKoKO = "ko-KO"
	// LocaleCodeJaJP is locale code
	LocaleCodeJaJP = "ja-JP"
	// LocaleCodeZhCN is locale code
	LocaleCodeZhCN = "zh-CN"
)

Variables

View Source
var (
	// LocaleUndefined is undefined locale
	LocaleUndefined = Locale{Code5: LocaleCodeUndefined, NativeTitle: "Undefined", EnglishTitle: "Undefined"}

	// LocaleEnUS is en-US locale
	LocaleEnUS = Locale{Code5: LocaleCodeEnUS, NativeTitle: "English", EnglishTitle: "English", FlagIcon: "🇺🇸"}

	// LocaleUaUa is locale
	LocaleUaUa = Locale{Code5: LocalCodeRuRu, NativeTitle: "Русский", EnglishTitle: "Russian", FlagIcon: "🇷🇺"}

	// LocaleRuRu is locale
	LocaleRuRu = Locale{Code5: LocalCodeRuRu, 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: "🇮🇹"}

	// 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: "🇮🇷"}

	// 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: "🇨🇳"}
)

LocalesByCode5 map of locales by 5-character code

Functions

This section is empty.

Types

type Locale

type Locale struct {
	Code5        string
	IsRtl        bool
	NativeTitle  string
	EnglishTitle string
	FlagIcon     string
}

Locale describes language

func GetLocaleByCode5 added in v0.0.2

func GetLocaleByCode5(code5 string) Locale

GetLocaleByCode5 returns locale by 5-character code

func (Locale) SiteCode

func (l Locale) SiteCode() string

SiteCode returns code for using in website URLs

func (Locale) String

func (l Locale) String() string

String represent locale information as string

func (Locale) TitleWithIcon

func (l Locale) TitleWithIcon() string

TitleWithIcon returns name of the language and flag emoji

func (Locale) TitleWithIconAndNumber

func (l Locale) TitleWithIconAndNumber(i int) string

TitleWithIconAndNumber returns name, flag emoji and a number // TODO: should bot be here

type LocalesProvider

type LocalesProvider interface {
	GetLocaleByCode5(code5 string) (Locale, error)
}

LocalesProvider provides locale by code

func NewSupportedLocales added in v0.0.4

func NewSupportedLocales(locales []string) LocalesProvider

type Logger

type Logger interface {
	Debugf(c context.Context, format string, args ...interface{})
	Errorf(c context.Context, format string, args ...interface{})
	Warningf(c context.Context, format string, args ...interface{})
}

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

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 {
	GetTranslator(c context.Context) Translator
	SupportedLocales() LocalesProvider
	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 is interface for translate providers

func NewMapTranslator

func NewMapTranslator(c context.Context, 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

Jump to

Keyboard shortcuts

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