我正在使用 Yarn berry 工作区 (3.6x) 配置 monorepo。 我整理的文件夹结构如下:
pakages
└──
| i18n
| └── locales
| ├── en
| | └── common.json
| └── de
| └── common.json
sevices
└──
└── next-js-project
考虑到可扩展性,我想仅将语言包(JSON 文件)放在 i18n 文件夹中,并配置要在每个项目内设置的其他 18n 配置设置。
但是,我不擅长导入json文件。
有什么办法可以做到吗?
// next-js-project/next-i18next.config.js
const path = require("path");
module.exports = {
i18n: {
locales: ["en", "ko"],
defaultLocale: "en",
localeDetection: false,
defaultNS: "common",
localePath: path.resolve("@mymonorepo/i18n/locales"),
debug: true
}
};
//index.tsx
export const getStaticProps = async ({ locale }) => {
console.log("locale", locale);
return {
props: {
...(await serverSideTranslations(locale, ["common"], nextI18NextConfig))
}
};
};
...
服务器错误 错误:在 D:\User\My-monorepo\services 中找不到默认命名空间 ext-js-project@po\i18n\public\locales