Skip to content

starius/mo.lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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