From 3dcd29180735552c656a403018f6343fda9f14cc Mon Sep 17 00:00:00 2001 From: Bob Davison Date: Wed, 4 Apr 2018 15:06:30 +0100 Subject: [PATCH] Use old language file selection when no default file exists --- lib/plugins/filter/template_locals/i18n.js | 2 +- test/scripts/filters/i18n_locals.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/plugins/filter/template_locals/i18n.js b/lib/plugins/filter/template_locals/i18n.js index 715b86f14f..50c54b14e4 100644 --- a/lib/plugins/filter/template_locals/i18n.js +++ b/lib/plugins/filter/template_locals/i18n.js @@ -30,7 +30,7 @@ function i18nLocalsFilter(locals) { page.canonical_path = page.canonical_path || locals.path; - const languages = _([].concat(lang, i18nConfigLanguages)).compact().uniq().value(); + const languages = _([].concat(lang, i18nConfigLanguages, i18nLanguages)).compact().uniq().value(); locals.__ = i18n.__(languages); locals._p = i18n._p(languages); diff --git a/test/scripts/filters/i18n_locals.js b/test/scripts/filters/i18n_locals.js index ced9729ad2..b4f1f96b39 100644 --- a/test/scripts/filters/i18n_locals.js +++ b/test/scripts/filters/i18n_locals.js @@ -151,4 +151,26 @@ describe('i18n locals', () => { i18n.languages = oldConfig; }); + + it('use config by default - with no set language and no default file take first available', () => { + var oldConfig = i18n.languages; + var oldSet = i18n.get('default'); + i18n.remove('default'); + i18n.languages = ['default']; + + var locals = { + config: hexo.config, + page: {}, + path: 'index.html' + }; + + i18nFilter(locals); + + locals.page.lang.should.eql('default'); + locals.page.canonical_path.should.eql('index.html'); + locals.__('Home').should.eql('Zuhause'); + + i18n.set('default', oldSet); + i18n.languages = oldConfig; + }); });