gettext

package
v0.0.0-...-e1966bd Latest Latest
Warning

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

Documentation

Index

Constants

This section is empty.

Variables

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,
	}
)

Functions

func GermanicPluralFormula

func GermanicPluralFormula(n int) int

Types

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: http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Plural-forms.html
	// 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/name.mo

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