% Language definition file (part of polyglossia v2.10 -- 2026/04/18)
%
\ProvidesFile{gloss-polish.ldf}[polyglossia: module for Polish]

\PolyglossiaSetup{polish}{
  bcp47=pl,
  bcp47-language=pl,
  bcp47-script=Latn,
  hyphennames={polish},
  hyphenmins={2,2},
  langtag=PLK,
  frenchspacing=true,
 }

% BCP-47 compliant aliases
\setlanguagealias*{polish}{pl}

\ifluatex
  \RequirePackage{luavlna}
\fi

\DeclareKeys[polyglossia/gloss/polish]
  {
    babelshorthands.if = polish@babelshorthands,
    babelshorthands.default:n = true,
    splithyphens.if = polish@splithyphens,
    splithyphens.default:n = true,
    vlna.if = polish@vlna,
    vlna.default:n = true,
  }

\ifsystem@babelshorthands
  \SetGlossOptions{polish}{babelshorthands=true}
  % Register default options
  \InitializeGlossOptions{polish}{babelshorthands=true,splithyphens=true,vlna=true}
\else
  \SetGlossOptions{polish}{babelshorthands=false}
  % Register default options
  \InitializeGlossOptions{polish}{babelshorthands=false,splithyphens=true,vlna=true}
\fi

\InitializeBabelShorthands

\let\xpg@hyphen@char-
\def\polish@@splhyphen#1{%
  \def\polish@sh@tmp{%
       \ifx\polish@sh@next\xpg@hyphen@char#1%
       \else\expandafter\polish@@@splhyphen{#1}\fi%
     }%
     \futurelet\polish@sh@next\polish@sh@tmp%
}

\def\polish@@@splhyphen#1{%
  \ifnum\hyphenchar \font>0%
    \kern\z@\discretionary{-}{\char\hyphenchar\the\font}{#1}%
    \nobreak\hskip\z@%
  \else%
    #1%
  \fi%
}

\def\polish@splhyphen{%
  \polish@@splhyphen{-}%
}

