% gloss-kazakh.ldf
% 
% Language definition file for Kazakh
%
% Copyright (C) 2026 Berik I. Tuleuov
%
% Kazakh translations and original language module:
%   Berik I. Tuleuov
%
% This file is part of the babel-kazakh package
% and provides Kazakh language support for Polyglossia.
%
% It 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 available at
%   https://www.latex-project.org/lppl.txt
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work is Berik I. Tuleuov
% Polyglossia language definition for Kazakh
% Encoding: UTF-8

\ProvidesFile{gloss-kazakh.ldf}
  [2026/10/30 v2.0 Polyglossia support for Kazakh]

% ------------------------------------------------
% Language name
% ------------------------------------------------
\PolyglossiaSetup{kazakh}{
  bcp47=kk,
  bcp47-language=kk,
  bcp47-script=Cyrl,
  script=Cyrillic,
  scripttag=cyrl,
  language=Kazakh,
  langtag=KAZ,
  hyphennames={kazakh},
  hyphenmins={2,2},
  frenchspacing=true,
  indentfirst=true
}

\setlanguagealias*{kazakh}{kk}

% ------------------------------------------------
% Captions in Kazakh
% ------------------------------------------------
\def\captionskazakh{%
  \def\prefacename{Алғысөз}%
  \def\refname{Пайдаланған әдебиет}%      Пайдаланылған әдебиеттер
  \def\abstractname{Түйіндеме}%
  \def\bibname{Әдебиет}%                  Әдебиеттер тізімі
  %\def\chaptername{Тарау}%
  %\def\appendixname{Қосымша}%
  \def\chaptername{тарау}%
  \def\appendixname{қосымша}%
  \def\contentsname{Мазмұны}%
  \def\listfigurename{Суреттер тізімі}%
  \def\listtablename{Кестелер тізімі}%
  \def\indexname{Көрсеткіш}%              Индекс
  %\def\figurename{Сурет}%
  %\def\tablename{Кесте}%
  %\def\partname{Бөлім}%
  \def\figurename{сурет}%
  \def\tablename{кесте}%
  \def\partname{бөлім}%
  \def\enclname{Қосымша}%
  \def\ccname{Көшірме}%
  \def\headtoname{Кімге}%
  \def\pagename{Бет}%
  \def\seename{қараңыз}%
  \def\alsoname{сондай-ақ қараңыз}%
  \def\proofname{Дәлелдеме}%              Дәлел
  \def\glossaryname{Сөздік}%
}
\def\datekazakh{%
   \def\today{%
     \number\day~\ifcase\month\or
       қаңтар\or ақпан\or наурыз\or сәуір\or мамыр\or маусым\or
       шілде\or тамыз\or қыркүйек\or қазан\or қараша\or желтоқсан%
     \fi
     \space\number\year\space ж.%
   }%
}

% ------------------------------------------------
% Date format
% ------------------------------------------------
%\def\kazakh@monthname#1{%
%  \ifcase#1\or
%    қаңтар\or ақпан\or наурыз\or сәуір\or мамыр\or маусым\or
%    шілде\or тамыз\or қыркүйек\or қазан\or қараша\or желтоқсан\fi}

%\def\kazakhdate{%
%  \number\day\space
%  \kazakh@monthname{\month}\space
%  \number\year\space ж.}

% \SetLocaleDateFormat{kazakh}{\kazakhdate}

% ------------------------------------------------
% Number–noun order:
%   1 бөлім, 3 тарау, A қосымша, 7 сурет, 10 кесте
% Standard LaTeX classes: article, report, book
% ------------------------------------------------

\let\xpg@save@fnum@figure\fnum@figure
\let\xpg@save@fnum@table\fnum@table

\def\kazakh@capsformat{%
  % Figures and tables
  \def\fnum@figure{\thefigure\space\figurename}%
  \def\fnum@table{\thetable\space\tablename}%

  % Chapters and appendices
  \ifcsdef{@makechapterhead}{%
    \let\xpg@save@kazakh@makechapterhead\@makechapterhead
    \patchcmd{\@makechapterhead}%
      {\@chapapp\space \thechapter}%
      {\thechapter\space\@chapapp}%
      {}%
      {\xpg@warning{Failed to patch chapter heading for Kazakh}}%
  }{}%
  
  % Running chapter headings
  \ifcsdef{chaptermark}{%
    \let\xpg@save@kazakh@chaptermark\chaptermark
    \patchcmd{\chaptermark}%
      {\@chapapp\ \thechapter.}%
      {\thechapter\ \@chapapp.}%
      {}%
      {\xpg@warning{Failed to patch chapter mark for Kazakh}}%
  }{}%

  % Parts; hyperref/nameref may use \NR@part
  \ifcsdef{NR@part}{%
    \let\xpg@save@kazakh@part\NR@part
    \patchcmd{\NR@part}%
      {\partname\nobreakspace\thepart}%
      {\thepart\nobreakspace\partname}%
      {}%
      {\xpg@warning{Failed to patch part heading for Kazakh}}%
  }{%
    \ifcsdef{@part}{%
      \let\xpg@save@kazakh@part\@part
      \patchcmd{\@part}%
        {\partname\nobreakspace\thepart}%
        {\thepart\nobreakspace\partname}%
        {}%
        {\xpg@warning{Failed to patch part heading for Kazakh}}%
    }{}%
  }%
}

\def\nokazakh@capsformat{%
  \let\fnum@figure\xpg@save@fnum@figure
  \let\fnum@table\xpg@save@fnum@table

  \ifcsdef{xpg@save@kazakh@makechapterhead}{%
    \let\@makechapterhead\xpg@save@kazakh@makechapterhead
  }{}%
  
  \ifcsdef{xpg@save@kazakh@chaptermark}{%
    \let\chaptermark\xpg@save@kazakh@chaptermark
  }{}%

  \ifcsdef{xpg@save@kazakh@part}{%
    \ifcsdef{NR@part}{%
      \let\NR@part\xpg@save@kazakh@part
    }{%
      \let\@part\xpg@save@kazakh@part
    }%
  }{}%
}

\def\blockextras@kazakh{%
  \kazakh@capsformat
}

\def\noextras@kazakh{%
  \nokazakh@capsformat
}


% ------------------------------------------------
% End of file
% ------------------------------------------------
\endinput
