You have to do almost no language checking yourself, if you use cleveref
's interface to define language-specific definitions. This interface is internal and not documented, so things could theoretically break in future versions, so I only recommend this for testing and the short term. A medium- to long-term solution would be to contact the maintainer and ask him to include language support for nynorsk
directly in the package.
For the example I just copied the language definitions from norsk
to nynorsk
, so you will have to translate the terms yourself.
\documentclass[5p,a4paper,nynorsk,english]{elsarticle}
\usepackage{babel}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{appendix}
\makeatletter
\cref@addlanguagedefs{nynorsk}{%
\PackageInfo{cleveref}{loaded `nynorsk' language definitions}%
\renewcommand{\crefrangeconjunction}{ til\nobreakspace}%
\renewcommand\crefrangepreconjunction{}%
\renewcommand\crefrangepostconjunction{}%
\renewcommand{\crefpairconjunction}{ og\nobreakspace}%
\renewcommand{\crefmiddleconjunction}{, }%
\renewcommand{\creflastconjunction}{ og\nobreakspace}%
\renewcommand{\crefpairgroupconjunction}{ og\nobreakspace}%
\renewcommand{\crefmiddlegroupconjunction}{, }%
\renewcommand{\creflastgroupconjunction}{ og\nobreakspace}%
%
\Crefname{equation}{Likning}{Likningene}%
\Crefname{figure}{Figur}{Figurene}%
\Crefname{subfigure}{Figur}{Figurene}%
\Crefname{table}{Tabell}{Tabellene}%
\Crefname{subtable}{Tabell}{Tabellene}%
\Crefname{page}{Side}{Siden}%
\Crefname{part}{Del}{Delene}%
\Crefname{chapter}{Kapittel}{Kapitlene}%
\Crefname{section}{Avsnitt}{Avsnittene}%
\Crefname{subsection}{Avsnitt}{Avsnittene}%
\Crefname{subsubsection}{Avsnitt}{Avsnittene}%
\Crefname{appendix}{Tillegg}{Tilleggene}%
\Crefname{subappendix}{Tillegg}{Tilleggene}%
\Crefname{subsubappendix}{Tillegg}{Tilleggene}%
\Crefname{subsubsubappendix}{Tillegg}{Tilleggene}%
\Crefname{enumi}{Punkt}{Punktene}%
\Crefname{enumii}{Punkt}{Punktene}%
\Crefname{enumiii}{Punkt}{Punktene}%
\Crefname{enumiv}{Punkt}{Punktene}%
\Crefname{enumv}{Punkt}{Punktene}%
\Crefname{footnote}{Fotnote}{Fotnotene}%
\Crefname{theorem}{Teorem}{Teoremene}%
\Crefname{lemma}{Lemma}{Lemma}%
\Crefname{corollary}{Korollar}{Korollarene}%
\Crefname{proposition}{P\aa stand}{P\aa standene}%
\Crefname{definition}{Definisjon}{Definisjonene}%
\Crefname{result}{Resultat}{Resultatene}%
\Crefname{example}{Eksempel}{Eksemplene}%
\Crefname{remark}{Bemerkning}{Bemerkningene}%
\Crefname{note}{Note}{Notene}%
\Crefname{algorithm}{Algoritme}{Algoritmene}%
\Crefname{listing}{Opplisting}{Opplistingene}%
\Crefname{line}{Linje}{Linjene}%
%
\if@cref@capitalise%
\crefname{equation}{Likning}{Likningene}%
\crefname{figure}{Figur}{Figurene}%
\crefname{subfigure}{Figur}{Figurene}%
\crefname{table}{Tabell}{Tabellene}%
\crefname{subtable}{Tabell}{Tabellene}%
\crefname{page}{Side}{Siden}%
\crefname{part}{Del}{Delene}%
\crefname{chapter}{Kapittel}{Kapitlene}%
\crefname{section}{Avsnitt}{Avsnittene}%
\crefname{subsection}{Avsnitt}{Avsnittene}%
\crefname{subsubsection}{Avsnitt}{Avsnittene}%
\crefname{appendix}{Tillegg}{Tilleggene}%
\crefname{subappendix}{Tillegg}{Tilleggene}%
\crefname{subsubappendix}{Tillegg}{Tilleggene}%
\crefname{subsubsubappendix}{Tillegg}{Tilleggene}%
\crefname{enumi}{Punkt}{Punktene}%
\crefname{enumii}{Punkt}{Punktene}%
\crefname{enumiii}{Punkt}{Punktene}%
\crefname{enumiv}{Punkt}{Punktene}%
\crefname{enumv}{Punkt}{Punktene}%
\crefname{footnote}{Fotnote}{Fotnotene}%
\crefname{theorem}{Teorem}{Teoremene}%
\crefname{lemma}{Lemma}{Lemma}%
\crefname{corollary}{Korollar}{Korollarene}%
\crefname{proposition}{P\aa stand}{P\aa standene}%
\crefname{definition}{Definisjon}{Definisjonene}%
\crefname{result}{Resultat}{Resultatene}%
\crefname{example}{Eksempel}{Eksemplene}%
\crefname{remark}{Bemerkning}{Bemerkningene}%
\crefname{note}{Note}{Notene}%
\crefname{algorithm}{Algoritme}{Algoritmene}%
\crefname{listing}{Opplisting}{Opplistingene}%
\crefname{line}{Linje}{Linjene}%
%
\else%
\crefname{equation}{likning}{likningene}%
\crefname{figure}{figur}{figurene}%
\crefname{subfigure}{figur}{figurene}%
\crefname{table}{tabell}{tabellene}%
\crefname{subtable}{tabell}{tabellene}%
\crefname{page}{side}{siden}%
\crefname{part}{del}{delene}%
\crefname{chapter}{kapittel}{kapitlene}%
\crefname{section}{avsnitt}{avsnittene}%
\crefname{subsection}{avsnitt}{avsnittene}%
\crefname{subsubsection}{avsnitt}{avsnittene}%
\crefname{appendix}{tillegg}{tilleggene}%
\crefname{subappendix}{tillegg}{tilleggene}%
\crefname{subsubappendix}{tillegg}{tilleggene}%
\crefname{subsubsubappendix}{tillegg}{tilleggene}%
\crefname{enumi}{punkt}{punktene}%
\crefname{enumii}{punkt}{punktene}%
\crefname{enumiii}{punkt}{punktene}%
\crefname{enumiv}{punkt}{punktene}%
\crefname{enumv}{punkt}{punktene}%
\crefname{footnote}{fotnote}{fotnotene}%
\crefname{theorem}{teorem}{teoremene}%
\crefname{lemma}{lemma}{lemma}%
\crefname{corollary}{korollar}{korollarene}%
\crefname{proposition}{p\aa stand}{p\aa standene}%
\crefname{definition}{definisjon}{definisjonene}%
\crefname{result}{resultat}{resultatene}%
\crefname{example}{eksempel}{eksemplene}%
\crefname{remark}{bemerkning}{bemerkningene}%
\crefname{note}{note}{notene}%
\crefname{algorithm}{algoritme}{algoritmene}%
\crefname{listing}{opplisting}{opplistingene}%
\crefname{line}{linje}{linjene}%
\fi}% end \cref@loadlanguagedefs
\makeatother
\begin{document}
\Cref{eq:E=mc}
\selectlanguage{nynorsk} % Switch between english and nynorsk
\begin{equation}
E=mc^2 \label{eq:E=mc}
\end{equation}
\Cref{eq:E=mc}
\appendix
\section{A} % To check that current language option is working.
\end{document}
There is one caveat. Due to the implementation of the language options our new language will not work correctly if it is the document main language. In that case it helps to explicitly switch the language to the main language directly after \begin{document}
. This is just a small hitch that won't be relevant once cleveref
supports your language out of the box, though.
cleveref.cfg
.\extrasnynorsk
. And by the way, I think that the most difficult part is not about the names for these special environments/commands, but rather those commands\crefpairconjunction
,\crefmiddleconjunction
,\creflastconjunction
, etc. which need to be carefully selected. You can see the preset definitions incleveref.dtx
, and define you own version, for example incleveref.cfg
as Bernard stated.