|
1 local SHOW_WARNINGS = false |
|
2 |
|
3 local function scandir(directory) |
|
4 local i, t, popen = 0, {}, io.popen |
|
5 local pfile = popen('ls -a "'..directory..'"') |
|
6 for filename in pfile:lines() do |
|
7 i = i + 1 |
|
8 t[i] = filename |
|
9 end |
|
10 pfile:close() |
|
11 return t |
|
12 end |
|
13 |
|
14 local locale_dir = "../share/hedgewars/Data/Locale" |
|
15 |
|
16 local files = scandir(locale_dir) |
|
17 |
|
18 for f = 1, #files do |
|
19 local filename = files[f] |
|
20 if string.match(filename, "^[a-zA-Z_]+%.lua$") ~= nil and filename ~= "stub.lua" then |
|
21 |
|
22 print("== "..filename.." ==") |
|
23 dofile(locale_dir .. "/" .. filename) |
|
24 local errors = 0 |
|
25 for eng, transl in pairs(locale) do |
|
26 local example = "[\""..tostring(eng).."\"] = \""..tostring(transl).."\"" |
|
27 |
|
28 -- Check for obvious errors |
|
29 if transl == "" then |
|
30 print("[EE] Empty translation: "..example) |
|
31 errors = errors + 1 |
|
32 end |
|
33 if eng == "" then |
|
34 print("[EE] Empty source string: "..example) |
|
35 errors = errors + 1 |
|
36 end |
|
37 if type(transl) ~= "string" then |
|
38 print("[EE] Translation is not a string: "..example) |
|
39 errors = errors + 1 |
|
40 end |
|
41 if type(eng) ~= "string" then |
|
42 print("[EE] Source is not a string: "..example) |
|
43 errors = errors + 1 |
|
44 end |
|
45 |
|
46 -- Check parameters |
|
47 local ne, nt = 0, 0 |
|
48 local patterns = { "c", "d", "E", "e", "f", "g", "G", "i", "o", "u", "X", "x", "q", "s", "%.%df", "%.f", "" } |
|
49 for p = 1, #patterns do |
|
50 for w in string.gmatch(eng, "%%"..patterns[p]) do |
|
51 ne = ne + 1 |
|
52 end |
|
53 for w in string.gmatch(transl, "%%"..patterns[p]) do |
|
54 nt = nt + 1 |
|
55 end |
|
56 end |
|
57 if ne ~= nt then |
|
58 print("[EE] Param mismatch!: [\""..eng.."\"] = \""..transl.."\"") |
|
59 errors = errors + 1 |
|
60 end |
|
61 |
|
62 -- Warnings |
|
63 if SHOW_WARNINGS and eng == transl then |
|
64 print("[WW] Translation unchanged: "..example) |
|
65 end |
|
66 end |
|
67 if errors == 0 then |
|
68 print("OK") |
|
69 end |
|
70 end |
|
71 end |