A command-line tool for compiling Uniforum style .po files into binary .mo files. The tool converts human-readable PO files into machine-readable MO files, which are used by gettext for efficient runtime translation lookup.
- Compiles PO files into binary MO files
- Supports multiple input directories for file search
- Configurable output file name and location
- Option to force overwrite existing files
- Control over endianness of output file
- Option to exclude hash table from binary output
- Reads from standard input when input file is "-"
curl -L -o $(go env GOPATH)/bin/msgofmt https://github.com/Tom5521/gotext-tools/releases/latest/download/msgofmt-$(go env GOOS)-$(go env GOARCH) && chmod +x $(go env GOPATH)/bin/msgofmtBasic usage:
msgofmt [flags] filename.po-
Input/Output Options:
--output-file,-o: Write output to specified file (default: "messages.mo").--directory,-D: Add DIRECTORY to list for input files search.--force,-f: Overwrite generated files if they already exist.
-
Binary Format Options:
--endianness: Write out 32-bit numbers in the given byte order (options: "big", "little", or "native"; default: "native").--no-hash: Binary file will not include the hash table.
-
Help:
--help,-h: Display help information.
Basic compilation with default output name:
msgofmt translations.poCompile with custom output file name:
msgofmt -o my-translations.mo translations.poCompile from standard input to standard output:
msgofmt -o - < translations.poCompile with forced overwrite:
msgofmt -f -o output.mo translations.poCompile with big-endian byte order:
msgofmt --endianness=big -o output.mo translations.poCompile without hash table:
msgofmt --no-hash -o output.mo translations.poSearch for input file in additional directories:
msgofmt -D locale -D translations -o output.mo es.po-
Input File:
- Reads a PO file containing translations in human-readable format.
- If input file is "-", reads from standard input.
-
Compilation Process:
- Parses the PO file structure and validates its contents.
- Converts text-based translations into binary format.
- Optionally includes a hash table for faster lookups (unless disabled).
- Handles byte order according to specified endianness.
-
Output:
- Generates a binary MO file that can be used by gettext-enabled applications.
- Outputs to specified file or standard output if "-" is specified.