scikit-learn 中文翻译

scikit-learn文档中文翻译:http://lijiancheng0614.github.io/scikit-learn/
scikit-learn是一个基于Python语言的机器学习工具。
源代码在https://github.com/scikit-learn/scikit-learn
目前稳定的版本是0.17,打算一边学习一边翻译文档:http://scikit-learn.org/0.17/index.html

fork scikit-learn

由于scikit-learn在github上公开了源代码,故只需fork就可以进行开发了。
我fork下来在 https://github.com/lijiancheng0614/scikit-learn ,并新建一个branch叫0.17.X-doc-zh,生成的文档放在gh-pages中,因此可以在 http://lijiancheng0614.github.io/scikit-learn/ 看到中文版的文档。

配置中文翻译环境

添加配置到conf.py

locale_dirs = ['locale/']
gettext_compact = False

添加make选项

echo.  gettext   to make PO message catalogs
echo.  html-zh   to make standalone HTML files in Chinese
if "%1" == "gettext" (
    %SPHINXBUILD% -b gettext %ALLSPHINXOPTS% %BUILDDIR%/locale
    if errorlevel 1 exit /b 1
    echo.
    echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
    goto end
)

if "%1" == "html-zh" (
    %SPHINXBUILD% -D language=zh -b html %ALLSPHINXOPTS% %BUILDDIR%/html-zh
    echo.
    echo.Build finished. The HTML pages are in %BUILDDIR%/html-zh.
    goto end
)

修复gen_rst.py的bug

with open(url, 'r') as fid:改为with open(url, 'r', encoding='utf-8') as fid:

修复Sphinx-1.3.5中gettext.py的问题

不知道是不是doc和Sphinx的兼容性问题,我这里需要修改gettext.py来处理传入参数类型不对的问题:

由于source的类型可能为docutils.statemachine.StringList,故把

pofile.write("#: %s\n" % "\n#: ".join(
    "%s:%s" % (safe_relpath(source, self.outdir), line)
    for source, line, _ in positions))

改为

pofile.write("#: %s\n" % "\n#: ".join(
    "%s:%s" % (safe_relpath(source, self.outdir) if isinstance(source, str) else '', line)
    for source, line, _ in positions))

翻译

准备翻译文件

  • 提取文档翻译信息到_build/local/

    make gettext
  • 生成po文件到locale/

    sphinx-intl update -p _build/locale -l zh

翻译po文件

msgstr所在行写入上一行msgid所对应的翻译内容,如

msgid "Hello World!"
msgstr "你好,世界!"

生成html并传到gh-pages

生成html

make html-zh

首次上传

这里把生成的html放在_build/html-zh中,并用git来版本控制,每次再fetch到外面的gh-pages的branch,然后上传到github上。

cd doc\_build\html-zh
git init
cd ..\..\..\
git fetch doc\_build\html-zh
git checkout -b gh-pages FETCH_HEAD
git push -u origin gh-pages

以后更新

只需在_build/html-zh中commit,然后fetch到外面的gh-pages的branch,再上传到github上。

git fetch doc\_build\html-zh :gh-pages
git push -u origin gh-pages

自定义

doc/themes/scikit-learn/layout.html中可以修改Github “fork me” ribbon和google_analytics信息。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值