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

Typesafe i18next keys #1029

Closed
JGreenlee opened this issue Nov 9, 2023 · 1 comment
Closed

Typesafe i18next keys #1029

JGreenlee opened this issue Nov 9, 2023 · 1 comment

Comments

@JGreenlee
Copy link

After we have removed Angular, we should explore the possibility of having the t function of i18next be typed according to en.json. https://www.i18next.com/overview/typescript
This way, we could ensure we never try to access a key that doesn't exist. It would also work with IntelliSense to give us autocompletion for existing keys.

We would need to:

  • upgrade to latest i18next and react-i18next
  • enable strictNullChecks in our tsconfig.json (a good idea anyway and more achievable now than several months ago)
  • add a file called types/i18next.d.ts:
import enJson from '../../i18n/en.json';

declare module 'i18next' {
  interface CustomTypeOptions {
    resources: { translation: typeof enJson };
  }
}
JGreenlee added a commit to JGreenlee/e-mission-phone that referenced this issue Nov 22, 2023
JGreenlee added a commit to JGreenlee/e-mission-phone that referenced this issue Jan 25, 2024
@JGreenlee
Copy link
Author

This was implemented and is on master now

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

No branches or pull requests

1 participant