diff --git a/lib/create-context.js b/lib/create-context.js index ce5730b..028256a 100644 --- a/lib/create-context.js +++ b/lib/create-context.js @@ -17,7 +17,7 @@ export default function createContext(i18n, opts = {}) { const localeRef = toRef(opts.locale); const { messages = {} } = opts; function lookup(key) { - const locale = localeRef.value || toValue(i18n.locale); + const locale = localeRef.value || toValue(i18n.locale) || ''; return searchMessage(i18n, messages, locale, key); } diff --git a/test/create-context-test.js b/test/create-context-test.js index 2a67b95..de481d3 100644 --- a/test/create-context-test.js +++ b/test/create-context-test.js @@ -205,6 +205,14 @@ describe('The context factory', function() { }); + it('falls back to the keys if no locale has been set', function() { + + const i18n = this.setup(); + const { t } = this.ctx(i18n); + expect(t('no_locale')).to.equal('no_locale'); + + }); + }); });