Reputation: 486
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?
Upvotes: 4
Views: 1782
Reputation: 2523
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);
Upvotes: 1