DocstringTranslation.jl Documentation
DocstringTranslation.cache_original
DocstringTranslation.cache_translation
DocstringTranslation.insertversion
DocstringTranslation.istranslated
DocstringTranslation.load_translation
DocstringTranslation.pathofcachedir
DocstringTranslation.prevminor
DocstringTranslation.translate_md!
DocstringTranslation.@switchlang!
DocstringTranslation.cache_original
— Methodcache_original(md::Markdown.MD)
Cache the original version of a Markdown document.
Arguments
md::Markdown.MD
: The Markdown document to cache
Details
Creates a cache directory if it doesn't exist and saves the original Markdown content to 'original.md' within that directory.
DocstringTranslation.cache_translation
— Methodcache_translation(md_hash_original::String, transmd::Markdown.MD)
Cache a translated version of a Markdown document.
Arguments
md_hash_original::String
: The hash of the original Markdown documenttransmd::Markdown.MD
: The translated Markdown document to cache
Details
Creates a cache directory if it doesn't exist and saves the translated content to a language-specific file (e.g., 'ja.md' for Japanese) within that directory.
DocstringTranslation.insertversion
— Methodinsertversion(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.istranslated
— Methodistranslated(md::Markdown.MD)
Check if a translation exists for the given Markdown document.
Arguments
md::Markdown.MD
: The Markdown document to check for translation
Returns
true
if a translation file exists in the cache directory for the current language, false
otherwise.
DocstringTranslation.load_translation
— Methodload_translation(md::Markdown.MD)
Load the cached translation for a given Markdown document.
Arguments
md::Markdown.MD
: The Markdown document to load the translation for
Returns
A new Markdown.MD
object containing the translated content.
Details
Loads the translation file from cache, post-processes it, and parses it as Markdown.
DocstringTranslation.pathofcachedir
— Functionpathofcachedir(md::Markdown.MD, allowold::Bool = false)
Get the cache directory path for a given Markdown document.
Arguments
md::Markdown.MD
: The Markdown document to get the cache path forallowold::Bool = false
: If true, allows falling back to previous minor version's cache directory
Returns
A string containing the full path to the cache directory.
Details
The cache directory path is constructed based on either:
- The module path from
md.meta[:module]
if present, using the module's version orVERSION
- The file path from
md.meta[:path]
if present, usingVERSION
If allowold
is true and the target directory doesn't exist, falls back to the previous minor version's directory.
Throws
ArgumentError
: If neither:module
nor:path
is found in the markdown metadata
DocstringTranslation.prevminor
— Methodprevminor(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.translate_md!
— Methodtranslate_md!(md::Markdown.MD)
Translate a Markdown document in-place using OpenAI translation.
Arguments
md::Markdown.MD
: The Markdown document to translate
Returns
The translated Markdown document (same object as input)
Details
Recursively translates all content in the Markdown document using multiple threads. Translation is done in-place, modifying the original document.
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.parsedoc
to insert translation engine for individual docstrings - Overrides
Documenter.Page
constructor to enable translation of entire documentation pages
Example
@switchlang! "ja" # Switch to Japanese translation