\def\polish@shorthands{%
  \xpg@activate@shorthands%
  \def\language@group{polish}%
  \declare@shorthand{polish}{"=}{\polish@splhyphen}%
  \declare@shorthand{polish}{""}{\xpg@invisible@break}%
  \declare@shorthand{polish}{"~}{\xpg@nobreak@hyphen}%
  \declare@shorthand{polish}{"-}{\xpg@add@hyphenation@point}%
  \declare@shorthand{polish}{"|}{\xpg@ligature@break}%
  \declare@shorthand{polish}{"/}{\xpg@breakable@slash}%
  \declare@shorthand{polish}{"`}{„}%
  \declare@shorthand{polish}{"'}{”}%
  \declare@shorthand{polish}{"<}{«}%
  \declare@shorthand{polish}{">}{»}%
}

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

\ifxetex
  % splithyphens
  \newXeTeXintercharclass\polish@hyphen % -
  % vlna
  \newXeTeXintercharclass\polish@openpunctuation
  \newXeTeXintercharclass\polish@nonsyllabicpreposition
  \ifdefined\e@alloc@intercharclass@top
    \chardef\polish@boundary=\e@alloc@intercharclass@top
  \else
    \ifdefined\XeTeXinterwordspaceshaping
      \chardef\polish@boundary=4095 %
      \def\newXeTeXintercharclass{%
        \e@alloc\XeTeXcharclass\chardef
              \xe@alloc@intercharclass\m@ne\@ucharclass@boundary}%
    \else
      \chardef\polish@boundary=255
    \fi
  \fi
\fi

\def\polish@hyphens{%
    \ifluatex
      \AfterPreamble{\enablesplithyphens{polish}}%
    \else
      \XeTeXinterchartokenstate=1
      \XeTeXcharclass `\- \polish@hyphen
      \XeTeXinterchartoks \z@ \polish@hyphen = {\polish@@splhyphen}% "-" -> "\polish@@splhyphen-"
      % necessary if used together with vlna:
      \XeTeXinterchartoks \polish@nonsyllabicpreposition \polish@hyphen = {\polish@@splhyphen}% "-" -> "\polish@@splhyphen-"
    \fi%
}

\def\nopolish@hyphens{%
    \ifluatex
      \AfterPreamble{\disablesplithyphens{polish}}%
    \else
      \XeTeXcharclass `\- \z@
    \fi%
}

% Add nonbreakable space after single-letter word to
% prevent them to land at the end of a line
% vlna code taken and adapted from xevlna.sty
\ifxetex
    \def\polish@nointerchartoks{\let\polish@interchartoks\polish@PreCSpreposition}%
    \def\polish@PreCSpreposition{%
       \def\next{}%
       \ifnum\catcode`\ =10 % nothing will be done in verbatim
       \ifmmode % nothing in math
       \else
          \let\polish@interchartoks\polish@nointerchartoks
          \let\next\polish@ExamineCSpreposition
       \fi\fi
       \next%
    }%
    \def\polish@ExamineCSpreposition #1{#1\futurelet\next\polish@ProcessCSpreposition}%
    \def\polish@ProcessCSpreposition{\ifx\next\polish@XeTeXspace\nobreak\fi}%
    \futurelet\polish@XeTeXspace{ }\polish@nointerchartoks
\fi

\def\polish@vlna{%
    \ifluatex
       \singlechars{polish}{AaIiOoUuWwZz}%
       \preventsingleon
    \else
        % Code taken and adapted from xevlna.sty
        \XeTeXinterchartokenstate=1
        \XeTeXcharclass `\( \polish@openpunctuation
        \XeTeXcharclass `\[ \polish@openpunctuation
        \XeTeXcharclass `\„ \polish@openpunctuation
        \XeTeXcharclass `\« \polish@openpunctuation
        \XeTeXcharclass `\W \polish@nonsyllabicpreposition
        \XeTeXcharclass `\w \polish@nonsyllabicpreposition
        \XeTeXcharclass `\Z \polish@nonsyllabicpreposition
        \XeTeXcharclass `\z \polish@nonsyllabicpreposition
        \XeTeXcharclass `\O \polish@nonsyllabicpreposition
        \XeTeXcharclass `\o \polish@nonsyllabicpreposition
        \XeTeXcharclass `\U \polish@nonsyllabicpreposition
        \XeTeXcharclass `\u \polish@nonsyllabicpreposition
        \XeTeXcharclass `\A \polish@nonsyllabicpreposition
        \XeTeXcharclass `\a \polish@nonsyllabicpreposition
        \XeTeXcharclass `\I \polish@nonsyllabicpreposition
        \XeTeXcharclass `\i \polish@nonsyllabicpreposition
        \XeTeXinterchartoks \polish@boundary \polish@nonsyllabicpreposition {\polish@interchartoks}%
        \XeTeXinterchartoks \polish@openpunctuation \polish@nonsyllabicpreposition {\polish@interchartoks}%
    \fi
}

\def\nopolish@vlna{%
    \ifluatex
        \preventsingleoff
    \else
        \XeTeXcharclass`\(\z@
        \XeTeXcharclass`\[\z@
        \XeTeXcharclass`\„\z@
        \XeTeXcharclass`\«\z@
        \XeTeXcharclass`\W\z@
        \XeTeXcharclass`\w\z@
        \XeTeXcharclass`\Z\z@
        \XeTeXcharclass`\z\z@
        \XeTeXcharclass`\O\z@
        \XeTeXcharclass`\o\z@
        \XeTeXcharclass`\U\z@
        \XeTeXcharclass`\u\z@
        \XeTeXcharclass`\A\z@
        \XeTeXcharclass`\a\z@
        \XeTeXcharclass`\I\z@
        \XeTeXcharclass`\i\z@
    \fi
}

\def\captionspolish{%
  \def\prefacename{Przedmowa}%
  \def\refname{Literatura}%
  \def\abstractname{Streszczenie}%
  \def\bibname{Bibliografia}%
  \def\chaptername{Rozdział}%
  \def\appendixname{Dodatek}%
  \def\contentsname{Spis treści}%
  \def\listfigurename{Spis rysunków}%
  \def\listtablename{Spis tabel}%
  \def\indexname{Indeks}%
  \def\figurename{Rysunek}%
  \def\tablename{Tabela}%
  \def\partname{Część}%
  \def\enclname{Załącznik}%
  \def\ccname{Kopie:}%
  \def\headtoname{Do}%
  \def\pagename{Strona}%
  \def\seename{Zobacz}%
  \def\alsoname{Zobacz też}%
  \def\proofname{Dowód}%
  \def\glossaryname{Słowniczek}%
}

\def\datepolish{%
  \def\today{\number\day\space\ifcase\month\or
      stycznia\or lutego\or marca\or kwietnia\or maja\or czerwca\or
      lipca\or sierpnia\or września\or października\or
      listopada\or grudnia\fi\space
      \number\year}%
}

\def\noextras@polish{%
  \ifpolish@babelshorthands\nopolish@shorthands\fi%
  \nopolish@hyphens%
  \nopolish@vlna%
  \ifxetex\XeTeXinterchartokenstate=0\fi%
}

\def\blockextras@polish{%
  \ifpolish@babelshorthands\polish@shorthands\else\nopolish@shorthands\fi%
  \ifpolish@vlna\polish@vlna\else\nopolish@vlna\fi%
  \ifpolish@splithyphens\polish@hyphens\else\nopolish@hyphens\fi%
}

\def\inlineextras@polish{%
  \ifpolish@babelshorthands\polish@shorthands\else\nopolish@shorthands\fi%
  \ifpolish@vlna\polish@vlna\else\nopolish@vlna\fi%
  \ifpolish@splithyphens\polish@hyphens\else\nopolish@hyphens\fi%
}

\def\nestedextras@polish{%
 \ifluatex%
  \ifpolish@vlna\polish@vlna\else\nopolish@vlna\fi%
  \ifpolish@splithyphens\polish@hyphens\else\nopolish@hyphens\fi%
 \fi%
}

\endinput
