Hello, I want to have a localised RowLabel for an array field when it is empty, but use one of the fields data when it is present.
Before starting on localisation, I had something like this:
RowLabel: ({ data }) => data.title || 'New item'
I tried picking the locale with the
useLocale
hook, but I believe this is the locale of the content and not the language preference of the user
RowLabel: ({ data }) => {
const locale = useLocale();
return (
data.title ||
i18n.accordionBlock.item.emptyRowLabel[locale]
);
},
You can use the following:
const { i18n } = useTranslation()
const userLanguage = i18n?.language
To get the currently selected language of the user logged into the dashboard
And I would turn this into a component that gets imported into your config file, instead of importing hooks into the config file.
Thanks for that, completely missed it in the docs
I extracted it out to a RowLabelWithFallback (wip name 😅 )
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.