DocstringTranslation.jl Documentation
DocstringTranslation.cache_originalDocstringTranslation.cache_translationDocstringTranslation.cached_translationDocstringTranslation.clear_translation_failures!DocstringTranslation.insertversionDocstringTranslation.load_translationDocstringTranslation.pathofcachedirDocstringTranslation.prevminorDocstringTranslation.structure_differenceDocstringTranslation.switchfallbackmodel!DocstringTranslation.translate_documenter_page_with_openaiDocstringTranslation.translate_pagesDocstringTranslation.translation_failuresDocstringTranslation.@switchlang!
DocstringTranslation.cache_original — Method
Save pristine Markdown as original.md.
DocstringTranslation.cache_translation — Method
Save a successfully translated document under its original hash.
DocstringTranslation.cached_translation — Method
Select a cached translation, or translate the pristine original and save on success.
DocstringTranslation.clear_translation_failures! — Method
Clear recorded failures between builds, allowing fallback hooks to retry them.
DocstringTranslation.insertversion — Method
insertversion(svec::AbstractVector, v::VersionNumber)Insert a version string into a copy of the given vector at the second position.
Arguments
svec::AbstractVector: The vector into which the version string will be inserted.v::VersionNumber: The version number used to create the version string.
Returns
A new vector with the version string inserted at the second position.
Details
The function creates a deep copy of the input vector svec and inserts a string representation of the version number v in the format "major.minor" at the second position.
DocstringTranslation.load_translation — Method
Load a compatible cached translation and restore the original metadata.
DocstringTranslation.pathofcachedir — Function
pathofcachedir(md::Markdown.MD, allowold::Bool=false)Return a cache directory inside the configured root. Unversioned modules use the Julia version. Absolute and parent-relative page paths share a portable directory and are distinguished by content hash.
DocstringTranslation.prevminor — Method
prevminor(v::VersionNumber)Return a VersionNumber with the same major version as v, but with minor version decremented by 1 (bounded at 0) and patch version set to 0.
DocstringTranslation.structure_difference — Function
Translate a complete Documenter page using translator and restore protected syntax.
DocstringTranslation.switchfallbackmodel! — Method
Set the model used only after primary translation fails; nothing disables it.
DocstringTranslation.translate_documenter_page_with_openai — Method
translate_documenter_page_with_openai(source; max_attempts=3,
fallback_model=default_fallback_model(), fallback_max_attempts=1)Translate and validate using the primary model. Only after it fails, try the fallback model (by default GPT-6.1 Sol, medium reasoning) on the same pristine source. Both phases use identical Markdown validation; neither caches bad output. Set the fallback model to nothing to disable escalation.
An injected request(text, promptfn) disables automatic network fallback unless fallback_request is supplied explicitly. This keeps custom providers and offline tests in control of all external requests.
DocstringTranslation.translate_pages — Method
DocstringTranslation.translate_pages(paths; concurrency=32)Translate Markdown files into the current language and populate the same cache used by @switchlang! and Documenter. Run this before Documenter.makedocs to overlap API requests across pages. Up to concurrency asynchronous workers run even with one Julia thread; concurrency must be a positive integer.
Return (translated, cached, failed) in input order. The first two fields are vectors of absolute file paths. failed contains path => exception pairs. Individual failures do not discard successful peers; rerun the batch to resume. Duplicate paths (including symlinks) are processed once per call. An empty input returns empty vectors. Without OPENAI_API_KEY, cached pages remain usable and uncached pages are reported as failures.
Set the language with @switchlang!, and configure the cache directory, target package and model before calling. Keep that configuration fixed until the batch completes. Concurrent calls have independent worker limits and do not deduplicate each other's requests.
For custom providers or offline testing, request(text, promptfn) may supply the response text, with available=true to enable it without an API key. Responses undergo the same protection and validation as ordinary page translations.
DocstringTranslation.translation_failures — Method
Return failures recorded in this process, including source and sanitized reason.
DocstringTranslation.@switchlang! — Macro
@switchlang!(lang)Switch the target language for docstring translation and modify the documentation system to automatically translate docstrings.
Arguments
lang: The target language code (e.g., "ja", "en") to translate docstrings into.
Details
This macro performs the following operations:
- Sets the target language for translation
- Overrides
Docs.parsedocto insert translation engine for individual docstrings - Overrides
Documenter.Pageconstructor to enable translation of entire documentation pages
Translation failures produce a warning and fall back to pristine original Markdown; they never become translated cache entries. Inspect DocstringTranslation.translation_failures() and clear failures between builds with DocstringTranslation.clear_translation_failures!().
Example
@switchlang! "ja" # Switch to Japanese translation