tech-install archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: reworking sysinst: A Lua based msg system

        One of the goals of reworking sysinst is to have a replacement for the
static, C based, msg system.  The new message system should provide at
least the following functionality

- support for easy translation into foreign languages
- support dynamically created message that contain variables
- be modular insfar as sysinst extension modules can come with their own
set of (translated) messages

Message catalogs

        Messages are organized in message catalogs, one catalog per language.
Once a language has been selected by the users, only that message
catalog is used.  Message catalogs are Lua tables and a Lua script can
add its messages by calling the msg() function:

msg('english', {greeting = 'Hello', monday = 'Monday'})
msg('german', {greeting = 'Guten Tag', monday = 'Montag'})

        The function call was chosen over a static table initialization so that
scripts that run later can add to the message catalogs.  The message
catalog is available as the global table '_M', so _M.greeting will
produce the greeting message in the chosen language.

Messages with variable content

        Message definitions are not static, in fact they can contain Lua code
or expressions.  The syntax is simple:  Text embraced in <% %> is
interpreted as Lua code which is executed when the message is being
produced.  Text embraced in <%= %> is interpreted as a Lua expression,
again produced when the message is rendered.  A special form of the
expression syntax is <%=fmt %> where fmt is a string.format() format
specifier.  To render messages, a function lt.render() exists (lt stands
for 'Lua Templates') which takes as arguments the message string and an
optional table.  The optional table must contain the variables to be
used in the string:

greeting = 'Hello Mr. <% name %>'
lt.render(greeting, {name = 'Balmer'})

Implementation Detail

        Message strings are converted to Lua code in the lt.render() C
function, which is then executed and it's result pushed on the stack.
This is done using a special lua_Reader that produces the Lua source code.

        Please note that not everything mentioned above is in the current diff
found at, but it soon will be.

Home | Main Index | Thread Index | Old Index