Skip to content

Commit

Permalink
Use old language file selection when no default file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
bobd91 committed Apr 4, 2018
1 parent e1ebf43 commit 3dcd291
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/plugins/filter/template_locals/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions test/scripts/filters/i18n_locals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});

0 comments on commit 3dcd291

Please sign in to comment.