[Tex/LaTex] Translation of keywords algorithm2e

algorithm2elanguages

I would like to use algorithm2e with translated keywords option (e.g. frenchkw), which should be working according to the documentation, but it doesn't do nothing for me.

\usepackage[vlined, lined, french, frenchkw]{algorithm2e}

\begin{algorithm}[H]
    \KwData{this text}
    \KwResult{how to write algorithm with \LaTeX2e }
    initialization\;
    \While{not at end of this document}{
        read current\;
        \eIf{understand}{
            go to next section\;
            current section becomes this one\;
        }{
        go back to the beginning of current section\;
    }
}
\caption{How to write algorithms}
\end{algorithm}

Result, notice how Algorithm caption is correctly translated, but keywords are not.

enter image description here

Best Answer

You have to specify that you'll be using only onelanguage for this to work:

enter image description here

\documentclass{article}

\usepackage[vlined, french, onelanguage]{algorithm2e}

\begin{document}

\begin{algorithm}[H]
  \KwData{this text}
  \KwResult{how to write algorithm with \LaTeX2e }
  initialization\;
  \While{not at end of this document}{
    read current\;
    \eIf{understand}{
      go to next section\;
      current section becomes this one\;
    }{
      go back to the beginning of current section\;
    }
  }
  \caption{How to write algorithms}
\end{algorithm}

\end{document}

While algorithm2e does provide options for the use of different languages, without onelanguage it requires the user to specify different inputs for these. So, instead of \KwData - an english/default definition - one would need use \Donnees - the french definition.

\documentclass{article}

\usepackage[vlined, french]{algorithm2e}

\begin{document}

\begin{algorithm}[H]
  \Donnees{this text}
  \Res{how to write algorithm with \LaTeX2e }
  initialization\;
  \Tq{not at end of this document}{
    read current\;
    \eSi{understand}{
      go to next section\;
      current section becomes this one\;
    }{
      go back to the beginning of current section\;
    }
  }
  \caption{How to write algorithms}
\end{algorithm}

\end{document}