【发布时间】:2021-06-06 04:04:51
【问题描述】:
我正在使用 Typescript 构建 Next.JS 应用程序,并希望访问页面/组件之外的 next-i18next 翻译,以便本地化验证消息,而所有验证引擎都在单独的实用程序类中定义。已经检查了 next-i18next 是否有任何类型的静态访问器,但那里没有运气。有什么建议吗?
【问题讨论】:
标签: next.js next-i18next
我正在使用 Typescript 构建 Next.JS 应用程序,并希望访问页面/组件之外的 next-i18next 翻译,以便本地化验证消息,而所有验证引擎都在单独的实用程序类中定义。已经检查了 next-i18next 是否有任何类型的静态访问器,但那里没有运气。有什么建议吗?
【问题讨论】:
标签: next.js next-i18next
我认为唯一的方法是将i18n 作为参数传递给您的实用程序类。
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);
【讨论】: