-
Notifications
You must be signed in to change notification settings - Fork 6
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
Lazy load translations #781
Conversation
The vite plugin checks configuration before checking if release creation is actually needed or not - we currently don't use this (though we likely will for #557) - the plugin is only used to manage tree shaking options. In due time we will configure this to (our own) Sentry instance.
switch (locale) { | ||
case 'nl': | ||
return messagesNL; | ||
default: | ||
return messagesEN; | ||
case 'nl': { | ||
localeToLoad = 'nl'; | ||
break; | ||
} | ||
case 'en': | ||
// in case (accidentally) a locale is set that we don't ship translations for yet, | ||
// fall back to English. | ||
// eslint-disable-next-line no-fallthrough | ||
default: { | ||
localeToLoad = 'en'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may look a bit over-engineered, but our backend does support things like nl_NL
and nl_BE
locales and doing things this way makes it future proof for languages we may add in the future that have regional variants.
Bundle ReportChanges will increase total bundle size by 12.05kB (0.13%) ⬆️. This is within the configured threshold ✅ Detailed changes
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #781 +/- ##
==========================================
- Coverage 83.34% 83.32% -0.02%
==========================================
Files 239 239
Lines 4755 4750 -5
Branches 1267 1275 +8
==========================================
- Hits 3963 3958 -5
Misses 757 757
Partials 35 35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
This should make the main bundle smaller and ensure we only fetch the translations that will actually be used.
d26ef59
to
4f9cb8a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, looks good to me!
I was slightly concerned that await import('./i18n/compiled/${localeToLoad}.json')
in the i18n.jsx
would load multiple times, but it doesn't. It seems to load only once, even after switching from NL to EN and back to NL
Indeed - browsers/bundlers are smart enough to cache that, luckily! |
Partly closes #76
Verified by creating a static build and using it in our backend, switching between languages works as expected 🎉