lua-users home
lua-l archive

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


On Wednesday 12, Xavier Wang wrote:
> maybe you can use a translate table.
>
> tr = {}
> tr.zh_CN = {}
> tr.en_US = {}
>
> tr.zh_CN["hello"]  = "你好"
> tr.en_US["hello"] = "hello"
>
> print(tr[lang]["hello"])

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

then to use it:
print(t"hello")
print(t"Non translated text defaults to the lookup string")

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.

> 2011/1/13 Gustavo de Sá Carvalho Honorato <gustavohonorato@gmail.com>
>
> > Hi,
> >
> > what is the best way to i18n Lua scripts? I've seen nothing about it in
> > the web.
> >
> > Thanks,
> > Gustavo



-- 
Robert G. Jakabosky