Last active
June 2, 2025 11:07
-
-
Save terasakisatoshi/f602e318a5804f1b6fdd3ed60b7259b8 to your computer and use it in GitHub Desktop.
個人でJuliaのdocstring/マニュアルを日本語翻訳にする方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#= | |
概要: docstring を日本語(:ja) に翻訳する | |
使い方: 事前にOpenAI API Key を取得してその値を環境変数 OPENAI_API_KEY をセットしておくこと | |
このスクリプトを cache.jl とすれば下記のように実行する | |
julia -t 64 cache.jl | |
下記のディレクトリに翻訳結果が溜まっていく. | |
機械翻訳に不満があれば対応する ja.md を修正すれば良い. | |
~/.julia/scratchspaces/d404e13b-1f8e-41a5-a26a-0b758a0c6c97/translation | |
=# | |
using DocstringTranslation | |
@switchlang! :ja | |
using Pkg; Pkg.activate(temp=true) | |
using Pkg; Pkg.add("ProgressMeter") | |
using Pkg; Pkg.add("DifferentialEquations") | |
using Pkg; Pkg.add("Plots") | |
using Pkg; Pkg.add("Pluto") | |
using Pkg; Pkg.add("PlutoUI") | |
using Pkg; Pkg.add("SpecialFunctions") | |
using Pkg; Pkg.add("Distributions") | |
using ProgressMeter: ProgressMeter | |
# 標準ライブラリの docstring を翻訳する | |
for (i, _stdlib) in enumerate(vcat(["Base", "Core"], readdir(Sys.STDLIB))) | |
stdlib = Symbol(_stdlib) | |
@info "Translating docstrings in $(stdlib)" | |
@eval begin | |
import $(stdlib) | |
p = ProgressMeter.Progress(length(collect(names($(stdlib))))) | |
Base.Threads.@threads for n in names($(stdlib)) | |
(Base.Docs.doc)((Base.Docs.Binding)($(stdlib), n)) | |
ProgressMeter.next!(p) | |
end | |
end | |
end | |
packages = [ | |
:DifferentialEquations, | |
:Plots, | |
:Pluto, | |
:PlutoUI, | |
:SpecialFunctions, | |
:Distributions | |
] | |
# サードパーティライブラリの docstring を翻訳する | |
for pkg in packages | |
@info "Translating docstrings in $(pkg)" | |
@eval begin | |
import $(pkg) | |
p = ProgressMeter.Progress(length(collect(names($(pkg))))) | |
Base.Threads.@threads for n in names($(pkg)) | |
(Base.Docs.doc)((Base.Docs.Binding)($(pkg), n)) | |
ProgressMeter.next!(p) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment