0

I am trying to add payloadcms/translations from payload to my cms written with payload cms and next,

    "@payloadcms/translations": "^3.42.0",
    "@payloadcms/ui": "^v3.42.0",

I have my fields like this :

{
      name: 'color',
      type: 'text',
      label: translate('machines:color'),
    },
    {
      // ui fields do not accept functions as labels
      name: 'Status',
      type: 'ui',
      label: translate('customMachines:color'),
      admin: {
        components: {
          Cell: '/appViews/views/Status.tsx#Status',
        },
      },
    },

the error I am getting is :

Type '({ t: defaultT }: { t: TFunction; }) => string' is not assignable to type 'string | Record<string, string> | undefined'.ts(2322)

seems it can not handle my translate fn that get the string value from the custom translations object. Seems the documentation does not specify this scenario. https://payloadcms.com/docs/configuration/i18n and I am not sure how to handle it at the moment.

is there a way to add translations to the UI fields on payload cms?

1
  • I think translate(...) returns a function (not a string), and Payload CMS field configs expect label to be string or Record<string, string> (for i18n), not a function. Commented Jun 10 at 7:34

1 Answer 1

1

translate() function at config time, use a static i18n object for label

label: {
  en: 'Color',
  de: 'Farbe',
  fr: 'Couleur',
}
Sign up to request clarification or add additional context in comments.

2 Comments

thanks a lot, I found it on the docs, but did not like the idea of having spread around translations, but happy to do it like this for now since seems there is no other solution at the moment as far as I managed to research
@JGarnie no problem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.