gettext

package module
v0.0.0-...-5cee46f Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2015 License: BSD-3-Clause Imports: 12 Imported by: 0

README

gettext

gettext implementation for Golang

Based on https://github.com/gorilla/i18n

Documentation

Index

Constants

View Source
const (
	DEFAULT_LANGUAGE = "en"
)

Variables

This section is empty.

Functions

func WriteMo

func WriteMo(w io.WriteSeeker, iter Iterator) error

WriteMo writes a MO file to w using the provided messages iterator.

Types

type Catalog

type Catalog struct {
	Header textproto.MIMEHeader
	// contains filtered or unexported fields
}

Catalog stores translations.

func NewCatalog

func NewCatalog() *Catalog

NewCatalog returns a new catalog instance.

func (*Catalog) Iter

func (c *Catalog) Iter() Iterator

Iter returns a messages iterator for this catalog.

func (*Catalog) ReadMo

func (c *Catalog) ReadMo(r io.ReadSeeker) error

ReadMo reads a MO file from r and adds its messages to the catalog.

func (*Catalog) Translate

func (c *Catalog) Translate(key string, args ...interface{}) string

Translate returns a singular string stored in the catalog, optionally formatting it using the provided arguments.

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection() *Collection

func (*Collection) Get

func (c *Collection) Get(langCode string) *Catalog

func (*Collection) LoadDirectory

func (c *Collection) LoadDirectory(path string) error

func (*Collection) SetDefaultLanguage

func (c *Collection) SetDefaultLanguage(langCode string)

type Iterator

type Iterator interface {
	// Size returns the amount of messages provided by the iterator.
	Size() int
	// Next returns the next message. At the end of the iteration,
	// io.EOF is returned as the error.
	Next() (*Message, error)
}

Iterator iterates over gettext messages.

func ReadMo

func ReadMo(r io.ReadSeeker) Iterator

ReadMo reads a MO file from r and returns a messages iterator.

type Message

type Message struct {
	Ctxt      []byte       // msgctxt: message context, if any
	Id        []byte       // msgid: untranslated singular string
	IdPlural  []byte       // msgid_plural: untranslated plural string
	Str       []byte       // msgstr: translated singular string
	StrPlural [][]byte     // msgstr[n]: translated plural strings
	Meta      *MessageMeta // message comments from PO file
}

Message stores a gettext message.

type MessageMeta

type MessageMeta struct {
	TranslatorComments [][]byte
	ExtractedComments  [][]byte
	References         [][]byte
	Flags              [][]byte
	PrevCtxt           []byte
	PrevId             []byte
	PrevIdPlural       []byte
}

MessageMeta stores meta-data from a gettext message.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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