Replies: 1 comment
-
Thanks for the question! I haven't found a compelling argument for arrays yet, to be honest. However they come with limitations:
It seems to me like the use cases for arrays can already be handled well with the current feature set, while avoiding limitations to some degree. I've also considered to recommend against programmatic invocations in general, also something like this: t(`${key}.title`) The benefit is really to have improved static analysis. So the example from the docs would become either: const stats = [{
title: t('yearsOfService.title'),
description: t('yearsOfService.title')
}, {
title: t('happyClients.title'),
description: t('happyClients.title')
}] … or: <ul>
<CompanyStatsItem title={t('yearsOfService.title')} description={t('yearsOfService.title')} />
<CompanyStatsItem title={t('happyClients.title')} description={t('happyClients.title')} />
</ul> In both cases, it's now also easy to include exceptions, e.g. providing different variables: <ul>
<CompanyStatsItem title={t('yearsOfService.title', {numYears: 12})} description={t('yearsOfService.title')} />
<CompanyStatsItem title={t('happyClients.title', {numClient: 3000})} description={t('happyClients.title')} />
</ul> Also, they are fully statically analyzable. It seems to me like arrays would introduce complexity for Do you have a use case that would significantly benefit if arrays were allowed in messages? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm moving this question here since, the original issue (#1878) got closed automatically as stale.
Link to page
https://next-intl.dev/docs/usage/messages#arrays-of-messages
Describe the problem
I know this has been discussed before, but most related issues seem to reference older conversations I can't track down. Could someone summarize the key points or link to the relevant threads? Should we add the produced summary to the documentation itself?
Beta Was this translation helpful? Give feedback.
All reactions