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.

i18n.language is undefined in custom component

default discord avatar
_sadajo_last year

I am running 1.11.6 and have a description component setup like this:



description: ({ value }) => (
          <CharacterCounterDescription
            value={value}
            min={min}
            max={max}
            recommendedMin={recommendedMin}
            recommendedMax={recommendedMax}
          />
        ),


Within

CharacterCounterDescription

, I am calling

useTranslation

from

react-i18next

    const { i18n } = useTranslation();

    console.log(i18n.language);


However, the console.log always returns

undefined

.



My payload config has the following in it



 i18n: {
    fallbackLng: 'en',
    debug: false,
    resources: {
      en: {
        custom: {
          ...en,
        },
      },
    },
  },


I've seen a warning in the console about needing to call

initReactI18next

-- is this not called by Payload?



Here's the error



react-i18next:: You will need to pass in an i18next instance by using initReactI18next 
FieldDescription@http://localhost:8080/admin/main.js:99101:48


I don't think I'm doing anything different than the docs describe here

https://payloadcms.com/docs/admin/components#getting-the-current-language



Perhaps I'm missing something though



My version of react-i18next was 13.0.1, once I changed it to be the same as what is in Payload's package.json, it works.



Would it make sense for Payload to define it as a peerDependency?

    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.