po

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package pofile implements reading and writing of PO/POT files following the GNU gettext format specification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LangNameNative

func LangNameNative(lang string) string

LangNameNative returns the native name of a language.

func PluralFormsForLang

func PluralFormsForLang(lang string) string

PluralFormsForLang returns the standard Plural-Forms header for a language code.

Types

type Entry

type Entry struct {
	// TranslatorComments are lines starting with "# " (translator comments).
	TranslatorComments []string
	// ExtractedComments are lines starting with "#." (extracted/automatic comments).
	ExtractedComments []string
	// References are source code locations, lines starting with "#:".
	References []string
	// Flags are format flags, lines starting with "#,".
	Flags []string
	// PreviousMsgID stores the previous msgid for fuzzy entries, lines starting with "#|".
	PreviousMsgID string

	// MsgCtxt is the message context (msgctxt).
	MsgCtxt string
	// MsgID is the untranslated string.
	MsgID string
	// MsgIDPlural is the untranslated plural string.
	MsgIDPlural string
	// MsgStr is the translated string (singular or the only form).
	MsgStr string
	// MsgStrPlural maps plural form index to translated string.
	MsgStrPlural map[int]string

	// Obsolete marks entries prefixed with "#~".
	Obsolete bool
}

Entry represents a single translatable message in a PO file.

func MakeHeader

func MakeHeader(packageName, packageVersion, bugsEmail, copyrightHolder, language string) *Entry

MakeHeader creates a standard PO/POT file header.

func (*Entry) HasFlag

func (e *Entry) HasFlag(flag string) bool

HasFlag checks if a specific flag is present.

func (*Entry) IsFuzzy

func (e *Entry) IsFuzzy() bool

IsFuzzy returns true if the entry is marked fuzzy.

func (*Entry) IsTranslated

func (e *Entry) IsTranslated() bool

IsTranslated returns true if the entry has a non-empty translation.

func (*Entry) SetFuzzy

func (e *Entry) SetFuzzy(fuzzy bool)

SetFuzzy adds or removes the fuzzy flag.

type File

type File struct {
	// Header is the metadata entry (msgid "").
	Header *Entry
	// Entries are the translatable message entries.
	Entries []*Entry
}

File represents a parsed PO/POT file.

func NewFile

func NewFile() *File

NewFile creates a new empty PO file.

func Parse

func Parse(r io.Reader) (*File, error)

Parse reads a PO/POT file from a reader.

func ParseFile

func ParseFile(path string) (*File, error)

ParseFile reads a PO/POT file from disk.

func (*File) EntryByMsgID

func (f *File) EntryByMsgID(msgid string) *Entry

EntryByMsgID finds an entry by its msgid.

func (*File) FuzzyEntries

func (f *File) FuzzyEntries() []*Entry

FuzzyEntries returns entries marked as fuzzy.

func (*File) HeaderField

func (f *File) HeaderField(name string) string

HeaderField returns a header field value by name.

func (*File) SetHeaderField

func (f *File) SetHeaderField(name, value string)

SetHeaderField sets a header field value.

func (*File) Stats

func (f *File) Stats() (total, translated, fuzzy, untranslated int)

Stats returns translation statistics.

func (*File) UntranslatedEntries

func (f *File) UntranslatedEntries() []*Entry

UntranslatedEntries returns entries that have no translation and are not fuzzy.

func (*File) Write

func (f *File) Write(w io.Writer) error

Write writes the PO file to a writer.

func (*File) WriteFile

func (f *File) WriteFile(path string) error

WriteFile writes the PO file to disk.

Jump to

Keyboard shortcuts

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