diff --git a/scripts/check-translations.js b/scripts/check-translations.js new file mode 100644 index 0000000000000000000000000000000000000000..8beb57298f50ac1f30cdf6457f35778a309d6f6d --- /dev/null +++ b/scripts/check-translations.js @@ -0,0 +1,44 @@ +'use strict'; + +const fs = require('fs'); + +// read and transform JaLHyd message file +const jalhydMessagesPath = "../jalhyd/src/util/message.ts"; +let jm = fs.readFileSync(jalhydMessagesPath, "utf-8"); +// extract enum block +jm = jm.replace(/export enum MessageCode \{([^{]+)\}[\s\S]+/m, (match, p1) => { + return p1; +}); +// remove comments +jm = jm.replace(/\/\*[\s\S]*?\*\//gm, ""); +jm = jm.replace(/\/\/.+/g, ""); + +// remove spaces +jm = jm.replace(/[ \t]+/g, ""); +// remove line breaks +jm = jm.replace(/\n/g, ""); +// split on ";" +const messages = jm.split(","); + +// console.log(messages); + +// read every language file +const localePath = "src/locale"; +const localeDir = fs.readdirSync(localePath); +for (let i = 0; i < localeDir.length; i++) { + const localeFile = localeDir[i]; + const res = localeFile.match(/^messages\.([a-z]{2})\.json$/); + if (res) { + const lang = res[1]; + console.log("Loading translations for language [" + lang + "]"); + const langFilePath = localePath + '/' + localeFile; + let translations = Object.keys(JSON.parse(fs.readFileSync(langFilePath, "utf-8"))); + // console.log(translations); + // check against JaLHyd messages list + for (const mess of messages) { + if (! translations.includes(mess)) { + console.log(" missing message in [" + lang + "] translation: " + mess); + } + } + } +}