v0.12.5 Latest Latest

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

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 10 Imported by: 0



Package i18n is internationalization and localization support for aah framework. Messages config format is `forge` config syntax (go-aah/config) which is similar to HOCON syntax aka typesafe config.

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.



This section is empty.


This section is empty.


This section is empty.


type I18n

type I18n struct {
	Store         map[string]*config.Config
	DefaultLocale string
	// contains filtered or unexported fields

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

func New

func New() *I18n

New method creates aah i18n message store

func NewWithVFS

func NewWithVFS(fs *vfs.VFS) *I18n

NewWithVFS method creates aah i18n message store with given Virtual FileSystem.

func (*I18n) Load

func (s *I18n) Load(paths ...string) error

Load processes the given message file or directory and adds to the message store

func (*I18n) Locales

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

Locales returns all the loaded locales from message store

func (*I18n) Lookup

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)

Jump to

Keyboard shortcuts

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