如何在 monorepo 结构的包内获取 i18n JSON 文件?

问题描述 投票:0回答:0

我正在使用 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

frontend internationalization monorepo yarn-workspaces yarn-berry
© www.soinside.com 2019 - 2024. All rights reserved.