Skip to content

Adds the ability to provide a function for notFound or translation dictionary

Choose a tag to compare

@alexdrel alexdrel released this 11 Nov 00:24
· 4 commits to master since this release

notFound property can be either a string, or a function returning a string.
If it is a string, then it will be returned as is any time a key is missing.
If you provide a function, then the function will be run with the missing key
and context as arguments.

T.setTexts(translations, {
  notFound: key => `**${key}**` // will render <strong>SomeKey</strong>
})

Translation dictionaries can be extended with functions (as in notFound).

T.setTexts({
    a: 'A',
    n: (_key, ctx) => ctx ? `Number ${ctx}` : '',
  });
T.translate('a')) // 'A'
T.translate('n', { context: 9 })) // 'Number 9'