lua-users home
lua-l archive

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


>Coda Highland <chighland@...> Fri, 21 Aug 2015 07:25:50 -0700

>>>       syslog('emergency',"%s stat(%q) = %s",dbtype,conf.file,errno[err])
>>>
>>>could be replaced with:
>>>
>>>       syslog('emergency',dbtype .. ' stat("' .. conf.file .. '") = ' ..
>> errno[err])
>>
>> I really could not have come up with a better example myself! Frankly the
>> second
>> Version "expresses intent" *much* more clearly than the first. I would
have
>> to
>> look up "%q" in a reference manual and the whole pattern concept is
opaque
>> unless you are steeped in "C". In the second version all you need to know
is
>> the meaning of ".." which is easily guessable from context. Also you do
not
>> have to worry about accidental escapes in the string literals (except for
>> quote
>> marks of course, which would remain a complexity).

>Clearly you have never worked with internationalized code. The second
>example would get my code rejected for sure if I submitted it in a
>professional context.

>Sure, for syslog, you can get away with it. But if your strings are
>user-facing and you ever want to ship in more than one language,
>breaking the format string apart makes translation a much clumsier
>process, if it's even possible at all. Having it as a single string
>means that the translator can (1) see the entire statement being
>translated, and (2) position the placeholders appropriately in the
>output.

>Yes, internationalization is more complicated than that (in practice,
>%s is insufficient and you need named or positional parameters, and
>then plurals and gender make a mess of things) but format strings are
>utterly fundamental to doing it right.

So wrap "message.syslog" as a function, put it and the other message
formatters in a language file and give that to the translator. Your whole
case
depends on a kind of coder's snobbery that says a translator cannot
cope with some simple Lua, but can internalise a complex and arbitrary
formatting syntax (plus you are admitting that the current Lua system is not
complex and arbitrary enough for this use case!)



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus