diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-21 13:29:17 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-21 13:29:17 +0100 |
commit | e5dd987d038e93d424a65038046723531c2519b3 (patch) | |
tree | 5d73c9fcbc78b526e1802139c94dfb80ccf7705b /lib | |
parent | 51fd8ae08c1616b6826e72dd86e658f4e921bed9 (diff) | |
download | gitbook-e5dd987d038e93d424a65038046723531c2519b3.zip gitbook-e5dd987d038e93d424a65038046723531c2519b3.tar.gz gitbook-e5dd987d038e93d424a65038046723531c2519b3.tar.bz2 |
Add i18n filter fro themes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/output/website.js | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/output/website.js b/lib/output/website.js index bbb3fdc..32647f6 100644 --- a/lib/output/website.js +++ b/lib/output/website.js @@ -2,6 +2,7 @@ var _ = require('lodash'); var path = require('path'); var util = require('util'); var nunjucks = require('nunjucks'); +var I18n = require('i18n-t'); var Promise = require('../utils/promise'); var fs = require('../utils/fs'); @@ -29,6 +30,9 @@ function _WebsiteOutput() { // Plugin instance for the default theme this.defaultTheme; + + // i18n for themes + this.i18n = new I18n(); } util.inherits(_WebsiteOutput, Output); @@ -68,15 +72,22 @@ WebsiteOutput.prototype.prepare = function() { that.themeDefault? that.themeDefault.root : null ]) .compact() - .map(templatesPath) .uniq() .value(); - that.env = new nunjucks.Environment(new nunjucks.FileSystemLoader(searchPaths)); + // Load i18n + _.each(searchPaths.reverse(), function(searchPath) { + var i18nRoot = path.resolve(searchPath, '_i18n'); + + if (!fs.existsSync(i18nRoot)) return; + that.i18n.load(i18nRoot); + }); + + + that.env = new nunjucks.Environment(new nunjucks.FileSystemLoader(_.map(searchPaths, templatesPath))); that.env.addFilter('t', function(s) { - // todo: i18n - return s; + return that.i18n.t(that.book.config.get('language'), s); }); // Transform an absolute path into a relative path |