po

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: BSD-3-Clause, MIT Imports: 12 Imported by: 1

Documentation

Overview

Package po allows to read and write gettext po files.

Index

Constants

View Source
const (
	HeaderProjectIDVersion        = "Project-Id-Version"
	HeaderReportMsgIDBugsTo       = "Report-Msgid-Bugs-To"
	HeaderPOTCreationDate         = "POT-Creation-Date"
	HeaderPORevisionDate          = "PO-Revision-Date"
	HeaderLastTranslator          = "Last-Translator"
	HeaderLanguageTeam            = "Language-Team"
	HeaderLanguage                = "Language"
	HeaderMIMEVersion             = "MIME-Version"
	HeaderContentType             = "Content-Type"
	HeaderContentTransferEncoding = "Content-Transfer-Encoding"
	HeaderPluralForms             = "Plural-Forms"
	HeaderXGenerator              = "X-Generator"
)

Variables

This section is empty.

Functions

func DecodePoString

func DecodePoString(text string) string

func EncodePoString

func EncodePoString(s string, lim int) string

Types

type Comment

type Comment struct {
	Translator     string       // #  translator-comments
	Extracted      string       // #. extracted-comments
	References     []*Reference // #: src/file.go:210
	Flags          []string     // #, fuzzy,go-format,range:0..10
	PrevMsgContext string       // #| msgctxt previous-context
	PrevMsgID      string       // #| msgid previous-untranslated-string
}

func NewComment

func NewComment() *Comment

func (*Comment) AddFlag

func (c *Comment) AddFlag(flag string)

func (*Comment) AddReference

func (c *Comment) AddReference(ref *Reference)

func (*Comment) HasFlag

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

func (*Comment) Less

func (c *Comment) Less(q *Comment) bool

func (*Comment) Merge

func (c *Comment) Merge(other *Comment)

type Encoder

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

An Encoder writes a po file to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (e *Encoder) Encode(f *File) error

func (*Encoder) SetSort deprecated

func (e *Encoder) SetSort(_ bool)

Deprecated: Obsolete, it is always sorted, the method is removed with version 1.0.

func (*Encoder) SetWrapWidth

func (e *Encoder) SetWrapWidth(wrapWidth int)

SetWrapWidth defines at which length the texts should be wrapped. To disable wrapping, the value can be set to -1. Default is -1.

func (*Encoder) SetWriteEmptyHeader

func (e *Encoder) SetWriteEmptyHeader(write bool)

SetWriteEmptyHeader sets whether a header without values should also be written or not. Default is true.

func (*Encoder) SetWriteHeader

func (e *Encoder) SetWriteHeader(write bool)

SetWriteHeader sets whether a header should be written or not. Default is true.

func (*Encoder) SetWriteReferences

func (e *Encoder) SetWriteReferences(write bool)

SetWriteReferences sets whether references to the origin of the text should be stored or not. Default is true.

type File

type File struct {
	Header   *Header
	Messages Messages
}

func MustParse

func MustParse(content []byte) *File

func NewFile

func NewFile() *File

func Parse

func Parse(content []byte) (*File, error)

func ParseString

func ParseString(content string) (*File, error)

func (*File) AddMessage

func (f *File) AddMessage(msg *Message)

func (*File) GetMessage

func (f *File) GetMessage(ctx string, id string) *Message

func (*File) String

func (f *File) String() string
type Header struct {
	Comment                 *Comment // Header Comments
	ProjectIDVersion        string   // Project-Id-Version: PACKAGE VERSION
	ReportMsgidBugsTo       string   // Report-Msgid-Bugs-To: FIRST AUTHOR <EMAIL@ADDRESS>
	POTCreationDate         string   // POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE
	PORevisionDate          string   // PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
	LastTranslator          string   // Last-Translator: FIRST AUTHOR <EMAIL@ADDRESS>
	LanguageTeam            string   // Language-Team:
	Language                string   // Language: de
	MimeVersion             string   // MIME-Version: 1.0
	ContentType             string   // Content-Type: text/plain; charset=UTF-8
	ContentTransferEncoding string   // Content-Transfer-Encoding: 8bit
	PluralForms             string   // Plural-Forms: nplurals=2; plural=(n != 1);
	XGenerator              string   // X-Generator: Poedit 3.0.1
	UnknownFields           map[string]string
}

func (*Header) Get

func (h *Header) Get(key string) string

func (*Header) SetField

func (h *Header) SetField(key, val string)

type Message

type Message struct {
	Comment  *Comment
	Context  string
	ID       string
	IDPlural string
	Str      map[int]string
}

Message is a representation of a single message in a catalog.

func NewMessage

func NewMessage() *Message

func (*Message) AddReference

func (m *Message) AddReference(ref *Reference)

func (*Message) Less

func (m *Message) Less(q *Message) bool

func (*Message) Merge

func (m *Message) Merge(other *Message)

type Messages

type Messages map[string]map[string]*Message

func (Messages) Add

func (m Messages) Add(msg *Message)

type Reference

type Reference struct {
	Path   string
	Line   int
	Column int
}

func (Reference) Equal

func (r Reference) Equal(o *Reference) bool

func (Reference) String

func (r Reference) String() string

Jump to

Keyboard shortcuts

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