forked from Think-and-Dev/solidoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18n.js
32 lines (27 loc) · 745 Bytes
/
i18n.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
"use strict";
const path = require("path");
const fs = require("fs-extra");
module.exports = {
getResource: function() {
function getPath() {
const language = global.config.language || "en";
const file = path.join(__dirname, "i18n", `${language}.json`);
const override = path.join(process.cwd(), ".solidok", "i18n", `${language}.json`);
if(fs.existsSync(override)) {
return override;
};
return file;
}
const file = getPath();
if(fs.existsSync(file)) {
var resource = require(file);
return resource;
}
return undefined;
},
translate: function(key) {
const resource = this.getResource();
const entry = resource[key];
return entry || key;
}
};