strongo

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 10 Imported by: 0

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"
	// 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: "🇺🇸"}

	// 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: "🇨🇳"}
)
View Source
var EnvironmentNames = map[Environment]string{
	EnvUnknown:    "unknown",
	EnvProduction: "production",
	EnvStaging:    "staging",
	EnvDevTest:    "dev",
	EnvLocal:      "local",
}

EnvironmentNames is mapping of environment codes to environment names

LocalesByCode5 map of locales by 5-character code

Functions

func AddHTTPHandler

func AddHTTPHandler(pattern string, handler func(http.ResponseWriter, *http.Request))

AddHTTPHandler adds http handler with / suffix

Types

type AppContext

type AppContext interface {
	AppUserEntityKind() string
	AppUserEntityType() reflect.Type
	NewAppUserEntity() AppUser
	GetTranslator(c context.Context) Translator
	SupportedLocales() LocalesProvider
}

AppContext is app user context for an app

type AppUser

type AppUser interface {
	SetPreferredLocale(code5 string) error
	GetPreferredLocale() string

	SetNames(first, last, user string)
}

AppUser defines app user interface

type AppUserBase

type AppUserBase struct {
	DtCreated time.Time
	user.AccountsOfUser
	Locale    string `datastore:",noindex"`
	FirstName string `datastore:",noindex"`
	LastName  string `datastore:",noindex"`
	UserName  string `datastore:",noindex"`
}

AppUserBase hold common properties for AppUser interface

func (*AppUserBase) GetFullName

func (u *AppUserBase) GetFullName() string

func (*AppUserBase) GetPreferredLocale

func (u *AppUserBase) GetPreferredLocale() string

GetPreferredLocale gets preferred locale

func (*AppUserBase) SetNames

func (u *AppUserBase) SetNames(first, last, user string)

SetNames sets names

func (*AppUserBase) SetPreferredLocale

func (u *AppUserBase) SetPreferredLocale(v string) error

SetPreferredLocale sets preferred locale

type ContextHandler

type ContextHandler func(c context.Context, w http.ResponseWriter, r *http.Request) // TODO: Should be somewhere else?

type Environment

type Environment int8

Environment defines environment

const (
	// EnvUnknown is unknown environment
	EnvUnknown Environment = iota
	// EnvProduction is production environment
	EnvProduction
	// EnvStaging is staging environment
	EnvStaging
	// EnvDevTest is developers test environment
	EnvDevTest
	// EnvLocal is developer's local environment
	EnvLocal
)

type ExecutionContext

type ExecutionContext interface {
	SingleLocaleTranslator
	Context() context.Context
}

ExecutionContext is execution context for UI app Contains translator and context.Context

func NewExecutionContext

func NewExecutionContext(c context.Context, translator SingleLocaleTranslator) ExecutionContext

NewExecutionContext creates new execution context

type HandleWithContext

type HandleWithContext func(handler ContextHandler) func(w http.ResponseWriter, r *http.Request)

type Locale

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

Locale describes language

func GetLocaleByCode5

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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