# change \crefname for appendix in document

I want to change how an appendix section is referred to for part of my document: I want "appendix A.1" in the main text and "section A.1" in the appendix.

I tried the following:

\documentclass{scrartcl}
\usepackage{cleveref}
\begin{document}
\cref{foo} and \cref{bar}

\appendix
\crefname{subappendix}{section}{sections}

\section{Foo}\label{foo}
\cref{foo} and \cref{bar}

\subsection{Bar}\label{bar}
\end{document}


I expected an output like:

appendix A and appendix A.1

A Foo

appendix A and section A.1

A.1 Bar

But I also get "appendix A.1" within the appendix.

It seems like I can only use \crefname in the preamble and affect the whole document. Is there a way to change the the reference name only for the appendix?

The apptools package introduces relevant conditionals \IfAppendix and \ifappendix:

\documentclass{scrartcl}
\usepackage{cleveref}
\usepackage{apptools}
\crefname{subappendix}{\IfAppendix{section}{appendix}}{\IfAppendix{sections}{appendices}s}

\begin{document}
\cref{foo} and \cref{bar}

\appendix

\section{Foo}\label{foo}
\cref{foo} and \cref{bar}

\subsection{Bar}\label{bar}
\end{document}