forked from bigcommerce/stencil-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlang-assembler.js
More file actions
37 lines (35 loc) · 1.13 KB
/
Copy pathlang-assembler.js
File metadata and controls
37 lines (35 loc) · 1.13 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
34
35
36
37
import async from 'async';
import fs from 'fs';
import path from 'path';
const LOCALE_DIRECTORY = 'lang';
/**
* Assembles together all of the lang files.
* This simply loads the files from the lang directory and puts them in an object where
* locale name is the key and locale data is the value
*
* @param callback
*/
function assemble(callback) {
fs.readdir(LOCALE_DIRECTORY, (err, localeFiles) => {
if (err) {
callback(err);
return;
}
// Ignore hidden files
// @example: MAC generates .DS_STORE
const filteredLocaleFiles = localeFiles.filter((fileName) => fileName[0] !== '.');
const localesToLoad = {};
for (const localeFile of filteredLocaleFiles) {
const localeName = path.basename(localeFile, '.json');
localesToLoad[localeName.toLowerCase()] = (cb2) => {
const localeFilePath = `${LOCALE_DIRECTORY}/${localeFile}`;
fs.readFile(localeFilePath, 'utf-8', cb2);
};
}
async.parallel(localesToLoad, callback);
});
}
export default {
assemble,
LOCALE_DIRECTORY,
};