po

package
v0.224.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeString

func DecodeString(s string) string

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

func EncodeString

func EncodeString(text string) string

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

Types

type Comment

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

Comment is a comment for an entry

func ParseComment

func ParseComment(s string) Comment

ParseComment parses a PO file comment from the given string

func (*Comment) HasFlag

func (c *Comment) HasFlag(flag string) bool

HasFlag returns true if this comment contains the given flag

func (*Comment) String

func (c *Comment) String() string

type Entry

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

Entry is an entry in a PO catalog

func (*Entry) Write

func (e *Entry) Write(w io.Writer)
type Header 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
}

Header contains metadata about a PO file

func NewHeader

func NewHeader(initialComment string, creationDate time.Time, locale i18n.Locale) *Header

NewHeader creates a new PO header with the given values

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

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  *Header
	Entries []*Entry
	// contains filtered or unexported fields
}

PO is a PO file of translation entries

func NewPO

func NewPO(h *Header) *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 *Entry)

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

Jump to

Keyboard shortcuts

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