Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typesafety/intellisense to translation keys #64

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

SjurSutterudSagen
Copy link
Contributor

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.

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.
@SjurSutterudSagen SjurSutterudSagen requested review from a team March 5, 2024 11:22
Copy link
Contributor

@MikaelNordberg MikaelNordberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@SjurSutterudSagen SjurSutterudSagen merged commit 17ba420 into main Mar 5, 2024
1 check passed
@SjurSutterudSagen SjurSutterudSagen deleted the feature/Add-typesafety-to-translation-keys branch March 5, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants