翻译
大约 1 分钟
翻译
翻译现有文章
注意
提示
对于还未完成翻译的文章,你可以添加 tag untranslated
用作标识
- 将根目录下的原文复制到
/zh/
下 - 进行翻译(切勿直接机翻)
翻译规范
为保证文档格式的一致性,下面列出了一些要求:
不要翻译文件名、分类和标签
同时请参考并遵循以下规范:
翻译为新语言
在配置文件中添加新的 locale:
复制一份
.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", }, ]);
import { navbar } from "vuepress-theme-hope"; export const navbarZh = navbar([ { text: "指南", link: "/zh/guide/", icon: "creative", }, { text: "功能", icon: "object", prefix: "/zh/features/", children: [ { text: "ES 标准", link: "es-standard/README.md", icon: "javascript", }, { text: "ES 提案", link: "es-proposal/README.md", icon: "proposal", }, { text: "Web 标准", link: "web-standard/README.md", icon: "link", }, { text: "工具函数", link: "helper/README.md", icon: "function", }, ], }, { text: "贡献", prefix: "/zh/dev/", icon: "tree", children: [ { text: "指南", icon: "question", link: "README.md", }, { text: "Polyfill", icon: "code", link: "polyfill.md", }, { text: "兼容性数据", icon: "form", link: "compat.md", }, { text: "文档", icon: "article", link: "docs/README.md", }, ], }, { text: "项目", prefix: "/zh/", icon: "more", children: [ { text: "关于", icon: "info", link: "project/README.md", }, { text: "变更日志", icon: "time", link: "project/changelog.md", }, { text: "安全策略", icon: "safe", link: "project/security.md", }, { text: "路线图", icon: "state", link: "project/roadmap.md", }, { text: "博客", link: "category/blog", icon: "blog", }, ], }, { text: "兼容性", link: "/zh/compat.md", icon: "form", }, { text: "赞助", link: "/zh/donate.md", icon: "like", }, ]);
复制一份
.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", }, ], });
import { sidebar } from "vuepress-theme-hope"; export const sidebarZh = sidebar({ "/zh/": [ { text: "指南", icon: "creative", prefix: "guide/", children: "structure", collapsible: true, }, { text: "功能", icon: "object", prefix: "features/", children: [ { text: "概述", icon: "info", link: "README.md", }, { text: "缺失的 Polyfill", icon: "notice", link: "missing-polyfills.md", }, { text: "ES 标准", icon: "javascript", prefix: "es-standard/", children: "structure", collapsible: true, }, { text: "ES 提案", icon: "proposal", prefix: "es-proposal/", children: "structure", collapsible: true, }, { text: "Web 标准", icon: "link", prefix: "web-standard/", children: "structure", collapsible: true, }, { text: "工具函数", icon: "function", prefix: "helper/", children: "structure", collapsible: true, }, ], collapsible: true, }, { text: "贡献", icon: "tree", prefix: "dev/", children: [ { text: "如何贡献", icon: "question", link: "README.md", }, { text: "添加新的 polyfill", icon: "code", link: "polyfill.md", }, { text: "测试", icon: "check", link: "testing.md", }, { text: "更新core-js-compat", icon: "form", link: "compat.md", }, { text: "撰写文档", icon: "form", prefix: "docs/", children: [ { text: "撰写文档", icon: "form", link: "README.md", }, { text: "为 polyfill 创建文档", icon: "code", link: "polyfill.md", }, { text: "翻译", icon: "language", link: "translate.md", }, ], collapsible: true, }, ], collapsible: true, }, { text: "项目", icon: "more", prefix: "project/", children: "structure", collapsible: true, }, { text: "赞助", icon: "like", link: "donate.md", }, ], });
在
.vuepress/config.ts
的locales
一栏新增一项:示例
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 ); }, });
在
.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, } );
翻译文档正文