[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Handling Translated Texts (i18n)
- From: Oliver Kroth <oliver.kroth@...>
- Date: Tue, 23 Feb 2016 17:32:49 +0100
Hi Scott,
I am handling this such that all texts in the source code are wrapped by
a function call to i18n() like:
print( i18n("Hello World!"))
The translation table i18ntext and the i18n() function
function i18n( key, default ) return i18ntext[ key ] or default or
key end
is loaded by the Lua applet using require("i18n")
Missing text is replaced by a default, if given, or the key itself if not.
I use a similar pattern for the JavaScript components as well; both
refer to the same text table.
I can create automatically (using a Lua script, what else :) ) the
translation table which has the native (English) text as key, and the
translation (or in the beginning the key again) as value.
It simply searches the Lua files with:
for quote, key in text:gmatch(
"i18n%s*[(]%s*([\"\'])(.-)%1" ) do
set[key] = key
end
to find the set of unique texts, which it then cross-checks against the
active translation table
--
Oliver
Stuff like:
* One big file with all translation, or separate files per language/region?
* Pull in via require, or some hand rolled loader?
* Use raw tables, meta-table object, or a function call to access the text?
* ID the texts via a native language value, or some unique ID number?
* Finding all locations of translated texts in code base to send off
for translation
Scott