~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/chai2010/gettext-go/gettext/mo/message.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
}