Is loading translations per page a good practice / solution ? #684
Replies: 2 comments
-
Hey, thank you for the kind words—glad to hear if
I understand your concern, but on the practical side, I have yet to see an app where providing messages on the server side in an atomic way poses a performance problem. In case we run into such a situation, I think we could enable further splitting of translations by overloading the // i18n.ts
import {getRequestConfig} from 'next-intl/server';
export default getRequestConfig(async ({locale}) => ({
// (proposal)
messages(namespace) {
return namespace.startsWith('auth.')
? (await import(`../messages/auth/${locale}.json`)).default
(await import(`../messages/shared/${locale}.json`)).default
}
})); This API is a bit more involved and potentially the user has to call For the apps I've seen so far, providing all messages in one go on the server side was absolutely fine. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Glad that you answered quicky ⏩ @amannn Also I notice 🤔 my idea is making the lib API more complex which makes me bend for your default behavior if there is no real advantages to this solution. Thanks 🫡 |
Beta Was this translation helpful? Give feedback.
-
Hi !
Thanks for latest version 🚀 of Next Intl, so much easier to use with Next 13+ new RSC !
Usage and documentation is really good, almost all questions I had while refactoring code were anticipated by doc. And 👍🏼 for i18n-ally extension suggestion.
However, while working on a large Next JS marketing website, with 4 locales translations over 40+ static pages and dynamic blog, I was wondering if importing all translations file in
i18n.ts
file is good for performances.To have better translations organisation and avoid git conflicts nightmares between developer working in same translation file, I divided original translation file across multiple files "1 per page".
So I had 2 solutions:
i18n.ts
.As solution 2 is not supported by Next Intl as much as I search in repo, here my question / idea...
Why not load a translation only on the page using it ?
Idea
Here is my solution ⬇️, I would like and advice on it, is it good practice, will it really improve performances on a full static / ISR website / dynamic page ?
Usage example :
RSC example
Client example
⬆️ Wrapped by ⬇️
Questions
use()
hook, did I get usage right by using youruseHook
logic ?Conclusion
I have also create a custom
i18n-ally
configuration regex for VSCode to support hooks that I can share if interested in.Thanks in advance for your advice !
Beta Was this translation helpful? Give feedback.
All reactions