Version: v0.0.0-...-e1966bd Latest Latest

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

Go to latest
Published: Nov 8, 2017 License: BSD-3-Clause Imports: 10 Imported by: 1




This section is empty.


View Source
var (
	ErrInvalidMagic = errors.New("gettext: magic has failed")
	ErrTruncated    = errors.New("gettext: truncated")
View Source
var (
	// NullCatalog has no translations so can be used as a fallback
	NullCatalog = &Catalog{
		Header:        make(map[string][]string),
		Strings:       map[string]*Translation{},
		PluralFormula: GermanicPluralFormula,


func GermanicPluralFormula

func GermanicPluralFormula(n int) int


type Catalog

type Catalog struct {
	Header  textproto.MIMEHeader
	Strings map[string]*Translation

	// TODO: Parsed from "Plural-Forms" header (e.g. 'Plural-Forms: nplurals=2; plural=n != 1;')
	// See:
	// NumPlurals    int
	PluralFormula PluralFormula

func ParseMO

func ParseMO(r io.ReadSeeker) (*Catalog, error)

func (*Catalog) GetText

func (c *Catalog) GetText(text string) string

func (*Catalog) NGetText

func (c *Catalog) NGetText(singular string, plural string, n int) string

type Domain

type Domain struct {
	Languages map[string]*Catalog

func NewDomain

func NewDomain(name string, path string) (*Domain, error)

Create a new Domain by parsing .mo files from path which must have subdirectories matching the GLOB path/*/LC_MESSAGES/

func (*Domain) GetCatalog

func (d *Domain) GetCatalog(langCode string) *Catalog

func (*Domain) GetText

func (d *Domain) GetText(langCode string, text string) string

func (*Domain) NGetText

func (d *Domain) NGetText(langCode string, singular string, plural string, n int) string

type PluralFormula

type PluralFormula func(int) int

type Translation

type Translation struct {
	Plural      string
	Translation []string

Jump to

Keyboard shortcuts

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