Add typesafety/intellisense to translation keys #64
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since we are going to be translating the app with i18next, it will be really helpful to get feedback during dev-time for mistakes made with the translation keys. This will give us errors when we try to use keys that do not exist, and also add auto-complete for the translation keys.
The auto-complete is a bit fiddly, and in "t('')" it seems to be activated by adding the ''. So if you don't get it, remove and re-add them.
Also added an example of using the Trans component for i18n.
Lastly, to build the 'resources.d.ts' file from our translation files, I installed the package i18next-resources-for-ts. It is fairly new, but has a score of 75 in the snyk-advisor. One thing to consider here is that, this is only needed since we use JSON files for storing the translations, if instead we used .ts file, this might not be needed. However, our current users are used to JSON files, so did not change this.
I was not sure which pre-script to add this new script to, if any. The file is only needed during development, and is not used during runtime. So neither the prestart or prebuild scripts seem to fit. For now, to get the typesafety, we need to run "npm run build-i18n-interface" when we start developing, or when we update the 'en' translation files.