My message/en.json looks like this
{
"items": [{
"name: "item 1",
"price: "100",
}, {
"name: "item 2",
"price: "200",
}]
}
My page.tsx
import { useTranslations } from 'next-intl';
export default function ProductSection() {
const t = useTranslations() as any;
return <>{t('items[0].price')}</>;
}
Also tried
import { useTranslations } from 'next-intl';
export default function ProductSection() {
const t = useTranslations('items') as any;
return <>{t('[0].price')}</>;
}
I tried above method but get the error message:
IntlError: MISSING_MESSAGE: Could not resolve `items[0].price` in messages for locale `en`.
There is a method on the Internet to map the array object and then loop, but it is not what I want. I don’t need to loop for the time being, I just need to get the item I need.