forked from GetStream/stream-chat-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-translations.js
More file actions
34 lines (31 loc) · 989 Bytes
/
validate-translations.js
File metadata and controls
34 lines (31 loc) · 989 Bytes
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
const path = require('path');
const fs = require('fs');
const i18nDirectoryRelativePath = '../src/i18n/';
const directoryPath = path.join(__dirname, i18nDirectoryRelativePath);
let countMissingTranslations = 0;
fs.readdir(directoryPath, function (err, files) {
if (err) {
return console.log('Unable to scan directory: ' + err);
}
files.forEach(function (file) {
if (file.split('.').reverse()[0] !== 'json') return;
// Do whatever you want to do with the file
const data = require(i18nDirectoryRelativePath + file);
const keys = Object.keys(data);
keys.forEach((key) => {
if (!data[key] || data[key] === '') {
countMissingTranslations = countMissingTranslations + 1;
console.error(
'\\033[91m',
'Missing translation for key "' + key + '" in "' + file + '"',
);
}
});
});
if (countMissingTranslations > 0) {
process.exitCode = 2;
process.exit();
} else {
process.exit(0);
}
});