Skip to content

starius/mo.lua

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

mo.lua, parser of MO files

Travis build Coverage Status License

Implementation by J.Jørgen von Bargen was sent to lua-l mailing list as public domain.

Installation

$ luarocks install mo

Usage

-- load this module
mo = require 'mo'

-- load .mo file with translations
-- returns translating function on success
-- returns nil, 'error message' on failure
_ = mo('russian.mo')

-- translate from English into Russian
print(_("hello")) -- prints "привет"
-- the function returns its argument if it can't translate it
print(_("unknown phrase")) -- prints "unknown phrase"

Unit tests

You need busted and gettext to run unit tests.

$ busted

See also

Let us translate some Lua project into Russian.

$ xgettext -p ru -s -j --language=Lua *.lua --from-code utf-8

This command creates (or adds to) file ru/messages.po. It finds texts like _("text") in source files and adds them to .po file.

There are a lot of programs to translate .po file. One of them is poedit.

To compile .po to .mo, run the following command:

$ msgfmt ru/messages.po -o ru/messages.mo

This module is used to parse .mo file from Lua.

GNU gettext