summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/generators/website.js58
-rw-r--r--lib/utils/fs.js1
-rw-r--r--package.json1
-rw-r--r--theme/i18n/fr.json3
-rw-r--r--theme/templates/website/glossary.html2
5 files changed, 45 insertions, 20 deletions
diff --git a/lib/generators/website.js b/lib/generators/website.js
index af4cd0c..5fd7fd1 100644
--- a/lib/generators/website.js
+++ b/lib/generators/website.js
@@ -6,6 +6,7 @@ var _ = require("lodash");
var nunjucks = require("nunjucks");
var AutoEscapeExtension = require("nunjucks-autoescape");
var FilterExtension = require("nunjucks-filter");
+var I18nExtension = require("nunjucks-i18n");
var fs = require("../utils/fs");
var BaseGenerator = require("../generator");
@@ -65,30 +66,49 @@ Generator.prototype.prepareTemplates = function() {
// Prepare template engine
Generator.prototype.prepareTemplateEngine = function() {
- var folders = _.chain(this.templates)
- .values()
- .map(path.dirname)
- .uniq()
- .value();
+ var that = this;
+
+ return fs.readdir(path.resolve(__dirname, "../../theme/i18n"))
+ .then(function(locales) {
+ locales = _.chain(locales)
+ .map(function(local) {
+ local = path.basename(local, ".json");
+ return [local, require("../../theme/i18n/"+local)];
+ })
+ .object()
+ .value();
- this.env = new nunjucks.Environment(
- new nunjucks.FileSystemLoader(folders),
- {
- autoescape: true
+ if (!_.contains(_.keys(locales), that.options.language)) {
+ that.book.logWarn("Language '"+that.options.language+"' is not available as a layout locales ("+_.keys(locales).join(", ")+")");
}
- );
- // Add filter
- this.env.addFilter("contentLink", this.book.contentLink.bind(this.book));
- this.env.addFilter('lvl', function(lvl) {
- return lvl.split(".").length;
- });
+ var folders = _.chain(that.templates)
+ .values()
+ .map(path.dirname)
+ .uniq()
+ .value();
- // Add extension
- this.env.addExtension('AutoEscapeExtension', new AutoEscapeExtension(this.env));
- this.env.addExtension('FilterExtension', new FilterExtension(this.env));
+ that.env = new nunjucks.Environment(
+ new nunjucks.FileSystemLoader(folders),
+ {
+ autoescape: true
+ }
+ );
- return Q();
+ // Add filter
+ that.env.addFilter("contentLink", that.book.contentLink.bind(that.book));
+ that.env.addFilter('lvl', function(lvl) {
+ return lvl.split(".").length;
+ });
+
+ // Add extension
+ that.env.addExtension('AutoEscapeExtension', new AutoEscapeExtension(that.env));
+ that.env.addExtension('FilterExtension', new FilterExtension(that.env));
+ that.env.addExtension('I18nExtension', new I18nExtension({
+ env: that.env,
+ translations: locales
+ }));
+ });
};
// Finis generation
diff --git a/lib/utils/fs.js b/lib/utils/fs.js
index 8a5d4e4..95fa73d 100644
--- a/lib/utils/fs.js
+++ b/lib/utils/fs.js
@@ -64,6 +64,7 @@ var getFiles = function(path) {
module.exports = {
list: getFiles,
stat: Q.denodeify(fs.stat),
+ readdir: Q.denodeify(fs.readdir),
readFile: Q.denodeify(fs.readFile),
writeFile: function(filename, data, options) {
var d = Q.defer();
diff --git a/package.json b/package.json
index 72aee56..191c731 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,7 @@
"nunjucks": "git+https://github.com/SamyPesse/nunjucks.git#4019d1b7379372336b86ce1b0bf84352a2029747",
"nunjucks-autoescape": "0.1.0",
"nunjucks-filter": "0.1.0",
+ "nunjucks-i18n": "1.0.0",
"semver": "2.2.1",
"npmi": "0.1.1",
"cheerio": "0.18.0",
diff --git a/theme/i18n/fr.json b/theme/i18n/fr.json
new file mode 100644
index 0000000..924f6b6
--- /dev/null
+++ b/theme/i18n/fr.json
@@ -0,0 +1,3 @@
+{
+ "GLOSSARY": "Glossaire"
+} \ No newline at end of file
diff --git a/theme/templates/website/glossary.html b/theme/templates/website/glossary.html
index e19d1b9..bb633e9 100644
--- a/theme/templates/website/glossary.html
+++ b/theme/templates/website/glossary.html
@@ -1,6 +1,6 @@
{% extends "page.html" %}
-{% block title %}Glossary | {{ title }}{% endblock %}
+{% block title %}{% i18n "GLOSSARY" %}Glossary{% endi18n %} | {{ title }}{% endblock %}
{% block page_inner %}
{% for item in glossary %}