示例#1
0
func poToMoData(t *testing.T, data []byte) []byte {
	poFile, err := po.LoadData(data)
	if err != nil {
		t.Fatal(err)
	}
	moFile := &mo.File{
		MimeHeader: mo.Header{
			ProjectIdVersion:        poFile.MimeHeader.ProjectIdVersion,
			ReportMsgidBugsTo:       poFile.MimeHeader.ReportMsgidBugsTo,
			POTCreationDate:         poFile.MimeHeader.POTCreationDate,
			PORevisionDate:          poFile.MimeHeader.PORevisionDate,
			LastTranslator:          poFile.MimeHeader.LastTranslator,
			LanguageTeam:            poFile.MimeHeader.LanguageTeam,
			Language:                poFile.MimeHeader.Language,
			MimeVersion:             poFile.MimeHeader.MimeVersion,
			ContentType:             poFile.MimeHeader.ContentType,
			ContentTransferEncoding: poFile.MimeHeader.ContentTransferEncoding,
			PluralForms:             poFile.MimeHeader.PluralForms,
			XGenerator:              poFile.MimeHeader.XGenerator,
			UnknowFields:            poFile.MimeHeader.UnknowFields,
		},
	}
	for _, v := range poFile.Messages {
		moFile.Messages = append(moFile.Messages, mo.Message{
			MsgContext:   v.MsgContext,
			MsgId:        v.MsgId,
			MsgIdPlural:  v.MsgIdPlural,
			MsgStr:       v.MsgStr,
			MsgStrPlural: v.MsgStrPlural,
		})
	}
	return moFile.Data()
}
示例#2
0
文件: tr.go 项目: faxal/gettext-go
func newPoTranslator(name string, data []byte) (*translator, error) {
	var (
		f   *po.File
		err error
	)
	if len(data) != 0 {
		f, err = po.LoadData(data)
	} else {
		f, err = po.Load(name)
	}
	if err != nil {
		return nil, err
	}
	var tr = &translator{
		MessageMap: make(map[string]mo.Message),
	}
	for _, v := range f.Messages {
		tr.MessageMap[tr.makeMapKey(v.MsgContext, v.MsgId)] = mo.Message{
			MsgContext:   v.MsgContext,
			MsgId:        v.MsgId,
			MsgIdPlural:  v.MsgIdPlural,
			MsgStr:       v.MsgStr,
			MsgStrPlural: v.MsgStrPlural,
		}
	}
	if lang := f.MimeHeader.Language; lang != "" {
		tr.PluralFormula = plural.Formula(lang)
	} else {
		tr.PluralFormula = plural.Formula("??")
	}
	return tr, nil
}