Localised RowLabel

default discord avatar
5 months ago

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


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 ||
  • default discord avatar
    5 months ago

    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.

  • default discord avatar
    5 months ago

    Thanks for that, completely missed it in the docs

    I extracted it out to a RowLabelWithFallback (wip name 😅 )

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.