diff --git a/src/useTranslation.js b/src/useTranslation.js index 375cbb0a..dc0890bc 100755 --- a/src/useTranslation.js +++ b/src/useTranslation.js @@ -19,8 +19,9 @@ export function useTranslation(ns, props = {}) { if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces(); if (!i18n) { warnOnce('You will need pass in an i18next instance by using initReactI18next'); - const retNotReady = [k => k, {}, false]; - retNotReady.t = k => k; + const notReadyT = k => (Array.isArray(k) ? k[k.length - 1] : k); + const retNotReady = [notReadyT, {}, false]; + retNotReady.t = notReadyT; retNotReady.i18n = {}; retNotReady.ready = false; return retNotReady; diff --git a/test/useTranslation.spec.js b/test/useTranslation.spec.js index 76a83e8f..ddc7900d 100644 --- a/test/useTranslation.spec.js +++ b/test/useTranslation.spec.js @@ -59,7 +59,12 @@ describe('useTranslation', () => { expect(typeof t).toBe('function'); expect(i18n).toEqual({}); - return
{t('key1')}
; + return ( + <> +
{t('key1')}
+
{t(['doh', 'Human friendly fallback'])}
+ + ); } it('should render content fallback', () => { @@ -67,6 +72,7 @@ describe('useTranslation', () => { const wrapper = mount(, {}); // console.log(wrapper.debug()); expect(wrapper.contains(
key1
)).toBe(true); + expect(wrapper.contains(
Human friendly fallback
)).toBe(true); expect(console.warn).toHaveBeenCalled(); }); });