DocstringTranslation.jl Documentation

DocstringTranslation.cache_originalMethod
cache_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.

source
DocstringTranslation.cache_translationMethod
cache_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 document
  • transmd::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.

source
DocstringTranslation.insertversionMethod
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.

source
DocstringTranslation.istranslatedMethod
istranslated(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.

source
DocstringTranslation.load_translationMethod
load_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.

source
DocstringTranslation.pathofcachedirFunction
pathofcachedir(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 for
  • allowold::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 or VERSION
  • The file path from md.meta[:path] if present, using VERSION

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
source
DocstringTranslation.prevminorMethod
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.

source
DocstringTranslation.translate_md!Method
translate_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.

source
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:

  1. Sets the target language for translation
  2. Overrides Docs.parsedoc to insert translation engine for individual docstrings
  3. Overrides Documenter.Page constructor to enable translation of entire documentation pages

Example

@switchlang! "ja"  # Switch to Japanese translation
source