You can find a demo implementation here.
See here on more information how to set up typesafe-i18n.
npm install typesafe-i18nrequires a node version >= 12.x
Initialize typesafe-i18n by running
npx typesafe-i18n --setup-autoYou could configure your development script to run the generator in parallel to nodemon by using npm-run-all.
{
"scripts": {
"dev": "npm-run-all --parallel nodemon typesafe-i18n",
"nodemon": "nodemon src/index.ts",
"typesafe-i18n": "typesafe-i18n"
}
}The generator will create some custom utils inside i18n-node.ts.
That's it. You can then start using typesafe-i18n inside your application.
import L from './i18n/i18n-node'
console.log(L.en.HI({ name: 'Node.js' })) // Hello Node.js!The file i18n-node.ts exports following function:
An object of type i18n you can use inside your code.
This is also the default export of that file.
For more information about typesafe-i18n, take a look at the main repository.