i18n

package
v0.101.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2020 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodePOString

func DecodePOString(s string) string

DecodePOString decodes the string values that appear after msgid, mgstr etc

func EncodePOString

func EncodePOString(text string) string

EncodePOString encodes the string values that appear after msgid, mgstr etc

Types

type Library

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

Library is a collection of PO files providing translations in different languages

func NewLibrary

func NewLibrary(path, srcLanguage string) *Library

NewLibrary creates new library from directory structure in path

func (*Library) Load

func (l *Library) Load(language, domain string) (*PO, error)

Load loads the PO for the given language and domain

func (*Library) Locales added in v0.101.0

func (l *Library) Locales() []string

Locales returns the names of the locales included in this library

func (*Library) Path

func (l *Library) Path() string

Path returns the root path of this library

func (*Library) SrcLanguage

func (l *Library) SrcLanguage() string

SrcLanguage returns the source language of this library

func (*Library) Update

func (l *Library) Update(domain string, pot *PO) error

Update updates the message IDs in the default language from the given PO, and merges those changes into the other PO files

type PO

type PO struct {
	Header  *POHeader
	Entries []*POEntry
	// contains filtered or unexported fields
}

PO is a PO file of translation entries

func NewPO

func NewPO(h *POHeader) *PO

NewPO creates a new PO catalog

func ReadPO

func ReadPO(r io.Reader) (*PO, error)

ReadPO reads a PO file from the given reader

func (*PO) AddEntry

func (p *PO) AddEntry(e *POEntry)

AddEntry adds the given entry to this PO

func (*PO) GetText

func (p *PO) GetText(context, text string) string

GetText gets the translations of text with the given context (optional)

func (*PO) Sort

func (p *PO) Sort()

Sort sorts entries by ID and context

func (*PO) Write

func (p *PO) Write(w io.Writer)

Write writes this PO to the given writer

type POComment

type POComment struct {
	Translator []string // #  translator-comments
	Extracted  []string // #. extracted-comments
	References []string // #: references
	Flags      []string // #, e.g. fuzzy,python-format
}

POComment is a comment for an entry

func ParsePOComment

func ParsePOComment(s string) POComment

ParsePOComment parses a PO file comment from the given string

func (*POComment) String

func (c *POComment) String() string

type POEntry

type POEntry struct {
	Comment    POComment // Comment
	MsgContext string    // msgctxt context
	MsgID      string    // msgid untranslated-string
	MsgStr     string    // msgstr translated-string
}

POEntry is an entry in a PO catalog

func (*POEntry) Write

func (e *POEntry) Write(w io.Writer)

type POHeader

type POHeader struct {
	InitialComment  string
	POTCreationDate time.Time         // POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE
	Language        string            // Language: e.g. en-US
	MIMEVersion     string            // MIME-Version: 1.0
	ContentType     string            // Content-Type: text/plain; charset=UTF-8
	Custom          map[string]string // other custom values
}

POHeader contains metadata about a PO file

func NewPOHeader

func NewPOHeader(initialComment string, creationDate time.Time, lang string) *POHeader

NewPOHeader creates a new PO header with the given values

Jump to

Keyboard shortcuts

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