Positive07 wrote:The Spanish translation is %100 complete
Can you tell us how did you get the .ini files from the Google spreadsheet? I'm impressed
Thanks so much for your help! Much appreciated!
This is the method I used (I'm afraid it's a little tedious):
First, you download the doc as a XLS file
Then export each sheet to CSV (make sure it's UTF8 format)
Save each sheet as 1.csv, 2.csv, 3.csv, etc (there are 13 sheets)
Finally run:
Code: Select all
-- Convert from CSV string to table (converts a single line of a CSV file)
function fromCSV (s)
s = s .. ',' -- ending comma
local t = {} -- table to collect fields
local fieldstart = 1
repeat
-- next field is quoted? (start with `"'?)
if string.find(s, '^"', fieldstart) then
local a, c
local i = fieldstart
repeat
-- find closing quote
a, i, c = string.find(s, '"("?)', i+1)
until c ~= '"' -- quote not followed by quote?
if not i then error('unmatched "') end
local f = string.sub(s, fieldstart+1, i-1)
table.insert(t, (string.gsub(f, '""', '"')))
fieldstart = string.find(s, ',', i) + 1
else -- unquoted; find next comma
local nexti = string.find(s, ',', fieldstart)
table.insert(t, string.sub(s, fieldstart, nexti-1))
fieldstart = nexti + 1
end
until fieldstart > string.len(s)
return t
end
local sec = { "lang", "dialog", "menu", "gameplay", "score", "video", "audio", "input", "progress", "build", "chess", "date", "territory" }
local langs = { "id", "en", "ar", "bg", "de", "el", "es", "fi", "fr", "he", "hi", "hu", "it", "ja", "ko", "nl", "pt", "pt_br", "pl", "ru", "sv", "zh" }
for li, lang in ipairs(langs) do
local out = io.open("csv/" .. lang .. ".ini", "w")
for i = 1, #sec do
local f = io.open("csv/" .. i .. ".csv", "r")
out:write("[" .. sec[i] .. "]\n")
for fields in f:lines() do
local csv = fromCSV(fields)
local id = csv[1]
if id and id ~= "" then
local e = csv[li] or ""
e = string.gsub(e, "\n", "")
out:write(id)
out:write("=")
out:write(e)
out:write("\n")
end
end
out:write("\n")
end
end
You can change it up to export the translations in a lua table, but ini is smaller and easier to maintain.
This is the function that I use to replace the $1, $2, $3, etc flags:
Code: Select all
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
Example:
Code: Select all
sz = "$1 minutes ago"
sz2 = format(sz, 60)
Thanks so much for your help.
BTW, if you want to have your game translated just add it as another sheet in the doc.