Not a bad start.
Although I believe it could be improved in a few ways.
In terms of the implementation "lib.getLocalized" might be kind of slow.
I would suggest parsing the entire localization file into a lookup table instead of iterating all lines.
Next, you may want to add support for arguments so you can do stuff like:
Code: Select all
-- text.points = Congrats, $1, you just earned $2 points -- English (left to right)
-- text.points = تهاني، 1$ ، لقد ربحت 2$ نقطة فقط -- Arabic (right to left)
sz = lib.getLocaliszed("text.points", "PLAYER", 54)
-- Congrats, PLAYER, you just earned 54 points!
I use a library that is similar to yours:
[snip]
Although it's not designed for Love2D (I might port it later on), some of the functionality there you might find useful in particular:
Code: Select all
lang.format = function(sz, ...)
-- replace flags $1, $2, etc with corresponding arguments
local n = select('#', ...)
if n > 0 then
for i = 1, n do
local a = select(i, ...)
sz = string.gsub(sz, "$" .. i, a)
end
end
return sz
end
Also, be careful with the "string" library since not all of its functionality was designed with UTF8 in mind.
PS. Oh ya, and take a look at my signature if you want to have your game localized.
