-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathi18n.js
More file actions
30 lines (27 loc) · 812 Bytes
/
i18n.js
File metadata and controls
30 lines (27 loc) · 812 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
const yaml = require('js-yaml');
const fs = require('fs');
const path = require('path');
module.exports = (hexo,pluginDir) => {
return {
i18n (dir,key) {
let lang = hexo.config.language;
let i18n = hexo.theme.i18n;
const mergeLang = (lang) => {
let themeLang = i18n.get(lang);
if(themeLang[key]) return;
try {
let coauthorLang = yaml.safeLoad(fs.readFileSync(path.join(pluginDir, dir, lang + '.yml'), 'utf-8'));
themeLang[key] = coauthorLang[key];
i18n.set(lang, themeLang);
} catch (e) {
hexo.log.warn(`Coauthor hasn't ${lang} language configuration.`);
}
}
if (Array.isArray(lang)) {
lang.forEach(item => mergeLang(item));
} else {
mergeLang(lang);
}
}
}
}