aahframe.work: aahframe.work/i18n Index | Files

package i18n

import "aahframe.work/i18n"

Package i18n is internationalization and localization support for aah framework. Messages store config format is same as aah configuration. Refer to https://docs.aahframework.org/configuration.html.

Message filename format is `message.<Language-ID>`. Language ID is combination of `Language + Region` or `Language` value. aah framework implements Language code is as per two-letter `ISO 639-1` standard and Region code is as per two-letter `ISO 3166-1` standard.

Supported message file extension formats are (incasesensitive)

1) Language + Region => en-us | en-US

2) Language          => en

For Example:
	message.en-US or message.en-us
	message.en-GB or message.en-gb
	message.en-CA or message.en-ca
	message.en
	message.es
	message.zh
	message.nl
	etc.

Note: Sub directories is supported, so you can organize message files.

Index

Package Files

i18n.go

type I18n Uses

type I18n struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

I18n holds the message store and related information for internationalization and localization.

func New Uses

func New(l log.Loggerer, opts ...Option) *I18n

New method creates aah i18n message store with given options.

func (*I18n) DefaultLocale Uses

func (s *I18n) DefaultLocale() string

DefaultLocale method returns the i18n store's default locale.

func (*I18n) Init Uses

func (s *I18n) Init() error

Load method loads message files into message store. Returns error for any failures.

func (*I18n) Locales Uses

func (s *I18n) Locales() []string

Locales returns all the loaded locales from message store

func (*I18n) Lookup Uses

func (s *I18n) Lookup(locale *ahttp.Locale, key string, args ...interface{}) string

Lookup returns value by given key, locale and it supports formatting a message before its return. If given message key or store doesn't exists for given locale; Lookup method returns empty string.

Lookup(locale, "i.love.aah.framework", "yes")

The sequence and fallback order of message fetch from store is -

* language and region-id (e.g.: en-US)
* language (e.g.: en)

type I18ner Uses

type I18ner interface {
    Lookup(locale *ahttp.Locale, key string, args ...interface{}) string
    DefaultLocale() string
    Locales() []string
}

I18ner interface is used to implement i18n message store.

type Option Uses

type Option func(*I18n)

Option type to provide configuration options to create i18n message store.

func DefaultLocale Uses

func DefaultLocale(locale string) Option

DefaultLocale option func is to message store default locale.

func Dirs Uses

func Dirs(dirs ...string) Option

Dirs option func is to supply n no. of directory path.

func Files Uses

func Files(files ...string) Option

Files option func is to supply n no. of file path.

func VFS Uses

func VFS(fs vfs.FileSystem) Option

Dirs option func is to set aah VFS instance.

Package i18n imports 10 packages (graph) and is imported by 3 packages. Updated 2019-04-17. Refresh now. Tools for package owners.