summaryrefslogtreecommitdiffstats
path: root/lib/output/website/prepareI18n.js
blob: cedd3b909c06a55235b4cb023dae83a66ab9d460 (plain)
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
var path = require('path');

var fs = require('../../utils/fs');
var Promise = require('../../utils/promise');
var listSearchPaths = require('./listSearchPaths');

/**
 * Prepare i18n, load translations from plugins and book
 *
 * @param {Output}
 * @return {Promise<Output>}
 */
function prepareI18n(output) {
    var state = output.getState();
    var i18n = state.getI18n();
    var searchPaths = listSearchPaths(output);

    searchPaths
        .reverse()
        .forEach(function(searchPath) {
            var i18nRoot = path.resolve(searchPath, '_i18n');

            if (!fs.existsSync(i18nRoot)) return;
            i18n.load(i18nRoot);
        });

    return Promise(output);
}

module.exports = prepareI18n;