1

I created a custom float environment, but my translations of the labels for use with cleveref are not working:

\cref@addlanguagedefs{brazilian}{%
    \AtBeginDocument{%
        \Crefname@preamble{frime}{quadro}{quadros}
        \Crefname@preamble{frime}{Quadro}{Quadros}
    }
}

Everything is working fine with standard "objects" (such as figure and lstlisting) as shown below:

enter image description here

How can I correctly add brazilian translations for the labels used by cleveref-based cross-references for frime-type floats?

\documentclass[brazilian,12pt]{memoir}
\usepackage{caption}
\usepackage{newfloat}
\usepackage{graphicx}
\usepackage{listings}
\usepackage[english,main=brazil]{babel}

\usepackage{hyperref}
\usepackage[brazilian]{cleveref}

\def\frimesname{Frame}
\def\listoffrimesname{List of Frames}

\DeclareFloatingEnvironment[fileext=loq,placement={!hbtp},name=\frimesname,
within=chapter,listname=\listoffrimesname]{frime}

\crefname{frime}{frame}{frames}
\Crefname{frime}{Frame}{Frames}

\makeatletter

\addto\captionsbrazil{\renewcommand{\frimesname}{Quadro}}
\addto\captionsbrazil{\renewcommand{\listoffrimesname}{Lista de Quadros}}

\cref@addlanguagedefs{brazilian}{%
    \AtBeginDocument{%
        \Crefname@preamble{frime}{quadro}{quadros}
        \Crefname@preamble{frime}{Quadro}{Quadros}
    }
}

\makeatother

\begin{document}

Cref figure \Cref{figuree}

autoref figure \autoref{figuree}

Cref frame \Cref{framee}

autoref frame \autoref{framee}

Cref listing \Cref{listingg}

autoref listing \autoref{listingg}

\begin{figure}[h]
    \caption{Opis}
    \label{figuree}
    \includegraphics{latex.png}
\end{figure}

\begin{frime}[h]
    \caption{Stuff.}
    \label{framee}
    Contents.
\end{frime}

\begin{lstlisting}[caption={Think},label={listingg}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires
\end{lstlisting}

\end{document}
2

Since you load the babel package with the options english and main=brazil, but load the cleveref package with the option brazilian, I suggest you replace

\makeatletter    
\addto\captionsbrazil{\renewcommand{\frimesname}{Quadro}}
\addto\captionsbrazil{\renewcommand{\listoffrimesname}{Lista de Quadros}}

\cref@addlanguagedefs{brazilian}{%
    \AtBeginDocument{%
        \Crefname@preamble{frime}{quadro}{quadros}
        \Crefname@preamble{frime}{Quadro}{Quadros}
    }
}    
\makeatother

with

\addto\captionsbrazil{%
    \renewcommand{\frimesname}{Quadro}
    \renewcommand{\listoffrimesname}{Lista de Quadros}
    \crefname{frime}{quadro}{quadros}
    \Crefname{frime}{Quadro}{Quadros}
}

A full MWE:

enter image description here

\documentclass[brazilian,12pt,demo]{memoir} % omit 'demo' option in real document
\usepackage{caption}
\usepackage{newfloat}
\usepackage{graphicx}
\usepackage{listings}
\usepackage[english,main=brazil]{babel}

\usepackage[colorlinks]{hyperref}
\usepackage[brazilian]{cleveref}

\def\frimesname{Frame}
\def\listoffrimesname{List of Frames}    
\DeclareFloatingEnvironment[fileext=loq,placement={!hbtp},name=\frimesname,
    within=chapter,listname=\listoffrimesname]{frime}

\crefname{frime}{frame}{frames}
\Crefname{frime}{Frame}{Frames}

%% new:
\addto\captionsbrazil{%
    \renewcommand{\frimesname}{Quadro}
    \renewcommand{\listoffrimesname}{Lista de Quadros}
    \crefname{frime}{quadro}{quadros}
    \Crefname{frime}{Quadro}{Quadros}
    \def\lstlistingautorefname{Listagem} % optional
}

\begin{document}
\setcounter{chapter}{2} % just for this example

Cref figure: \Cref{figuree}

autoref figure: \autoref{figuree}

Cref frame: \Cref{framee}

autoref frame: \autoref{framee}

Cref listing: \Cref{listingg}

autoref listing: \autoref{listingg}


\listoffrimes
\bigskip\hrule

\begin{figure}[h]
    \centering
    \caption{Opis}
    \label{figuree}
    \includegraphics{latex.png}
\end{figure}

\begin{frime}[h]
    \centering
    \caption{Stuff.}
    \label{framee}
    Contents.
\end{frime}

\begin{lstlisting}[caption={Think},label={listingg}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires ...
\end{lstlisting}

\end{document}
  • 1
    Thank you very much! This thing was getting me crazy! – user Aug 2 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.