-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathjest-transform-i18next.js
More file actions
24 lines (23 loc) · 727 Bytes
/
jest-transform-i18next.js
File metadata and controls
24 lines (23 loc) · 727 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
const fs = require('fs');
const path = require('path');
module.exports = {
process: function() {
const pathname = arguments[1];
const dir = path.dirname(pathname);
const locales = fs.readdirSync(dir);
const result = {};
for (const locale of locales) {
if (fs.statSync(path.join(dir, locale)).isDirectory()) {
const localeFiles = fs.readdirSync(path.join(dir, locale));
for (const localeFile of localeFiles) {
if (localeFile.indexOf('.json') >= 0) {
result[locale] = JSON.parse(fs.readFileSync(path.join(dir, locale, localeFile), 'utf8'));
}
}
}
}
return {
code: `module.exports = ${JSON.stringify(result)};`
};
}
};