lua-users home
lua-l archive

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


On Thursday 13, Mateusz Czaplinski wrote:
> On Thu, Jan 13, 2011 at 2:36 AM, Robert G. Jakabosky
>
> <bobby@sharedrealm.com> wrote:
> > [...]
> > or you could use a function to make the lookup nicer:
> > current_locale = "en_US"
> > t = function(text)
> >  local tr_locale = tr[current_locale] or tr.default
> >  return tr_locale[text] or text
> > end
> > [...]
> > Instead of a function named t you could use an underscore _.  I think
> > some C/C++ based translation library (maybe QT) uses this _("hello") for
> > translating text.
>
> Uh oh, maybe unless you commonly use _ as a marker for "dummy variable
> to assign to", as in:
>   for _, v in ipairs(tab) do --[[ something ]]-- end
> or:
>   local x, _, z = fooBar()
> - then I wouldn't advise _ for i18n as you might get some some issues
> because of variable scoping...
>
> Actually, I thought this use of _ (as "dummy") is common and suggested
> by PIL, but now after what you wrote, I'm starting to lose my
> certainity... do I regularly follow some non-standard practice?

I do the same with for loop variables that I don't want to use.  The first 
time I saw the use of _ I thought the compiler used it as a special way to 
omit that variable.  I have since found that it is just a valid variable 
name.

I have seen the use of _ before, but I can't remember where.

So some other variable name should be used for the translation function.  
Maybe a one character name for the translation function would be a bad idea.  
I just liked the idea of a very short prefix that could be used to automate 
the translation of text and I really like that Lua doesn't require the used 
of () for function calls (at least not for literals).


-- 
Robert G. Jakabosky