Let’s read Julia documentation in your preferred language

SatoshiTerasaki@AtelierArith

https://atelierarith.github.io/AtelierArith_JuliaCon2025_talk/slide/slide.html#/title-slide

Overview

  • Background and Challenges
  • Introduction to DocstringTranslation.jl
  • Multilingual translation of Julia documentation
  • Running demonstration (if possible)

Background and Challenges

  • Julia allows us to write code with high-level operations without losing execution performance (solving two-language problem)
  • I want more people to use Julia

Background and Challenges

When you want to learn something about Julia, we need to do before reading Julia’s official documentation.

julia> using Pkg; Pkg.activate("YourBrain"); Pkg.add("English")

This requirements may be non-trivial for someone like me.

if you in Set(NativeEnglishSpeakers)
    println("No problem :D.")
elseif you  Set(GoodAtReadingEnglish)
    println("It's Okay.")
else
    # This block happens if `you` is `me`
    lang = native_language(you) # e.g., Japanese
    @assert lang  "English"
    println("Meh.")
    println("It takes a lot of time to understand correctly in English.")
    println("I want to read documentation in $(lang).")
end

Challenges (in Japan)

  • For Japanese, learning English is not easy than English native speakers expected.
  • The number of Japanese who use English daily is limited
    • We usually read, write, listen and discuss something in Japanese

Challenges (in Japan)

  • Threfore many technical documents are expected to be readable in Japanese
    • This is a key factor for making Japanese try and use something(=Julia)
  • To grow the Julia community in Japan, I think we need documentation written in Japanese. That’s why I created DocstringTranslation.jl package.

Solution

  • Manual translation for Julia documents requires significant time
    • My life is too short
  • Developing an automated translation system utilizing machine translation

What is DocstringTranslation.jl?

A package for translating Julia docstrings using OpenAI API

