Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Localised RowLabel

default discord avatar
_sadajo_2 years ago
2

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]
                    );
                  },
  • discord user avatar
    jarrod_not_jared
    2 years 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
    _sadajo_2 years ago

    Thanks for that, completely missed it in the docs



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

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.