...

Source file src/github.com/chai2010/gettext-go/mo/message.go

Documentation: github.com/chai2010/gettext-go/mo

     1  // Copyright 2013 ChaiShushan <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package mo
     6  
     7  import (
     8  	"bytes"
     9  	"fmt"
    10  )
    11  
    12  // A MO file is made up of many entries,
    13  // each entry holding the relation between an original untranslated string
    14  // and its corresponding translation.
    15  //
    16  // See http://www.gnu.org/software/gettext/manual/html_node/MO-Files.html
    17  type Message struct {
    18  	MsgContext   string   // msgctxt context
    19  	MsgId        string   // msgid untranslated-string
    20  	MsgIdPlural  string   // msgid_plural untranslated-string-plural
    21  	MsgStr       string   // msgstr translated-string
    22  	MsgStrPlural []string // msgstr[0] translated-string-case-0
    23  }
    24  
    25  // String returns the po format entry string.
    26  func (p Message) String() string {
    27  	var buf bytes.Buffer
    28  	fmt.Fprintf(&buf, "msgid %s", encodePoString(p.MsgId))
    29  	if p.MsgIdPlural != "" {
    30  		fmt.Fprintf(&buf, "msgid_plural %s", encodePoString(p.MsgIdPlural))
    31  	}
    32  	if p.MsgStr != "" {
    33  		fmt.Fprintf(&buf, "msgstr %s", encodePoString(p.MsgStr))
    34  	}
    35  	for i := 0; i < len(p.MsgStrPlural); i++ {
    36  		fmt.Fprintf(&buf, "msgstr[%d] %s", i, encodePoString(p.MsgStrPlural[i]))
    37  	}
    38  	return buf.String()
    39  }
    40  
    41  func (m_i *Message) less(m_j *Message) bool {
    42  	if a, b := m_i.MsgContext, m_j.MsgContext; a != b {
    43  		return a < b
    44  	}
    45  	if a, b := m_i.MsgId, m_j.MsgId; a != b {
    46  		return a < b
    47  	}
    48  	if a, b := m_i.MsgIdPlural, m_j.MsgIdPlural; a != b {
    49  		return a < b
    50  	}
    51  	return false
    52  }
    53  

View as plain text