This gist contains 3 files:
- codegen.ts: this file scans the locales directory and writes a typings.d.ts file based on it
- useTranslation.ts: this file use the typings.d.ts file produced by codegen.ts to type namespaces & messages
- typings.d.ts: this is the file produced by codegen.ts, i put an example here of what to expect
Please note, you may need to change the paths in codegen.ts (line 14 and line 127)
This code was made for use with next-translate and nextjs but can easily be adapted for anything else. If you are using nextjs, you should import codegen.ts in your app component and the codegen file will run in development on the server side (with on demand imports as to stop next/swc bundling fs and typescript into your client bundles)