-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathVerifyLang.js
More file actions
33 lines (30 loc) · 1.18 KB
/
Copy pathVerifyLang.js
File metadata and controls
33 lines (30 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// script that check if language keys are translated in all files
const fs = require('fs')
const path = require('path')
const languagesDir = path.join(__dirname, '..', 'app', 'i18next')
const baseLanguageFile = path.join(languagesDir, 'en.json')
const baseLanguage = JSON.parse(fs.readFileSync(baseLanguageFile, 'utf8'))
const checkTranslations = (baseObj, compareObj, parentKey = '') => {
for (const key in baseObj) {
const fullKey = parentKey ? `${parentKey}.${key}` : key
if (typeof baseObj[key] === 'object' && baseObj[key] !== null) {
if (!(key in compareObj)) {
console.log(`Missing key: ${fullKey}`)
} else {
checkTranslations(baseObj[key], compareObj[key], fullKey)
}
} else {
if (!(key in compareObj)) {
console.log(`Missing key: ${fullKey}`)
}
}
}
}
fs.readdirSync(languagesDir).forEach(file => {
if (file.endsWith('.json') && file !== 'en.json') {
const filePath = path.join(languagesDir, file)
const compareLanguage = JSON.parse(fs.readFileSync(filePath, 'utf8'))
console.log(`\nChecking translations for ${file}:`)
checkTranslations(baseLanguage, compareLanguage)
}
})