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



Am 04.03.12 14:46, schrieb Manuel Bouyer:
> On Sun, Mar 04, 2012 at 12:45:18PM +0100, Marc Balmer wrote:
>>>> 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'})
>>>
>>> Messages are data, not program code - keep them separate.
>>
>> Message _are_ data.  They are organized in Lua tables, the msg()
>> function takes such a table and adds it to the respective language
>> message catalog (stuff in {} is a Lua table).  Keep in mind that Lua was
>> designed as a data description language and has a powerful syntax for that.
> 
> I guess what martin means here is that the message catalogs should not be
> inside LUA scripts, but in separate files (just as they are now). Then
> a module can add a new file to the already existing message table
> (like msg('/path/to/module/messages.catalog')). Maybe msg() should then
> try to load the message.catalog for the current language, as well as
> the english one for fallback.

Ah, I see.  That is exactly what I did, I also think that the message
catalogs are best put into separate files, one per language, at least
for the default installer script.

Having the possibility to quickly throw together a test extension with
code and message catalog in one file adds to the flexibility, though.

> 
>>
>>>
>>> How do you identify messages in your code? By index?
>>
>> By index:
>>
>> msg('english', { monday = 'Monday'})
>>
>> msg_display(_M.monday)
> 
> BTW, should a module be allowed to overwrite an existing index ?
> or maybe each module should have its own namespace ?

Since the overwriting likely can't be prevented anyway, the programmer
needs to be careful.  But I already started to experiment with
namespaces (tables can be used easily as namespaces)

> 
>> [...]
>>>
>>>  - there needs to be an easy method to query all the tables for missing
>>>    translations for a give language, i.e. something like 
>>>
>>>     make list-missing-translations LANG=de
>>>
>>>    and it would print the identification and english text of all messages
>>>    that have no german translation yet
>>
>> That could probably be done in sysinst itself.
> 
> I don't think a translator should have to build a run sysinst to find this.
> This should be available as a host tool.

The Lua scripts that sysinst reads and executes must be read and
executed by such a tool, which then can analyse the loaded message
catalogs.  That can probably be done with a relatively simple Lua
script.  I did not yet look into this in detail.



Home | Main Index | Thread Index | Old Index