Problem using autostyle from csquote with multi languages macros

I get some macros to enable me to generate a document in three different languages from the same .txt file (for example a CV). But the format of the quote is dependent of the order in which I load the languages with babel instead of the selected languages. For example in the MWE the selected language is English, but the quotation format is French since this is the last loaded language in babel.

\documentclass[]{article}
\usepackage[UKenglish,german,french]{babel}
\usepackage[autostyle=true]{csquotes}
% define the commands to switch and the flags in LaTeX
\newcommand{\GERMAN}{\germantrue \frenchfalse \englishfalse
\selectlanguage{german}}
\newcommand{\FRENCH}{\germanfalse  \frenchtrue \englishfalse
\selectlanguage{french}}
\newcommand{\ENGLISH}{\germanfalse  \frenchfalse \englishtrue
\selectlanguage{UKenglish}}
\newif\ifgerman \germantrue
\newif\iffrench \frenchtrue
\newif\ifenglish \englishtrue

% then choose one language to be displayed
%\GERMAN
%\FRENCH
\ENGLISH
\newcommand\hide[1] {}
\newcommand\german[1] {\ifgerman #1 \else \fi}
\newcommand\french[1] {\iffrench #1 \else \fi}
\newcommand\english[1] {\ifenglish #1 \else \fi}
\begin{document}
\german{\enquote{Etwas}}\french{\enquote{Quelque chose}}\english{\enquote{something}}
\end{document}


So the result is ≪ something ≫ intead of something'

How should I change the code to make that the autostyle consider the selected language ?

• What about \newcommand{\english}[1]{\ifengish\selectlanguage{UKenglish}#1\fi}? – jon Apr 4 '16 at 18:59
• Thanks you @jon. It seems to work. Can you explain what make the difference ? – Pierrick Apr 4 '16 at 19:25
• Don't load packages inside \newcmmands. As to the why, I'd have to dig deeper into the question. – jon Apr 4 '16 at 19:32

You are calling your command to early: babel sets the main language at begin document and so overwrites your \selectlanguage. If you move your commands behind \begin{document} or use \AtBeginDocument it works fine:

\documentclass[]{article}
\usepackage[UKenglish,german,french]{babel}
\usepackage[autostyle]{csquotes}

% define the commands to switch and the flags in LaTeX
\newcommand{\GERMAN}{\germantrue \frenchfalse \englishfalse
\selectlanguage{german}}
\newcommand{\FRENCH}{\germanfalse  \frenchtrue \englishfalse
\selectlanguage{french}}
\newcommand{\ENGLISH}{\germanfalse  \frenchfalse \englishtrue
\selectlanguage{UKenglish}}
\newif\ifgerman \germantrue
\newif\iffrench \frenchtrue
\newif\ifenglish \englishtrue

% then choose one language to be displayed
\AtBeginDocument{\GERMAN}
%\FRENCH
%%\ENGLISH
\newcommand\hide[1] {}
\newcommand\german[1] {\ifgerman #1 \else \fi}
\newcommand\french[1] {\iffrench #1 \else \fi}
\newcommand\english[1] {\ifenglish #1 \else \fi}
\begin{document}\languagename
\german{\enquote{Etwas}}\french{\enquote{Quelque chose}}\english{\enquote{something}}
\end{document}
`