i18n

package
v0.0.0-...-82e7740 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2019 License: MIT Imports: 5 Imported by: 10

README

comm-i18n GoDoc

i18n library for Go

Installation

go get gopkg.in/goyy/goyy.v0/comm/i18n

Usage

en_US := map[string]string{
	"say":  "Hello, world!",
	"sayf": "Hello, %s!",
}
locales := map[string]map[string]string{
	i18n.Locale_en_US: en_US,
}
i18N := i18n.New(locales, i18n.Locale_en_US)
fmt.Println(i18N.Message("say"))           // Output: Hello, world!
fmt.Println(i18N.Messagef("sayf", "goyy")) // Output: Hello, goyy!

Documentation

Overview

Package i18n implements i18n utility functions.

Usage

en_US := map[string]string{
	"say":  "Hello, world!",
	"sayf": "Hello, %s!",
}
locales := map[string]map[string]string{
	i18n.LocaleEnUS: en_US,
}
i18N := i18n.New(locales, i18n.LocaleEnUS)
fmt.Println(i18N.Message("say"))           // Output: Hello, world!
fmt.Println(i18N.Messagef("sayf", "goyy")) // Output: Hello, goyy!

Index

Constants

View Source
const (
	// LocaleCsCZ cs_CZ
	LocaleCsCZ = "cs_CZ"
	// LocaleDaDK da_DK
	LocaleDaDK = "da_DK"
	// LocaleDeDE de_DE
	LocaleDeDE = "de_DE"
	// LocaleEnGB en_GB
	LocaleEnGB = "en_GB"
	// LocaleEnUS en_US
	LocaleEnUS = "en_US"
	// LocaleEnXM en_XM
	LocaleEnXM = "en_XM"
	// LocaleEsES es_ES
	LocaleEsES = "es_ES"
	// LocaleEsLA es_LA
	LocaleEsLA = "es_LA"
	// LocaleEsMX es_MX
	LocaleEsMX = "es_MX"
	// LocaleEsNA es_NA
	LocaleEsNA = "es_NA"
	// LocaleFiFI fi_FI
	LocaleFiFI = "fi_FI"
	// LocaleFrCA fr_CA
	LocaleFrCA = "fr_CA"
	// LocaleFrFR fr_FR
	LocaleFrFR = "fr_FR"
	// LocaleFrXM fr_XM
	LocaleFrXM = "fr_XM"
	// LocaleHuHU hu_HU
	LocaleHuHU = "hu_HU"
	// LocaleItIT it_IT
	LocaleItIT = "it_IT"
	// LocaleJaJP ja_JP
	LocaleJaJP = "ja_JP"
	// LocaleKoKR ko_KR
	LocaleKoKR = "ko_KR"
	// LocaleNbNO nb_NO
	LocaleNbNO = "nb_NO"
	// LocaleNlNL nl_NL
	LocaleNlNL = "nl_NL"
	// LocalePlPL pl_PL
	LocalePlPL = "pl_PL"
	// LocalePtBR pt_BR
	LocalePtBR = "pt_BR"
	// LocaleRoRO ro_RO
	LocaleRoRO = "ro_RO"
	// LocaleRuRU ru_RU
	LocaleRuRU = "ru_RU"
	// LocaleSvSE sv_SE
	LocaleSvSE = "sv_SE"
	// LocaleTrTR tr_TR
	LocaleTrTR = "tr_TR"
	// LocaleUkUA uk_UA
	LocaleUkUA = "uk_UA"
	// LocaleZhCN zh_CN
	LocaleZhCN = "zh_CN"
	// LocaleZhTW zh_TW
	LocaleZhTW = "zh_TW"
)

Variables

This section is empty.

Functions

func DefaultLocale

func DefaultLocale() string

DefaultLocale gets the default locale.

func SetDefaultLocale

func SetDefaultLocale(locale string)

SetDefaultLocale sets the default locale.

Types

type I18n

type I18n interface {
	Message(key string) string
	Messagef(key string, args ...interface{}) string
	Error(key string) error
	Errorf(key string, args ...interface{}) error
	Panic(key string)
	Panicf(key string, args ...interface{})
	Locale() string
	SetLocale(locale string)
}

I18n is the interface that wraps the operation i18n method.

func New

func New(locales map[string]map[string]string) I18n

New creates a new I18n by map. Get the latest default locale.

func NewBy

func NewBy(locales map[string]map[string]string, locale string) I18n

NewBy creates a new I18n by map and locale.

func NewByEnv

func NewByEnv(locales map[string]map[string]string) I18n

NewByEnv creates a new I18n by map. locale value from the I18N_LOCALE of the environment variable.

Jump to

Keyboard shortcuts

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