4

I'm building Next.JS application with Typescript and would like to access next-i18next translations outside of page/component, in order to localize validation messages, while all the validation engine is defined in separate utility class. Have checked next-i18next for any kind of static accessors, but no luck there. Any suggestions?

saniokazzz
  • 476
  • 1
  • 6
  • 21

1 Answers1

1

I thought the only way is passing the i18n as a parameter to your utility class.

import { withTranslation, WithTranslation } from 'i18n';
import { checkFunction } from '../utils';

type Props = WithTranslation;

const Page: React.FC<Props> = (props) => {
  const result = checkFunction(props.i18n);
}

export default withTranslation(['common'])(Page);
bcjohn
  • 2,383
  • 12
  • 27
  • 3
    Thank You, I understand that withTranslation could be used, but I would like to have more solid solution, as in this case it's easy to forget including one of translation namespaces if there are few. I would like to find solution without passing translation function. – saniokazzz Mar 09 '21 at 08:27