mo

package
v0.0.0-...-21d24d8 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2018 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Overview

Package mo provides support for reading and writing GNU MO file.

Examples:

import (
	"github.com/JohnnyEstilles/gettext-go/gettext/mo"
)

func main() {
	moFile, err := mo.Load("test.mo")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%v", moFile)
}

GNU MO file struct:

        byte
             +------------------------------------------+
          0  | magic number = 0x950412de                |
             |                                          |
          4  | file format revision = 0                 |
             |                                          |
          8  | number of strings                        |  == N
             |                                          |
         12  | offset of table with original strings    |  == O
             |                                          |
         16  | offset of table with translation strings |  == T
             |                                          |
         20  | size of hashing table                    |  == S
             |                                          |
         24  | offset of hashing table                  |  == H
             |                                          |
             .                                          .
             .    (possibly more entries later)         .
             .                                          .
             |                                          |
          O  | length & offset 0th string  ----------------.
      O + 8  | length & offset 1st string  ------------------.
              ...                                    ...   | |
O + ((N-1)*8)| length & offset (N-1)th string           |  | |
             |                                          |  | |
          T  | length & offset 0th translation  ---------------.
      T + 8  | length & offset 1st translation  -----------------.
              ...                                    ...   | | | |
T + ((N-1)*8)| length & offset (N-1)th translation      |  | | | |
             |                                          |  | | | |
          H  | start hash table                         |  | | | |
              ...                                    ...   | | | |
  H + S * 4  | end hash table                           |  | | | |
             |                                          |  | | | |
             | NUL terminated 0th string  <----------------' | | |
             |                                          |    | | |
             | NUL terminated 1st string  <------------------' | |
             |                                          |      | |
              ...                                    ...       | |
             |                                          |      | |
             | NUL terminated 0th translation  <---------------' |
             |                                          |        |
             | NUL terminated 1st translation  <-----------------'
             |                                          |
              ...                                    ...
             |                                          |
             +------------------------------------------+

The GNU MO file specification is at http://www.gnu.org/software/gettext/manual/html_node/MO-Files.html.

Index

Constants

View Source
const (
	MoHeaderSize        = 28
	MoMagicLittleEndian = 0x950412de
	MoMagicBigEndian    = 0xde120495

	EotSeparator = "\x04" // msgctxt and msgid separator
	NulSeparator = "\x00" // msgid and msgstr separator
)

MoHeaderSize represents the length in bytes of the .mo file header

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	MagicNumber  uint32
	MajorVersion uint16
	MinorVersion uint16
	MsgIDCount   uint32
	MsgIDOffset  uint32
	MsgStrOffset uint32
	HashSize     uint32
	HashOffset   uint32
	MimeHeader   common.Header
	Messages     []common.Message
}

File represents an MO File.

See http://www.gnu.org/software/gettext/manual/html_node/MO-Files.html

func Load

func Load(name string) (*File, error)

Load loads a named mo file.

func LoadData

func LoadData(data []byte) (*File, error)

LoadData loads mo file format data.

func (*File) Data

func (f *File) Data() []byte

Data returns a mo file format data.

func (*File) Save

func (f *File) Save(name string) error

Save saves a mo file.

func (*File) String

func (f *File) String() string

String returns the po format file string.

Jump to

Keyboard shortcuts

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