translator

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// HeaderPluralForms 表明该语言的复数形式
	HeaderPluralForms = "Plural-Forms"
	// HeaderLanguage 表明该文件是什么语言
	HeaderLanguage = "Language"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	MsgCmts []string
	MsgCtxt string
	MsgID   string
	MsgID2  string
	MsgStr  string
	MsgStrN []string
}

Entry 一个翻译条目

func (*Entry) Key

func (e *Entry) Key() string

Key 一个翻译条目的 Key

type File

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

File 一个翻译文件

func ReadMo

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

ReadMo read mo from []byte content

func ReadPo

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

ReadPo read po file

func ReadPot added in v0.0.8

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

func (*File) AddEntry

func (file *File) AddEntry(e *Entry)

AddEntry adds a Entry

func (*File) GetHeader

func (file *File) GetHeader(key string) (value string, ok bool)

GetHeader get header value by key

func (*File) Lang

func (file *File) Lang() string

Lang get this translations' language

func (*File) SaveAsMo

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

SaveAsMo save as machine object file(.mo)

0: magic number = 0x950412de
4: version = 0
8: count = count

12: offset of origin string table = O = 75 16: offset of translation string table 20: size of hash table = 0 24: offset of hash table = 0 28: custom header entry: flag size = len(flag) = 43 32: custom header entry: flag 75: offsetO: id table: (length & offset) * count xx: offsetT: string table. xx=75+count*8 aa: offsetID: ids. aa=75+count*8*2 bb: offsetStr: strs.

func (*File) SaveAsPo

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

SaveAsPo save as a po file

func (*File) SaveAsPot

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

SaveAsPot save this File as pot format

func (*File) SortedEntry

func (file *File) SortedEntry() (entries []*Entry)

SortedEntry sort entry by key

func (*File) X

func (file *File) X(msgCtxt, msgID string, args ...interface{}) string

X is ashort name for pgettext

func (*File) XN64

func (file *File) XN64(msgCtxt, msgID, msgIDPlural string, n int64, args ...interface{}) string

XN64 is ashort name for npgettext

type Translator

type Translator interface {
	// Lang return the language 返回翻译之后的语言
	Lang() string
	// X short name of pgettext. msgCtxt can be empty. 单数翻译接口
	X(msgCtxt, msgID string, args ...interface{}) string
	// XN64 short name of npgettext. msgCtxt can be empty. 复数翻译接口
	XN64(msgCtxt, msgID, msgIDPlural string, n int64, args ...interface{}) string
}

Translator 翻译家接口

Jump to

Keyboard shortcuts

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