%% fc-malagasy-numberwords.def
%% This work may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3c of this license
%% or (at your option) any later version. The latest version of this
%% license is in: https://www.latex-project.org/lppl.txt
%% This work has the LPPL maintenance status 'maintained'.
%% The Current Maintainer of this work is the malagasy-numberwords
%% contributors (RALAHADY Bruno Bakys, TOTOHASINA André).
%% This work consists of the files malagasy-numberwords.sty and
%% fc-malagasy-numberwords.def.
%%
%% Couche d'interoperabilite entre fmtcount et malagasy-numberwords (Étape 10 du
%% méta-prompt). Conformement à la section 15 ("ne pas dupliquer fmtcount, le
%% moteur linguistique doit rester independant"), ce fichier NE réimplémente PAS
%% la grammaire : il délègue entièrement aux macros \mnw@fullnumber et
%% \mnw@ordinal de malagasy-numberwords.sty (a charger AVANT ce fichier).
%%
%% Limite heritee de fmtcount lui-meme (pas de malagasy-numberwords) : les
%% macros \numberstring/\ordinalstring de fmtcount ne fonctionnent que pour
%% 0 <= n <= 99999 (verifie dans fc-english.def) ; malagasy-numberwords.sty va
%% bien au-dela (jusqu'a ~2^31), mais cette couche respecte la limite déclarée
%% de fmtcount pour rester un adaptateur fidele, pas un contournement silencieux.
%%
%% Le malgache n'a pas d'accord grammatical de genre sur les nombres : les
%% variantes M/F/N sont de simples alias les unes des autres (contrairement au
%% francais, qui a un fc-french.def substantiellement plus complexe pour cette
%% raison).
%%
%% Absence de notation ordinale abregee sourcee (type "1er"/"1st") pour le
%% malgache : \@ordinalM (utilisee par \ordinal, cense produire une forme
%% courte) delegue donc a la forme pleinement epelee (\ordinalstring) plutot
%% que d'inventer une abreviation non attestee.

\ProvidesFCLanguage{malagasy}[2026/09/05]%

\newcommand*{\@numberstringMmalagasy}[2]{%
  \ifnum#1>99999
    \PackageError{fmtcount}{Out of range}%
      {This macro only works for values less than 100000}%
  \else
    \ifnum#1<0
      \PackageError{fmtcount}{Negative numbers not permitted}%
        {malagasy-numberwords does not support negative numbers}%
    \fi
  \fi
  \mnw@fullnumber{#1}%
  \edef#2{\mnw@fullresult}%
}%
\global\let\@numberstringMmalagasy\@numberstringMmalagasy
\global\let\@numberstringFmalagasy=\@numberstringMmalagasy
\global\let\@numberstringNmalagasy=\@numberstringMmalagasy

\newcommand*{\@NumberstringMmalagasy}[2]{%
  \@numberstringMmalagasy{#1}{#2}%
  \edef#2{\expandafter\fc@malagasy@upperfirst#2\@nil}%
}%
\global\let\@NumberstringMmalagasy\@NumberstringMmalagasy
\global\let\@NumberstringFmalagasy=\@NumberstringMmalagasy
\global\let\@NumberstringNmalagasy=\@NumberstringMmalagasy

\newcommand*{\@ordinalstringMmalagasy}[2]{%
  \ifnum#1>99999
    \PackageError{fmtcount}{Out of range}%
      {This macro only works for values less than 100000}%
  \fi
  \mnw@ordinal{#1}%
  \edef#2{\mnw@ordinalresult}%
}%
\global\let\@ordinalstringMmalagasy\@ordinalstringMmalagasy
\global\let\@ordinalstringFmalagasy=\@ordinalstringMmalagasy
\global\let\@ordinalstringNmalagasy=\@ordinalstringMmalagasy

\newcommand*{\@OrdinalstringMmalagasy}[2]{%
  \@ordinalstringMmalagasy{#1}{#2}%
  \edef#2{\expandafter\fc@malagasy@upperfirst#2\@nil}%
}%
\global\let\@OrdinalstringMmalagasy\@OrdinalstringMmalagasy
\global\let\@OrdinalstringFmalagasy=\@OrdinalstringMmalagasy
\global\let\@OrdinalstringNmalagasy=\@OrdinalstringMmalagasy

% Pas de notation ordinale abregee sourcee -- \@ordinalM (utilisee par
% \ordinal) delegue a la forme pleinement epelee plutot que d'inventer une
% abreviation.
\newcommand*{\@ordinalMmalagasy}[2]{%
  \mnw@ordinal{#1}%
  \edef#2{\mnw@ordinalresult}%
}%
\global\let\@ordinalMmalagasy\@ordinalMmalagasy
\global\let\@ordinalFmalagasy=\@ordinalMmalagasy
\global\let\@ordinalNmalagasy=\@ordinalMmalagasy

% Mise en majuscule du premier caractere (pour Numberstring/Ordinalstring) --
% convention non sourcee specifiquement pour le malgache, calquee sur l'usage
% general de majuscule de phrase.
\def\fc@malagasy@upperfirst#1#2\@nil{\MakeUppercase{#1}#2}%
