po

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: Apache-2.0, BSD-3-Clause Imports: 8 Imported by: 1

README

PO files tools

The content of this directory is based on the original work of ChaiShushan <chaishushan{AT}gmail.com> in the po directory of https://github.com/chai2010/gettext-go

Documentation

Overview

Package po provides support for reading and writing GNU PO file.

Examples:

import (
	"github.com/chai2010/gettext-go/gettext/po"
)

func main() {
	poFile, err := po.Load("test.po")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%v", poFile)
}

The GNU PO file specification is at http://www.gnu.org/software/gettext/manual/html_node/PO-Files.html.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	StartLine         int      // comment start line
	TranslatorComment string   // #  translator-comments // TrimSpace
	ExtractedComment  string   // #. extracted-comments
	ReferenceFile     []string // #: src/msgcmp.c:338 src/po-lex.c:699
	ReferenceLine     []int    // #: src/msgcmp.c:338 src/po-lex.c:699
	Flags             []string // #, fuzzy,c-format,range:0..10
	PrevMsgContext    string   // #| msgctxt previous-context
	PrevMsgId         string   // #| msgid previous-untranslated-string
}

Comment represents every message's comments.

func (*Comment) GetFuzzy

func (p *Comment) GetFuzzy() bool

GetFuzzy gets the fuzzy flag.

func (*Comment) SetFuzzy

func (p *Comment) SetFuzzy(fuzzy bool)

SetFuzzy sets the fuzzy flag.

func (Comment) String

func (p Comment) String() string

String returns the po format comment string.

type File

type File struct {
	MimeHeader Header
	Messages   []Message
}

File represents an PO File.

See http://www.gnu.org/software/gettext/manual/html_node/PO-Files.html

func Load

func Load(name string) (*File, error)

Load loads a named po file.

func LoadData

func LoadData(data []byte) (*File, error)

LoadData loads po file format data.

func (*File) Data

func (f *File) Data() []byte

Data returns a po file format data.

func (*File) Save

func (f *File) Save(name string) error

Save saves a po file.

func (*File) String

func (f *File) String() string

String returns the po format file string.

type Header struct {
	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: golang-china
	Language                string // Language: zh_CN
	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 ? 0 : 1;
	XGenerator              string // X-Generator: Poedit 1.5.5
	UnknowFields            map[string]string
}

Header is the initial comments "SOME DESCRIPTIVE TITLE", "YEAR" and "FIRST AUTHOR <EMAIL@ADDRESS>, YEAR" ought to be replaced by sensible information.

See http://www.gnu.org/software/gettext/manual/html_node/Header-Entry.html#Header-Entry

func (Header) String

func (p Header) String() string

String returns the po format header string.

type Message

type Message struct {
	Comment               // Coments
	MsgContext   string   // msgctxt context
	MsgId        string   // msgid untranslated-string
	MsgIdPlural  string   // msgid_plural untranslated-string-plural
	MsgStr       string   // msgstr translated-string
	MsgStrPlural []string // msgstr[0] translated-string-case-0
}

A Message is a PO file entry. A PO file is made up of many entries, each entry holding the relation between an original untranslated string and its corresponding translation.

See http://www.gnu.org/software/gettext/manual/html_node/PO-Files.html

func (Message) String

func (p Message) String() string

String returns the po format entry string.

Jump to

Keyboard shortcuts

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