0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

🗑【Sphinx】autodocの索引ページで、モジュールを「モ」ではなく「ま」の項目に表示する

Last updated at Posted at 2021-09-22

後日談

以下の記事で手動で行っていた内容ですが、Sphinx拡張側で辞書をを作って対応しました。「モジュール」であれば「も」もしくは「ま」の項目に表示されます。初期設定では「ま」です。


sphinx.ext.autodoc を使った時、索引では「モジュール」は「モ」の項目に表示されます。

これを次のように「ま」の項目に表示する方法を消化します。

2021-09-22 13.21.39  96e895f333b5.png

2021-09-22 13.22.02  c1d046727d15.png

🧪セットアップ

①sphinx_kana_termをセットする

次のページからSphinx拡張のコードをコピペして準備します。

  • ファイル名は sphinx_kana_term.py とします。
    • sphinx_kana_term/__init__.py としても動作します。

pip install ... じゃなくてすいません…

②sphinxのメッセージカタログを編集する

ファイルは他の場所でもOKです。利用環境の都合に合わせてください。

mkdir /usr/local/share/locale/ja/ja/LC_MESSAGES
cd /usr/local/share/locale/ja/ja/LC_MESSAGES
cp /usr/local/lib/python3.8/site-packages/sphinx/locale/ja/LC_MESSAGES/sphinx.po .
vi sphinx.po

次のように書き換えてください。

…
# : sphinx/domains/javascript.py:331 sphinx/domains/python.py:58
# : sphinx/domains/python.py:1120
msgid "module"
msgstr "まも|モジュール"
…
  • モジュール は二つあるので間違わないようにしてください。
  • msgid "module" の単数形の方です。

③confi.py

import os
import sys
sys.path.insert(0, os.path.abspath('_ext'))
  • 私の環境では複数のSphinxプロジェクト共通のディレクティブを用意しているため、パスが異なります。
extensions = [
    'sphinx_kana_term',
    'sphinx.ext.autodoc',
    'sphinx.ext.todo',
]

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?