Add some useful translation checker scripts for Lua
authorWuzzy <Wuzzy2@mail.ru>
Fri, 02 Nov 2018 17:43:06 +0100
changeset 14089 30565866db82
parent 14088 f483f844da98
child 14090 43d956f41cd4
Add some useful translation checker scripts for Lua
tools/README.md
tools/check_lua_locale_files.lua
tools/check_lua_locale_files.sh
tools/check_translations.sh
--- a/tools/README.md	Fri Nov 02 19:37:47 2018 +0300
+++ b/tools/README.md	Fri Nov 02 17:43:06 2018 +0100
@@ -14,6 +14,7 @@
 * `create_dmg.sh`: Generate a .dmg file (relevant for Mac)
 * `dmg_pkg_install.sh`: Downloads and install a .dmg from a URL (relevant for Mac)
 * `docgen.sh`: Generate QTfrontend documentation with Doxygen (it's not very good)
+* `check_translations.sh`: Check most translation files for mistakes and generate a simple progress report
 
 ### Directories
 * `hwmapconverter`: C++ application to edit HWMAP files in text form
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/check_lua_locale_files.lua	Fri Nov 02 17:43:06 2018 +0100
@@ -0,0 +1,71 @@
+local SHOW_WARNINGS = false
+
+local function scandir(directory)
+	local i, t, popen = 0, {}, io.popen
+	local pfile = popen('ls -a "'..directory..'"')
+	for filename in pfile:lines() do
+		i = i + 1
+		t[i] = filename
+	end
+	pfile:close()
+	return t
+end
+
+local locale_dir = "../share/hedgewars/Data/Locale"
+
+local files = scandir(locale_dir)
+
+for f = 1, #files do
+	local filename = files[f]
+	if string.match(filename, "^[a-zA-Z_]+%.lua$") ~= nil and filename ~= "stub.lua" then
+
+		print("== "..filename.." ==")
+		dofile(locale_dir .. "/" .. filename)
+		local errors = 0
+		for eng, transl in pairs(locale) do
+			local example = "[\""..tostring(eng).."\"] = \""..tostring(transl).."\""
+
+			-- Check for obvious errors
+			if transl == "" then
+				print("[EE] Empty translation: "..example)
+				errors = errors + 1
+			end
+			if eng == "" then
+				print("[EE] Empty source string: "..example)
+				errors = errors + 1
+			end
+			if type(transl) ~= "string" then
+				print("[EE] Translation is not a string: "..example)
+				errors = errors + 1
+			end
+			if type(eng) ~= "string" then
+				print("[EE] Source is not a string: "..example)
+				errors = errors + 1
+			end
+
+			-- Check parameters
+			local ne, nt = 0, 0
+			local patterns = { "c", "d", "E", "e", "f", "g", "G", "i", "o", "u", "X", "x", "q", "s", "%.%df", "%.f", "" }
+			for p = 1, #patterns do
+				for w in string.gmatch(eng, "%%"..patterns[p]) do
+					ne = ne + 1
+				end
+				for w in string.gmatch(transl, "%%"..patterns[p]) do
+					nt = nt + 1
+				end
+			end
+			if ne ~= nt then
+				print("[EE] Param mismatch!: [\""..eng.."\"] = \""..transl.."\"")
+				errors = errors + 1
+			end
+
+			-- Warnings
+			if SHOW_WARNINGS and eng == transl then
+				print("[WW] Translation unchanged: "..example)
+			end
+		end
+		if errors == 0 then
+			print("OK")
+		end
+	end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/check_lua_locale_files.sh	Fri Nov 02 17:43:06 2018 +0100
@@ -0,0 +1,5 @@
+#!/bin/sh -
+echo "*** Luacheck of Lua locale files:"
+luacheck ../share/hedgewars/Data/Locale/*.lua --globals locale -q
+echo "Missing translations in Lua locale files:"
+grep -c -- "^--" ../share/hedgewars/Data/Locale/*.lua
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/check_translations.sh	Fri Nov 02 17:43:06 2018 +0100
@@ -0,0 +1,15 @@
+#!/bin/sh -
+# Script to check locale files
+
+# HOW TO USE:
+# - Run this script in the tools/ directory.
+# Result: Problems and missing translations in some locale files will be reported
+
+# SYNTAX:
+#
+#     ./check_locale_files.sh
+#
+
+./check_engine_locale_files.sh ALL 0
+./check_lua_locale_files.sh
+lua ./check_lua_locale_files.lua