amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.58k stars 236 forks source link

Ability to iterate of a normal JSON array #1528

Closed sshmaxime closed 5 days ago

sshmaxime commented 1 week ago

Is your feature request related to a problem? Please describe.

In the docs it is mentioned that it is recommended to have an object to represent an array: https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages

Ideally, I want to iterate over an array until the end of it without having to do this:

const messages = useMessages();
const keys = Object.keys(messages.homepage);

Is this possible ? Couldn't find anything in the doc

Describe the solution you'd like

Be able to iterate of an array looking like that:

{
   "categories":[
      {
         "title":"Y"
      },
      {
         "title":"X"
      },
      {
         "title":"Z"
      }
   ]
}

Describe alternatives you've considered

None.

amannn commented 5 days ago

Nope, currently only the approach that is outlined in the docs is supported. This has already been discussed various times in GitHub issues and discussions, please also see related conversations.