Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

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.


$ luarocks install mo


-- load this module
mo = require 'mo'

-- load .mo file with translations
-- returns translating function on success
-- returns nil, 'error message' on failure
_ = 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/

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

GNU gettext

You can’t perform that action at this time.