go-gettext: github.com/samuel/go-gettext/gettext Index | Files

package gettext

import "github.com/samuel/go-gettext/gettext"


Package Files

catalog.go domain.go mo.go plural.go


var (
    ErrInvalidMagic = errors.New("gettext: magic has failed")
    ErrTruncated    = errors.New("gettext: truncated")
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 Uses

func GermanicPluralFormula(n int) int

type Catalog Uses

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 Uses

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

func (*Catalog) GetText Uses

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

func (*Catalog) NGetText Uses

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

type Domain Uses

type Domain struct {
    Languages map[string]*Catalog

func NewDomain Uses

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 Uses

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

func (*Domain) GetText Uses

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

func (*Domain) NGetText Uses

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

type PluralFormula Uses

type PluralFormula func(int) int

type Translation Uses

type Translation struct {
    Plural      string
    Translation []string

Package gettext imports 10 packages (graph) and is imported by 3 packages. Updated 2017-11-09. Refresh now. Tools for package owners.