Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add translation support for mermaid #130

Open
MrGeneration opened this issue Oct 25, 2023 · 1 comment
Open

Add translation support for mermaid #130

MrGeneration opened this issue Oct 25, 2023 · 1 comment

Comments

@MrGeneration
Copy link

Hey,

it would be great if sphinx-mermaid would have internationalization support so that you can render diagrams in several languages.

@jnuernberg
Copy link

Hi,
Through trial and error, I was able to figure out, that sphinx-intl can cope with mermaid graphs, if you include them as files and then use the same naming convention as for figure translations. I.e. you include the mermaid-graph as file, then translate it and save it to a new file, following the naming convention. In that case, the rightly translated graph will be picked up.

In the Sphinx options for internationalization, you can set the figure_language_filename to enable internationalization for figures. By default, this is {root}.{language}{ext}.

Let me give you an example:

  • First, in the base.rst file of the original language, you include your mermaid graph. The graph is stored in a separate file called mermaid.mmd
    After this paragraph follows a mermaid graph:
    
    .. mermaid:: mermaid.mmd
       :align: center
  • In the mermaid.mmd file, you have your mermaid graph, i.e.:
    flowchart TD
      S(((Beginning)))
      T[End]
      S--towards-->T
    
  • In a separate file, you store your translated mermaid graph with the right language specifier. Suppose, we want to translate our mermaid graph to german, we'd save it in a separate file named mermaid.de.mmd like so.
    flowchart TD
      S(((Anfang)))
      T[Ende]
      S--bis-->T
    
  • Now, in the file structure, you put them side by side in the same directory, i.e.
    ./
    + base.rst
    + mermaid.mmd
    + mermaid.de.mmd
    

With this structure, sphinx-intl will pick up the rightly translated mermaid graph for internationalization in your documentation.

However, there are some culprits: In particular, if you are using captions, these are not being caught, when running sphinx-build -M gettext. In other words, the following will show show the english caption in all of your translations and I reckon, that this is part of sphinxcontrib-mermaid.

.. mermaid:: mermaid.mmd
  :align: center
  :caption: What a beautiful mermaid graph! 

I hope this helps,

Jacob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants