-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathfind-untranslated.js
45 lines (38 loc) · 1.66 KB
/
find-untranslated.js
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
34
35
36
37
38
39
40
41
42
43
44
45
const fs = require('fs-extra')
const path = require('path')
// const __dirname = path.dirname(new URL(import.meta.url).pathname)
const ProjectSourceRoot = path.resolve(__dirname, '..')
const directoryPath = path.join(ProjectSourceRoot, './src/locales')
const englishJsonFilename = 'en-US.json' // Set the English JSON filename
// Function to load JSON files and check for untranslated strings
function findUntranslatedStrings(dirPath) {
const files = fs.readdirSync(dirPath)
const englishFilePath = path.join(dirPath, englishJsonFilename)
const englishData = fs.readJsonSync(englishFilePath)
const untranslated = {}
files.forEach((file) => {
if (path.extname(file) === '.json' && file !== englishJsonFilename) {
const filePath = path.join(dirPath, file)
const data = fs.readJsonSync(filePath)
const languageCode = path.basename(file, '.json')
// Check each key in the JSON file
Object.entries(data).forEach(([key, value]) => {
if (value === '') {
if (!untranslated[key]) {
untranslated[key] = {
untranslated: [],
englishSource:
englishData[key] ||
'No English source available',
}
}
untranslated[key].untranslated.push(languageCode)
}
})
}
})
return untranslated
}
// Execute the function and log the results
const untranslated = findUntranslatedStrings(directoryPath)
console.log(JSON.stringify(untranslated, null, 2))