x: within.website/x/i18n Index | Files

package i18n

import "within.website/x/i18n"

Package i18n handles internationalization and the like for Go programs.


Package Files

doc.go legal.go lingo.go locale.go

type L Uses

type L struct {
    // contains filtered or unexported fields

L represents Lingo bundle, containing map of all Ts by locale, as well as default locale and list of supported locales

func New Uses

func New(deflt, path string) *L

New creates the Lingo bundle. Params: Default locale, to be used when requested locale is not found. Path, absolute or relative path to a folder where translation .json files are kept

func (*L) TranslationsForLocale Uses

func (l *L) TranslationsForLocale(locale string) T

TranslationsForLocale will get the T for specific locale. If no locale is found, returns default T

func (*L) TranslationsForRequest Uses

func (l *L) TranslationsForRequest(r *http.Request) T

TranslationsForRequest will get the best matched T for given Request. If no T is found, returns default T

type Locale Uses

type Locale struct {
    Lang, Country string
    Qual          float64

Locale is locale value from the Accept-Language header in request

func GetLocales Uses

func GetLocales(r *http.Request) []Locale

GetLocales returns supported locales for the given requet

func GetPreferredLocale Uses

func GetPreferredLocale(r *http.Request) (*Locale, error)

GetPreferredLocale return preferred locale for the given reuqest returns error if there is no preferred locale

func ParseLocale Uses

func ParseLocale(locale string) Locale

ParseLocale creates a Locale from a locale string

func (*Locale) Name Uses

func (l *Locale) Name() string

Name returns the locale value in 'lang' or 'lang_country' format eg: de_DE, en_US, gb

type T Uses

type T struct {
    // contains filtered or unexported fields

T represents translations map for specific locale

func (T) Value Uses

func (t T) Value(key string, args ...string) string

Value traverses the translations map and finds translation for given key. If no translation is found, returns value of given key.

Package i18n imports 8 packages (graph) and is imported by 3 packages. Updated 2019-06-07. Refresh now. Tools for package owners.