%%%
% Ecriture des nombres en lettres
%%%
\def\filedateEcrireLettres{2025/12/17}%
\def\fileversionEcrireLettres{0.1a}%
\message{-- \filedateEcrireLettres\space v\fileversionEcrireLettres}%
%
\setKVdefault[ClesEcriture]{Math=false,Majuscule=false,E=false,Tradition=false,Zero=false}%

\makeatletter
%\newcommand\PfC@EcriturePluriel[1]{%
%  \IfStrEq*{\languagename}{english}{}{\xintifboolexpr{#1 > 1}{s}{}}%
%}%

\newcommand\PfC@Dixieme[1]{%
  \IfStrEq*{\languagename}{french}{dixième\ifnum#1>1\relax s\fi}{}%
  \IfStrEq*{\languagename}{english}{tenth}{}%
  \IfStrEq*{\languagename}{spanish}{décim\ifnum#1>1\relax as\else o\fi}{}% 
}%
\newcommand\PfC@Centieme[1]{%
  \IfStrEq*{\languagename}{french}{centième\ifnum#1>1\relax s\fi}{}%
  \IfStrEq*{\languagename}{english}{hundredth}{}%
  \IfStrEq*{\languagename}{spanish}{centésima\ifnum#1>1\relax s\fi}{}%
}%

\newcommand\PfC@Millieme[1]{%
  \IfStrEq*{\languagename}{french}{millième\ifnum#1>1\relax s\fi}{}%
  \IfStrEq*{\languagename}{english}{thousandth}{}%
  \IfStrEq*{\languagename}{spanish}{milésima\ifnum#1>1\relax s\fi}{}%
}%
\newcommand\PfC@DixMillieme[1]{%
  \IfStrEq*{\languagename}{french}{dix-millième\ifnum#1>1\relax s\fi}{}%
  \IfStrEq*{\languagename}{english}{ten-thousandth}{}%
  \IfStrEq*{\languagename}{spanish}{diezmilésima\ifnum#1>1\relax s\fi}{}%
}%
\newcommand\PfC@CentMillieme[1]{%
  \IfStrEq*{\languagename}{french}{cent-millième\ifnum#1>1\relax s\fi}{}%
  \IfStrEq*{\languagename}{english}{hundred-thousandth}{}%
  \IfStrEq*{\languagename}{spanish}{cienmilésima\ifnum#1>1\relax s\fi}{}%
}%
\newcommand\PfC@Millionieme[1]{%
  \IfStrEq*{\languagename}{french}{millionième\ifnum#1>1\relax s\fi}{}%
  \IfStrEq*{\languagename}{english}{millionth}{}%
  \IfStrEq*{\languagename}{spanish}{millonésima\ifnum#1>1\relax s\fi}{}%
}%

\newcommand\PfC@NomVirgule{%
  \IfStrEq*{\languagename}{french}{virgule}{}%
  \IfStrEq*{\languagename}{english}{and}{}%
  \IfStrEq*{\languagename}{spanish}{con}{}%
}%

\newcommand\PfC@NomUnite[1]{%
  \IfStrEq*{\languagename}{french}{unité\ifnum#1>1\relax s\fi}{}%
  \IfStrEq*{\languagename}{english}{}{}%
  \IfStrEq*{\languagename}{spanish}{unidad\ifnum#1>1\relax es\fi}{}%
}%

\newcommand\PfC@EcritureDecimale{%
  \StrLen{\PfC@ListeEcriture[2]}[\LongueurDecimale]%
  \xintifboolexpr{\LongueurDecimale == 6}{%
    ~\PfC@Millionieme{\PfC@ListeEcriture[2]}%
  }{\xintifboolexpr{\LongueurDecimale == 5}{%
      ~\PfC@CentMillieme{\PfC@ListeEcriture[2]}%
    }{\xintifboolexpr{\LongueurDecimale == 4}{%
        ~\PfC@DixMillieme{\PfC@ListeEcriture[2]}%
      }{\xintifboolexpr{\LongueurDecimale == 3}{%
          ~\PfC@Millieme{\PfC@ListeEcriture[2]}%
        }{\xintifboolexpr{\LongueurDecimale == 2}{%
            ~\PfC@Centieme{\PfC@ListeEcriture[2]}%
          }{\xintifboolexpr{\LongueurDecimale == 1}{%
              ~\PfC@Dixieme{\PfC@ListeEcriture[2]}%
            }{}%
          }%
        }%
      }%
    }%
  }%
}%

%\begin{enumerate}
%\item\
%\end{enumerate}

\NewDocumentCommand\Ecriture{omO{m}}{%
  \useKVdefault[ClesEcriture]%
  \setKV[ClesEcriture]{#1}%
  \IfStrEq*{\languagename}{french}{}{\setKV[ClesEcriture]{Math}\setKV[ClesEcriture]{Tradition}}%
  \setsepchar{.}\ignoreemptyitems%
  \readlist*\PfC@ListeEcriture{#2}%
  \reademptyitems%
  \IfStrEq*{\languagename}{french}{%
    \ifboolKV[ClesEcriture]{Tradition}{%
      \fmtcountsetoptions{french={dash or space=traditional}}%
    }{%
      \fmtcountsetoptions{french={dash or space=always}}%
    }%
  }{}%
  \xintifboolexpr{\PfC@ListeEcriturelen == 2}{%
    \ifboolKV[ClesEcriture]{Majuscule}{%
      \ifboolKV[ClesEcriture]{Zero}{}{\Numberstringnum{\PfC@ListeEcriture[1]}}\ifboolKV[ClesEcriture]{Math}{\ifboolKV[ClesEcriture]{Zero}{}{\ifboolKV[ClesEcriture]{E}{e}{}~\PfC@NomUnite{\PfC@ListeEcriture[1]}}}{}\ifboolKV[ClesEcriture]{Tradition}{\IfStrEq*{\languagename}{english}{}{~}\PfC@NomVirgule~}{-\PfC@NomVirgule-}\numberstringnum{\PfC@ListeEcriture[2]}\ifboolKV[ClesEcriture]{Math}{\PfC@EcritureDecimale}{}%
    }{%
      \ifboolKV[ClesEcriture]{Zero}{}{\numberstringnum{\PfC@ListeEcriture[1]}}\ifboolKV[ClesEcriture]{Math}{\ifboolKV[ClesEcriture]{Zero}{}{\ifboolKV[ClesEcriture]{E}{e}{}~\PfC@NomUnite{\PfC@ListeEcriture[1]}}}{}\ifboolKV[ClesEcriture]{Tradition}{\IfStrEq*{\languagename}{english}{}{~}\PfC@NomVirgule~}{-\PfC@NomVirgule-}\numberstringnum{\PfC@ListeEcriture[2]}\ifboolKV[ClesEcriture]{Math}{\PfC@EcritureDecimale}{}%
    }%
  }{%
    \ifboolKV[ClesEcriture]{Majuscule}{%
      \Numberstringnum{\PfC@ListeEcriture[1]}[#3]\ifboolKV[ClesEcriture]{Math}{\ifboolKV[ClesEcriture]{E}{e}{}~\PfC@NomUnite{\PfC@ListeEcriture[1]}}{}%
    }{%
      \numberstringnum{\PfC@ListeEcriture[1]}[#3]\ifboolKV[ClesEcriture]{Math}{\ifboolKV[ClesEcriture]{E}{e}{}~\PfC@NomUnite{\PfC@ListeEcriture[1]}}{}%
     }%
  }%
}%
\makeatother
