message.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. package mo
  5. import (
  6. "bytes"
  7. "fmt"
  8. )
  9. // A MO file is made up of many entries,
  10. // each entry holding the relation between an original untranslated string
  11. // and its corresponding translation.
  12. //
  13. // See http://www.gnu.org/software/gettext/manual/html_node/MO-Files.html
  14. type Message struct {
  15. MsgContext string // msgctxt context
  16. MsgId string // msgid untranslated-string
  17. MsgIdPlural string // msgid_plural untranslated-string-plural
  18. MsgStr string // msgstr translated-string
  19. MsgStrPlural []string // msgstr[0] translated-string-case-0
  20. }
  21. // String returns the po format entry string.
  22. func (p Message) String() string {
  23. var buf bytes.Buffer
  24. fmt.Fprintf(&buf, "msgid %s", encodePoString(p.MsgId))
  25. if p.MsgIdPlural != "" {
  26. fmt.Fprintf(&buf, "msgid_plural %s", encodePoString(p.MsgIdPlural))
  27. }
  28. if p.MsgStr != "" {
  29. fmt.Fprintf(&buf, "msgstr %s", encodePoString(p.MsgStr))
  30. }
  31. for i := 0; i < len(p.MsgStrPlural); i++ {
  32. fmt.Fprintf(&buf, "msgstr[%d] %s", i, encodePoString(p.MsgStrPlural[i]))
  33. }
  34. return buf.String()
  35. }