跳转至

贡献指南

欢迎所有对 ormar 的贡献!

问题

为了让我们尽可能简单地为您提供帮助,请包括以下内容:

  • 操作系统
  • Python版本
  • Ormar版本
  • 数据库后端(mysql、sqlite 或 postgresql)

请尝试始终包含上述内容,除非您无法安装 ormar 或知道它与您的问题或功能请求无关。

请求请求

开始并创建拉取请求应该非常简单。

!!!注意 除非您的更改是微不足道的(拼写错误、文档调整等),否则请在创建拉取请求之前创建一个问题来讨论更改。

为了使贡献尽可能简单和快速,您需要在本地运行测试和 linting。

您需要安装 python 3.6.2、3.7 或 3.8、poetry 和 git。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 1. clone your fork and cd into the repo directory
git clone git@github.com:<your username>/ormar.git
cd ormar

# 2. Install ormar, dependencies and test dependencies
poetry install -E dev

# 3. Checkout a new branch and make your changes
git checkout -b my-new-feature-branch
# make your changes...

# 4. Formatting and linting
# ormar uses black for formatting, flake8 for linting and mypy for type hints check
# run all of the following as all those calls will be run on travis after every push
black ormar tests
flake8 ormar
mypy ormar tests

# 5. Run tests
# on localhost all tests are run against sglite backend
# rest of the backends will be checked after push
pytest -svv --cov=ormar --cov=tests --cov-fail-under=100 --cov-report=term-missing

# 6. Build documentation
mkdocs build
# if you have changed the documentation make sure it builds successfully
# you can also use `mkdocs serve` to serve the documentation at localhost:8000

# ... commit, push, and create your pull request

!!!tip 有关 ormar 如何以及为何如此工作的更多信息,请参阅 API 文档

文档多语言翻译

ormar 文档使用 mkdocs-static-i18n 插件实现多语言支持,源语言为中文(docs/zh/),支持 9 种目标语言:en、ru、hi、id、de、nl、ko、ja、fr。

翻译脚本

翻译脚本位于 scripts/translate-docs.mjs,使用腾讯 Transmart 和火山引擎两个免费翻译 API,自动将 docs/zh/ 下的 Markdown 文件翻译到各目标语言目录。

脚本会智能保护 Markdown 语法(代码块、mkdocstrings ::: 引用、admonition 标记、内联代码、链接等),仅翻译自然语言文本。

前置依赖

  • Node.js 18+(需支持原生 fetch)
  • 无需安装额外 npm 包,脚本仅使用 Node.js 标准库

常用命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# 翻译所有语言(增量模式,跳过已存在的目标文件)
node scripts/translate-docs.mjs

# 仅翻译指定语言
node scripts/translate-docs.mjs --locale=en

# 强制重新翻译所有文件(覆盖已有翻译)
node scripts/translate-docs.mjs --force

# 预览将要翻译的文件列表(不实际翻译)
node scripts/translate-docs.mjs --dry-run

# 翻译单个文件到指定语言(输出到 stdout)
node scripts/translate-docs.mjs --file=index.md --locale=en

# 提高并发数(默认 2,适合网络稳定时加速)
TRANSLATION_CONCURRENCY=4 node scripts/translate-docs.mjs

工作流程

  1. 修改 docs/zh/ 下的中文源文件
  2. 运行 node scripts/translate-docs.mjs(增量模式仅翻译新增/修改的文件)
  3. 如果中文内容有重大修改,使用 --force 重新翻译全部文件
  4. 运行 mkdocs build 验证构建结果

翻译引擎路由

目标语言 引擎 原因
en、ru、de、fr 腾讯 Transmart 支持批次翻译(每批 25 条)
hi、id、nl 火山引擎 腾讯不支持这些语言
ja、ko 火山引擎 腾讯翻译会注入字典注释

注意事项

  • 翻译脚本是增量式的:已存在的目标文件会被跳过,除非使用 --force
  • fallback_to_default: true 配置确保目标语言缺少文件时自动回退到中文
  • 如需修改某语言的翻译,可直接编辑 docs/{locale}/ 下的文件,不会被脚本覆盖(除非 --force)