julia> @doc exp
  exp(x)

  Compute the natural base exponential of x, in other words ^x.

  See also exp2, exp10, and cis.

  Examples
  ≡≡≡≡≡≡≡≡

  julia> exp(1.0)
  2.718281828459045

  julia> exp(im * pi)  cis(pi)
  true

  exp(A::AbstractMatrix)

  Compute the matrix exponential of A, defined as:

  e^A = \sum_{n=0}^{\infty} \frac{A^n}{n!}.

  For symmetric or Hermitian matrices A, an eigendecomposition (eigen) is used; otherwise, the scaling and squaring algorithm
  (see [^H05]) is employed.

  │ [^H05]

  │  Nicholas J. Higham, "The squaring and scaling method for the matrix exponential revisited", SIAM Journal
  │  on Matrix Analysis and Applications, 26(4), 2005, 1179-1193. doi:10.1137/090768539
  │  (https://doi.org/10.1137/090768539)

  Examples
  ≡≡≡≡≡≡≡≡

  julia> A = Matrix(1.0I, 2, 2)
  2×2 Matrix{Float64}:
   1.0  0.0
   0.0  1.0

  julia> exp(A)
  2×2 Matrix{Float64}:
   2.71828  0.0
   0.0      2.71828

What is DocstringTranslation.jl?

A package for translating Julia docstrings using OpenAI API

julia> ENV["OPENAI_API_KEY"] = "sk-<blah>"
julia> using DocstringTranslation
julia> @switchlang! :ja
julia> @doc exp
  exp(x)

  xの自然基底指数を計算します。言い換えれば、ℯ^xです。

  他にexp2、exp10、およびcisも参照してください。


  ≡≡

  julia> exp(1.0)
  2.718281828459045

  julia> exp(im * pi)  cis(pi)
  true

  exp(A::AbstractMatrix)

  行列 A の行列指数関数を計算します。定義は次の通りです。

  e^A = \sum_{n=0}^{\infty} \frac{A^n}{n!}.

  対称行列またはエルミート行列 A
  の場合は、固有分解(eigen)が使用され、それ以外の場合はスケーリングと平方化アルゴリズム([^\H05]を参照)が選択されます。

  │ [^H05]

  │  Nicholas J. Higham, "The squaring and scaling
  │  method for the matrix exponential revisited",
  │  SIAM Journal on Matrix Analysis and
  │  Applications, 26(4), 2005, 1179-1193.
  │  doi:10.1137/090768539
  │  (https://doi.org/10.1137/090768539)


  ≡≡

  julia> A = Matrix(1.0I, 2, 2)
  2×2 Matrix{Float64}:
   1.0  0.0
   0.0  1.0

  julia> exp(A)
  2×2 Matrix{Float64}:
   2.71828  0.0
   0.0      2.71828

What is DocstringTranslation.jl?

A package for translating Julia docstrings using OpenAI API

@doc exp (Original)

julia> @doc exp
  exp(x)

  Compute the natural base exponential of x, in other words ^x.

  See also exp2, exp10, and cis.

  Examples
  ≡≡≡≡≡≡≡≡

  julia> exp(1.0)
  2.718281828459045

  julia> exp(im * pi)  cis(pi)
  true

  exp(A::AbstractMatrix)

  Compute the matrix exponential of A, defined as:

  e^A = \sum_{n=0}^{\infty} \frac{A^n}{n!}.

  For symmetric or Hermitian matrices A, an eigendecomposition (eigen) is used; otherwise, the scaling and squaring algorithm
  (see [^H05]) is employed.

  │ [^H05]

  │  Nicholas J. Higham, "The squaring and scaling method for the matrix exponential revisited", SIAM Journal
  │  on Matrix Analysis and Applications, 26(4), 2005, 1179-1193. doi:10.1137/090768539
  │  (https://doi.org/10.1137/090768539)

  Examples
  ≡≡≡≡≡≡≡≡

  julia> A = Matrix(1.0I, 2, 2)
  2×2 Matrix{Float64}:
   1.0  0.0
   0.0  1.0

  julia> exp(A)
  2×2 Matrix{Float64}:
   2.71828  0.0
   0.0      2.71828

@doc exp (Translated into Japanese)

julia> ENV["OPENAI_API_KEY"] = "sk-<blah>"
julia> using DocstringTranslation
julia> @switchlang! :ja
julia> @doc exp
  exp(x)

  xの自然基底指数を計算します。言い換えれば、ℯ^xです。

  他にexp2、exp10、およびcisも参照してください。


  ≡≡

  julia> exp(1.0)
  2.718281828459045

  julia> exp(im * pi)  cis(pi)
  true

  exp(A::AbstractMatrix)

  行列 A の行列指数関数を計算します。定義は次の通りです。

  e^A = \sum_{n=0}^{\infty} \frac{A^n}{n!}.

  対称行列またはエルミート行列 A
  の場合は、固有分解(eigen)が使用され、それ以外の場合はスケーリングと平方化アルゴリズム([^\H05]を参照)が選択されます。

  │ [^H05]

  │  Nicholas J. Higham, "The squaring and scaling
  │  method for the matrix exponential revisited",
  │  SIAM Journal on Matrix Analysis and
  │  Applications, 26(4), 2005, 1179-1193.
  │  doi:10.1137/090768539
  │  (https://doi.org/10.1137/090768539)


  ≡≡

  julia> A = Matrix(1.0I, 2, 2)
  2×2 Matrix{Float64}:
   1.0  0.0
   0.0  1.0

  julia> exp(A)
  2×2 Matrix{Float64}:
   2.71828  0.0
   0.0      2.71828

What is DocstringTranslation.jl?

How Translation Works

  • @switchlang! :ja overrides the Docs.parsedoc(d::DocStr) method.
# Rough implementation outline
@eval function Docs.parsedoc(d::DocStr)
    if d.object === nothing
        md = Docs.formatdoc(d)
        md.meta[:module] = d.data[:module]
        md.meta[:path] = d.data[:path]
        begin # hack
          # inject a translation engine such as OpenAI.jl
          translated_md = translate_docstring_with_openai(md)
        end # hack
        d.object = translated_md
    end
    d.object
end

For more details, refer to the actual implementation.

Docstrings on IJulia.jl

We can view translated docstrings on Jupyter Notebook

Live Docs on Pluto.jl

We can view translated docstrings on Pluto Notebook

Applications

  • We’ve shown we can translate docstrings into any languages.
  • What about files in docs?
    • Can we translate documentation built with Documenter.jl?

Translation of documentation built with Documenter.jl

--- a/docs/make.jl
+++ b/docs/make.jl
@@ -4,6 +4,10 @@ using DocumenterCitations
 # `using SpecialFunctions` for all doctests
 DocMeta.setdocmeta!(SpecialFunctions, :DocTestSetup, :(using SpecialFunctions); recursive=true)

+using DocstringTranslation
+@switchlang! :ja
+DocstringTranslation.switchtargetpackage!(SpecialFunctions)
+
 bib = CitationBibliography(
        joinpath(@__DIR__, "src", "refs.bi
b");
        style = :authoryear,

Translation of Documenter.jl-based documentation

Translation Results for Julia’s Official Documentation

Multilingual Julia Documentation:

Additional Information

We are experimenting with various backends. In terms of accuracy and speed, I think the OpenAI backend is the best.

Summary

  • Introduce DocstringTranslation.jl
  • Enables multilingual support for Julia documentation
  • Supports both docstrings and Documenter.jl
  • Solves yet another two-language problem (I believe)

Future Plans:

  • Translate Julia documentation for more languages
  • Support Franklin.jl based documentation

Thank You

Repositories:

Appendix

About Result Caching

  • Uses Scratch.jl to store translation results locally
  • Prevents repeated API calls each time the REPL starts
  • Allows modification of translation results by editing <lang>.md files (e.g., ja.md)
  • Enables sharing of translation results among users
$ tree ~/.julia/scratchspaces/d404e13b-1f8e-41a5-a26a-0b758a0c6c97/translation
├── Base
│   └── 1.11
│       └── Math
│           └── 77be4ada26c623c913ebbdae5d8450a4dfe8f3cbf67837faac9d7193342d2bfe
│               ├── ja.md
│               └── original.md
└── LinearAlgebra
    └── 1.11
        └── 46c0494a8a2adffc6f71752b60448da1743997b5b1791b71e3830113e9b9cc46
            ├── ja.md
            └── original.md

8 directories, 4 files

Challenges (in Japan)

  • In Japan especially in industry, C++/Python is widely used.
    • There is lots of resources written in Japanese for C++/Python on the internet.
  • When I introduce Julia to others, they said to me:
    • “Few libraries and documentation available for Julia” Python user says
    • “I don’t want to use Julia because it is a minor language” C++ user says
    • “Julia is difficult” C++ user says
  • What was worse
    • “Because Julia is not effective, production systems must strictly prohibit the use of the Julia language. From now on, if you use it, be prepared for possible termination.” CEO at my workplace (This is NOT a joke.)
  • Starting August 2025, I’ll be unemployed. This Is Not a Drill.