tools/check_lua_locale_files.lua
author Wuzzy <Wuzzy2@mail.ru>
Thu, 11 Jul 2019 04:42:50 +0200
changeset 15248 263b9850c16d
parent 14110 30565866db82
permissions -rwxr-xr-x
Tweak position of big splashes right or left
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14110
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     1
local SHOW_WARNINGS = false
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     2
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     3
local function scandir(directory)
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     4
	local i, t, popen = 0, {}, io.popen
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     5
	local pfile = popen('ls -a "'..directory..'"')
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     6
	for filename in pfile:lines() do
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     7
		i = i + 1
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     8
		t[i] = filename
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     9
	end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    10
	pfile:close()
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    11
	return t
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    12
end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    13
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    14
local locale_dir = "../share/hedgewars/Data/Locale"
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    15
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    16
local files = scandir(locale_dir)
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    17
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    18
for f = 1, #files do
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    19
	local filename = files[f]
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    20
	if string.match(filename, "^[a-zA-Z_]+%.lua$") ~= nil and filename ~= "stub.lua" then
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    21
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    22
		print("== "..filename.." ==")
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    23
		dofile(locale_dir .. "/" .. filename)
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    24
		local errors = 0
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    25
		for eng, transl in pairs(locale) do
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    26
			local example = "[\""..tostring(eng).."\"] = \""..tostring(transl).."\""
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    27
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    28
			-- Check for obvious errors
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    29
			if transl == "" then
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    30
				print("[EE] Empty translation: "..example)
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    31
				errors = errors + 1
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    32
			end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    33
			if eng == "" then
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    34
				print("[EE] Empty source string: "..example)
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    35
				errors = errors + 1
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    36
			end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    37
			if type(transl) ~= "string" then
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    38
				print("[EE] Translation is not a string: "..example)
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    39
				errors = errors + 1
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    40
			end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    41
			if type(eng) ~= "string" then
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    42
				print("[EE] Source is not a string: "..example)
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    43
				errors = errors + 1
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    44
			end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    45
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    46
			-- Check parameters
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    47
			local ne, nt = 0, 0
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    48
			local patterns = { "c", "d", "E", "e", "f", "g", "G", "i", "o", "u", "X", "x", "q", "s", "%.%df", "%.f", "" }
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    49
			for p = 1, #patterns do
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    50
				for w in string.gmatch(eng, "%%"..patterns[p]) do
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    51
					ne = ne + 1
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    52
				end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    53
				for w in string.gmatch(transl, "%%"..patterns[p]) do
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    54
					nt = nt + 1
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    55
				end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    56
			end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    57
			if ne ~= nt then
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    58
				print("[EE] Param mismatch!: [\""..eng.."\"] = \""..transl.."\"")
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    59
				errors = errors + 1
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    60
			end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    61
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    62
			-- Warnings
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    63
			if SHOW_WARNINGS and eng == transl then
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    64
				print("[WW] Translation unchanged: "..example)
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    65
			end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    66
		end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    67
		if errors == 0 then
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    68
			print("OK")
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    69
		end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    70
	end
30565866db82 Add some useful translation checker scripts for Lua
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    71
end