Skip to content
/ intl Public

Minimalistic Go internationalization library

License

Notifications You must be signed in to change notification settings

ex-vi/intl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 }}!"