0

I have an array of objects called "Options", that I use as a prop to a dropdown/select Material-UI component. I want to use the next-i18next library on the labels. I already implemented with success through all the next app just like the documentation explains. I tried using the {t('key')} and it doesn't allow.

import { useTranslation } from 'next-i18next'
const UsersPage = () => {
   const { t } = useTranslation('user');
   const Options = [
      { value: 'fullName', label: 'Nome' },
      { value: 'cpf', label: 'CPF' },
      { value: 'id', label: 'Padrão' },
   ]
   ...rest of the component
}

export const getStaticProps = async ({ locale }) => ({
  props: {
    ...await serverSideTranslations(locale, ['user', 'home']),
  },
})

export default UsersPage;
Raissa Correia
  • 169
  • 4
  • 18

1 Answers1

0

The msefer answer is right:

`${t("key")}`

inside JSON or string building in props like

const since = `${t('since')}`;
const until = `${t('until')}`;
    ...

 <ListItemText
   primary={value.name}
   secondary={since + value.beginDate + until + value.endDate}
  />
Raissa Correia
  • 169
  • 4
  • 18