[Tex/LaTex] How to write pseudo code in other languages (Spanish)

algorithm2espanish

I'm using this code in LaTeX

\documentclass[12pt,a4paper]{report}
\usepackage[spanish]{babel}
\selectlanguage{spanish} 
\usepackage{algorithm2e} %for psuedo code
\usepackage[lmargin=3.81cm,tmargin=2.54cm,rmargin=2.54cm,bmargin=2.52cm]{geometry}
\begin{document}

\begin{algorithm}[H] %or another one check
 \caption{How to write algorithms}
     \SetAlgoLined

     \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\;
      }
     }

\end{algorithm}

\end{document}

But I need that statements like 'if .. then .. else' to be changed to 'si.. entonces … de lo contrario'.

I tried that but doesn't work, I mean the output is the same as if I didn't select a language.

Best Answer

Option spanish only translates algorithm to algoritmo but option onelanguage also translates keywords.

\documentclass[12pt,a4paper]{report}
\usepackage[spanish]{babel}
\selectlanguage{spanish} 
\usepackage[spanish,onelanguage]{algorithm2e} %for psuedo code
\usepackage[lmargin=3.81cm,tmargin=2.54cm,rmargin=2.54cm,bmargin=2.52cm]{geometry}
\begin{document}

\begin{algorithm}[H] %or another one check
 \caption{How to write algorithms}
     \SetAlgoLined

     \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\;
      }
     }

\end{algorithm}

\end{document}

enter image description here