跳至主要內容

翻译

大约 1 分钟

翻译

翻译现有文章

注意

提示

对于还未完成翻译的文章,你可以添加 tag untranslated 用作标识

  1. 将根目录下的原文复制到/zh/
  2. 进行翻译(切勿直接机翻)

翻译规范

为保证文档格式的一致性,下面列出了一些要求:

翻译为新语言

  1. 在配置文件中添加新的 locale:

    1. 复制一份 .vuepress/navbar/en.ts 并命名为 .vuepress/navbar/lang.ts,给所有的 link 加上路径前缀(/lang),然后翻译 text 的内容:

      示例
      import { navbar } from "vuepress-theme-hope";
      
      export const navbarEn = navbar([
        {
          text: "Guide",
          link: "/guide/",
          icon: "creative",
        },
        {
          text: "Features",
          icon: "object",
          prefix: "/features/",
          children: [
            {
              text: "ES Standards",
              link: "es-standard/README.md",
              icon: "javascript",
            },
            {
              text: "ES Proposals",
              link: "es-proposal/README.md",
              icon: "proposal",
            },
            {
              text: "Web Standards",
              link: "web-standard/README.md",
              icon: "link",
            },
            {
              text: "Helpers",
              link: "helper/README.md",
              icon: "function",
            },
          ],
        },
        {
          text: "Contribution",
          prefix: "/dev/",
          icon: "tree",
          children: [
            {
              text: "Guide",
              icon: "question",
              link: "README.md",
            },
            {
              text: "Polyfill",
              icon: "code",
              link: "polyfill.md",
            },
            {
              text: "Compat Data",
              icon: "form",
              link: "compat.md",
            },
            {
              text: "Documents",
              icon: "article",
              link: "docs/README.md",
            },
          ],
        },
        {
          text: "Project",
          prefix: "/",
          icon: "more",
          children: [
            {
              text: "About",
              icon: "info",
              link: "project/README.md",
            },
            {
              text: "Changelog",
              icon: "time",
              link: "project/changelog.md",
            },
            {
              text: "Security",
              icon: "safe",
              link: "project/security.md",
            },
            {
              text: "Roadmap",
              icon: "state",
              link: "project/roadmap.md",
            },
            {
              text: "Blog",
              icon: "blog",
              link: "category/blog/",
            },
          ],
        },
        {
          text: "Compatibility",
          icon: "form",
          link: "/compat.md",
        },
        {
          text: "Sponsor",
          icon: "like",
          link: "/donate.md",
        },
      ]);
      
    2. 复制一份 .vuepress/sidebar/en.ts 并命名为 .vuepress/sidebar/lang.ts,将第四行的 "/" 替换为 "/lang",然后翻译 text 的内容:

      示例
      import { sidebar } from "vuepress-theme-hope";
      
      export const sidebarEn = sidebar({
        "/": [
          {
            text: "Guide",
            icon: "creative",
            prefix: "guide/",
            children: "structure",
            collapsible: true,
          },
          {
            text: "Features",
            icon: "object",
            prefix: "features/",
            children: [
              {
                text: "Overview",
                icon: "info",
                link: "README.md",
              },
              {
                text: "Missing Polyfills",
                icon: "notice",
                link: "missing-polyfills.md",
              },
              {
                text: "ES Standards",
                icon: "javascript",
                prefix: "es-standard/",
                children: "structure",
                collapsible: true,
              },
              {
                text: "ES Proposals",
                icon: "proposal",
                prefix: "es-proposal/",
                children: "structure",
                collapsible: true,
              },
              {
                text: "Web Standards",
                icon: "link",
                prefix: "web-standard/",
                children: "structure",
                collapsible: true,
              },
              {
                text: "Helpers",
                icon: "function",
                prefix: "helper/",
                children: "structure",
                collapsible: true,
              },
            ],
            collapsible: true,
          },
          {
            text: "Contribution",
            icon: "tree",
            prefix: "dev/",
            children: [
              {
                text: "How to contribute",
                icon: "question",
                link: "README.md",
              },
              {
                text: "Add a new polyfill",
                icon: "code",
                link: "polyfill.md",
              },
              {
                text: "Testing",
                icon: "check",
                link: "testing.md",
              },
              {
                text: "Update core-js-compat",
                icon: "form",
                link: "compat.md",
              },
              {
                text: "Writing documents",
                icon: "form",
                prefix: "docs/",
                children: [
                  {
                    text: "Writing documents",
                    icon: "form",
                    link: "README.md",
                  },
                  {
                    text: "Create doc for polyfill",
                    icon: "code",
                    link: "polyfill.md",
                  },
                  {
                    text: "Translate",
                    icon: "language",
                    link: "translate.md",
                  },
                ],
                collapsible: true,
              },
            ],
            collapsible: true,
          },
          {
            text: "Project",
            icon: "more",
            prefix: "project/",
            children: "structure",
            collapsible: true,
          },
          {
            text: "Sponsor",
            icon: "like",
            link: "donate.md",
          },
        ],
      });
      
    3. .vuepress/config.tslocales 一栏新增一项:

      示例
      import { defineUserConfig } from "vuepress";
      import { getDirname, path } from "@vuepress/utils";
      import i18nPlugin from "vuepress-plugin-i18n";
      import { redirectPlugin } from "vuepress-plugin-redirect";
      import searchPlugin from "@vuepress/plugin-search";
      import shikiPlugin from "@vuepress/plugin-shiki";
      import theme from "./theme.js";
      import { version } from "../../packages/core-js/package.json";
      
      const __dirname = getDirname(import.meta.url);
      export default defineUserConfig({
        lang: "en-US",
        description: "Modular standard library for JavaScript",
        locales: {
          "/": {
            lang: "en-US",
            title: "Core-JS Document",
            description: "Modular standard library for JavaScript",
          },
          "/zh/": {
            lang: "zh-CN",
            title: "Core-JS 文档",
            description: "模块化 JavaScript 标准库",
          },
        },
        theme,
        alias: {
          "@compat-tests": () =>
            path.resolve(__dirname, "..", "..", "tests", "compat", "tests.js"),
        },
        markdown: {
          importCode: {
            handleImportPath: (str) =>
              str.replace(/^@docs-root/, path.resolve(__dirname, "..")),
          },
        },
        plugins: [
          i18nPlugin({
            translationGuide: "/dev/docs/translate.html",
            updatedTime: "file",
          }),
          searchPlugin(),
          shikiPlugin({
            theme: "one-dark-pro",
          }),
          redirectPlugin({
            localeConfig: {
              "/": ["en-US", "en-UK", "en"],
              "/zh/": ["zh-CN", "zh-TW", "zh"],
            },
            switchLocale: "modal",
          }),
        ],
        extendsPage: (page) => {
          if (page.sfcBlocks.template?.contentStripped)
            page.sfcBlocks.template.contentStripped =
              page.sfcBlocks.template.contentStripped.replaceAll(
                "3.31.1",
                version
              );
        },
      });
      














       
       
       













































    4. .vuepress/theme.ts导入刚才创建的 navbar 和 sidebar,并将它们添加到主题设置的 locales 一栏:

      示例
      import { hopeTheme } from "vuepress-theme-hope";
      import { navbarEn, navbarZh } from "./navbar/index.js";
      import { sidebarEn, sidebarZh } from "./sidebar/index.js";
      
      export default hopeTheme(
        {
          favicon: "logo.png",
          repo: "https://github.com/zloirock/core-js",
          docsBranch: "master",
          docsDir: "docs",
          iconAssets: "iconfont",
          locales: {
            "/": {
              navbar: navbarEn,
              sidebar: sidebarEn,
              copyright: `© 2014-${new Date().getFullYear()} Core-JS contributors`,
            },
            "/zh/": {
              navbar: navbarZh,
              sidebar: sidebarZh,
              copyright: `© 2014-${new Date().getFullYear()} Core-JS 贡献者`,
            },
          },
          displayFooter: true,
          plugins: {
            autoCatalog: {
              locales: {
                "/": { title: "Index" },
                "/zh/": { title: "索引" },
              },
            },
            blog: true,
            mdEnhance: {
              attrs: true,
              tabs: true,
              imgLazyload: true,
              include: true,
              tasklist: true,
              codetabs: true,
            },
            prismjs: false,
          },
        },
        {
          custom: true,
        }
      );
      

       
       










       
       
       
       






























  2. 翻译文档正文