Skip to content

Commit

Permalink
Merge pull request #5 from whisthub/fix/undefined-locale
Browse files Browse the repository at this point in the history
fix: don't throw if locale is undefined
  • Loading branch information
sebamarynissen committed Jul 16, 2024
2 parents bd2a2fd + 10a18db commit 229809c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/create-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 8 additions & 0 deletions test/create-context-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

});

});

});

0 comments on commit 229809c

Please sign in to comment.