% Language definition file (part of polyglossia v2.10 -- 2026/04/18)
%
\ProvidesFile{gloss-ukrainian.ldf}[polyglossia: module for Ukrainian]
% Strings taken from Babel
% and revised by Roman Kyrylych

\RequirePackage{xpg-cyrillicnumbers}

\PolyglossiaSetup{ukrainian}{%
  bcp47=uk,
  bcp47-language=uk,
  bcp47-script=Cyrl,
  script=Cyrillic,
  scripttag=cyrl,
  langtag=UKR,
  hyphennames={ukrainian},
  hyphenmins={2,2},
  frenchspacing=true,
   localnumeral=ukrainiannumerals,
  Localnumeral=Ukrainiannumerals
}

% BCP-47 compliant aliases
\setlanguagealias*{ukrainian}{uk}

\newif\ifcyrillic@numerals
\newif\ifcyrillic@asbuk@numerals

\DeclareKeys[polyglossia/gloss/ukrainian]
  {
    babelshorthands.if = ukrainian@babelshorthands,
    babelshorthands.default:n = true,
    mathfunctions.if = ukrainian@mathfunctions,
    mathfunctions.default:n = true,
    numerals.choice:,
    numerals / arabic.code =
      {%
        \cyrillic@numeralsfalse
        \cyrillic@asbuk@numeralsfalse
        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-latn}%
      },
    numerals / cyrillic.code =
      {%  
        \cyrillic@numeralstrue
        \cyrillic@asbuk@numeralsfalse
        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
      },
    numerals / cyrillic-trad.code =
      {%
        \cyrillic@numeralstrue
        \cyrillic@asbuk@numeralsfalse
        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
      },
    numerals / cyrillic-alph.code =
      {%
        \cyrillic@numeralstrue
        \cyrillic@asbuk@numeralstrue
        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
      },
    numerals.default:n = arabic,
    numerals/unknown.code = \xpg@warning{Unknown Ukrainian numerals value `#1'}
  }

\ifsystem@babelshorthands
  \SetGlossOptions{ukrainian}{babelshorthands=true}
  % Register default options
  \InitializeGlossOptions{ukrainian}{numerals=arabic,mathfunctions=true,babelshorthands=true}
\else
  \SetGlossOptions{ukrainian}{babelshorthands=false}
  % Register default options
  \InitializeGlossOptions{ukrainian}{numerals=arabic,mathfunctions=true,babelshorthands=false}
\fi

\InitializeBabelShorthands

\def\ukrainian@shorthands{%
  \xpg@activate@shorthands%
  \def\language@group{ukrainian}%
%  \declare@shorthand{ukrainian}{"`}{„}%
%  \declare@shorthand{ukrainian}{"'}{“}%
%  \declare@shorthand{ukrainian}{"<}{«}%
%  \declare@shorthand{ukrainian}{">}{»}%
  \declare@shorthand{ukrainian}{""}{\xpg@invisible@break}%
  \declare@shorthand{ukrainian}{"~}{\xpg@nobreak@hyphen}%
  \declare@shorthand{ukrainian}{"=}{\xpg@breakable@hyphen}%
  \declare@shorthand{ukrainian}{"|}{\xpg@ligature@break}%
  \declare@shorthand{ukrainian}{"-}{\xpg@cyrillic@dash}%
  \declare@shorthand{ukrainian}{",}{\xpg@thinspace@allow@hyphenation@after}%
}

\ifx\cyrdash\undefined
  \def\cyrdash{\leavevmode\hbox to.8em{\textendash\hss\textendash}}%
\fi

\def\noukrainian@shorthands{%
  \xpg@deactivate@shorthands%
}

\def\captionsukrainian{%
   \def\refname{Література}%
   \def\abstractname{Анотація}%
   \def\bibname{Бібліоґрафія}%
   \def\prefacename{Вступ}%
   \def\chaptername{Розділ}%
   \def\appendixname{Додаток}%
   \def\contentsname{Зміст}%
   \def\listfigurename{Перелік ілюстрацій}%
   \def\listtablename{Перелік таблиць}%
   \def\indexname{Покажчик}%
   \def\authorname{Іменний покажчик}% babel has "Їменний покажчик"
   \def\figurename{Рис.}%
   \def\tablename{Табл.}%
   %\def\thepart{}%
   \def\partname{Частина}%
   \def\pagename{с.}%
   \def\seename{див.}%
   \def\alsoname{див.\ також}%
   \def\enclname{вкладка}%
   \def\ccname{копія}%
   \def\headtoname{До}%
   \def\proofname{Доведення}%
   \def\glossaryname{Словник термінів}%
}

\def\dateukrainian{%
   \def\today{\number\day~\ifcase\month\or
    січня\or
    лютого\or
    березня\or
    квітня\or
    травня\or
    червня\or
    липня\or
    серпня\or
    вересня\or
    жовтня\or
    листопада\or
    грудня\fi%
    \space\number\year~р.}%
}

% The following is based on some ideas from ruscor.sty
\def\ukrainian@capsformat{%
  \def\@seccntformat##1{\csname pre##1\endcsname%
  \csname the##1\endcsname%
  \csname post##1\endcsname}%
  \def\@aftersepkern{\hspace{0.5em}}%
  \def\postchapter{.\@aftersepkern}%
  \def\postsection{.\@aftersepkern}%
  \def\postsubsection{.\@aftersepkern}%
  \def\postsubsubsection{.\@aftersepkern}%
  \def\postparagraph{.\@aftersepkern}%
  \def\postsubparagraph{.\@aftersepkern}%
  \def\prechapter{}%
  \def\presection{}%
  \def\presubsection{}%
  \def\presubsubsection{}%
  \def\preparagraph{}%
  \def\presubparagraph{}%
}

\newcommand{\ukrainiannumerals}[2]{\ukrainiannumber{#2}}
\newcommand{\Ukrainiannumerals}[2]{\Ukrainiannumber{#2}}

\def\ukrainiannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \ukrainian@asbuk@alph{#1}%
    \else
      \cyr@alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\def\Ukrainiannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \ukrainian@asbuk@Alph{#1}%
    \else
      \cyr@Alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\let\ukrainiannumeral=\ukrainiannumber
\let\Ukrainiannumeral=\Ukrainiannumber

\def\Asbuk#1{\expandafter\ukrainian@asbuk@Alph\csname c@#1\endcsname}
\def\asbuk#1{\expandafter\ukrainian@asbuk@alph\csname c@#1\endcsname}

\def\AsbukTrad#1{\expandafter\cyr@Alph\csname c@#1\endcsname}
\def\asbukTrad#1{\expandafter\cyr@alph\csname c@#1\endcsname}

% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
% thus ends at 30.
\def\ukrainian@asbuk@Alph#1{\ifcase#1\or
   А\or Б\or В\or Г\or Д\or Е\or Ж\or
   З\or И\or К\or Л\or М\or Н\or О\or
   П\or Р\or С\or Т\or У\or Ф\or Х\or
   Ц\or Ч\or Ш\or Щ\or Э\or Ю\or Я%
   \else\xpg@ill@value{#1}{ukrainian@asbuk@Alph}\fi%
}

\def\ukrainian@asbuk@alph#1{\ifcase#1\or
   а\or б\or в\or г\or д\or е\or ж\or
   з\or и\or к\or л\or м\or н\or о\or
   п\or р\or с\or т\or у\or ф\or х\or
   ц\or ч\or ш\or щ\or э\or ю\or я%
   \else\xpg@ill@value{#1}{ukrainian@asbuk@alph}\fi%
}

\def\ukrainian@numbers{%
  \ifcyrillic@numerals
     \def\ukrainian@alph##1{\expandafter\ukrainiannumeral\expandafter{\the##1}}%
     \def\ukrainian@Alph##1{\expandafter\Ukrainiannumeral\expandafter{\the##1}}%
     \let\@Alph\ukrainian@Alph%
     \let\@alph\ukrainian@alph%
  \fi
}

\def\noukrainian@numbers{%
   \let\@Alph\latin@Alph%
   \let\@alph\latin@alph%
}

\def\noextras@ukrainian{%
  \def\@seccntformat##1{\csname the##1\endcsname\quad}% = LaTeX kernel
  \ifcyrillic@numerals\noukrainian@numbers\fi
  \ifukrainian@babelshorthands\noukrainian@shorthands\fi%
}

\def\blockextras@ukrainian{%
  \ukrainian@capsformat%
  \ifcyrillic@numerals\ukrainian@numbers\else\noukrainian@numbers\fi%
  \ifukrainian@babelshorthands\ukrainian@shorthands\else\noukrainian@shorthands\fi%
}

\def\inlineextras@ukrainian{%
  \ifukrainian@babelshorthands\ukrainian@shorthands\else\noukrainian@shorthands\fi%
}

%%% stuff from Babel
\AtBeginDocument{%
\ifukrainian@mathfunctions%
  \def\sh{\mathop{\operator@font sh}\nolimits}
  \def\ch{\mathop{\operator@font ch}\nolimits}
  \def\tg{\mathop{\operator@font tg}\nolimits}
  \def\arctg{\mathop{\operator@font arctg}\nolimits}
  \def\arcctg{\mathop{\operator@font arcctg}\nolimits}
  \def\ctg{\mathop{\operator@font ctg}\nolimits}
  \def\cth{\mathop{\operator@font cth}\nolimits}
  \def\cosec{\mathop{\operator@font cosec}\nolimits}
  \def\Prob{\mathop{\kern\z@\mathsf{P}}\nolimits}
  \def\Variance{\mathop{\kern\z@\mathsf{D}}\nolimits}
  \def\nsd{\mathop{\mathrm{н.с.д.}}\nolimits}
  \def\nsk{\mathop{\mathrm{н.с.к.}}\nolimits}
  \def\NSD{\mathop{\mathrm{НСД}}\nolimits}
  \def\NSK{\mathop{\mathrm{НСК}}\nolimits}
  \def\nod{\mathop{\mathrm{н.о.д.}}\nolimits}
  \def\nok{\mathop{\mathrm{н.о.к.}}\nolimits}
  \def\NOD{\mathop{\mathrm{НОД}}\nolimits}
  \def\NOK{\mathop{\mathrm{НОК}}\nolimits}
  \def\Proj{\mathop{\mathrm{пр}}\nolimits}
\fi
}

\endinput
