diff --git a/app/client/lib/localization.ts b/app/client/lib/localization.ts index 08421ec4..5bb2b967 100644 --- a/app/client/lib/localization.ts +++ b/app/client/lib/localization.ts @@ -161,9 +161,16 @@ export function makeT(scope: string, instance?: typeof i18next) { scopedInstance = (instance ?? i18next).cloneInstance({ keySeparator: false, nsSeparator: false, + saveMissing: true, + missingKeyHandler: (lng, ns, _key) => console.warn(`Missing translation for key: ${_key}`) }); + // Create a version of `t` function that will use the provided prefix as default. - scopedResolver = scopedInstance.getFixedT(null, null, scope); + const fixedResolver = scopedInstance.getFixedT(null, null, scope); + + // Override the resolver with a custom one, that will use the argument as a default. + // This will remove all the overloads from the function, but we don't need them. + scopedResolver = (_key: string, _args?: any) => fixedResolver(_key, {defaultValue: _key, ..._args}); } // If the key has interpolation or we did pass some arguments, make sure that // the key exists. diff --git a/app/common/getCurrentTime.ts b/app/common/getCurrentTime.ts index 8201c2d7..b54c814f 100644 --- a/app/common/getCurrentTime.ts +++ b/app/common/getCurrentTime.ts @@ -9,5 +9,5 @@ export default function getCurrentTime(): moment.Moment { if (typeof window === 'undefined' || !window) { return getDefault(); } const searchParams = new URLSearchParams(window.location.search); - return searchParams.has('currentTime') ? moment(searchParams.get('currentTime')) : getDefault(); + return searchParams.has('currentTime') ? moment(searchParams.get('currentTime')!) : getDefault(); } diff --git a/test/client/lib/localization.ts b/test/client/lib/localization.ts index 3a62109e..e0257057 100644 --- a/test/client/lib/localization.ts +++ b/test/client/lib/localization.ts @@ -127,4 +127,9 @@ describe('localization', function() { const scoped = makeT('Parent', instance); assert.equal(scoped('Not.Valid:Characters'), 'Works'); }); + + it('makeT helper fallbacks to an argument', function() { + const scoped = makeT('Parent', instance); + assert.equal(scoped("I'm not there"), "I'm not there"); + }); });