intl

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: MIT Imports: 5 Imported by: 0

README

intl

Minimalistic Go internationalization (i18n) package.

Usage

Setting up an INTL instance

langSrcs = []LangSource{
    {
        Lang:     "EN",
        Filepath: "path/to/file.yml",
    },
}

i, err := intl.New(langSrcs...)

Getting the specific locale before use

locale, err := i.GetLocale("EN")

Using locale to get a basic message

msg, err := locale.Msg("msg-name")

Using locale to get a template message

data := MsgTmpl{"name": "John Doe"}
msg, err := locale.Msg("template-msg-name", data)

Language files

Files are just a collection of messages. Messages can optionally be templates, following the default go text/template logic.

# example.yml

greet: "Welcome!"
dialog-start: "Hello, {{ .name }}!"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Intl

type Intl struct {
	// contains filtered or unexported fields
}

func New

func New(sources ...LangSource) (*Intl, error)

func (*Intl) GetLocale

func (i *Intl) GetLocale(lang string) (*Locale, error)

type LangSource

type LangSource struct {
	Lang     string
	Filepath string
}

type Locale

type Locale struct {
	// contains filtered or unexported fields
}

func (*Locale) Msg

func (l *Locale) Msg(id string, tmpl ...MsgTmpl) (string, error)

type MsgTmpl

type MsgTmpl map[string]interface{}

Jump to

Keyboard shortcuts

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