mo.lua, parser of MO files
Implementation by J.Jørgen von Bargen was sent to lua-l mailing list as public domain.
Installation
$ luarocks install moUsage
-- 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.
$ bustedSee also
Let us translate some Lua project into Russian.
$ xgettext -p ru -s -j --language=Lua *.lua --from-code utf-8This 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.moThis module is used to parse .mo file from Lua.


