I would like to iterate through a comma separated list to translate some words. I already found how to do so using \docsvlist from the etoolbox package. However, there is a large space printed before the first word and between the words when there should only be a "normal" space after the printed comma. I think the problem comes from the nesting of the \ifstrequal commands used for the translation.
Below is a MWE including an example calling all the possible translations and another example calling only the first translation to show the impact of the nesting.
How can I avoid these additional spaces?
MWE
\documentclass{article}
\usepackage{etoolbox}
\begin{document}
\newcommand\TranslateAnimal[1]{
\ifstrequal{#1}{Cat}{Chat}{
\ifstrequal{#1}{Dog}{Chien}{
\ifstrequal{#1}{Mouse}{Souris}{
\ifstrequal{#1}{Bird}{Oiseau}{
\ifstrequal{#1}{Horse}{Cheval}{
#1 % If there is no known translation
}}}}}
}
\newcommand{\TranslateAnimalList}[2][,]{
\def\nextitem{\def\nextitem{#1}}% Separator
\renewcommand*{\do}[1]{\nextitem\TranslateAnimal{##1}} % How to process each item
\docsvlist{#2}% Process list
}
There are additional large spaces before the first word and after words: \TranslateAnimalList{Cat,Bird,Dog,Horse,Mouse,Seal,Donkey}
Compare with: \TranslateAnimalList{Cat,Cat,Cat,Cat,Cat,Cat,Cat} where there is only a large space before the first word
\end{document}

\TranslateAnimalhas 8 spaces, use%at ends of lines to comment them out, and remove the space after#1– David Carlisle Nov 11 '20 at 23:54