aboutsummaryrefslogtreecommitdiff
path: root/advtrains/locale/update-l10n.lua
diff options
context:
space:
mode:
authorywang <yw05@forksworld.de>2021-03-27 16:45:41 +0100
committerY. Wang <yw05@forksworld.de>2022-10-15 01:18:34 +0200
commit73e558ffb279548593a539cf9369f17b9fafb009 (patch)
tree0cfbcd14d04b153867c95fcd1019b058e5646b03 /advtrains/locale/update-l10n.lua
parent5ab7b11f3e2734dc55b3dcf26d14fc1345ebde65 (diff)
downloadadvtrains-73e558ffb279548593a539cf9369f17b9fafb009.tar.gz
advtrains-73e558ffb279548593a539cf9369f17b9fafb009.tar.bz2
advtrains-73e558ffb279548593a539cf9369f17b9fafb009.zip
Update German translation; add script to update l10n files
Diffstat (limited to 'advtrains/locale/update-l10n.lua')
-rw-r--r--advtrains/locale/update-l10n.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/advtrains/locale/update-l10n.lua b/advtrains/locale/update-l10n.lua
new file mode 100644
index 0000000..011f9c6
--- /dev/null
+++ b/advtrains/locale/update-l10n.lua
@@ -0,0 +1,46 @@
+local lang = arg[1] or error("No language supplied")
+local tfn = string.format("advtrains.%s.tr", lang)
+local f = io.open(tfn, "rb") or error("Cannot read from translation file")
+local tf = {}
+for l in f:lines() do
+ tf[#tf+1] = l
+end
+f:close()
+
+local ot = {[0] = ""}
+local f = io.open("template.txt", "rb") or error("Cannot read from translation template")
+for l in f:lines() do
+ if l == "" then -- blank line
+ if ot[#ot] ~= l then ot[#ot+1] = l end
+ elseif l:find("^#") then -- comment
+ if ot[#ot] ~= l then ot[#ot+1] = l end
+ else
+ s = l:match("^(.+[^@]=)")
+ if s then
+ local found = false
+ for i = 1, #tf, 1 do
+ if tf[i]:find(s, 1, true) == 1 then
+ found = i
+ break
+ end
+ end
+ if found then
+ local fc = found-1
+ while fc > 0 do
+ if not tf[fc]:find("^#") then break end
+ fc = fc-1
+ end
+ for i = fc+1, found, 1 do
+ if ot[#ot] ~= tf[i] then ot[#ot+1] = tf[i] end
+ end
+ else
+ if ot[#ot] ~= l then ot[#ot+1] = l end
+ end
+ end
+ end
+end
+f:close()
+
+local f = io.open(tfn, "wb") or error("Cannot write to translation file")
+f:write(table.concat(ot,"\n"))
+f:close() \ No newline at end of file