docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

i18n translate a file _category_.json error

Open ygs-code opened this issue 1 month ago • 0 comments

Have you read the Contributing Guidelines on issues?

Prerequisites

  • [x] I'm using the latest version of Docusaurus.
  • [x] I have tried the npm run clear or yarn clear command.
  • [x] I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • [x] I have tried creating a repro with https://new.docusaurus.io.
  • [x] I have read the console error message carefully (if applicable).

Description

I used i18n, but it didn't work when I was translating the content of the category.json file. The details are as follows. My i18n configuration

  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'zh-CN'],
    // locales: ['en', 'fr', 'es'],
    localeConfigs: {
      en: {
        label: 'English',
        direction: 'ltr',
        htmlLang: 'en-GB',
      },
      "zh-CN": {
        label: '中文',
        direction: 'ltr',
      },
    },
  },


 themeConfig:
    /** @type {import('@docusaurus/preset-classic').ThemeConfig} */
    ({
      image: 'img/docusaurus-social-card.jpg',
      navbar: {
        title: 'Vcity.ai',
        logo: {
          alt: 'Vcity.ai Logo',
          src: 'img/logo.svg',
        },
        items: [
          {
            type: 'localeDropdown',
            position: 'right',
          },
        ],
      },
      footer: {
        style: 'dark',
      
      },
      prism: {
        theme: prismThemes.github,
        darkTheme: prismThemes.dracula,
      },
    }),
 presets: [
    [
      'classic',
      /** @type {import('@docusaurus/preset-classic').Options} */
      ({
        docs: {
          routeBasePath: '/',
          sidebarPath: './sidebars.js',
          remarkPlugins: [remarkMath],
          rehypePlugins: [
            rehypeKatex,
          ],
        },
        theme: {
          customCss: './src/css/custom.css',
        },
      }),
    ],
  ],

My document directory and files

vcity-ai-doc/docs/nodeoper/category.json

En locale

{
  "label": "Node Operators document",
  "position": 3,
  "key": "Node-Operators-document",
  "link": {
    "type": "generated-index",
    "description": "This is the Node Operators document, which includes documentation for both Linux and Windows platforms."
  }
}


zh-CN locale

vcity-ai-doc/i18n/zh-CN/docusaurus-plugin-content-docs/current/nodeoper/category.json

{
  "label": "节点运营者文档",
  "position": 3,
   "key": "Node-Operators-document",
  "link": {
    "type": "generated-index",
    "description": "这是节点运营者文档,其中包含了适用于 Linux 和 Windows 平台的文档内容。"
  }
}

When I run the npm run start -- --locale zh-CN command to start , However, the category.json file has not been translated into Chinese.

Image

The GitHub address of my project: https://github.com/ygs-code/vcity-ai-doc.git

I hope you can help me solve this problem. Thank you.

Reproducible demo

No response

Steps to reproduce

I reorganized the node_modules and updated the Docusaurus dependencies.

Expected behavior

I hope that the category.json file can be translated into Chinese according to my settings.

Actual behavior

I used i18n, but it didn't work when I was translating the content of the category.json file. The details are as follows. My i18n configuration

  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'zh-CN'],
    // locales: ['en', 'fr', 'es'],
    localeConfigs: {
      en: {
        label: 'English',
        direction: 'ltr',
        htmlLang: 'en-GB',
      },
      "zh-CN": {
        label: '中文',
        direction: 'ltr',
      },
    },
  },


 themeConfig:
    /** @type {import('@docusaurus/preset-classic').ThemeConfig} */
    ({
      image: 'img/docusaurus-social-card.jpg',
      navbar: {
        title: 'Vcity.ai',
        logo: {
          alt: 'Vcity.ai Logo',
          src: 'img/logo.svg',
        },
        items: [
          {
            type: 'localeDropdown',
            position: 'right',
          },
        ],
      },
      footer: {
        style: 'dark',
      
      },
      prism: {
        theme: prismThemes.github,
        darkTheme: prismThemes.dracula,
      },
    }),
 presets: [
    [
      'classic',
      /** @type {import('@docusaurus/preset-classic').Options} */
      ({
        docs: {
          routeBasePath: '/',
          sidebarPath: './sidebars.js',
          remarkPlugins: [remarkMath],
          rehypePlugins: [
            rehypeKatex,
          ],
        },
        theme: {
          customCss: './src/css/custom.css',
        },
      }),
    ],
  ],

My document directory and files

vcity-ai-doc/docs/nodeoper/category.json

En locale

{
  "label": "Node Operators document",
  "position": 3,
  "key": "Node-Operators-document",
  "link": {
    "type": "generated-index",
    "description": "This is the Node Operators document, which includes documentation for both Linux and Windows platforms."
  }
}


zh-CN locale

vcity-ai-doc/i18n/zh-CN/docusaurus-plugin-content-docs/current/nodeoper/category.json

{
  "label": "节点运营者文档",
  "position": 3,
   "key": "Node-Operators-document",
  "link": {
    "type": "generated-index",
    "description": "这是节点运营者文档,其中包含了适用于 Linux 和 Windows 平台的文档内容。"
  }
}

When I run the npm run start -- --locale zh-CN command to start , However, the category.json file has not been translated into Chinese.

Image

Your environment

  • Public source code: https://github.com/ygs-code/vcity-ai-doc.git
  • Public site URL:https://docusaurus.io/
  • Docusaurus version used: 3.9.2
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): v24.11.1
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): mac os 15

Self-service

  • [ ] I'd be willing to fix this bug myself.

ygs-code avatar Dec 04 '25 03:12 ygs-code