texlive[52555] Master/texmf-dist: polyglossia (28oct19)

commits+karl at tug.org commits+karl at tug.org
Mon Oct 28 21:58:50 CET 2019


Revision: 52555
          http://tug.org/svn/texlive?view=revision&revision=52555
Author:   karl
Date:     2019-10-28 21:58:49 +0100 (Mon, 28 Oct 2019)
Log Message:
-----------
polyglossia (28oct19)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/polyglossia/README
    trunk/Master/texmf-dist/doc/latex/polyglossia/example-arabic.pdf
    trunk/Master/texmf-dist/doc/latex/polyglossia/example-korean.pdf
    trunk/Master/texmf-dist/doc/latex/polyglossia/example-thai.pdf
    trunk/Master/texmf-dist/doc/latex/polyglossia/examples.pdf
    trunk/Master/texmf-dist/doc/latex/polyglossia/polyglossia.pdf
    trunk/Master/texmf-dist/doc/latex/polyglossia/polyglossia.tex
    trunk/Master/texmf-dist/source/latex/polyglossia/polyglossia.dtx
    trunk/Master/texmf-dist/tex/latex/polyglossia/babel-hebrewalph.def
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-albanian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arabic.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-armenian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-asturian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasai.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasam.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-basque.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bengali.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-brazil.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-breton.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bulgarian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-catalan.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-croatian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-czech.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-danish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-divehi.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dutch.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-english.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-esperanto.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-estonian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-farsi.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-finnish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-french.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulan.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-galician.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-german.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-greek.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hebrew.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hindi.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-icelandic.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-interlingua.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-irish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-italian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kannada.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-khmer.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-korean.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lao.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latin.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latvian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lithuanian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lsorbian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-macedonian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-magyar.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-marathi.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nko.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norsk.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nynorsk.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-occitan.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-piedmontese.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-polish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuges.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romanian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romansh.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-russian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-samin.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sanskrit.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-scottish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-serbian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovak.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovenian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swedish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-syriac.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-thai.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-tibetan.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ukrainian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-urdu.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-usorbian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-welsh.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/hebrewcal.sty
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-frpt.lua
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.lua
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty
    trunk/Master/texmf-dist/tex/latex/polyglossia/xgreek-fixes.def

Added Paths:
-----------
    trunk/Master/texmf-dist/tex/latex/polyglossia/cyrillicnumbers.sty
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gaelic.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hungarian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurdish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latex.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malay.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mongolian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norwegian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-persian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuguese.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sami.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sorbian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-korean.lua

Removed Paths:
-------------
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-classiclatin.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-liturgicallatin.ldf

Modified: trunk/Master/texmf-dist/doc/latex/polyglossia/README
===================================================================
--- trunk/Master/texmf-dist/doc/latex/polyglossia/README	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/doc/latex/polyglossia/README	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,7 +1,7 @@
 
    ¦----------------------------------------------¦
    ¦                                              ¦
-   ¦       THE POLYGLOSSIA PACKAGE v1.44          ¦
+   ¦       THE POLYGLOSSIA PACKAGE v1.45          ¦
    ¦                                              ¦
    ¦     Modern multilingual typesetting          ¦
    ¦        with XeLaTeX and LuaLaTeX             ¦
@@ -10,7 +10,8 @@
 
 This package provides an alternative to Babel for users of XeLaTeX and LuaLaTeX
 (with a few languages incompletely supported for the latter). This version
-includes support for 78 different languages.
+includes support for 75 different languages, some of which in different regional,
+national or scriptal varieties.
 
 Polyglossia makes it possible to automate the following tasks:
 
@@ -28,7 +29,8 @@
 * For languages that have their own numeration system, modifying the formatting
   of numbers appropriately.
 * Ensuring the proper directionality if the document contains languages
-  written from right to left (via the package bidi, available separately).
+  written from right to left (via the packages bidi and luabidi, available
+  separately).
 
 LICENSE
 
@@ -39,13 +41,13 @@
 LICENCE.txt for the text of the LPPL v1.3c, or
 http://www.latex-project.org/lppl.txt for the latest version.
 
-This work has the LPPL maintenance status ‘maintained’.  The current maintainer is Arthur Reutenauer.
+This work has the LPPL maintenance status ‘maintained’.  The current maintainer is
+Arthur Reutenauer.
 
 BUGS
 
-Polyglossia is full of bugs.  If you run into one, or suspect you do, or you
-have a request or comment, please use the GitHub issue tracker:
-http://github.com/reutenauer/polyglossia/issues
+If you run into a bug, or suspect you do, or you have a request or comment, please
+use the GitHub issue tracker: http://github.com/reutenauer/polyglossia/issues
 
 This is more efficient than contacting me by email as it allows me to track the
 issues and follow progress.

Modified: trunk/Master/texmf-dist/doc/latex/polyglossia/example-arabic.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/polyglossia/example-korean.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/polyglossia/example-thai.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/polyglossia/examples.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/polyglossia/polyglossia.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/polyglossia/polyglossia.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/polyglossia/polyglossia.tex	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/doc/latex/polyglossia/polyglossia.tex	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,11 +1,14 @@
+% !TeX spellcheck = en_US
+% !TeX TS-program = xelatex
 \documentclass[11pt]{ltxdoc}
 \usepackage{color}
-\usepackage{xspace,fancyvrb}
+\usepackage{xspace,fancyvrb,booktabs}
 \usepackage[neverdecrease]{paralist}
 \definecolor{myblue}{rgb}{0.02,0.04,0.48}
 \definecolor{lightblue}{rgb}{0.61,.8,.8}
 \definecolor{myred}{rgb}{0.65,0.04,0.07}
 \usepackage[
+    unicode=true,
     bookmarks=true,
     colorlinks=true,
     linkcolor=myblue,
@@ -13,8 +16,8 @@
     citecolor=myblue,
     hyperindex=false,
     hyperfootnotes=false,
-    pdftitle={Polyglossia: An alternative to Babel for XeLaTeX and LuaLaTeX},
-    pdfauthor={F Charette, A Reutenauer},
+    pdftitle={Polyglossia: Modern multilingual typesetting with XeLaTeX and LuaLaTeX},
+    pdfauthor={F Charette, A Reutenauer, B Roucariès, J Spitzmüller},
     pdfkeywords={xetex, xelatex, luatex, lualatex, multilingual, babel, hyphenation}
     ]{hyperref}
 \usepackage{metalogo}
@@ -23,7 +26,7 @@
 \usepackage[babelshorthands]{polyglossia}
 \usepackage{farsical}
 \setmainlanguage[variant=british,ordinalmonthday=false]{english}
-\setotherlanguages{arabic,hebrew,syriac,greek,russian,catalan}
+\setotherlanguages{arabic,armenian,hebrew,syriac,greek,russian,serbian,catalan}
 \usepackage[protrusion]{microtype}
 \newcommand*\Cmd[1]{\cmd{#1}\DescribeMacro{#1}\xspace}
 \newcommand*\pkg[1]{\textsf{\color{myblue}#1}}
@@ -31,6 +34,7 @@
 \newcommand*\TR[1]{\textcolor{myred}{#1}}
 \newcommand*\TX[1]{\hyperref[#1]{\textcolor{myred}{#1}}}
 \newcommand*\TB[1]{\textcolor{myblue}{\bf #1}}
+\newcommand*\TA[1]{\textsc{\color{myblue}#1}}
 \newcommand*\link[1]{\href{#1}{#1}}
 \def\eg{\textit{e.g.,}\xspace}
 \def\ie{\textit{i.e.,}\xspace}
@@ -52,12 +56,25 @@
 \renewenvironment{itemize}{\begin{compactitem}[\char"2023]}%[{\fontspec{DejaVu Sans}\char"25BB}]}%
 		{\end{compactitem}}
 \renewenvironment{enumerate}{\begin{compactenum}}{\end{compactenum}}
+\newenvironment{shorthands}{%
+	 \begin{list}{}%
+	 	{\settowidth{\labelwidth}{MM}%
+	 	 \setlength{\leftmargin}{\labelwidth}%
+	 	 \addtolength{\leftmargin}{\labelsep}%
+	     \renewcommand{\makelabel}[1]{##1\hfil}}}%
+	{\end{list}}
 
+% This is to prevent page breaks too short after subsections
+\def\condbreak#1{%
+	\vskip 0pt plus #1\pagebreak[3]\vskip 0pt plus -#1\relax}
+\pretocmd{\subsection}{\condbreak{2\baselineskip}}{}{}
+
 %% fontspec declarations:
 \setmainfont{Linux Libertine O}
 \setsansfont{Linux Biolinum O}
 \setmonofont[Scale=MatchLowercase]{DejaVu Sans Mono}
 \newfontfamily\arabicfont[Script=Arabic]{Amiri}
+\newfontfamily\armenianfont[Script=Armenian]{DejaVu Sans}
 \newfontfamily\syriacfont[Script=Syriac]{Serto Jerusalem}
 \newfontfamily\hebrewfont[Script=Hebrew]{Ezra SIL}
 
@@ -68,14 +85,17 @@
 \RecordChanges
 % COMMENT THE NEXT LINE TO INCLUDE THE CODE
 \AtBeginDocument{\OnlyDescription}
+
+
 \begin{document}
-\hyphenation{Kha-li-ghi}
+\hyphenation{Kha-li-ghi Reu-ten-auer}
 \GetFileInfo{polyglossia.sty}
 
 \title{\textcolor{lightblue}{\Huge\fontspec[LetterSpace=40]{GFS Ambrosia} Πολυγλωσσια}
 \\[16pt]
-\color{myblue}Polyglossia: An Alternative to Babel for \XeLaTeX\ and \LuaLaTeX}
-\author{\scshape\color{myblue}François Charette\\\color{myblue}Current maintainer: \scshape Arthur Reutenauer}
+\color{myblue}Polyglossia: Modern multilingual typesetting with \XeLaTeX\ and \LuaLaTeX}
+\author{\TA{François Charette} \and \TA{Arthur Reutenauer}\thanks{Current maintainer}
+	    \and \TA{Bastien Roucariès} \and \TA{Jürgen Spitzmüller}}
 \date{\filedate \qquad \fileversion\\
 \footnotesize (\textsc{pdf} file generated on \today)}
 
@@ -93,8 +113,8 @@
 
 \section{Introduction}
 
-Polyglossia is a package for facilitating multilingual typesetting with
-\XeLaTeX\ and (at an early stage) \LuaLaTeX.  Basically, it
+\pkg{Polyglossia} is a package for facilitating multilingual typesetting with
+\XeLaTeX\ and (with some exceptions) \LuaLaTeX.  Basically, it
 can be used as an alternative to \pkg{babel} for performing the following
 tasks automatically:
 
@@ -126,43 +146,39 @@
 and modern. The package \pkg{antomega} has been very beneficial in our attempt to
 reach this objective.
 
-\paragraph{Requirements:} The current version of \pkg{polyglossia} makes use of some convenient
-macros defined in the \pkg{etoolbox} package by Philipp Lehmann. Being designed
-for \XeLaTeX\ and \LuaLaTeX, it obviously also relies on \pkg{fontspec} by Will
-Robertson. For languages written from right to left, it needs the package \pkg{bidi}
-by Vafa Khalighi (\textarabic{وفا خليقي}). Polyglossia also bundles three packages for calendaric
-computations (\pkg{hebrewcal}, \pkg{hijrical}, and \pkg{farsical}).
+\paragraph{Requirements} The current version of \pkg{polyglossia} makes use of some convenient
+macros defined in the \pkg{etoolbox} package by \TA{Philipp Lehmann} and \TA{Joseph Wright}.
+Being designed for \XeLaTeX\ and \LuaLaTeX, it obviously also relies on \pkg{fontspec} by
+\TA{Will Robertson}. For languages written from right to left, it needs the package \pkg{bidi}
+(for \XeTeX) or  \pkg{luabidi} (for \LuaTeX) by \TA{Vafa Khalighi} (\textarabic{وفا خليقي}) and
+the \pkg{bidi-tex GitHub Organisation}.
+Polyglossia also bundles three packages for calendaric computations (\pkg{hebrewcal},
+\pkg{hijrical}, and \pkg{farsical}).
 
-\section{Loading language definition files}
 
-\subsection{The recommended way}
-You can determine the default language by means of the command:
-	\displaycmd{\setdefaultlanguage[⟨options⟩]\{lang\}}{\setdefaultlanguage}
-(or equivalently \Cmd\setmainlanguage).
-Secondary languages can be loaded with
-	\displaycmd{\setotherlanguage[⟨options⟩]\{lang\}.}{\setotherlanguage}
-These commands have the advantage of being explicit and of allowing you to set
-language-specific options.\footnote{ %
-	More on language-specific options below.}
-It is also possible to load a series of secondary languages at once using
-	\displaycmd{\setotherlanguages\{lang1,lang2,lang3,…\}.}{\setotherlanguages}
-Language-specific options can be set or changed at any time by means of
-	\displaycmd{\setkeys\{⟨lang⟩\}\{opt1=value1,opt2=value2,…\}.}{\setkeys}
+\section{Setting up multilingual documents}
 
+\subsection{Activating languages}
 
-\subsection{The “Babel way” – obsolete}
-\new{v1.2.0}
-{\color{red}\bfseries Warning}: \pkg{polyglossia} no longer supports loading
-language definition files as package options!
-%As with \pkg{babel}, \pkg{polyglossia} also allows you to load language definition files
-%as package options. In most cases, option \texttt{⟨lang⟩} will load the file
-%\file{gloss-⟨lang⟩.ldf}. Note however that the \textit{first} language listed in \\
-%\centerline{\cmd{\usepackage[lang1,lang2,…]{polyglossia}}}
-%will be the default language for the document, which
-%is the opposite convention of \pkg{babel}.
-%Note also that this method may not work in some cases, and should be
-%considered deprecated.
+The default language of a document is specified by means of the command
+	\displaycmd{\setdefaultlanguage[⟨options⟩]\{⟨lang⟩\}}{\setdefaultlanguage}
+(or, equivalently, \Cmd\setmainlanguage).
+Secondary languages are specified with
+	\displaycmd{\setotherlanguage[⟨options⟩]\{⟨lang⟩\}.}{\setotherlanguage}
+All these commands allow you to set language-specific options.\footnote{%
+	Section~\ref{specific} documents these options for the respective languages.}
+It is also possible to load a series of secondary languages at once (but without options)
+using
+	\displaycmd{\setotherlanguages\{⟨lang1⟩,⟨lang2⟩,⟨lang3⟩,…\}.}{\setotherlanguages}
 
+All language-specific options can be modified locally by means of the
+language-switching commands described in section \ref{languageswitching}.
+
+\paragraph{Note} In general, it is advisable to activate the languages \emph{after} all
+packages have been loaded. This is particularly important if you use right-to-left scripts
+or languages with babel shorthands.
+
+
 \subsection{Supported languages}
 
 Table~\ref{tab:lang} lists all languages currently supported.
@@ -169,69 +185,156 @@
 Those in red have specific options and/or commands
 that are explained in section \ref{specific} below.
 
-\begin{table}[h]\centering
+\begin{table}[ht]\centering
 \label{tab:lang}
-% Produced with tools/insert-language-list.rb -- AR, 2015-07-14
-% Edited by hand -- AR 2019-04-04
+% Produced with tools/insert-language-list.rb -- JS, 2019-10-18
+% Edited by hand -- JS, 2019-10-18
 \begin{tabular}{lllll}
-\hline
-albanian       & danish         & interlingua    & nko            & \TX{slovenian}\\
-amharic        & divehi         & irish          & norsk          & spanish       \\
-\TX{arabic}    & \TX{dutch}     & \TX{italian}   & nynorsk        & swedish       \\
-armenian       & \TX{english}   & kannada        & occitan        & \TX{syriac}   \\
-asturian       & \TX{esperanto} & khmer          & piedmontese    & tamil         \\
-bahasai        & estonian       & \TX{korean}    & polish         & telugu        \\
-bahasam        & \TX{farsi}     & \TX{lao}       & portuges       & \TX{thai}     \\
-basque         & finnish        & \TX{latin}     & romanian       & tibetan       \\
-\TX{bengali}   & french         & latvian        & romansh        & turkish       \\
-brazil[ian]    & friulan        & lithuanian     & \TX{russian}   & turkmen       \\
-breton         & galician       & \TX{lsorbian}  & samin          & \TX{ukrainian}\\
-bulgarian      & \TX{german}    & \TX{magyar}    & \TX{sanskrit}  & urdu          \\
-\TX{catalan}   & \TX{greek}     & macedonian     & scottish       & \TX{usorbian} \\
-coptic         & \TX{hebrew}    & malayalam      & \TX{serbian}   & vietnamese    \\
-croatian       & \TX{hindi}     & marathi        & slovak         & \TX{welsh}    \\
-czech          & icelandic      \\
-\hline
+\toprule
+albanian     & \TX{dutch}     & interlingua  & \TX{mongolian}  & \TX{slovenian}\\
+amharic      & \TX{english}   & \TX{italian} & nko             & \TX{sorbian}\\
+\TX{arabic}  & \TX{esperanto} & japanese     & \TX{norwegian}  & spanish\\
+\TX{armenian}& estonian       & kannada      & occitan         & swedish\\
+asturian     & \TX{finnish}   & khmer        & \TX{persian}    & \TX{syriac}\\
+basque       & \TX{french}    & \TX{korean}  & piedmontese     & tamil\\
+\TX{bengali} & friulian       & \TX{kurdish} & polish          & telugu\\
+breton       & \TX{gaelic}    & \TX{lao}     & \TX{portuguese} & \TX{thai}\\
+bulgarian    & galician       & \TX{latin}   & romanian        & \TX{tibetan}\\
+\TX{catalan} & \TX{german}    & latvian      & romansh         & turkish\\
+coptic       & \TX{greek}     & lithuanian   & \TX{russian}    & turkmen\\
+croatian     & \TX{hebrew}    & macedonian   & \TX{sami}       & \TX{ukrainian}\\
+\TX{czech}   & \TX{hindi}     & \TX{malay}   & \TX{sanskrit}   & urdu\\
+danish       & \TX{hungarian} & malayalam    & \TX{serbian}    & vietnamese\\
+divehi       & icelandic      & marathi      & slovak          & \TX{welsh}\\
+\bottomrule
 \end{tabular}
+
+
 \caption{Languages currently supported in \pkg{polyglossia}}
 \end{table}
 
-\textit{NB:} The support for Amharic\new{v1.0.1} should be considered an experimental attempt to
-port the package \pkg{ethiop}.\footnote{ Feedback is welcome.}
+\paragraph{Version Notes} The support for Amharic\new{v1.0.1} should be considered an experimental attempt to
+port the package \pkg{ethiop}.\footnote{Feedback is welcome.}
 Version 1.1.1\new{v1.1.1} added support for Asturian, %\footnote{ Provided by Kevin Godby and Xuacu Saturio.}, 
 Lithuanian, %\footnote{ Provided by Kevin Godby and Paulius Sladkevičius.},
 and Urdu. %\footnote{ Provided by Kamal Abdali.}
 %
 Version 1.2\new{v1.2.0} adds support for Armenian, Occitan, Bengali,
-Lao, Malayalam, Marathi, Tamil, Telugu, and Turkmen.\footnote{ %
+Lao, Malayalam, Marathi, Tamil, Telugu, and Turkmen.\footnote{%
   See acknowledgements at the end for due credit to the various contributors.}
+Version 1.43\new{v1.43} silently introduced basic support for Japanese. This
+is considered experimental, and feedback is appreciated.
+In version 1.45\new{v1.45}, support for Kurdish and Mongolian as well as some new
+variants (Canadian French and English) have been added. Furthermore,  for consistency reasons, some language have
+been renamed (\emph{farsi}\textrightarrow\emph{persian}, \emph{friulan}\textrightarrow\emph{friulian},
+\emph{magyar}\textrightarrow\emph{hungarian}, \emph{portuges}\textrightarrow\emph{portuguese},
+\emph{samin}\textrightarrow\emph{sami}) or merged (\emph{bahasai}\slash\emph{bahasam}\textrightarrow\emph{malay},
+\emph{brazil}\slash\emph{portuges}\textrightarrow\emph{portuguese},
+\emph{lsorbian}\slash\emph{usorbian}\textrightarrow\emph{sorbian},
+\emph{irish}\slash\emph{scottish}\textrightarrow\emph{gaelic},
+\emph{norsk}\slash\emph{nynorsk}\textrightarrow\emph{norwegian}). The old names are still supported for backwards
+compatibility reasons, but they might not give access to newer language features.
 
 
+\subsection{Relation to Babel languages}
 
-Polyglossia can also be loaded with the option
-‘babelshorthands’\new{v1.1.1}, which globally activates \pkg{babel}
-shorthands whenever available. Currently shorthands are implemented for
-Catalan, Dutch, German, Italian, and Russian: see these respective
-languages for details.
+If you are familiar with the \pkg{babel} package, you will note that \pkg{polyglossia}'s language naming
+slightly differs. Whereas \pkg{babel} has a unique name for each language variety (\eg\emph{american} and \emph{british}),
+\pkg{polyglossia} differentiates language varieties via language options.
 
-Another option (turned off by default) is ‘localmarks’, which
-redefines the internal \LaTeX\ macros \cmd\markboth\ and \cmd\markright.
-\new{v1.2.0}Note that this was formerly turned on by default, but we
-now realize that it causes more problems than otherwise. For backwards-compatibility
-the opposite option ‘nolocalmarks’ is still available.
+Furthermore, \pkg{babel} uses sometimes abbreviations for language names (\eg\emph{bahasam} for Bahasa Malayu) as well
+as endonyms, \ie language names coming from the designated languages (such as \emph{bahasa}, \emph{canadien} or \emph{magyar}).
+As opposed to this, \pkg{polyglossia} always uses spelled-out (lower-cased) English language names.
 
-There is also the option ‘quiet’ which turns off most info messages and some of the warnings
-issued by \LaTeX, \pkg{fontspec} and \pkg{polyglossia}.
+Table~\ref{tab:bbllang} lists the language names that differ in both packages. \pkg{Babel} names marked in red can also be used
+in \pkg{polyglossia} as an alias.\footnote{This is for historical reasons, since earlier versions of \pkg{polyglossia} used
+	those names as well. Note, however, that you need to use the matching language switching commands, then, as
+    well, \eg \cmd\textportuges\ with \emph{portuges} (rather than \cmd\textportuguese).}
 
-\section{Language-switching commands}
+\begin{table}
+\label{tab:bbllang}
+\begin{tabular}{lll}
+\toprule 
+\textbf{Babel name} & \textbf{Polyglossia name} & \textbf{Polyglossia options}\tabularnewline
+\midrule
+acadien         & french     & variant=acadian                \\
+american        & english    & \emph{(default)}               \\
+australian      & english    & variant=australian             \\
+austrian        & german     & variant=austrian, spelling=old \\
+bahasa          & malay      & \emph{(default)}               \\
+\TR{bahasam}    & malay      & variant=malaysian              \\
+\TR{brazil}     & portuguese & variant=brazilian              \\
+british         & english    & variant=british                \\
+canadian        & english    & variant=canadian               \\
+canadien        & french     & variant=canadian               \\
+\TR{farsi}      & persian    &                                \\
+\TR{friulan}    & friulian   &                                \\
+german          & german     & spelling=old                   \\
+\TR{irish}      & gaelic     & variant=irish                  \\
+kurmanji        & kurdish    & variant=kurmanji               \\
+lowersorbian    & sorbian    & variant=lower                  \\
+\TR{magyar}     & hungarian  &                                \\
+naustrian       & german     & variant=austrian               \\
+newzealand      & english    & variant=newzealand             \\
+ngerman         & german     & \emph{(default)}               \\
+\TR{norsk}      & norwegian  & variant=bokmal                 \\
+nswissgerman    & german     & variant=swiss                  \\
+\TR{nynorsk}    & norwegian  & \emph{(default)}               \\
+polutonikogreek & greek      & variant=polytonic              \\
+\TR{portuges}   & portuguese & \emph{(default)}               \\
+\TR{samin}      & sami       &                                \\
+\TR{scottish}   & gaelic     & variant=scottish               \\
+serbianc        & serbian    & script=Cyrillic                \\
+slovene         & slovenian  &                                \\
+swissgerman     & german     & variant=swiss, spelling=old    \\
+uppersorbian    & sorbian    & variant=upper                  \\
+\bottomrule
+\end{tabular}
+	
+\caption{Babel-polyglossia language name matching}
+\end{table}
 
-Whenever a language definition file \file{gloss-⟨lang⟩.ldf} is loaded,
-the command \cmd{\text⟨lang⟩[⟨options⟩]\{…\}} \DescribeMacro{\text⟨lang⟩}
+
+\subsection{Global options}
+
+\pkg{Polyglossia} can be loaded with the following global package options:
+
+\begin{itemize}
+	\item \TB{babelshorthands}\new{v1.1.1} globally activates \pkg{babel}
+          shorthands whenever available. Currently shorthands are implemented for
+          Catalan, Czech, Dutch, Finnish, German, Italian, Mongolian, and Russian.
+          Please refer to the respective language descriptions (sec.~\ref{specific}) for details.
+
+    \item \TB{localmarks} redefines the internal \LaTeX\ macros \cmd\markboth\ and \cmd\markright.
+          In earlier versions of \pkg{polyglossia},\new{v1.2.0} this option was set by default, but we
+          now realize that it causes more problems than it helps, so it is now off by default.
+          For backwards-compatibility, the option \TB{nolocalmarks} which used to switch off the previous
+          default, and now does nothing, is still available.
+
+    \item \TB{quiet} turns off most info messages and some of the warnings issued by \LaTeX,
+          \pkg{fontspec} and \pkg{polyglossia}.
+\end{itemize}
+
+\section{Language-switching commands}\label{languageswitching}
+
+\subsection{Recommended commands}
+For each activated language the command
+\cmd{\text⟨lang⟩[⟨options⟩]\{…\}} \DescribeMacro{\text⟨lang⟩}
 becomes available for short insertions of text in that language.
 For example ¦\textrussian{\today}¦ yields \textrussian{\today}
-Longer passages are better put between the environment ¦⟨lang⟩¦
-(again with the possibility of setting language options locally.
-\DescribeEnv{⟨lang⟩}
+This command switches to the correct hyphenation patterns, it activates
+some extra features for the selected language (such as extra spacing before
+punctuation in French), and it translates the date when using ¦\today¦.
+It does not, however, translate so-called \textit{caption strings}, i.\,e.
+``chapter'', ``figure'' etc., to the local language (these remain in the main
+language).
+
+The\DescribeEnv{⟨lang⟩}\ environment ¦⟨lang⟩¦, which is also available for any activated language,
+is meant for longer passages of text. It behaves slightly different than the \cmd{\text⟨lang⟩\{…\}}
+command: It does everything the latter does, but additionally, the caption strings are translated
+as well, and the language is also passed to auxiliary files, the table of contents and the lists of
+figures/tables.
+Like the command, the environment provides the possibility of setting language options locally.
 For instance the following allows us to quote the beginning
 of Homer’s \textit{Iliad}:
 
@@ -252,10 +355,31 @@
 \end{greek}
 \bigskip
 
-Note that for Arabic one cannot use the environment ¦arabic¦,
+\noindent\DescribeEnv{Arabic} Note that for Arabic one cannot use the environment ¦arabic¦,
 as \cmd\arabic\ is defined internally by \LaTeX. In this case
-we need to use the environment ¦Arabic¦ instead\DescribeEnv{Arabic}.
+we need to use the environment ¦Arabic¦ instead.
 
+\subsection{Babel commands}
+Some macros defined in \pkg{babel}’s \file{hyphen.cfg} (and thus usually
+compiled into the \XeLaTeX\ and \LuaLaTeX\ format) are redefined, but keep a
+similar behaviour.
+\begin{itemize}
+\item \DescribeMacro{\selectlanguage}\cmd{\selectlanguage[⟨options⟩]\{⟨lang⟩\}}
+\item \DescribeMacro{\foreignlanguage}\cmd{\foreignlanguage[⟨options⟩]\{⟨lang⟩\}\{…\}}
+\item \DescribeEnv{otherlanguage}\cmd{\begin\{otherlanguage\}[⟨options⟩]\{⟨lang⟩\}} \dots{} \cmd{\end\{otherlanguage\}}
+\item \DescribeEnv{otherlanguage*}\cmd{\begin\{otherlanguage*\}[⟨options⟩]\{⟨lang⟩\}} \dots{} \cmd{\end\{otherlanguage*\}}
+\end{itemize}
+%
+¦\selectlanguage{⟨lang⟩}¦ and the ¦otherlanguage¦ environment are identical to the
+the ¦⟨lang⟩¦ environment, except that ¦\selectlanguage{⟨lang⟩}¦
+does not need to be explicitly closed. The command ¦\foreinlanguage{⟨lang⟩}{…}¦ and the ¦otherlanguage*¦
+environment are identical with the use of the ¦\text⟨lang⟩¦ command, with the one
+notable exception that they do not translate the date with ¦\today¦.
+
+Since the \XeLaTeX\ and \LuaLaTeX\ format incorporate \pkg{babel}’s \file{hyphen.cfg},
+the low-level commands for hyphenation and language switching
+defined there are also accessible.
+
 \subsection{Other commands}
 The following commands are probably of lesser interest to the end user, but
 ought to be mentioned here.
@@ -268,19 +392,14 @@
 	to another one in the middle of a document: \textit{this may have adverse effects}!
 
 \item \Cmd\normalfontlatin: in an environment where \cmd\normalfont\ has been redefined
-	to a non-latin script, this will call the font defined with \cmd\setmainfont\ etc.
-	Likewise it is possible to use \Cmd\rmfamilylatin, \Cmd\sffamilylatin,
+	to a non-latin script, this will reset to the font defined with \cmd\setmainfont\ etc.
+	In a similar vein, it is possible to use \Cmd\rmfamilylatin, \Cmd\sffamilylatin,
 	and \Cmd\ttfamilylatin.
 
-\item Some macros defined in \pkg{babel}’s \file{hyphen.cfg} (and thus usually
-	compiled into the \XeLaTeX\ and \LuaLaTeX\ format) are redefined, but keep a similar
-	behaviour, namely \Cmd\selectlanguage, \Cmd\foreignlanguage,
-	and the environment ¦otherlanguage¦\DescribeEnv{otherlanguage}.
+\item \Cmd\latinalph: Representation of counter as a lower-case letter:  1 = a, 2 = b, etc.
+
+\item \Cmd\latinAlph: Representation of counter as a uper-case letter:  1 = A, 2 = B, etc.
 \end{itemize}
-%
-Since the \XeLaTeX\ and \LuaLaTeX\ format incorporate \pkg{babel}’s \file{hyphen.cfg},
-the low-level commands for hyphenation and language switching
-defined there are also accessible.
 
 \section{Font setup}
 
@@ -307,14 +426,35 @@
 does not appear to support the script of that language, an error message is
 displayed.
 
-\section{Hyphenation disabling}
+\section{Adapting hyphenation}
 
+\subsection{Hyphenation exceptions}
+
+\TeX\ provides the command ¦\hyphenation{⟨exceptions⟩}¦ to globally define hyphenation exceptions
+which override the hyphenation patterns for specified words. The command takes as argument a space-separated
+list of words where hyphenation points are marked by a dash (if no dash is used, the respective word is not
+hyphenated at all):
+\begin{Verbatim}
+\hyphenation{%
+  po-ly-glos-sia
+  LaTeX
+}
+\end{Verbatim}
+%
+These exceptions, however, apply to all languages. In addition to this, \pkg{polyglossia} provides
+the command\new{v.1.45}
+\displaycmd{\pghyphenation[⟨options⟩]\{⟨lang⟩\}\{⟨exceptions⟩\}}{\pghyphenation}
+which can be used to define exceptions that only apply to a specific language or language variant,
+respectively.
+
+\subsection{Hyphenation disabling}
+
 In some very specific contexts (such as music score creation), \TeX{} hyphenation
 is something to avoid as it may cause troubles. \pkg{polyglossia} provides two
-functions: \cmd\disablehyphenation{} and \cmd\enablehyphenation . Note that when
-you select a new language, hyphenation will be in the same state (enabled or
-disabled) as before. When you reenable it, it will take the last selected
-language.
+functions: \Cmd\disablehyphenation\ and \Cmd\enablehyphenation. Note that if
+you select a new language while hyphenation is disabled, it will remain disabled.
+If you re-enable it, the hyphenation patterns of the currently selected language
+will be activated.
 
 \section{Language-specific options and commands}\label{specific}
 
@@ -324,7 +464,7 @@
 %\subsection{amharic}\label{amharic}
 
 \subsection{arabic}\label{arabic}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
 	\item \TB{calendar} = \textit{gregorian} or islamic (= hijri)
 	\item \TB{locale} = \textit{default},\footnote{ %
@@ -339,7 +479,7 @@
   \item \TB{abjadjimnotail} = \textit{false} or true. \new{v1.0.3}
     Set this to true if you want the \textit{abjad} form of the number three to be \textarabic{ج‍} – as in the manuscript tradition – instead of the modern usage \textarabic{ج}.
 	\end{itemize}
-\textbf{Commands}:
+\paragraph*{Commands:}
 	\begin{itemize}
 	\item \Cmd\abjad and \Cmd\abjadmaghribi (see section \ref{abjad})
   \item \Cmd\aemph to emphasize text with ¦\overline¦.\new{v1.2.0}
@@ -347,8 +487,15 @@
     This command is also available for Farsi, Urdu, etc.
 	\end{itemize}
 
-\subsection{bengali}\label{bengali}\new{v1.2.0}
-\textbf{Options}:
+\subsection{armenian}\label{armenian}
+\paragraph*{Options:}
+\begin{itemize}
+	\item \TB{variant}\new{v1.45} = eastern or \textit{western}
+	\item \TB{numerals}\new{v1.45} = armenian or \textit{arabic}
+\end{itemize}
+
+\subsection[bengali]{bengali\new{v1.2.0}}\label{bengali}
+\paragraph*{Options:}
 	\begin{itemize}
 		\item \TB{numerals} = Western, Bengali or \textit{Devanagari}
 		\item \TB{changecounternumbering} = true or \textit{false} (use specified
@@ -356,70 +503,129 @@
 	\end{itemize}
 
 \subsection{catalan}\label{catalan}
-\textbf{Options:}
+\paragraph*{Options:}
 \begin{itemize}
   \item \TB{babelshorthands} = \textit{false} or true. \new{v1.1.1}
     Activates the shorthands \texttt{"l} and \texttt{"L} to type geminated l’s.
 \end{itemize}
-\textbf{Commands}:
+
+\paragraph*{Commands:}
 \begin{itemize}
-  \item \Cmd{\l.l} and \Cmd{\L.L} behave as in \pkg{babel} to type a geminated l, as in \textit{co\l.laborar}. \new{v1.1.1}
-    In polyglossia the same can also be achieved with \Cmd{\l·l} and \Cmd{\L·L}.\footnote{ %
-        NB: · is the glyph U+00B7 MIDDLE DOT.}
+  \item \Cmd{\l.l} and \Cmd{\L.L}\new{v1.1.1} can be used to type a geminated l, as in \textit{co\l.laborar},
+        similar to \pkg{babel} (the glyph U+00B7 MIDDLE DOT is used as a geminating sign).
 \end{itemize}
 
+\subsection{czech}\label{czech}
+
+\paragraph*{Options:}
+\begin{itemize}
+	\item \TB{babelshorthands} = \textit{false} or true. \new{v1.45}
+	if this is turned on, the following shorthands for Czech are activated:
+	\begin{shorthands}
+		\item[¦"=¦] for an explicit hyphen sign which is repeated at the beginning
+		            of the next line when hyphenated, as common in Czech typesetting
+		            (also see option ¦splithyphens¦).
+		\item[¦"‘¦] for Czech left double quotes (looks like ,,).
+		\item[¦"’¦] for Czech right double quotes (looks like “).
+		\item[¦">¦] for Czech left double guillemets (looks like >>).
+		\item[¦"<¦] for Czech right double guillemets (looks like <<).
+	\end{shorthands}
+	\item \TB{splithyphens} = \textit{false} or true. \new{v1.45}
+	      According to Czech typesetting conventions, if a word with a hard hyphen (such as \emph{je-li})
+	      is hyphenated at this hyphen, a second hyphenation character is to be inserted at the beginning
+	      of the line that follows the hyphenation (\emph{je-/-li}).\\
+          If this option is true, this is done automatically (so the shorthand ¦"=¦ is not needed).
+          Note, however, that the option is only available for \XeTeX. If you are using \LuaTeX,
+          load the \pkg{luavlna} package to the same effect.
+    \item \TB{vlna} = \textit{false} or true. \new{v1.45}
+         According to Czech typesetting conventions, single-letter words (non-syllable prepositions)
+         must not occur at line ends.\\
+         If this option is true, this is taken care of. Note, however, that the option
+         is only available for \XeTeX. If you are using \LuaTeX, load the \pkg{luavlna} package
+         to the same effect.
+\end{itemize}
+
 \subsection{dutch}\label{dutch}
-\textbf{Options:}
+\paragraph*{Options:}
 \begin{itemize}
   \item \TB{babelshorthands} = \textit{false} or true. \new{v1.1.1}
-		if this is turned on, all shorthands defined in \pkg{babel}
-		for fine-tuning the hyphenation of Dutch words are activated.
-		\begin{itemize}
-		\item ¦"-¦ for an explicit hyphen sign, allowing hyphenation in the rest of the word
-		\item ¦"~¦ for a compound word mark without a breakpoint
-		\item ¦"|¦ disables the ligature at this position
-		\item ¦""¦ is like ¦"-¦, but produces no hyphen sign
-			(for compound words with a hyphen, e.g., ¦foo-""bar¦)
-		\item ¦"/¦ to enable hyphenation in two words written together but separated by a slash.
-    \item In addition, the macro \Cmd\- is redefined to allow hyphens in the rest of the word.
-		\end{itemize}
+		if this is turned on, the following shorthands defined for fine-tuning hyphenation and
+		micro-typography of Dutch words are activated:
+		\begin{shorthands}
+		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+			        in the hyphenation patterns (as opposed to ¦\-¦ in default \TeX).
+		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
+			        cases where the hyphen should stick at the following syllable.
+		\item[¦"|¦] disables a ligature at this position.
+		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
+		\item[¦"/¦] a slash that allows for a subsequent line break. As opposed to ¦\slash¦,
+		            hyphenation at the breakpoints preset in the hyphenation patterns is still allowed.
+		\end{shorthands}
+        In addition, the macro \Cmd\- is redefined to allow hyphens in the rest of the word (equivalent to ¦"-¦).
 \end{itemize}
 
 \subsection{english}\label{english}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
-	\item \TB{variant} = \textit{american} (= us), usmax (same as ‘american’ but with additional hyphenation patterns), british (= uk), australian or newzealand
+	\item \TB{variant} = \textit{american} (= us), usmax (same as ‘american’ but with additional hyphenation patterns),
+	british (= uk), australian, canadian\new{v1.45} or newzealand
 	\item \TB{ordinalmonthday} = true/\textit{false} (true by default only when variant = british)
 	\end{itemize}
 
 \subsection{esperanto}\label{esperanto}
-\textbf{Commands}:
+\paragraph*{Commands:}
 	\begin{itemize}
-	\item \Cmd\hodiau\ and \Cmd\hodiaun are special forms of \cmd\today\ (see the \pkg{babel} documentation)
+	\item \Cmd\hodiau\ and \Cmd\hodiaun are special forms of \cmd\today. The former produces the date in Esperanto
+	      preceded by the article (\emph{la}), which is the most common date format.
+	      The latter produces the same date format in accusative case.
 	\end{itemize}
 
-\subsection{farsi}\label{farsi}
-\textbf{Options}:
-	\begin{itemize}
-	\item \TB{numerals} = western or \textit{eastern}
-	\item \TB{locale} (not yet implemented)
-	\item \TB{calendar} (not yet implemented)
-	\end{itemize}
-\textbf{Commands}:
-	\begin{itemize}
-	\item \Cmd\abjad (see section \ref{abjad})
-  \item \Cmd\aemph (see section \ref{arabic}).
-	\end{itemize}
+\subsection{finnish}\label{finnish}
+\paragraph*{Options:}
+\begin{itemize}
+  \item \TB{babelshorthands} = \textit{false} or true. \new{v1.45}
+		if this is turned on, the following shorthands for fine-tuning hyphenation and micro-typography
+		of Finnish words are activated:
+		\begin{shorthands}
+		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+                    in the hyphenation patterns (as opposed to ¦\-¦).
+        \item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
+                    cases where the hyphen should stick at the following syllable.
+        \item[¦"|¦] disables a ligature at this position.
+        \item[¦""¦] allows for a line break at this position (without hyphenation sign).
+        \item[¦"/¦] a slash that allows for a subsequent line break. As opposed to ¦\slash¦,
+                  hyphenation at the breakpoints preset in the hyphenation patterns is still allowed.
+		\end{shorthands}
+\end{itemize}
 
-\subsection{french}\label{french}\new{v1.5.0}
-\textbf{Options}:
+\subsection{french}\label{french}
+\paragraph*{Options:}
 	\begin{itemize}
-		\item \TB{automaticspacesaroundguillemets} = true or \textit{false} (default value = true. Adds space after the opening guillemets and before the closing guillemets. Such space is usually not typed in source code, and you should let polyglossia add it. However, if your source code contains such space, you can set this option to false.)
-		\item \TB{frenchfootnote} = true or \textit{false} (default value = true. Determines whether the footnote mark starting the footnote is normal script followed by a dot (default) or superscript without a dot.)
+		\item\TB{variant} = \textit{french} or canadian (=~acadian).\new{v1.45}
+		Currently, the three variants do not differ; they are supported for compatibility with \pkg{babel} (where they do not differ either).
+		\item \TB{autospacing} = true or \textit{false} (default value = true). One of the most distinct features of French typography is the addition
+		of extra spacing around punctuation and quotation marks (guillemets). By default, polyglossia adds these spaces automatically, so you don't need
+		to enter them. This options allows you to switch this feature off globally.
+		\item \TB{autospaceguillemets}\footnote{Up to version 1.44, the option was called \textit{automaticspacesaroundguillemets}. For backards compatibility reasons, the more verbose old option is still supported.} = true or \textit{false} (default value = true). If you only want to disable the automatic addition of spacing after opening and before closing guillemets (and not at punctuation), set this to \textit{false}. Note
+		that the more general option \textit{autospacing} overrides this.
+		\item \TB{autospacetypewriter}\footnote{Babel's syntax \textit{OriginalTypewriter} is also supported.}\new{1.45} = true or \textit{false} (default value = true). By default, automatic spacing is disabled in typewriter font. If this is enabled, spacing in typewriter context is the same as with roman and sans serif font, depending on the \textit{autospacing} and \textit{autospaceguillemets} settings (note that this was the default up to v.~1.44).	
+		\item \TB{frenchfootnote} = true or \textit{false} (default value = true). If \textit{true}, footnotes start with a non-superscripted number followed by a dot, as common in French typography. Note that this might interfere with the specific footnote handling of classes or packages.
+		Also note that this option is only functional (by design) if French is the main language.
 	\end{itemize}
+\paragraph*{Commands:}
+\begin{itemize}
+	\item \Cmd\NoAutoSpacing\new{v1.45} disables automatic spacing around punctuation and quotation marks in all following text. The command can also be used locally if braces are used for grouping: ¦{\NoAutoSpacing foo:bar}¦
+	\item \Cmd\AutoSpacing\new{v1.45} enables automatic spacing around punctuation and quotation marks in all following text. The command can also be used locally if braces are used for grouping: ¦{\AutoSpacing regarde!}¦
+\end{itemize}
 
+\subsection[gaelic]{gaelic\new{v1.45}}\label{gaelic}
+\paragraph*{Options:}
+\begin{itemize}
+	\item \TB{variant} = \textit{irish} or scottish
+\end{itemize}
+
 \subsection{german}\label{german}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
 	\item\TB{variant} = \textit{german}, austrian or swiss.\new{v1.33.4}
 		Setting variant=austrian or variant=swiss uses some lexical variants.
@@ -434,39 +640,43 @@
 		the file \texttt{language.dat} that comes with \TeX Live 2008 and later.
 	\item\TB{babelshorthands} = \textit{false} or true: \new{v1.0.3}
 		if this is turned on, all shorthands defined in \pkg{babel}
-		for fine-tuning the hyphenation of German words are activated.
-		\begin{itemize}
-		\item  ¦"ck¦ for ¦ck¦ to be hyphenated as ¦k-k¦
-		\item  ¦"ff¦ for ¦ff¦ to be hyphenated as ¦ff-f¦; this is also available for the letters l, m, n, p, r and t
-		\item ¦"|¦ disables the ligature at this position
-		\item ¦"-¦ for an explicit hyphen sign, allowing hyphenation in the rest of the word
-		\item ¦""¦ is like ¦"-¦, but produces no hyphen sign
-			(for compound words with a hyphen, e.g., ¦foo-""bar¦)
-		\item ¦"~¦ for a compound word mark without a breakpoint
-		\item ¦"=¦ for a compound word mark with a breakpoint,
-			allowing hyphenation in the composing words.
-		\item ¦"/¦ a slash that allows for a line break and maintains hyphenation points.
-		\end{itemize}
+		for fine-tuning hyphenation and micro-typography of German words are activated.
+		\begin{shorthands}
+		\item[¦"ck¦] for ¦ck¦ to be hyphenated as ¦k-k¦ (1901 spelling).
+		\item[¦"ff¦] for ¦ff¦ to be hyphenated as ¦ff-f¦ (1901 spelling); this is also available
+		           for the letters l, m, n, p, r and t.
+		\item[¦"|¦] disables a ligature at this position (\eg ¦Auf"|lage¦).
+		\item[¦"=¦] for an explicit hyphen with a breakpoint, allowing for hyphenation at the
+		           other points preset in the hyphenation patterns (as opposed to plain ¦-¦).
+		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
+		           cases where the hyphen should stick at the following syllable,\eg ¦bergauf und "~ab¦.
+		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+		           in the hyphenation patterns (as opposed to ¦\-¦).
+		\item[¦""¦] allows for a line break at this position (without hyphenation sign); 
+		           \eg ¦(pseudo"~)""wissenschaftlich¦.
+		\item[¦"/¦] a slash that allows for a subsequent line break. As opposed to ¦\slash¦, hyphenation at the breakpoints
+		           preset in the hyphenation patterns is still allowed.
+		\end{shorthands}
 
 		There are also four shorthands for quotation signs:
-		\begin{itemize}
-		\item  ¦"`¦ for German left double quotes („)
-		\item  ¦"'¦ for German right double quotes (“)
-		\item  ¦"<¦ for French left double quotes («)
-		\item  ¦">¦ for French right double quotes (»).
-		\end{itemize}
+		\begin{shorthands}
+		\item[¦"`¦] for German left double quotes („)
+		\item[¦"'¦] for German right double quotes (“)
+		\item[¦"<¦] for French left double quotes («)
+		\item[¦">¦] for French right double quotes (»).
+		\end{shorthands}
 	\item\TB{script} = \textit{latin} or fraktur.\new{v1.2.0}
 		Setting script=fraktur modifies the captions for typesetting German in Fraktur.
 	\end{itemize}
 
 \subsection{greek}\label{greek}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
 	\item \TB{variant} = \textit{monotonic} (= mono), polytonic (= poly), or ancient
 	\item \TB{numerals} = \textit{greek} or arabic
 	\item \TB{attic} = \textit{false}/true
 	\end{itemize}
-\textbf{Commands}:
+\paragraph*{Commands:}
 	\begin{itemize}
 	\item \Cmd\Greeknumber and \Cmd\greeknumber \ (see section \ref{abjad}).
 	\item The command \Cmd\atticnumeral (= \Cmd\atticnum) (activated with
@@ -477,116 +687,251 @@
 	\end{itemize}
 
 \subsection{hebrew}\label{hebrew}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
 	\item \TB{numerals} = hebrew or \textit{arabic}
 	\item \TB{calendar} = hebrew or \textit{gregorian}
+	\item \TB{marcheshvan} = true or \textit{false} (default value = true). If true, the second month of the civil year will be output as \texthebrew{מרחשון} (Marcheshvan)
+	rather than \texthebrew{חשון} (Heshvan), which is the default.
 	\end{itemize}
-\textbf{Commands}:
+\paragraph*{Commands:}
 	\begin{itemize}
 	\item \Cmd\hebrewnumeral\ (= \Cmd\hebrewalph) (see section \ref{abjad}).
   \item \Cmd\aemph (see section \ref{arabic}).
 	\end{itemize}
 
-\subsection{hindi}\label{hindi}\new{v1.2.0}
-\textbf{Options}:
+\subsection[hindi]{hindi\new{v1.2.0}}\label{hindi}
+\paragraph*{Options:}
 	\begin{itemize}
     \item \TB{numerals} = Western or \textit{Devanagari}
 	\end{itemize}
 
+\subsection{hungarian}\label{hungarian}
+\paragraph*{Commands:}
+\begin{itemize}
+	\item \Cmd\ontoday\ (= \Cmd\ondatehungarian): special form of \cmd\today\ which produces a slightly different
+	date format as used in prepositional phrases (such as ‘on February 10th’) in Hungarian.
+\end{itemize}
+
 \subsection{italian}\label{italian}
-\textbf{Option:}
+\paragraph*{Options:}
 \begin{itemize}
   \item \TB{babelshorthands} = \textit{false} or true. \new{v1.2.0cc}% TODO: check version
-	Activates the ¦"¦ character as a switch to perform etymological
-	hyphenation when followed by a letter, or other tasks when followed by
-	certain analphabetic characters; in particular ¦""¦ is used to enter
-	double raised open quotes (the Italian keyboard misses the backtick),
-	and ¦"<¦  and ¦">¦ to insert open and closed guillemets without any
-	spacing after the open or before the closed sign. ¦"/¦ is made
-	equivalent to \slash allowing a linebreak after the slash without any
-	hyphen sign; ¦"-¦ produces  a short rule/hyphen and a discretional line
-	break alowing line breaks in the second compound word fragment.
+  Activates the ¦"¦ character as a switch to perform etymological
+  hyphenation when followed by a letter. Furthermore, the following shorthands are activated:
+  \begin{shorthands}
+  	\item[¦""¦] double raised open quotes (the Italian keyboard misses the backtick).
+  	\item[¦"<¦] open guillemet (looks like <<).
+  	\item[¦">¦] closing guillemet (looks like >>).
+  	\item[¦"/¦] a slash that allows for a subsequent line break. As opposed to ¦\slash¦,
+               hyphenation at the breakpoints preset in the hyphenation patterns is still allowed.
+  	\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+               in the hyphenation patterns (as opposed to ¦\-¦).
+  \end{shorthands}
 \end{itemize}
 
-\subsection{korean}\label{korean}\new{v1.40.0}
-The language definition file includes U. S. hyphenation patterns in order to
-enable hyphenation when writing English within Korean text.
+\subsection[korean]{korean\new{v1.40.0}}\label{korean}
+\paragraph*{Options:}
+  \begin{itemize}
+  \item \TB{variant} = \textit{plain}, classic or modern:
+    for spacing before/after CJK punctuations.
+    `classic' is suitable for text with no interword spaces,
+    `modern' for text with interword spaces.
+  \item \TB{captions} = \textit{hangul} or hanja
+  \end{itemize}
 
-\subsection{lao}\label{lao}\new{v1.2.0}
-\textbf{Options}:
+\subsection[kurdish]{kurdish\new{v1.45}}\label{kurdish}
+Kurdish support includes Sorani Kurdish and Kurmanji Kurdish, both in either Arabic or Latin script.
+
+\paragraph*{Options:}
+\begin{itemize}
+	\item \TB{variant} = kurmanji or \textit{sorani}
+	\item \TB{script} = Arabic or Latin. Defaults are ¦Arabic¦ for Sorani and ¦Latin¦ for Kurmanji.
+	\item \TB{numerals} = western or eastern. Defaults are ¦western¦ for Latin and ¦eastern¦ for Arabic script, depending on the selection above.
+	\item \TB{abjadjimnotail} = \textit{false} or true.
+	Set this to true if you want the \textit{abjad} form of the number three to be \textarabic{ج‍} – as in the manuscript tradition – instead of the modern usage \textarabic{ج}.
+	\item \TB{locale} (not yet implemented)
+	\item \TB{calendar} (not yet implemented)
+\end{itemize}
+\paragraph*{Commands:}
+\begin{itemize}
+	\item \Cmd\ontoday: special form of \cmd\today\ which produces a slightly different
+	date format as used in prepositional phrases (as in ‘on February 10th’). Only available for Latin script.
+	\item \Cmd\abjad (see section \ref{abjad})
+	\item \Cmd\aemph (see section \ref{arabic})
+\end{itemize}
+
+\subsection[lao]{lao\new{v1.2.0}}\label{lao}
+\paragraph*{Options:}
 	\begin{itemize}
 	\item \TB{numerals} = lao or \textit{arabic}
 	\end{itemize}
 
 \subsection{latin}\label{latin}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
 	\item \TB{variant} = classic, medieval or \textit{modern}
 	\end{itemize}
 
-\subsection{lsorbian and usorbian}\label{lsorbian}\label{usorbian}
-\textbf{Commands}:
-	\begin{itemize}
-	\item \Cmd\oldtoday : see the \pkg{babel} documentation.
-	\end{itemize}
+\subsection{malay}\label{malay}
+\paragraph*{Options:}
+\begin{itemize}
+	\item \TB{variant}\new{v1.45} = \textit{indonesian} (=~bahasai in \pkg{babel}) or
+	malaysian (=~bahasam in \pkg{babel})
+\end{itemize}
 
-\subsection{magyar}\label{magyar}
-\textbf{Commands}:
-	\begin{itemize}
-	\item \Cmd\ontoday\ (= \Cmd\ondatemagyar): special forms of \cmd\today\
-		(see the \pkg{babel} documentation).
-	\end{itemize}
+\subsection[mongolian]{mongolian\new{v1.45}}\label{mongolian}
+Currently, only the Khalkha variety in Cyrillic script is supported.
 
+\paragraph*{Options:}
+\begin{itemize}
+	\item \TB{babelshorthands} = \textit{false} or true.
+	If this is turned on, the following shorthands are activated:
+	\begin{shorthands}
+        \item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+		           in the hyphenation patterns (as opposed to ¦\-¦).
+		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
+		           cases where the hyphen should stick at the following syllable.
+		\item[¦"|¦] disables a ligature at this position.
+		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
+		\item[¦"---¦] Cyrillic emdash in plain text.
+		\item[¦"--~¦] Cyrillic emdash in compound names (surnames).
+		\item[¦"--*¦] Cyrillic emdash for denoting direct speech.
+		\item[¦",¦] thinspace for initials with a breakpoint in following surname.
+		\item[¦"‘¦] for German left double quotes (looks like ,,).
+		\item[¦"’¦] for German right double quotes (looks like “).
+		\item[¦"<¦] for French left double quotes (looks like <<).
+		\item[¦">¦] for French right double quotes (looks like >>).
+	\end{shorthands}
+	\item \TB{numerals} = \textit{arabic} or cyrillic. Uses either Arabic numerals or Cyrillic
+	alphanumerical numbering.
+\end{itemize}
+%
+\paragraph*{Commands:}
+\begin{itemize}
+	\item \Cmd\Asbuk: produces uppercased Cyrillic alphanumerals, for
+	environments such as ¦enumerate¦. The command takes a counter as argument,
+	\eg ¦\textrussian{\Asbuk{page}}¦ produces \textrussian{\Asbuk{page}}.
+	\item \Cmd\asbuk: same in lowercase
+\end{itemize}
 
+\subsection{norwegian}\label{norwegian}
+\paragraph*{Options:}
+\begin{itemize}
+	\item \TB{variant}\new{v1.45} = bokmal (=~`norsk' in \pkg{babel}) or \textit{nynorsk}
+\end{itemize}
+
+\subsection{persian}\label{persian}
+\paragraph*{Options:}
+\begin{itemize}
+	\item \TB{numerals} = western or \textit{eastern}
+	\item \TB{abjadjimnotail} = \textit{false} or true. \new{v1.0.3}
+	Set this to true if you want the \textit{abjad} form of the number three to be \textarabic{ج‍} – as in the manuscript tradition – instead of the modern usage \textarabic{ج}.
+	\item \TB{locale} (not yet implemented)
+	\item \TB{calendar} (not yet implemented)
+\end{itemize}
+\paragraph*{Commands:}
+\begin{itemize}
+	\item \Cmd\abjad (see section \ref{abjad})
+	\item \Cmd\aemph (see section \ref{arabic}).
+\end{itemize}
+
+\subsection{portuguese}\label{portuguese}
+\paragraph*{Options:}
+\begin{itemize}
+	\item \TB{variant}\new{v1.45} = brazilian or \textit{portuguese}
+\end{itemize}
+
 \subsection{russian}\label{russian}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
-	\item \TB{babelshorthands} = \textit{false} or true. % TODO check and document!
+	\item \TB{babelshorthands} = \textit{false} or true.
+	If this is turned on, the following shorthands are activated:
+	\begin{shorthands}
+		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+		           in the hyphenation patterns (as opposed to ¦\-¦).
+		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
+		           cases where the hyphen should stick at the following syllable.
+		\item[¦"|¦] disables a ligature at this position.
+		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
+		\item[¦"---¦] Cyrillic emdash in plain text.
+		\item[¦"--~¦] Cyrillic emdash in compound names (surnames).
+		\item[¦"--*¦] Cyrillic emdash for denoting direct speech.
+% These are commented out in gloss-russian
+%		\item[¦",¦] thinspace for initials with a breakpoint in following surname.
+%		\item[¦"‘¦] for German left double quotes (looks like ,,).
+%		\item[¦"’¦] for German right double quotes (looks like “).
+%		\item[¦"<¦] for French left double quotes (looks like <<).
+%		\item[¦">¦] for French right double quotes (looks like >>).
+	\end{shorthands}
 	\item \TB{spelling} = \textit{modern} or old (for captions and date only, not for hyphenation)
+	\item \TB{numerals} = \textit{arabic} or cyrillic. Uses either Arabic numerals or Cyrillic
+	alphanumerical numbering.
 	\end{itemize}
-
-\textbf{Commands}:
+%
+\paragraph*{Commands:}
 	\begin{itemize}
-	\item \Cmd\Asbuk: produces the uppercase Russian alphabet, for
-	environments such as ¦enumerate¦
+	\item \Cmd\Asbuk: produces uppercased Cyrillic alphanumerals, for
+	environments such as ¦enumerate¦. The command takes a counter as argument,
+	\eg ¦\textrussian{\Asbuk{page}}¦ produces \textrussian{\Asbuk{page}}.
 	\item \Cmd\asbuk: same in lowercase
 	\end{itemize}
 
+\subsection[sami]{sami\new{v1.45}}\label{sami}
+Currently support for Sami is limited to Northern Sami.
+
 \subsection{sanskrit}\label{sanskrit}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
-	\item \TB{Script} (default = Devanagari). \new{v1.0.2}
-	The value is passed to \pkg{fontspec} in cases where ¦\sanskritfont¦ or
-	¦\devanagarifont¦ are not defined. This can be useful if you typeset
-	Sanskrit texts in scripts other than Devanagari.
-	  %TODO \item Numerals <<<<
+	\item \TB{Script} = \textit{Devanagari}\new{v1.0.2}, Gujarati, Malayalam, Bengali, Kannada,
+	Telugu or Latin.
+	The value is passed to \pkg{fontspec} in cases where the respective ¦\<script>font¦ is not defined.
+	This can be useful if you typeset Sanskrit texts in scripts other than Devanagari.
+	\item \TB{Numerals} = \textit{Devanagari}\new{v1.45} or Western
 	\end{itemize}
-  \pkg{polyglossia} currently supports the typesetting of Sanskrit in the
-  following writing systems: Devanagari, Gujarati, Malayalam, Bengali, Kannada,
-  Telugu, and Latin.  Use the ¦Script=¦ option to select the writing system 
-  you want, and enter your input in that script.
  
 \subsection{serbian}\label{serbian}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
-	\item \TB{script} = \textit{cyrillic} or latin
+	\item \TB{Script} = \textit{Cyrillic} or Latin. Will likely go to a variant.
+	\item \TB{numerals} = \textit{arabic} or cyrillic. Uses either Arabic numerals or Cyrillic
+	      alphanumerical numbering.
 	\end{itemize}
+\paragraph*{Commands:}
+\begin{itemize}
+	\item \Cmd\Asbuk: produces uppercased Cyrillic alphanumerals, for
+	environments such as ¦enumerate¦. The command takes a counter as argument,\\
+	Example: ¦\textserbian[numerals=cyrillic]{\Asbuk{page}}¦ produces \textserbian[numerals=cyrillic]{\Asbuk{page}}.
+	\item \Cmd\asbuk: same in lowercase
+\end{itemize}
 
+
 \subsection{slovenian}\label{slovenian}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
-	\item \TB{localaph} = true \textit{false}
+	\item \TB{localalph} = true or \textit{false}
 	\end{itemize}
 
+\subsection{sorbian}\label{sorbian}
+\paragraph*{Options:}
+\begin{itemize}
+	\item \TB{variant}\new{v1.45} = lower or \textit{upper}
+	\item \TB{olddate}\new{v1.45} = true or \textit{false} (default value = true). If true, ¦\today¦
+	      will use traditional Sorbian month names (\ie it will be synonymous to ¦\oldtoday¦ below)
+\end{itemize}
+\paragraph*{Commands:}
+\begin{itemize}
+	\item \Cmd\oldtoday: outputs the current date using traditional Sorbian month names, even if \TB{olddate} is false.
+\end{itemize}
+
 \subsection{syriac}\label{syriac}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
 	\item \TB{numerals} = \textit{western} (i.e., 1234567890), eastern
 		(for which the Oriental Arabic numerals are used: \textarabic{١٢٣٤٥٦٧٨٩٠}),
 		or abjad. \new{v1.0.1}.
 	\end{itemize}
-\textbf{Commands}:
+\paragraph*{Commands:}
 	\begin{itemize}
 	\item \Cmd\abjadsyriac (see section \ref{abjad})
   \item \Cmd\aemph (see section \ref{arabic}).
@@ -593,17 +938,23 @@
 	\end{itemize}
 
 \subsection{thai}\label{thai}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
 	\item \TB{numerals} = thai or \textit{arabic}
 	\end{itemize}
-
-To insert the word breaks, you need to use an external processor.
+%
+To insert word breaks, you need to use an external processor.
 See the documentation to \pkg{thai-latex} and the file \file{testthai.tex}
 that comes with this package.
 
-\subsection{ukrainian}\label{russian}
-\textbf{Commands}:
+\subsection{tibetan}\label{tibetan}
+\paragraph*{Options:}
+\begin{itemize}
+	\item \TB{numerals} = tibetan or \textit{arabic}
+\end{itemize}
+
+\subsection{ukrainian}\label{ukrainian}
+\paragraph*{Commands:}
 	\begin{itemize}
 	\item \Cmd\Asbuk: produces the uppercase Ukrainian alphabet, for
 	environments such as ¦enumerate¦
@@ -611,80 +962,229 @@
 	\end{itemize}
 
 \subsection{welsh}\label{welsh}
-\textbf{Options}:
+\paragraph*{Options:}
 	\begin{itemize}
 	\item \TB{date} = long or \textit{short}
 	\end{itemize}
 
-\section{Modifying or extending captions and date formats}
 
-To redefine internal macros, you can use the command ¦\gappto¦ from the package
-\pkg{etoolbox}. For compatibility with \pkg{babel} the command ¦\addto¦ is also available
-with the same effect. For instance, to change the ¦\chaptername¦ for language ¦lingua¦,
+\section{Modifying or extending captions, date formats and language settings}
+
+\pkg{Polyglossia} uses the following macros to define language-specific captions
+(\ie strings such as ``chapter''), date formats and additional language settings
+(¦⟨lang⟩¦ is to be replaces with the respective language name):
+
+\begin{itemize}
+	\item \Cmd{\captions⟨lang⟩} stores definitions of caption strings
+	           (such as, in the case of English, ¦\def\chaptername{Chapter}¦)
+	\item \Cmd{\date⟨lang⟩} stores definitions of date formats (usually redefinitions
+	           of ¦\today¦, in some cases also definitions of additional date commands)
+	\item \Cmd{\blockextras⟨lang⟩} stores macros that are to be executed when the language
+              ⟨lang⟩ is activated via ¦\selectlanguage¦ command or the ¦⟨lang⟩¦ environment
+	\item \Cmd{\inlineextras⟨lang⟩} stores macros that are to be executed when the language
+	          ⟨lang⟩ is activated locally via ¦\text⟨lang⟩¦ command
+	\item \Cmd{\noextras⟨lang⟩} stores macros that are to be executed when the language
+	          ¦⟨lang⟩¦ is closed 
+\end{itemize} 
+%
+In order to redefine internal macros, we recommend to use the command ¦\gappto¦.
+For compatibility with \pkg{babel} the command ¦\addto¦ is also available
+to the same effect. For instance, to change the ¦\chaptername¦ for language ¦lingua¦,
 you can do this:
 \begin{verbatim}
-\gappto\captionslingua{\renewcommand{\chaptername}{Caput}}
+\gappto\captionslingua{\def\chaptername{Caput}}
 \end{verbatim}
+%
+Note that this needs to be done after the respective language has been loaded with
+¦\setmainlanguage¦ or ¦\setotherlanguage¦.
 
-\section{Non-Western decimal digits}
+Specifically for package authors, analogous commands are provided which are only executed
+if a specific language \emph{variety} is used. As opposed to the macros above, these refer
+to babel names. Other than that, the function is identical:
 
-Several scripts have their own versions of the decimal digits commonly called
-‘Arabic numerals’.  With the appropriate language option set, \pkg{polyglossia}
+\begin{itemize}
+	\item \Cmd{\captions at bbl@⟨babelname⟩} 
+	\item \Cmd{\date at bbl@⟨babelname⟩}
+	\item \Cmd{\blockextras at bbl@⟨babelname⟩}
+	\item \Cmd{\inlineextras at bbl@⟨babelname⟩}
+	\item \Cmd{\noextras at bbl@⟨babelname⟩} 
+\end{itemize}
+%
+By default, these macros are undefined. If they are defined (\eg by an external package),
+they will be executed after their respective ¦⟨lang⟩¦ counterpart and thus can be used to
+overwrite definitions of the former. Again, use ¦\gappto¦ to define\slash modify these macros.
+For instance, to add a new caption ¦\footnotename¦ to the Swiss variety of German (babel name
+¦nswissgerman¦), you can do this:
+\begin{verbatim}
+\gappto\captions at bbl@nswissgerman{\def\footnotename{Fussnote}}
+\end{verbatim}
+%
+If you do this in a document preamble rather than in a package, you need to embrace the redefinition
+by ¦\makeatletter¦ and ¦\makeatother¦ due to the ¦@¦ in the macro names.
+
+\section{Script-specific numbering}
+
+Languages and scripts have specific numbering conventions. Some use decimal digits
+(\eg Arabic numerals), some use alphabetic or alphanumerical notation (\eg Roman numbering).
+In some cases, different conventions are available (\eg Mashriq or Maghrib numbering
+in Arabic script, Arabic or Hebrew [=~alphanumeric] numbering in Hebrew).
+
+If the latter is the case, \pkg{polyglossia} provides language options which allow you to select
+or switch to the suitable convention. With the appropriate language option set, \pkg{polyglossia}
 will automatically convert the output of internal \LaTeX\ counters to their
 localized forms, for instance to display page, chapter and section numbers.
 
-In previous versions this conversion was achieved my means of TECKit fontmappings.
-If needed they can be activated with the fontspec ¦Mapping¦ option,
+For manual input of numbers, macros are provided. These convert Arabic numeric input to the respective
+local decimal digit (see sec.~\ref{sec:decdigit}), alphanumeric representation (see sec.~\ref{abjad})
+or whatever is appropriate (see sec.~\ref{sec:localnumber}). The possibilities are described in turn.
+
+\subsection{General localization of numbering}\label{sec:localnumber}
+
+As of 1.45,\new{1.45} \pkg{polyglossia} provides a generic macro \Cmd\localnumeral\ which converts numbers
+to the current local form (which might be script-specific decimal digit, an alphabetic numbering or something else).
+For instance in an Arabic environment
+¦\localnumeral{42}¦ yields \textarabic{\localnumeral{42}}, whereas in an Hebrew environment, it
+results in \texthebrew[numerals=hebrew]{\localnumeral{42}} with ¦numerals=hebrew¦, and \texthebrew{\localnumeral{42}}
+with ¦numerals=arabic¦. Note that, as opposed to the various ¦digits¦ macros (described in sec.~\ref{sec:decdigit}),
+the argument of ¦\localnumeral¦ must consist of numbers only.
+
+For\new{1.45} the conversion of counters, the starred version \Cmd{\localnumeral*} is provided. This takes a counter as argument.
+For instance in an Arabic environment ¦\localnumeral*{page}¦ yields \textarabic{\localnumeral*{page}}.
+
+For scripts with alphanumeric numbering, the variants \Cmd{\Localnumeral} and \Cmd{\Localnumeral*} provide the uppercased 
+versions.\medskip
+
+\noindent All these macros provide the following options:
+
+\begin{itemize}
+	\item \TB{lang} =\DescribeMacro{[lang=]}\ \textit{local}, main, or <language>.\\
+	Output number in the local form of the currently active language for ¦local¦, the main language of the document for ¦main¦,
+    and any (loaded) language for ¦<language>¦ (\eg ¦\localnumeral[lang=arabic]{42}}¦).
+\end{itemize}
+
+\subsection{Non-Western decimal digits}\label{sec:decdigit}
+
+In addition\new{v1.1.1} to the generic macros described above, \pkg{polyglossia} provides language-specific conversion macros
+which can be used if the generic ones do not suit the need.\footnote{%
+A third method are so-called TECKit fontmappings.
+Those can be activated with the \pkg{fontspec} ¦Mapping¦ option,
 using ¦arabicdigits¦, ¦farsidigits¦ or ¦thaidigits¦.
 For instance if \cmd\arabicfont\ is defined with the option ¦Mapping=arabicdigits¦,
-then by typing ¦\textarabic{2010}¦ one will obtain \textarabic{٢٠١٠}.
+typing \cmd{\textarabic\{2010\}} results in \textarabic{٢٠١٠}. Note that this method has some drawbacks, though,
+for instance when the value of a counter has to be written and read from auxiliary files.
+So please use this with care.}
+The macros have the form ¦\<script>digits¦. They convert Arabic numerical input and leave every other input untouched.
+In an Arabic context, for instance, ¦\arabicdigits{9182/738543-X}¦ yields \textarabic{\arabicdigits{9182/738543-X}}.
 
-With version v1.1.1\new{v1.1.1} the same conversion is achieved directly by
-simple \TeX\ macros. This prevents some problems that occur when the value of a
-counter has to be written and read from auxiliary files.\footnote{ %
-  For instance the package \pkg{lastpage} did not work with \pkg{polyglossia} in situations
-  where the display of counters was redefined to include a font-switching command.}
-These macros (currently \Cmd\arabicdigits, \Cmd\farsidigits\ and \Cmd\thaidigits\ are provided)
-are also available to the users. For instance in an Arabic environment
-¦\arabicdigits{9182/738543-X}¦ yields
-\textarabic{\arabicdigits{9182/738543-X}}.
+Currently, the following macros are provided:
 
-\section{Alphabetic numbering in Greek, Arabic, Hebrew, Syriac and Farsi}\label{abjad}
+\begin{itemize}
+	\item \Cmd\arabicdigits
+	\item \Cmd\bengalidigits
+	\item \Cmd\devanagaridigits
+	\item \Cmd\farsidigits
+	\item \Cmd\kannadadigits
+	\item \Cmd\khmerdigits
+	\item \Cmd\laodigits
+	\item \Cmd\nkodigits
+	\item \Cmd\thaidigits
+	\item \Cmd\tibetandigits
+\end{itemize}
 
-In certain languages, numbers can be represented
-by a special alphanumerical notation.\footnote{ %
-	See, e.g., \url{http://en.wikipedia.org/wiki/Greek_numerals},
+
+\subsection{Non-Latin alphabetic numbering}\label{abjad}
+
+For languages which use special (non-Latin) alphanumerical notation\footnote{%
+	For instance, see \url{http://en.wikipedia.org/wiki/Greek_numerals},
 	\url{http://en.wikipedia.org/wiki/Abjad_numerals},
-	and \url{http://en.wikipedia.org/wiki/Hebrew_numerals}.}
-	%% \url{http://en.wikipedia.org/wiki/Syriac_alphabet}
+	\url{http://en.wikipedia.org/wiki/Hebrew_numerals},
+	and \url{http://en.wikipedia.org/wiki/Syriac_alphabet}.}, dedicated macros are provided.
 
-The Greek numerals are obtained with \Cmd\greeknumeral (or \Cmd\Greeknumeral\ in uppercase).
-Example: ¦\greeknumeral{1863}¦ yields \textgreek{\greeknumeral{1863}}.
+They work in a similar way than the ¦\<script>digits¦ macros described above: They take Arabic numerical input
+and output the respective value in the local alphabetic numbering scheme (most of these macros are equivalent
+to ¦\localnumeral¦ and ¦\Localnumeral¦ in the respective context).
 
-The Arabic \textit{abjad} numbers can be generated with the command \Cmd\abjad.
-Example: ¦\abjad{1863}¦ yields \textarabic{\abjad{1863}}.
-In the Maghrib the conventions are somewhat different, and the maghribi forms
-of the \textit{abjad} numerals are obtained with the \Cmd\abjadmaghribi\ command.
-Example: ¦\abjadmaghribi{1863}¦ yields \textarabic{\abjadmaghribi{1863}}.
+The following macros are provided:
 
-The code for Hebrew numerals, which was incorrect in previous versions, was
-ported from the implementation in \pkg{babel} with v1.1.1\new{v1.1.1}, and the
-user interface is identical to the one in \pkg{babel}.
-The commands \Cmd\hebrewnumeral, \Cmd\Hebrewnumeral and \Cmd\Hebrewnumeralfinal\ behave exactly
-as they do in \pkg{babel}: the second command prints the number with \textit{gereshayim} before
-the last letter, and the latter uses in addition the final forms of Hebrew letters.
-Examples:
-¦\hebrewnumeral{1750}¦ yields \texthebrew{\hebrewnumeral{1750}},
-¦\Hebrewnumeral{1750}¦ yields \texthebrew{\Hebrewnumeral{1750}},
-and ¦\Hebrewnumeralfinal{1750}¦ yields \texthebrew{\Hebrewnumeralfinal{1750}}.
+\begin{itemize}
+    \item \Cmd\abjad outputs Arabic \textit{abjad} numbers according to the Mashriq varieties.
+			Example: ¦\abjad{1863}¦ yields \textarabic{\abjad{1863}}.
+			
+	\item \Cmd\abjadmaghribi outputs Arabic \textit{abjad} numbers according to the Maghrib varieties.
+			Example: ¦\abjadmaghribi{1863}¦ yields \textarabic{\abjadmaghribi{1863}}.
+			
+	\item \Cmd\abjadsyriac outputs Syriac abjad numerals.\footnote{%
+				A fine guide to numerals in Syriac can be found at \link{http://www.garzo.co.uk/documents/syriac-numerals.pdf}.}\\
+			Example: ¦\abjadsyriac{463}¦ yields \textsyriac{\abjadsyriac{463}}.
+	
+	\item \Cmd\armeniannumeral produces Armenian alphabetic numbering.
+	          Example: ¦\armeniannumeral{1863}¦ yields \textarmenian{\armeniannumeral{1863}}.
 
+	\item \Cmd\greeknumeral produces Greek alphabetic numbering, \Cmd\Greeknumeral outputs uppercased variants.
+			Example: ¦\greeknumeral{1863}¦ yields \textgreek{\greeknumeral{1863}},
+			¦\Greeknumeral{1863}¦ results in \textgreek{\Greeknumeral{1863}}.
 
-Support is also provided for Syriac abjad numerals, which can be generated
-with \Cmd\abjadsyriac.\footnote{ %
-A fine guide to numerals in Syriac can be found at \link{http://www.garzo.co.uk/documents/syriac-numerals.pdf}.}
-Example: ¦\abjadsyriac{463}¦ yields \textsyriac{\abjadsyriac{463}}.
+	\item \Cmd\hebrewnumeral, \Cmd\Hebrewnumeral and \Cmd\Hebrewnumeralfinal generate variants of Hebrew alphanumeric numerals.
+			The commands behave exactly as they do in \pkg{babel}: ¦\hebrewnumeral¦ outputs the numbers without any decoration,
+			¦\Hebrewnumeral¦ adds \textit{gereshayim} before the last letter, ¦\Hebrewnumeralfinal¦ uses in addition the final forms of Hebrew letters.
+			Examples:
+			¦\hebrewnumeral{1750}¦ yields \texthebrew{\hebrewnumeral{1750}},
+			¦\Hebrewnumeral{1750}¦ yields \texthebrew{\Hebrewnumeral{1750}},
+			and ¦\Hebrewnumeralfinal{1750}¦ yields \texthebrew{\Hebrewnumeralfinal{1750}}.
+	
+	\item \Cmd\russiannumeral produces Russian numbering, with uppercased variant (for alphanumerical variant) via \Cmd\Russiannumeral.
+	        Depending on the ¦numerals¦ option in the Russian language selection, this is either Arabic digit or Cyrillic
+	        alphanumercial output.\\
+	        Example: With ¦numerals=latin¦ ¦\russiannumeral{19}¦ yields \textrussian{\russiannumeral{19}},
+	        with ¦numerals=cyrillic¦ ¦\russiannumeral{19}¦ results in \textrussian[numerals=cyrillic]{\russiannumeral{19}}.
+			
+	\item \Cmd\serbiannumeral produces Serbian numbering, with uppercased variant (for alphanumerical variant) via \Cmd\Serbiannumeral.
+		    Depending on the ¦numerals¦ option in the Serbian language selection, this is either Arabic digit or Cyrillic
+		    alphanumercial output.\\
+		    Example: With ¦numerals=latin¦ ¦\serbiannumeral{19}¦ yields \textserbian{\serbiannumeral{19}},
+			with ¦numerals=cyrillic¦ ¦\serbiannumeral{19}¦ results in \textserbian[numerals=cyrillic]{\serbiannumeral{19}}.
+\end{itemize}
 
 
+\section{Footnotes in right-to-left context}
+
+With languages that use right-to-left scripts, footnote apparatuses are usually placed at the right side of the page bottom.
+Consequently, the footnote rule also is to be placed right. Things get more tricky, though, if right-to-left and left-to-right
+scripts are mixed. Then you might want to put the footnotes on some pages left, on some right, or even mix positions on a page.
+Thus, footnote handling in right-to-left context sometimes needs manual intervention. This is described in what follows.
+
+\subsection{Horizontal footnote position}
+
+When right-to-left languages are used, the ¦\footnote¦ command becomes sensitive to the text directionality. The footnote is
+always placed on the side that is currently the origin of direction: on the left side of the page in LTR paragraphs and
+on the right in RTL paragraphs.
+
+For cases where this is not desired, two additional footnote commands are provided: \Cmd\RTLfootnote and \Cmd\LTRfootnote.
+¦\LTRfootnote¦ always places the footnote on the left side, notwithstanding the current
+directionality. Likewise, ¦\RTLfootnote¦ always places it on the right side. Like ¦\footnote¦, ¦\RTLfootnote¦
+and ¦\LTRfootnote¦ provide an optional argument to customize the number.
+
+
+\subsection{Footnote rule length and position}
+
+The default placement of the footnote rule differs in \XeTeX\ and \LuaTeX\ output (this is due to differences in the \textsf{bidi}
+and \textsf{luabidi} packages). With \XeTeX, footnote rules are always placed left, which is often wrong in RTL context.
+With \LuaTeX, by contrast, the rule is placed always right if the main language is a right-to-left language, and always left
+if the main language is a left-to-right language, which is the right thing in many cases.
+
+In both cases, you can change the default behavior as follows:
+\begin{itemize}
+	\item Put \Cmd\leftfootnoterule in the preamble to have all rules left-aligned.
+	\item Put \Cmd\rightfootnoterule in the preamble to have all rules right-aligned.
+	\item Put \Cmd\autofootnoterule in the preamble to have automatic placement depending on the context (see below for elaboration).
+	\item Put \Cmd\textwidthfootnoterule in the preamble to have a rule that spans the whole text width.
+\end{itemize}
+With ¦\autofootnoterule¦, the first footnote on the current page determines the placement. Note that this automatic can fail with
+footnotes at page boundaries that differ in directionality from the first footnote on the page. You can work around such cases by switching to ¦\rightfootnoterule¦ or ¦\leftfootnoterule¦ on these pages.
+
+Note also that the rule switches might interfere in bad ways with packages or classes that redefine footnotes themselves. This is also the reason
+why ¦\autofootnoterule¦ is not used by default.
+
 \section{Calendars}
 
 \subsection{Hebrew calendar (hebrewcal.sty)}
@@ -706,8 +1206,7 @@
 \Cmd\Hijritoday\ formats the Hijri date for the current day.
 This command is now locale-aware\new{v1.1.1}: its output will differ depending on the
 currently active language. Presently \pkg{polyglossia}’s language definition files
-for Arabic, Farsi, Urdu, Turkish, Bahasa Indonesia and Bahasa Melayu
-provide a localized version of ¦\Hijritoday¦.
+for Arabic, Farsi, Urdu, Turkish and Malay provide a localized version of ¦\Hijritoday¦.
 If the formatting macro for the current language is undefined, the Hijri date will be formatted
 in Arabic or in roman transliteration, depending of the current writing direction.
 You can define a new format or redefine one with the command
@@ -736,38 +1235,69 @@
 
 %\section{Varia}
 
+\section{Accessing language information}
 
+The following is specifically relevant to package authors who need information about the languages in use.
+
+In order to get such information, \pkg{polyglossia} provides the following macros:
+
+\begin{itemize}
+	\item \Cmd\languagename\ stores the currently active (polyglossia) language name.
+	\item \Cmd\mainlanguagename\ stores the (polyglossia) language name of the main document language.
+	\item \Cmd\languagevariant\ stores the language variant if set. The macro is empty if no variant has been set.
+	\item \Cmd\mainlanguagevariant\ stores the language variant of the main document language if set.
+	       The macro is empty if no variant has been set.
+	\item \Cmd\babelname\ stores the corresponding name of the currently active language (variant) in \pkg{babel}.
+	      This might not only be useful if you want to support both \pkg{babel} and \pkg{polyglossia}, but also
+	      since this name is unique for a given language variety (\eg ngerman, german, swissgerman etc.).
+	      Note that this macro is also defined for languages that are not supported in \pkg{babel}. In that
+	      case, they are equal to the polyglossia language name.
+	\item \Cmd\mainbabelname\ analogously stores the name of document's main language (variant) in \pkg{babel}.
+\end{itemize}
+%
+If you want to have a full list of loaded languages/variants, use the following macros:
+\begin{itemize}
+	\item \Cmd{\xpg at loaded}\ stores a comma-separated list of all loaded languages (polyglossia name)
+	\item \Cmd{\xpg at vloaded}\ stores a comma-separated list of all loaded variants
+	\item \Cmd{\xpg at bloaded}\ stores a comma-separated list of \pkg{babel} names of all language variants 
+\end{itemize}
+%
+Finally, you can test whether a language is loaded by
+\displaycmd{\iflanguageloaded\{⟨lang⟩\}\{⟨true⟩\}\{⟨false⟩\}}{\iflanguageloaded}
+where \texttt{⟨lang⟩} is a \pkg{polyglossia} language name, or
+\displaycmd{\ifbabellanguageloaded\{⟨lang⟩\}\{⟨true⟩\}\{⟨false⟩\}}{\ifbabellanguageloaded}
+where \texttt{⟨lang⟩} is a \pkg{babel} language name.
+
 \section{Acknowledgements (by François Charette)}
 \pkg{Polyglossia} is notable for being a recycle box of previous contributions
 by other people. I take this opportunity to thank the following individuals,
-whose splendid work has made my task almost trivial in comparision: Johannes
-Braams and the numerous contributors to the \pkg{babel}{} package (in particular
-Boris Lavva and others for its Hebrew support), Alexej Kryukov (\pkg{antomega}), Will
-Robertson (\pkg{fontspec}), Apostolos Syropoulos (\pkg{xgreek}), Youssef Jabri
-(\pkg{arabi}), and Vafa Khalighi (\pkg{xepersian} and \pkg{bidi}).
-The work of Mojca Miklavec and Arthur Reutenauer on hyphenation patterns with their package
+whose splendid work has made my task almost trivial in comparision: \TA{Johannes
+Braams} and the numerous contributors to the \pkg{babel} package (in particular
+\TA{Boris Lavva} and others for its Hebrew support), \TA{Alexej Kryuko}v (\pkg{antomega}),
+\TA{Will Robertson} (\pkg{fontspec}), \TA{Apostolos Syropoulos} (\pkg{xgreek}), \TA{Youssef Jabri}
+(\pkg{arabi}), and \TA{Vafa Khalighi} (\pkg{xepersian} and \pkg{bidi}).
+The work of \TA{Mojca Miklavec} and \TA{Arthur Reutenauer} on hyphenation patterns with their package
 \pkg{hyph-utf8} is of course invaluable. I should also thank other
-individuals for their assistance in supporting specific languages: Yves Codet
-(Sanskrit), Zdenek Wagner (Hindi), Mikhal Oren (Hebrew), Sergey Astanin (Russian),
-Khaled Hosny (Arabic), Sertaç Ö. Yıldız (Turkish), Kamal Abdali (Urdu),
-and several other members of the \XeTeX\ user community, notably Enrico Gregorio, who
+individuals for their assistance in supporting specific languages: \TA{Yves Codet}
+(Sanskrit), \TA{Zdenĕk Wagner} (Hindi), \TA{Mikhal Oren} (Hebrew), \TA{Sergey Astanin} (Russian),
+\TA{Khaled Hosny} (Arabic), \TA{Sertaç Ö. Yıldız} (Turkish), \TA{Kamal Abdali} (Urdu),
+and several other members of the \XeTeX\ user community, notably \TA{Enrico Gregorio}, who
 has sent me many useful suggestions and corrections and contributed the ¦\newXeTeXintercharclass¦
 mechanism in xelatex.ini which is now used by polyglossia.
-More recently, Kevin Godby of the \href{http://ubuntu-manual.org}{Ubuntu Manual} project has
+More recently, \TA{Kevin Godby} of the \href{http://ubuntu-manual.org}{Ubuntu Manual} project has
 contributed very useful feedback, bug hunting and, with the help of translators,
 new language definition files for Asturian, Lithuanian, Occitan, Bengali, Malayalam, Marathi, Tamil, and Telugu.
 It is particularly heartening to realize that this package is used to typeset a widely-read
 document in dozens of different languages!
-Support for Lao was also added thanks to Brian Wilson.
-I also thank Alan Munn for kindly proof-reading the penultimate version of this documentation.
-And of course my gratitude also goes to Jonathan Kew, the formidable author of \XeTeX!
+Support for Lao was also added thanks to \TA{Brian Wilson}.
+I also thank \TA{Alan Munn} for kindly proof-reading the penultimate version of this documentation.
+And of course my gratitude also goes to \TA{Jonathan Kew}, the formidable author of \XeTeX!
 
 \section{More acknowledgements (by Arthur Reutenauer)}
 Many thanks to all the people who have contributed bugfixes and new features to
-Polyglossia since I took over.  Most of them can be identified from the version
-control log on \href{https://github.com/reutenauer/polyglossia}{GitHub} and I won’t try to name them
+Polyglossia since I took over.  Most of them can be identified from the contributor statistics on \href{https://github.com/reutenauer/polyglossia/graphs/contributors}{GitHub} and I won’t try to name them
 all (maybe, one day ...); among the ones who sent contributions directly to me
-I would like to especially thank Claudio Beccari, the indefatigable champion of
+I would like to especially thank \TA{Claudio Beccari}, the indefatigable champion of
 Romance languages, and beyond!
 
 \end{document}

Modified: trunk/Master/texmf-dist/source/latex/polyglossia/polyglossia.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/polyglossia/polyglossia.dtx	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/source/latex/polyglossia/polyglossia.dtx	2019-10-28 20:58:49 UTC (rev 52555)
@@ -11,7 +11,7 @@
 
    ¦----------------------------------------------¦
    ¦                                              ¦
-   ¦       THE POLYGLOSSIA PACKAGE v1.44          ¦
+   ¦       THE POLYGLOSSIA PACKAGE v1.45          ¦
    ¦                                              ¦
    ¦     Modern multilingual typesetting          ¦
    ¦        with XeLaTeX and LuaLaTeX             ¦
@@ -20,7 +20,8 @@
 
 This package provides an alternative to Babel for users of XeLaTeX and LuaLaTeX
 (with a few languages incompletely supported for the latter). This version
-includes support for 78 different languages.
+includes support for 75 different languages, some of which in different regional,
+national or scriptal varieties.
 
 Polyglossia makes it possible to automate the following tasks:
 
@@ -38,7 +39,8 @@
 * For languages that have their own numeration system, modifying the formatting
   of numbers appropriately.
 * Ensuring the proper directionality if the document contains languages
-  written from right to left (via the package bidi, available separately).
+  written from right to left (via the packages bidi and luabidi, available
+  separately).
 
 LICENSE
 
@@ -49,13 +51,13 @@
 LICENCE.txt for the text of the LPPL v1.3c, or
 http://www.latex-project.org/lppl.txt for the latest version.
 
-This work has the LPPL maintenance status ‘maintained’.  The current maintainer is Arthur Reutenauer.
+This work has the LPPL maintenance status ‘maintained’.  The current maintainer is
+Arthur Reutenauer.
 
 BUGS
 
-Polyglossia is full of bugs.  If you run into one, or suspect you do, or you
-have a request or comment, please use the GitHub issue tracker:
-http://github.com/reutenauer/polyglossia/issues
+If you run into a bug, or suspect you do, or you have a request or comment, please
+use the GitHub issue tracker: http://github.com/reutenauer/polyglossia/issues
 
 This is more efficient than contacting me by email as it allows me to track the
 issues and follow progress.
@@ -115,7 +117,6 @@
 \generate{\file{gloss-breton.ldf}{\from{polyglossia.dtx}{gloss-breton.ldf}}}
 \generate{\file{gloss-bulgarian.ldf}{\from{polyglossia.dtx}{gloss-bulgarian.ldf}}}
 \generate{\file{gloss-catalan.ldf}{\from{polyglossia.dtx}{gloss-catalan.ldf}}}
-\generate{\file{gloss-classiclatin.ldf}{\from{polyglossia.dtx}{gloss-classiclatin.ldf}}}
 \generate{\file{gloss-coptic.ldf}{\from{polyglossia.dtx}{gloss-coptic.ldf}}}
 \generate{\file{gloss-croatian.ldf}{\from{polyglossia.dtx}{gloss-croatian.ldf}}}
 \generate{\file{gloss-czech.ldf}{\from{polyglossia.dtx}{gloss-czech.ldf}}}
@@ -129,11 +130,14 @@
 \generate{\file{gloss-finnish.ldf}{\from{polyglossia.dtx}{gloss-finnish.ldf}}}
 \generate{\file{gloss-french.ldf}{\from{polyglossia.dtx}{gloss-french.ldf}}}
 \generate{\file{gloss-friulan.ldf}{\from{polyglossia.dtx}{gloss-friulan.ldf}}}
+\generate{\file{gloss-friulian.ldf}{\from{polyglossia.dtx}{gloss-friulian.ldf}}}
+\generate{\file{gloss-gaelic.ldf}{\from{polyglossia.dtx}{gloss-gaelic.ldf}}}
 \generate{\file{gloss-galician.ldf}{\from{polyglossia.dtx}{gloss-galician.ldf}}}
 \generate{\file{gloss-german.ldf}{\from{polyglossia.dtx}{gloss-german.ldf}}}
 \generate{\file{gloss-greek.ldf}{\from{polyglossia.dtx}{gloss-greek.ldf}}}
 \generate{\file{gloss-hebrew.ldf}{\from{polyglossia.dtx}{gloss-hebrew.ldf}}}
 \generate{\file{gloss-hindi.ldf}{\from{polyglossia.dtx}{gloss-hindi.ldf}}}
+\generate{\file{gloss-hungarian.ldf}{\from{polyglossia.dtx}{gloss-hungarian.ldf}}}
 \generate{\file{gloss-icelandic.ldf}{\from{polyglossia.dtx}{gloss-icelandic.ldf}}}
 \generate{\file{gloss-interlingua.ldf}{\from{polyglossia.dtx}{gloss-interlingua.ldf}}}
 \generate{\file{gloss-irish.ldf}{\from{polyglossia.dtx}{gloss-irish.ldf}}}
@@ -142,26 +146,33 @@
 \generate{\file{gloss-kannada.ldf}{\from{polyglossia.dtx}{gloss-kannada.ldf}}}
 \generate{\file{gloss-khmer.ldf}{\from{polyglossia.dtx}{gloss-khmer.ldf}}}
 \generate{\file{gloss-korean.ldf}{\from{polyglossia.dtx}{gloss-korean.ldf}}}
+\generate{\file{gloss-kurdish.ldf}{\from{polyglossia.dtx}{gloss-kurdish.ldf}}}
 \generate{\file{gloss-lao.ldf}{\from{polyglossia.dtx}{gloss-lao.ldf}}}
+\generate{\file{gloss-latex.ldf}{\from{polyglossia.dtx}{gloss-latex.ldf}}}
 \generate{\file{gloss-latin.ldf}{\from{polyglossia.dtx}{gloss-latin.ldf}}}
 \generate{\file{gloss-latvian.ldf}{\from{polyglossia.dtx}{gloss-latvian.ldf}}}
 \generate{\file{gloss-lithuanian.ldf}{\from{polyglossia.dtx}{gloss-lithuanian.ldf}}}
-\generate{\file{gloss-liturgicallatin.ldf}{\from{polyglossia.dtx}{gloss-liturgicallatin.ldf}}}
 \generate{\file{gloss-lsorbian.ldf}{\from{polyglossia.dtx}{gloss-lsorbian.ldf}}}
 \generate{\file{gloss-macedonian.ldf}{\from{polyglossia.dtx}{gloss-macedonian.ldf}}}
 \generate{\file{gloss-magyar.ldf}{\from{polyglossia.dtx}{gloss-magyar.ldf}}}
+\generate{\file{gloss-malay.ldf}{\from{polyglossia.dtx}{gloss-malay.ldf}}}
 \generate{\file{gloss-malayalam.ldf}{\from{polyglossia.dtx}{gloss-malayalam.ldf}}}
 \generate{\file{gloss-marathi.ldf}{\from{polyglossia.dtx}{gloss-marathi.ldf}}}
+\generate{\file{gloss-mongolian.ldf}{\from{polyglossia.dtx}{gloss-mongolian.ldf}}}
 \generate{\file{gloss-nko.ldf}{\from{polyglossia.dtx}{gloss-nko.ldf}}}
 \generate{\file{gloss-norsk.ldf}{\from{polyglossia.dtx}{gloss-norsk.ldf}}}
+\generate{\file{gloss-norwegian.ldf}{\from{polyglossia.dtx}{gloss-norwegian.ldf}}}
 \generate{\file{gloss-nynorsk.ldf}{\from{polyglossia.dtx}{gloss-nynorsk.ldf}}}
 \generate{\file{gloss-occitan.ldf}{\from{polyglossia.dtx}{gloss-occitan.ldf}}}
+\generate{\file{gloss-persian.ldf}{\from{polyglossia.dtx}{gloss-persian.ldf}}}
 \generate{\file{gloss-piedmontese.ldf}{\from{polyglossia.dtx}{gloss-piedmontese.ldf}}}
 \generate{\file{gloss-polish.ldf}{\from{polyglossia.dtx}{gloss-polish.ldf}}}
 \generate{\file{gloss-portuges.ldf}{\from{polyglossia.dtx}{gloss-portuges.ldf}}}
+\generate{\file{gloss-portuguese.ldf}{\from{polyglossia.dtx}{gloss-portuguese.ldf}}}
 \generate{\file{gloss-romanian.ldf}{\from{polyglossia.dtx}{gloss-romanian.ldf}}}
 \generate{\file{gloss-romansh.ldf}{\from{polyglossia.dtx}{gloss-romansh.ldf}}}
 \generate{\file{gloss-russian.ldf}{\from{polyglossia.dtx}{gloss-russian.ldf}}}
+\generate{\file{gloss-sami.ldf}{\from{polyglossia.dtx}{gloss-sami.ldf}}}
 \generate{\file{gloss-samin.ldf}{\from{polyglossia.dtx}{gloss-samin.ldf}}}
 \generate{\file{gloss-sanskrit.ldf}{\from{polyglossia.dtx}{gloss-sanskrit.ldf}}}
 \generate{\file{gloss-scottish.ldf}{\from{polyglossia.dtx}{gloss-scottish.ldf}}}
@@ -168,6 +179,7 @@
 \generate{\file{gloss-serbian.ldf}{\from{polyglossia.dtx}{gloss-serbian.ldf}}}
 \generate{\file{gloss-slovak.ldf}{\from{polyglossia.dtx}{gloss-slovak.ldf}}}
 \generate{\file{gloss-slovenian.ldf}{\from{polyglossia.dtx}{gloss-slovenian.ldf}}}
+\generate{\file{gloss-sorbian.ldf}{\from{polyglossia.dtx}{gloss-sorbian.ldf}}}
 \generate{\file{gloss-spanish.ldf}{\from{polyglossia.dtx}{gloss-spanish.ldf}}}
 \generate{\file{gloss-swedish.ldf}{\from{polyglossia.dtx}{gloss-swedish.ldf}}}
 \generate{\file{gloss-syriac.ldf}{\from{polyglossia.dtx}{gloss-syriac.ldf}}}
@@ -189,6 +201,7 @@
 \generate{\file{thaidigits.map}{\from{polyglossia.dtx}{thaidigits.map}}}
 \def\MetaPrefix{-- }
 \generate{\file{polyglossia-frpt.lua}{\from{polyglossia.dtx}{polyglossia-frpt.lua}}}
+\generate{\file{polyglossia-korean.lua}{\from{polyglossia.dtx}{polyglossia-korean.lua}}}
 \generate{\file{polyglossia-tibt.lua}{\from{polyglossia.dtx}{polyglossia-tibt.lua}}}
 \generate{\file{polyglossia.lua}{\from{polyglossia.dtx}{polyglossia.lua}}}
 \let\MetaPrefix\DoubleperCent
@@ -206,14 +219,17 @@
 %</internal>
 %
 %<*driver>
+% !TeX spellcheck = en_US
+% !TeX TS-program = xelatex
 \documentclass[11pt]{ltxdoc}
 \usepackage{color}
-\usepackage{xspace,fancyvrb}
+\usepackage{xspace,fancyvrb,booktabs}
 \usepackage[neverdecrease]{paralist}
 \definecolor{myblue}{rgb}{0.02,0.04,0.48}
 \definecolor{lightblue}{rgb}{0.61,.8,.8}
 \definecolor{myred}{rgb}{0.65,0.04,0.07}
 \usepackage[
+    unicode=true,
     bookmarks=true,
     colorlinks=true,
     linkcolor=myblue,
@@ -221,8 +237,8 @@
     citecolor=myblue,
     hyperindex=false,
     hyperfootnotes=false,
-    pdftitle={Polyglossia: An alternative to Babel for XeLaTeX and LuaLaTeX},
-    pdfauthor={F Charette, A Reutenauer},
+    pdftitle={Polyglossia: Modern multilingual typesetting with XeLaTeX and LuaLaTeX},
+    pdfauthor={F Charette, A Reutenauer, B Roucariès, J Spitzmüller},
     pdfkeywords={xetex, xelatex, luatex, lualatex, multilingual, babel, hyphenation}
     ]{hyperref}
 \usepackage{metalogo}
@@ -231,7 +247,7 @@
 \usepackage[babelshorthands]{polyglossia}
 \usepackage{farsical}
 \setmainlanguage[variant=british,ordinalmonthday=false]{english}
-\setotherlanguages{arabic,hebrew,syriac,greek,russian,catalan}
+\setotherlanguages{arabic,armenian,hebrew,syriac,greek,russian,serbian,catalan}
 \usepackage[protrusion]{microtype}
 \newcommand*\Cmd[1]{\cmd{#1}\DescribeMacro{#1}\xspace}
 \newcommand*\pkg[1]{\textsf{\color{myblue}#1}}
@@ -239,6 +255,7 @@
 \newcommand*\TR[1]{\textcolor{myred}{#1}}
 \newcommand*\TX[1]{\hyperref[#1]{\textcolor{myred}{#1}}}
 \newcommand*\TB[1]{\textcolor{myblue}{\bf #1}}
+\newcommand*\TA[1]{\textsc{\color{myblue}#1}}
 \newcommand*\link[1]{\href{#1}{#1}}
 \def\eg{\textit{e.g.,}\xspace}
 \def\ie{\textit{i.e.,}\xspace}
@@ -260,12 +277,25 @@
 \renewenvironment{itemize}{\begin{compactitem}[\char"2023]}%[{\fontspec{DejaVu Sans}\char"25BB}]}%
 		{\end{compactitem}}
 \renewenvironment{enumerate}{\begin{compactenum}}{\end{compactenum}}
+\newenvironment{shorthands}{%
+	 \begin{list}{}%
+	 	{\settowidth{\labelwidth}{MM}%
+	 	 \setlength{\leftmargin}{\labelwidth}%
+	 	 \addtolength{\leftmargin}{\labelsep}%
+	     \renewcommand{\makelabel}[1]{##1\hfil}}}%
+	{\end{list}}
 
+% This is to prevent page breaks too short after subsections
+\def\condbreak#1{%
+	\vskip 0pt plus #1\pagebreak[3]\vskip 0pt plus -#1\relax}
+\pretocmd{\subsection}{\condbreak{2\baselineskip}}{}{}
+
 %% fontspec declarations:
 \setmainfont{Linux Libertine O}
 \setsansfont{Linux Biolinum O}
 \setmonofont[Scale=MatchLowercase]{DejaVu Sans Mono}
 \newfontfamily\arabicfont[Script=Arabic]{Amiri}
+\newfontfamily\armenianfont[Script=Armenian]{DejaVu Sans}
 \newfontfamily\syriacfont[Script=Syriac]{Serto Jerusalem}
 \newfontfamily\hebrewfont[Script=Hebrew]{Ezra SIL}
 
@@ -276,6 +306,8 @@
 \RecordChanges
 % COMMENT THE NEXT LINE TO INCLUDE THE CODE
 \AtBeginDocument{\OnlyDescription}
+
+
 \begin{document}
 \ifxetex
   \DocInput{polyglossia.dtx}
@@ -288,13 +320,14 @@
 % \errorcontextlines=999
 % \makeatletter
 % 
-% \hyphenation{Kha-li-ghi}
+% \hyphenation{Kha-li-ghi Reu-ten-auer}
 % \GetFileInfo{polyglossia.sty}
 % 
 % \title{\textcolor{lightblue}{\Huge\fontspec[LetterSpace=40]{GFS Ambrosia} Πολυγλωσσια}
 % \\[16pt]
-% \color{myblue}Polyglossia: An Alternative to Babel for \XeLaTeX\ and \LuaLaTeX}
-% \author{\scshape\color{myblue}François Charette\\\color{myblue}Current maintainer: \scshape Arthur Reutenauer}
+% \color{myblue}Polyglossia: Modern multilingual typesetting with \XeLaTeX\ and \LuaLaTeX}
+% \author{\TA{François Charette} \and \TA{Arthur Reutenauer}\thanks{Current maintainer}
+% 	    \and \TA{Bastien Roucariès} \and \TA{Jürgen Spitzmüller}}
 % \date{\filedate \qquad \fileversion\\
 % \footnotesize (\textsc{pdf} file generated on \today)}
 % 
@@ -312,8 +345,8 @@
 % 
 % \section{Introduction}
 % 
-% Polyglossia is a package for facilitating multilingual typesetting with
-% \XeLaTeX\ and (at an early stage) \LuaLaTeX.  Basically, it
+% \pkg{Polyglossia} is a package for facilitating multilingual typesetting with
+% \XeLaTeX\ and (with some exceptions) \LuaLaTeX.  Basically, it
 % can be used as an alternative to \pkg{babel} for performing the following
 % tasks automatically:
 % 
@@ -345,43 +378,39 @@
 % and modern. The package \pkg{antomega} has been very beneficial in our attempt to
 % reach this objective.
 % 
-% \paragraph{Requirements:} The current version of \pkg{polyglossia} makes use of some convenient
-% macros defined in the \pkg{etoolbox} package by Philipp Lehmann. Being designed
-% for \XeLaTeX\ and \LuaLaTeX, it obviously also relies on \pkg{fontspec} by Will
-% Robertson. For languages written from right to left, it needs the package \pkg{bidi}
-% by Vafa Khalighi (\textarabic{وفا خليقي}). Polyglossia also bundles three packages for calendaric
-% computations (\pkg{hebrewcal}, \pkg{hijrical}, and \pkg{farsical}).
+% \paragraph{Requirements} The current version of \pkg{polyglossia} makes use of some convenient
+% macros defined in the \pkg{etoolbox} package by \TA{Philipp Lehmann} and \TA{Joseph Wright}.
+% Being designed for \XeLaTeX\ and \LuaLaTeX, it obviously also relies on \pkg{fontspec} by
+% \TA{Will Robertson}. For languages written from right to left, it needs the package \pkg{bidi}
+% (for \XeTeX) or  \pkg{luabidi} (for \LuaTeX) by \TA{Vafa Khalighi} (\textarabic{وفا خليقي}) and
+% the \pkg{bidi-tex GitHub Organisation}.
+% Polyglossia also bundles three packages for calendaric computations (\pkg{hebrewcal},
+% \pkg{hijrical}, and \pkg{farsical}).
 % 
-% \section{Loading language definition files}
 % 
-% \subsection{The recommended way}
-% You can determine the default language by means of the command:
-% 	\displaycmd{\setdefaultlanguage[⟨options⟩]\{lang\}}{\setdefaultlanguage}
-% (or equivalently \Cmd\setmainlanguage).
-% Secondary languages can be loaded with
-% 	\displaycmd{\setotherlanguage[⟨options⟩]\{lang\}.}{\setotherlanguage}
-% These commands have the advantage of being explicit and of allowing you to set
-% language-specific options.\footnote{ %
-% 	More on language-specific options below.}
-% It is also possible to load a series of secondary languages at once using
-% 	\displaycmd{\setotherlanguages\{lang1,lang2,lang3,…\}.}{\setotherlanguages}
-% Language-specific options can be set or changed at any time by means of
-% 	\displaycmd{\setkeys\{⟨lang⟩\}\{opt1=value1,opt2=value2,…\}.}{\setkeys}
+% \section{Setting up multilingual documents}
 % 
+% \subsection{Activating languages}
 % 
-% \subsection{The “Babel way” – obsolete}
-% \new{v1.2.0}
-% {\color{red}\bfseries Warning}: \pkg{polyglossia} no longer supports loading
-% language definition files as package options!
-% ^^AAs with \pkg{babel}, \pkg{polyglossia} also allows you to load language definition files
-% ^^Aas package options. In most cases, option \texttt{⟨lang⟩} will load the file
-% ^^A\file{gloss-⟨lang⟩.ldf}. Note however that the \textit{first} language listed in \\
-% ^^A\centerline{\cmd{\usepackage[lang1,lang2,…]{polyglossia}}}
-% ^^Awill be the default language for the document, which
-% ^^Ais the opposite convention of \pkg{babel}.
-% ^^ANote also that this method may not work in some cases, and should be
-% ^^Aconsidered deprecated.
+% The default language of a document is specified by means of the command
+% 	\displaycmd{\setdefaultlanguage[⟨options⟩]\{⟨lang⟩\}}{\setdefaultlanguage}
+% (or, equivalently, \Cmd\setmainlanguage).
+% Secondary languages are specified with
+% 	\displaycmd{\setotherlanguage[⟨options⟩]\{⟨lang⟩\}.}{\setotherlanguage}
+% All these commands allow you to set language-specific options.\footnote{%
+% 	Section~\ref{specific} documents these options for the respective languages.}
+% It is also possible to load a series of secondary languages at once (but without options)
+% using
+% 	\displaycmd{\setotherlanguages\{⟨lang1⟩,⟨lang2⟩,⟨lang3⟩,…\}.}{\setotherlanguages}
 % 
+% All language-specific options can be modified locally by means of the
+% language-switching commands described in section \ref{languageswitching}.
+% 
+% \paragraph{Note} In general, it is advisable to activate the languages \emph{after} all
+% packages have been loaded. This is particularly important if you use right-to-left scripts
+% or languages with babel shorthands.
+% 
+% 
 % \subsection{Supported languages}
 % 
 % Table~\ref{tab:lang} lists all languages currently supported.
@@ -388,69 +417,156 @@
 % Those in red have specific options and/or commands
 % that are explained in section \ref{specific} below.
 % 
-% \begin{table}[h]\centering
+% \begin{table}[ht]\centering
 % \label{tab:lang}
-% ^^A Produced with tools/insert-language-list.rb -- AR, 2015-07-14
-% ^^A Edited by hand -- AR 2019-04-04
+% ^^A Produced with tools/insert-language-list.rb -- JS, 2019-10-18
+% ^^A Edited by hand -- JS, 2019-10-18
 % \begin{tabular}{lllll}
-% \hline
-% albanian       & danish         & interlingua    & nko            & \TX{slovenian}\\
-% amharic        & divehi         & irish          & norsk          & spanish       \\
-% \TX{arabic}    & \TX{dutch}     & \TX{italian}   & nynorsk        & swedish       \\
-% armenian       & \TX{english}   & kannada        & occitan        & \TX{syriac}   \\
-% asturian       & \TX{esperanto} & khmer          & piedmontese    & tamil         \\
-% bahasai        & estonian       & \TX{korean}    & polish         & telugu        \\
-% bahasam        & \TX{farsi}     & \TX{lao}       & portuges       & \TX{thai}     \\
-% basque         & finnish        & \TX{latin}     & romanian       & tibetan       \\
-% \TX{bengali}   & french         & latvian        & romansh        & turkish       \\
-% brazil[ian]    & friulan        & lithuanian     & \TX{russian}   & turkmen       \\
-% breton         & galician       & \TX{lsorbian}  & samin          & \TX{ukrainian}\\
-% bulgarian      & \TX{german}    & \TX{magyar}    & \TX{sanskrit}  & urdu          \\
-% \TX{catalan}   & \TX{greek}     & macedonian     & scottish       & \TX{usorbian} \\
-% coptic         & \TX{hebrew}    & malayalam      & \TX{serbian}   & vietnamese    \\
-% croatian       & \TX{hindi}     & marathi        & slovak         & \TX{welsh}    \\
-% czech          & icelandic      \\
-% \hline
+% \toprule
+% albanian     & \TX{dutch}     & interlingua  & \TX{mongolian}  & \TX{slovenian}\\
+% amharic      & \TX{english}   & \TX{italian} & nko             & \TX{sorbian}\\
+% \TX{arabic}  & \TX{esperanto} & japanese     & \TX{norwegian}  & spanish\\
+% \TX{armenian}& estonian       & kannada      & occitan         & swedish\\
+% asturian     & \TX{finnish}   & khmer        & \TX{persian}    & \TX{syriac}\\
+% basque       & \TX{french}    & \TX{korean}  & piedmontese     & tamil\\
+% \TX{bengali} & friulian       & \TX{kurdish} & polish          & telugu\\
+% breton       & \TX{gaelic}    & \TX{lao}     & \TX{portuguese} & \TX{thai}\\
+% bulgarian    & galician       & \TX{latin}   & romanian        & \TX{tibetan}\\
+% \TX{catalan} & \TX{german}    & latvian      & romansh         & turkish\\
+% coptic       & \TX{greek}     & lithuanian   & \TX{russian}    & turkmen\\
+% croatian     & \TX{hebrew}    & macedonian   & \TX{sami}       & \TX{ukrainian}\\
+% \TX{czech}   & \TX{hindi}     & \TX{malay}   & \TX{sanskrit}   & urdu\\
+% danish       & \TX{hungarian} & malayalam    & \TX{serbian}    & vietnamese\\
+% divehi       & icelandic      & marathi      & slovak          & \TX{welsh}\\
+% \bottomrule
 % \end{tabular}
+% 
+% 
 % \caption{Languages currently supported in \pkg{polyglossia}}
 % \end{table}
 % 
-% \textit{NB:} The support for Amharic\new{v1.0.1} should be considered an experimental attempt to
-% port the package \pkg{ethiop}.\footnote{ Feedback is welcome.}
+% \paragraph{Version Notes} The support for Amharic\new{v1.0.1} should be considered an experimental attempt to
+% port the package \pkg{ethiop}.\footnote{Feedback is welcome.}
 % Version 1.1.1\new{v1.1.1} added support for Asturian, %\footnote{ Provided by Kevin Godby and Xuacu Saturio.}, 
 % Lithuanian, %\footnote{ Provided by Kevin Godby and Paulius Sladkevičius.},
 % and Urdu. %\footnote{ Provided by Kamal Abdali.}
 % ^^A
 % Version 1.2\new{v1.2.0} adds support for Armenian, Occitan, Bengali,
-% Lao, Malayalam, Marathi, Tamil, Telugu, and Turkmen.\footnote{ %
+% Lao, Malayalam, Marathi, Tamil, Telugu, and Turkmen.\footnote{%
 %   See acknowledgements at the end for due credit to the various contributors.}
+% Version 1.43\new{v1.43} silently introduced basic support for Japanese. This
+% is considered experimental, and feedback is appreciated.
+% In version 1.45\new{v1.45}, support for Kurdish and Mongolian as well as some new
+% variants (Canadian French and English) have been added. Furthermore,  for consistency reasons, some language have
+% been renamed (\emph{farsi}\textrightarrow\emph{persian}, \emph{friulan}\textrightarrow\emph{friulian},
+% \emph{magyar}\textrightarrow\emph{hungarian}, \emph{portuges}\textrightarrow\emph{portuguese},
+% \emph{samin}\textrightarrow\emph{sami}) or merged (\emph{bahasai}\slash\emph{bahasam}\textrightarrow\emph{malay},
+% \emph{brazil}\slash\emph{portuges}\textrightarrow\emph{portuguese},
+% \emph{lsorbian}\slash\emph{usorbian}\textrightarrow\emph{sorbian},
+% \emph{irish}\slash\emph{scottish}\textrightarrow\emph{gaelic},
+% \emph{norsk}\slash\emph{nynorsk}\textrightarrow\emph{norwegian}). The old names are still supported for backwards
+% compatibility reasons, but they might not give access to newer language features.
 % 
 % 
+% \subsection{Relation to Babel languages}
 % 
-% Polyglossia can also be loaded with the option
-% ‘babelshorthands’\new{v1.1.1}, which globally activates \pkg{babel}
-% shorthands whenever available. Currently shorthands are implemented for
-% Catalan, Dutch, German, Italian, and Russian: see these respective
-% languages for details.
+% If you are familiar with the \pkg{babel} package, you will note that \pkg{polyglossia}'s language naming
+% slightly differs. Whereas \pkg{babel} has a unique name for each language variety (\eg\emph{american} and \emph{british}),
+% \pkg{polyglossia} differentiates language varieties via language options.
 % 
-% Another option (turned off by default) is ‘localmarks’, which
-% redefines the internal \LaTeX\ macros \cmd\markboth\ and \cmd\markright.
-% \new{v1.2.0}Note that this was formerly turned on by default, but we
-% now realize that it causes more problems than otherwise. For backwards-compatibility
-% the opposite option ‘nolocalmarks’ is still available.
+% Furthermore, \pkg{babel} uses sometimes abbreviations for language names (\eg\emph{bahasam} for Bahasa Malayu) as well
+% as endonyms, \ie language names coming from the designated languages (such as \emph{bahasa}, \emph{canadien} or \emph{magyar}).
+% As opposed to this, \pkg{polyglossia} always uses spelled-out (lower-cased) English language names.
 % 
-% There is also the option ‘quiet’ which turns off most info messages and some of the warnings
-% issued by \LaTeX, \pkg{fontspec} and \pkg{polyglossia}.
+% Table~\ref{tab:bbllang} lists the language names that differ in both packages. \pkg{Babel} names marked in red can also be used
+% in \pkg{polyglossia} as an alias.\footnote{This is for historical reasons, since earlier versions of \pkg{polyglossia} used
+% 	those names as well. Note, however, that you need to use the matching language switching commands, then, as
+%     well, \eg \cmd\textportuges\ with \emph{portuges} (rather than \cmd\textportuguese).}
 % 
-% \section{Language-switching commands}
+% \begin{table}
+% \label{tab:bbllang}
+% \begin{tabular}{lll}
+% \toprule 
+% \textbf{Babel name} & \textbf{Polyglossia name} & \textbf{Polyglossia options}\tabularnewline
+% \midrule
+% acadien         & french     & variant=acadian                \\
+% american        & english    & \emph{(default)}               \\
+% australian      & english    & variant=australian             \\
+% austrian        & german     & variant=austrian, spelling=old \\
+% bahasa          & malay      & \emph{(default)}               \\
+% \TR{bahasam}    & malay      & variant=malaysian              \\
+% \TR{brazil}     & portuguese & variant=brazilian              \\
+% british         & english    & variant=british                \\
+% canadian        & english    & variant=canadian               \\
+% canadien        & french     & variant=canadian               \\
+% \TR{farsi}      & persian    &                                \\
+% \TR{friulan}    & friulian   &                                \\
+% german          & german     & spelling=old                   \\
+% \TR{irish}      & gaelic     & variant=irish                  \\
+% kurmanji        & kurdish    & variant=kurmanji               \\
+% lowersorbian    & sorbian    & variant=lower                  \\
+% \TR{magyar}     & hungarian  &                                \\
+% naustrian       & german     & variant=austrian               \\
+% newzealand      & english    & variant=newzealand             \\
+% ngerman         & german     & \emph{(default)}               \\
+% \TR{norsk}      & norwegian  & variant=bokmal                 \\
+% nswissgerman    & german     & variant=swiss                  \\
+% \TR{nynorsk}    & norwegian  & \emph{(default)}               \\
+% polutonikogreek & greek      & variant=polytonic              \\
+% \TR{portuges}   & portuguese & \emph{(default)}               \\
+% \TR{samin}      & sami       &                                \\
+% \TR{scottish}   & gaelic     & variant=scottish               \\
+% serbianc        & serbian    & script=Cyrillic                \\
+% slovene         & slovenian  &                                \\
+% swissgerman     & german     & variant=swiss, spelling=old    \\
+% uppersorbian    & sorbian    & variant=upper                  \\
+% \bottomrule
+% \end{tabular}
+% 	
+% \caption{Babel-polyglossia language name matching}
+% \end{table}
 % 
-% Whenever a language definition file \file{gloss-⟨lang⟩.ldf} is loaded,
-% the command \cmd{\text⟨lang⟩[⟨options⟩]\{…\}} \DescribeMacro{\text⟨lang⟩}
+% 
+% \subsection{Global options}
+% 
+% \pkg{Polyglossia} can be loaded with the following global package options:
+% 
+% \begin{itemize}
+% 	\item \TB{babelshorthands}\new{v1.1.1} globally activates \pkg{babel}
+%           shorthands whenever available. Currently shorthands are implemented for
+%           Catalan, Czech, Dutch, Finnish, German, Italian, Mongolian, and Russian.
+%           Please refer to the respective language descriptions (sec.~\ref{specific}) for details.
+% 
+%     \item \TB{localmarks} redefines the internal \LaTeX\ macros \cmd\markboth\ and \cmd\markright.
+%           In earlier versions of \pkg{polyglossia},\new{v1.2.0} this option was set by default, but we
+%           now realize that it causes more problems than it helps, so it is now off by default.
+%           For backwards-compatibility, the option \TB{nolocalmarks} which used to switch off the previous
+%           default, and now does nothing, is still available.
+% 
+%     \item \TB{quiet} turns off most info messages and some of the warnings issued by \LaTeX,
+%           \pkg{fontspec} and \pkg{polyglossia}.
+% \end{itemize}
+% 
+% \section{Language-switching commands}\label{languageswitching}
+% 
+% \subsection{Recommended commands}
+% For each activated language the command
+% \cmd{\text⟨lang⟩[⟨options⟩]\{…\}} \DescribeMacro{\text⟨lang⟩}
 % becomes available for short insertions of text in that language.
 % For example ¦\textrussian{\today}¦ yields \textrussian{\today}
-% Longer passages are better put between the environment ¦⟨lang⟩¦
-% (again with the possibility of setting language options locally.
-% \DescribeEnv{⟨lang⟩}
+% This command switches to the correct hyphenation patterns, it activates
+% some extra features for the selected language (such as extra spacing before
+% punctuation in French), and it translates the date when using ¦\today¦.
+% It does not, however, translate so-called \textit{caption strings}, i.\,e.
+% ``chapter'', ``figure'' etc., to the local language (these remain in the main
+% language).
+% 
+% The\DescribeEnv{⟨lang⟩}\ environment ¦⟨lang⟩¦, which is also available for any activated language,
+% is meant for longer passages of text. It behaves slightly different than the \cmd{\text⟨lang⟩\{…\}}
+% command: It does everything the latter does, but additionally, the caption strings are translated
+% as well, and the language is also passed to auxiliary files, the table of contents and the lists of
+% figures/tables.
+% Like the command, the environment provides the possibility of setting language options locally.
 % For instance the following allows us to quote the beginning
 % of Homer’s \textit{Iliad}:
 % 
@@ -471,10 +587,31 @@
 % \end{greek}
 % \bigskip
 % 
-% Note that for Arabic one cannot use the environment ¦arabic¦,
+% \noindent\DescribeEnv{Arabic} Note that for Arabic one cannot use the environment ¦arabic¦,
 % as \cmd\arabic\ is defined internally by \LaTeX. In this case
-% we need to use the environment ¦Arabic¦ instead\DescribeEnv{Arabic}.
+% we need to use the environment ¦Arabic¦ instead.
 % 
+% \subsection{Babel commands}
+% Some macros defined in \pkg{babel}’s \file{hyphen.cfg} (and thus usually
+% compiled into the \XeLaTeX\ and \LuaLaTeX\ format) are redefined, but keep a
+% similar behaviour.
+% \begin{itemize}
+% \item \DescribeMacro{\selectlanguage}\cmd{\selectlanguage[⟨options⟩]\{⟨lang⟩\}}
+% \item \DescribeMacro{\foreignlanguage}\cmd{\foreignlanguage[⟨options⟩]\{⟨lang⟩\}\{…\}}
+% \item \DescribeEnv{otherlanguage}\cmd{\begin\{otherlanguage\}[⟨options⟩]\{⟨lang⟩\}} \dots{} \cmd{\end\{otherlanguage\}}
+% \item \DescribeEnv{otherlanguage*}\cmd{\begin\{otherlanguage*\}[⟨options⟩]\{⟨lang⟩\}} \dots{} \cmd{\end\{otherlanguage*\}}
+% \end{itemize}
+% ^^A
+% ¦\selectlanguage{⟨lang⟩}¦ and the ¦otherlanguage¦ environment are identical to the
+% the ¦⟨lang⟩¦ environment, except that ¦\selectlanguage{⟨lang⟩}¦
+% does not need to be explicitly closed. The command ¦\foreinlanguage{⟨lang⟩}{…}¦ and the ¦otherlanguage*¦
+% environment are identical with the use of the ¦\text⟨lang⟩¦ command, with the one
+% notable exception that they do not translate the date with ¦\today¦.
+% 
+% Since the \XeLaTeX\ and \LuaLaTeX\ format incorporate \pkg{babel}’s \file{hyphen.cfg},
+% the low-level commands for hyphenation and language switching
+% defined there are also accessible.
+% 
 % \subsection{Other commands}
 % The following commands are probably of lesser interest to the end user, but
 % ought to be mentioned here.
@@ -487,19 +624,14 @@
 % 	to another one in the middle of a document: \textit{this may have adverse effects}!
 % 
 % \item \Cmd\normalfontlatin: in an environment where \cmd\normalfont\ has been redefined
-% 	to a non-latin script, this will call the font defined with \cmd\setmainfont\ etc.
-% 	Likewise it is possible to use \Cmd\rmfamilylatin, \Cmd\sffamilylatin,
+% 	to a non-latin script, this will reset to the font defined with \cmd\setmainfont\ etc.
+% 	In a similar vein, it is possible to use \Cmd\rmfamilylatin, \Cmd\sffamilylatin,
 % 	and \Cmd\ttfamilylatin.
 % 
-% \item Some macros defined in \pkg{babel}’s \file{hyphen.cfg} (and thus usually
-% 	compiled into the \XeLaTeX\ and \LuaLaTeX\ format) are redefined, but keep a similar
-% 	behaviour, namely \Cmd\selectlanguage, \Cmd\foreignlanguage,
-% 	and the environment ¦otherlanguage¦\DescribeEnv{otherlanguage}.
+% \item \Cmd\latinalph: Representation of counter as a lower-case letter:  1 = a, 2 = b, etc.
+% 
+% \item \Cmd\latinAlph: Representation of counter as a uper-case letter:  1 = A, 2 = B, etc.
 % \end{itemize}
-% ^^A
-% Since the \XeLaTeX\ and \LuaLaTeX\ format incorporate \pkg{babel}’s \file{hyphen.cfg},
-% the low-level commands for hyphenation and language switching
-% defined there are also accessible.
 % 
 % \section{Font setup}
 % 
@@ -526,14 +658,35 @@
 % does not appear to support the script of that language, an error message is
 % displayed.
 % 
-% \section{Hyphenation disabling}
+% \section{Adapting hyphenation}
 % 
+% \subsection{Hyphenation exceptions}
+% 
+% \TeX\ provides the command ¦\hyphenation{⟨exceptions⟩}¦ to globally define hyphenation exceptions
+% which override the hyphenation patterns for specified words. The command takes as argument a space-separated
+% list of words where hyphenation points are marked by a dash (if no dash is used, the respective word is not
+% hyphenated at all):
+% \begin{Verbatim}
+% \hyphenation{%
+%   po-ly-glos-sia
+%   LaTeX
+% }
+% \end{Verbatim}
+% ^^A
+% These exceptions, however, apply to all languages. In addition to this, \pkg{polyglossia} provides
+% the command\new{v.1.45}
+% \displaycmd{\pghyphenation[⟨options⟩]\{⟨lang⟩\}\{⟨exceptions⟩\}}{\pghyphenation}
+% which can be used to define exceptions that only apply to a specific language or language variant,
+% respectively.
+% 
+% \subsection{Hyphenation disabling}
+% 
 % In some very specific contexts (such as music score creation), \TeX{} hyphenation
 % is something to avoid as it may cause troubles. \pkg{polyglossia} provides two
-% functions: \cmd\disablehyphenation{} and \cmd\enablehyphenation . Note that when
-% you select a new language, hyphenation will be in the same state (enabled or
-% disabled) as before. When you reenable it, it will take the last selected
-% language.
+% functions: \Cmd\disablehyphenation\ and \Cmd\enablehyphenation. Note that if
+% you select a new language while hyphenation is disabled, it will remain disabled.
+% If you re-enable it, the hyphenation patterns of the currently selected language
+% will be activated.
 % 
 % \section{Language-specific options and commands}\label{specific}
 % 
@@ -543,7 +696,7 @@
 % ^^A\subsection{amharic}\label{amharic}
 % 
 % \subsection{arabic}\label{arabic}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
 % 	\item \TB{calendar} = \textit{gregorian} or islamic (= hijri)
 % 	\item \TB{locale} = \textit{default},\footnote{ %
@@ -558,7 +711,7 @@
 %   \item \TB{abjadjimnotail} = \textit{false} or true. \new{v1.0.3}
 %     Set this to true if you want the \textit{abjad} form of the number three to be \textarabic{ج‍} – as in the manuscript tradition – instead of the modern usage \textarabic{ج}.
 % 	\end{itemize}
-% \textbf{Commands}:
+% \paragraph*{Commands:}
 % 	\begin{itemize}
 % 	\item \Cmd\abjad and \Cmd\abjadmaghribi (see section \ref{abjad})
 %   \item \Cmd\aemph to emphasize text with ¦\overline¦.\new{v1.2.0}
@@ -566,8 +719,15 @@
 %     This command is also available for Farsi, Urdu, etc.
 % 	\end{itemize}
 % 
-% \subsection{bengali}\label{bengali}\new{v1.2.0}
-% \textbf{Options}:
+% \subsection{armenian}\label{armenian}
+% \paragraph*{Options:}
+% \begin{itemize}
+% 	\item \TB{variant}\new{v1.45} = eastern or \textit{western}
+% 	\item \TB{numerals}\new{v1.45} = armenian or \textit{arabic}
+% \end{itemize}
+% 
+% \subsection[bengali]{bengali\new{v1.2.0}}\label{bengali}
+% \paragraph*{Options:}
 % 	\begin{itemize}
 % 		\item \TB{numerals} = Western, Bengali or \textit{Devanagari}
 % 		\item \TB{changecounternumbering} = true or \textit{false} (use specified
@@ -575,70 +735,129 @@
 % 	\end{itemize}
 % 
 % \subsection{catalan}\label{catalan}
-% \textbf{Options:}
+% \paragraph*{Options:}
 % \begin{itemize}
 %   \item \TB{babelshorthands} = \textit{false} or true. \new{v1.1.1}
 %     Activates the shorthands \texttt{"l} and \texttt{"L} to type geminated l’s.
 % \end{itemize}
-% \textbf{Commands}:
+% 
+% \paragraph*{Commands:}
 % \begin{itemize}
-%   \item \Cmd{\l.l} and \Cmd{\L.L} behave as in \pkg{babel} to type a geminated l, as in \textit{co\l.laborar}. \new{v1.1.1}
-%     In polyglossia the same can also be achieved with \Cmd{\l·l} and \Cmd{\L·L}.\footnote{ %
-%         NB: · is the glyph U+00B7 MIDDLE DOT.}
+%   \item \Cmd{\l.l} and \Cmd{\L.L}\new{v1.1.1} can be used to type a geminated l, as in \textit{co\l.laborar},
+%         similar to \pkg{babel} (the glyph U+00B7 MIDDLE DOT is used as a geminating sign).
 % \end{itemize}
 % 
+% \subsection{czech}\label{czech}
+% 
+% \paragraph*{Options:}
+% \begin{itemize}
+% 	\item \TB{babelshorthands} = \textit{false} or true. \new{v1.45}
+% 	if this is turned on, the following shorthands for Czech are activated:
+% 	\begin{shorthands}
+% 		\item[¦"=¦] for an explicit hyphen sign which is repeated at the beginning
+% 		            of the next line when hyphenated, as common in Czech typesetting
+% 		            (also see option ¦splithyphens¦).
+% 		\item[¦"‘¦] for Czech left double quotes (looks like ,,).
+% 		\item[¦"’¦] for Czech right double quotes (looks like “).
+% 		\item[¦">¦] for Czech left double guillemets (looks like >>).
+% 		\item[¦"<¦] for Czech right double guillemets (looks like <<).
+% 	\end{shorthands}
+% 	\item \TB{splithyphens} = \textit{false} or true. \new{v1.45}
+% 	      According to Czech typesetting conventions, if a word with a hard hyphen (such as \emph{je-li})
+% 	      is hyphenated at this hyphen, a second hyphenation character is to be inserted at the beginning
+% 	      of the line that follows the hyphenation (\emph{je-/-li}).\\
+%           If this option is true, this is done automatically (so the shorthand ¦"=¦ is not needed).
+%           Note, however, that the option is only available for \XeTeX. If you are using \LuaTeX,
+%           load the \pkg{luavlna} package to the same effect.
+%     \item \TB{vlna} = \textit{false} or true. \new{v1.45}
+%          According to Czech typesetting conventions, single-letter words (non-syllable prepositions)
+%          must not occur at line ends.\\
+%          If this option is true, this is taken care of. Note, however, that the option
+%          is only available for \XeTeX. If you are using \LuaTeX, load the \pkg{luavlna} package
+%          to the same effect.
+% \end{itemize}
+% 
 % \subsection{dutch}\label{dutch}
-% \textbf{Options:}
+% \paragraph*{Options:}
 % \begin{itemize}
 %   \item \TB{babelshorthands} = \textit{false} or true. \new{v1.1.1}
-% 		if this is turned on, all shorthands defined in \pkg{babel}
-% 		for fine-tuning the hyphenation of Dutch words are activated.
-% 		\begin{itemize}
-% 		\item ¦"-¦ for an explicit hyphen sign, allowing hyphenation in the rest of the word
-% 		\item ¦"~¦ for a compound word mark without a breakpoint
-% 		\item ¦"|¦ disables the ligature at this position
-% 		\item ¦""¦ is like ¦"-¦, but produces no hyphen sign
-% 			(for compound words with a hyphen, e.g., ¦foo-""bar¦)
-% 		\item ¦"/¦ to enable hyphenation in two words written together but separated by a slash.
-%     \item In addition, the macro \Cmd\- is redefined to allow hyphens in the rest of the word.
-% 		\end{itemize}
+% 		if this is turned on, the following shorthands defined for fine-tuning hyphenation and
+% 		micro-typography of Dutch words are activated:
+% 		\begin{shorthands}
+% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+% 			        in the hyphenation patterns (as opposed to ¦\-¦ in default \TeX).
+% 		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
+% 			        cases where the hyphen should stick at the following syllable.
+% 		\item[¦"|¦] disables a ligature at this position.
+% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
+% 		\item[¦"/¦] a slash that allows for a subsequent line break. As opposed to ¦\slash¦,
+% 		            hyphenation at the breakpoints preset in the hyphenation patterns is still allowed.
+% 		\end{shorthands}
+%         In addition, the macro \Cmd\- is redefined to allow hyphens in the rest of the word (equivalent to ¦"-¦).
 % \end{itemize}
 % 
 % \subsection{english}\label{english}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
-% 	\item \TB{variant} = \textit{american} (= us), usmax (same as ‘american’ but with additional hyphenation patterns), british (= uk), australian or newzealand
+% 	\item \TB{variant} = \textit{american} (= us), usmax (same as ‘american’ but with additional hyphenation patterns),
+% 	british (= uk), australian, canadian\new{v1.45} or newzealand
 % 	\item \TB{ordinalmonthday} = true/\textit{false} (true by default only when variant = british)
 % 	\end{itemize}
 % 
 % \subsection{esperanto}\label{esperanto}
-% \textbf{Commands}:
+% \paragraph*{Commands:}
 % 	\begin{itemize}
-% 	\item \Cmd\hodiau\ and \Cmd\hodiaun are special forms of \cmd\today\ (see the \pkg{babel} documentation)
+% 	\item \Cmd\hodiau\ and \Cmd\hodiaun are special forms of \cmd\today. The former produces the date in Esperanto
+% 	      preceded by the article (\emph{la}), which is the most common date format.
+% 	      The latter produces the same date format in accusative case.
 % 	\end{itemize}
 % 
-% \subsection{farsi}\label{farsi}
-% \textbf{Options}:
-% 	\begin{itemize}
-% 	\item \TB{numerals} = western or \textit{eastern}
-% 	\item \TB{locale} (not yet implemented)
-% 	\item \TB{calendar} (not yet implemented)
-% 	\end{itemize}
-% \textbf{Commands}:
-% 	\begin{itemize}
-% 	\item \Cmd\abjad (see section \ref{abjad})
-%   \item \Cmd\aemph (see section \ref{arabic}).
-% 	\end{itemize}
+% \subsection{finnish}\label{finnish}
+% \paragraph*{Options:}
+% \begin{itemize}
+%   \item \TB{babelshorthands} = \textit{false} or true. \new{v1.45}
+% 		if this is turned on, the following shorthands for fine-tuning hyphenation and micro-typography
+% 		of Finnish words are activated:
+% 		\begin{shorthands}
+% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+%                     in the hyphenation patterns (as opposed to ¦\-¦).
+%         \item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
+%                     cases where the hyphen should stick at the following syllable.
+%         \item[¦"|¦] disables a ligature at this position.
+%         \item[¦""¦] allows for a line break at this position (without hyphenation sign).
+%         \item[¦"/¦] a slash that allows for a subsequent line break. As opposed to ¦\slash¦,
+%                   hyphenation at the breakpoints preset in the hyphenation patterns is still allowed.
+% 		\end{shorthands}
+% \end{itemize}
 % 
-% \subsection{french}\label{french}\new{v1.5.0}
-% \textbf{Options}:
+% \subsection{french}\label{french}
+% \paragraph*{Options:}
 % 	\begin{itemize}
-% 		\item \TB{automaticspacesaroundguillemets} = true or \textit{false} (default value = true. Adds space after the opening guillemets and before the closing guillemets. Such space is usually not typed in source code, and you should let polyglossia add it. However, if your source code contains such space, you can set this option to false.)
-% 		\item \TB{frenchfootnote} = true or \textit{false} (default value = true. Determines whether the footnote mark starting the footnote is normal script followed by a dot (default) or superscript without a dot.)
+% 		\item\TB{variant} = \textit{french} or canadian (=~acadian).\new{v1.45}
+% 		Currently, the three variants do not differ; they are supported for compatibility with \pkg{babel} (where they do not differ either).
+% 		\item \TB{autospacing} = true or \textit{false} (default value = true). One of the most distinct features of French typography is the addition
+% 		of extra spacing around punctuation and quotation marks (guillemets). By default, polyglossia adds these spaces automatically, so you don't need
+% 		to enter them. This options allows you to switch this feature off globally.
+% 		\item \TB{autospaceguillemets}\footnote{Up to version 1.44, the option was called \textit{automaticspacesaroundguillemets}. For backards compatibility reasons, the more verbose old option is still supported.} = true or \textit{false} (default value = true). If you only want to disable the automatic addition of spacing after opening and before closing guillemets (and not at punctuation), set this to \textit{false}. Note
+% 		that the more general option \textit{autospacing} overrides this.
+% 		\item \TB{autospacetypewriter}\footnote{Babel's syntax \textit{OriginalTypewriter} is also supported.}\new{1.45} = true or \textit{false} (default value = true). By default, automatic spacing is disabled in typewriter font. If this is enabled, spacing in typewriter context is the same as with roman and sans serif font, depending on the \textit{autospacing} and \textit{autospaceguillemets} settings (note that this was the default up to v.~1.44).	
+% 		\item \TB{frenchfootnote} = true or \textit{false} (default value = true). If \textit{true}, footnotes start with a non-superscripted number followed by a dot, as common in French typography. Note that this might interfere with the specific footnote handling of classes or packages.
+% 		Also note that this option is only functional (by design) if French is the main language.
 % 	\end{itemize}
+% \paragraph*{Commands:}
+% \begin{itemize}
+% 	\item \Cmd\NoAutoSpacing\new{v1.45} disables automatic spacing around punctuation and quotation marks in all following text. The command can also be used locally if braces are used for grouping: ¦{\NoAutoSpacing foo:bar}¦
+% 	\item \Cmd\AutoSpacing\new{v1.45} enables automatic spacing around punctuation and quotation marks in all following text. The command can also be used locally if braces are used for grouping: ¦{\AutoSpacing regarde!}¦
+% \end{itemize}
 % 
+% \subsection[gaelic]{gaelic\new{v1.45}}\label{gaelic}
+% \paragraph*{Options:}
+% \begin{itemize}
+% 	\item \TB{variant} = \textit{irish} or scottish
+% \end{itemize}
+% 
 % \subsection{german}\label{german}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
 % 	\item\TB{variant} = \textit{german}, austrian or swiss.\new{v1.33.4}
 % 		Setting variant=austrian or variant=swiss uses some lexical variants.
@@ -653,39 +872,43 @@
 % 		the file \texttt{language.dat} that comes with \TeX Live 2008 and later.
 % 	\item\TB{babelshorthands} = \textit{false} or true: \new{v1.0.3}
 % 		if this is turned on, all shorthands defined in \pkg{babel}
-% 		for fine-tuning the hyphenation of German words are activated.
-% 		\begin{itemize}
-% 		\item  ¦"ck¦ for ¦ck¦ to be hyphenated as ¦k-k¦
-% 		\item  ¦"ff¦ for ¦ff¦ to be hyphenated as ¦ff-f¦; this is also available for the letters l, m, n, p, r and t
-% 		\item ¦"|¦ disables the ligature at this position
-% 		\item ¦"-¦ for an explicit hyphen sign, allowing hyphenation in the rest of the word
-% 		\item ¦""¦ is like ¦"-¦, but produces no hyphen sign
-% 			(for compound words with a hyphen, e.g., ¦foo-""bar¦)
-% 		\item ¦"~¦ for a compound word mark without a breakpoint
-% 		\item ¦"=¦ for a compound word mark with a breakpoint,
-% 			allowing hyphenation in the composing words.
-% 		\item ¦"/¦ a slash that allows for a line break and maintains hyphenation points.
-% 		\end{itemize}
+% 		for fine-tuning hyphenation and micro-typography of German words are activated.
+% 		\begin{shorthands}
+% 		\item[¦"ck¦] for ¦ck¦ to be hyphenated as ¦k-k¦ (1901 spelling).
+% 		\item[¦"ff¦] for ¦ff¦ to be hyphenated as ¦ff-f¦ (1901 spelling); this is also available
+% 		           for the letters l, m, n, p, r and t.
+% 		\item[¦"|¦] disables a ligature at this position (\eg ¦Auf"|lage¦).
+% 		\item[¦"=¦] for an explicit hyphen with a breakpoint, allowing for hyphenation at the
+% 		           other points preset in the hyphenation patterns (as opposed to plain ¦-¦).
+% 		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
+% 		           cases where the hyphen should stick at the following syllable,\eg ¦bergauf und "~ab¦.
+% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+% 		           in the hyphenation patterns (as opposed to ¦\-¦).
+% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign); 
+% 		           \eg ¦(pseudo"~)""wissenschaftlich¦.
+% 		\item[¦"/¦] a slash that allows for a subsequent line break. As opposed to ¦\slash¦, hyphenation at the breakpoints
+% 		           preset in the hyphenation patterns is still allowed.
+% 		\end{shorthands}
 % 
 % 		There are also four shorthands for quotation signs:
-% 		\begin{itemize}
-% 		\item  ¦"`¦ for German left double quotes („)
-% 		\item  ¦"'¦ for German right double quotes (“)
-% 		\item  ¦"<¦ for French left double quotes («)
-% 		\item  ¦">¦ for French right double quotes (»).
-% 		\end{itemize}
+% 		\begin{shorthands}
+% 		\item[¦"`¦] for German left double quotes („)
+% 		\item[¦"'¦] for German right double quotes (“)
+% 		\item[¦"<¦] for French left double quotes («)
+% 		\item[¦">¦] for French right double quotes (»).
+% 		\end{shorthands}
 % 	\item\TB{script} = \textit{latin} or fraktur.\new{v1.2.0}
 % 		Setting script=fraktur modifies the captions for typesetting German in Fraktur.
 % 	\end{itemize}
 % 
 % \subsection{greek}\label{greek}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
 % 	\item \TB{variant} = \textit{monotonic} (= mono), polytonic (= poly), or ancient
 % 	\item \TB{numerals} = \textit{greek} or arabic
 % 	\item \TB{attic} = \textit{false}/true
 % 	\end{itemize}
-% \textbf{Commands}:
+% \paragraph*{Commands:}
 % 	\begin{itemize}
 % 	\item \Cmd\Greeknumber and \Cmd\greeknumber \ (see section \ref{abjad}).
 % 	\item The command \Cmd\atticnumeral (= \Cmd\atticnum) (activated with
@@ -696,116 +919,251 @@
 % 	\end{itemize}
 % 
 % \subsection{hebrew}\label{hebrew}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
 % 	\item \TB{numerals} = hebrew or \textit{arabic}
 % 	\item \TB{calendar} = hebrew or \textit{gregorian}
+% 	\item \TB{marcheshvan} = true or \textit{false} (default value = true). If true, the second month of the civil year will be output as \texthebrew{מרחשון} (Marcheshvan)
+% 	rather than \texthebrew{חשון} (Heshvan), which is the default.
 % 	\end{itemize}
-% \textbf{Commands}:
+% \paragraph*{Commands:}
 % 	\begin{itemize}
 % 	\item \Cmd\hebrewnumeral\ (= \Cmd\hebrewalph) (see section \ref{abjad}).
 %   \item \Cmd\aemph (see section \ref{arabic}).
 % 	\end{itemize}
 % 
-% \subsection{hindi}\label{hindi}\new{v1.2.0}
-% \textbf{Options}:
+% \subsection[hindi]{hindi\new{v1.2.0}}\label{hindi}
+% \paragraph*{Options:}
 % 	\begin{itemize}
 %     \item \TB{numerals} = Western or \textit{Devanagari}
 % 	\end{itemize}
 % 
+% \subsection{hungarian}\label{hungarian}
+% \paragraph*{Commands:}
+% \begin{itemize}
+% 	\item \Cmd\ontoday\ (= \Cmd\ondatehungarian): special form of \cmd\today\ which produces a slightly different
+% 	date format as used in prepositional phrases (such as ‘on February 10th’) in Hungarian.
+% \end{itemize}
+% 
 % \subsection{italian}\label{italian}
-% \textbf{Option:}
+% \paragraph*{Options:}
 % \begin{itemize}
 %   \item \TB{babelshorthands} = \textit{false} or true. \new{v1.2.0cc}% TODO: check version
-% 	Activates the ¦"¦ character as a switch to perform etymological
-% 	hyphenation when followed by a letter, or other tasks when followed by
-% 	certain analphabetic characters; in particular ¦""¦ is used to enter
-% 	double raised open quotes (the Italian keyboard misses the backtick),
-% 	and ¦"<¦  and ¦">¦ to insert open and closed guillemets without any
-% 	spacing after the open or before the closed sign. ¦"/¦ is made
-% 	equivalent to \slash allowing a linebreak after the slash without any
-% 	hyphen sign; ¦"-¦ produces  a short rule/hyphen and a discretional line
-% 	break alowing line breaks in the second compound word fragment.
+%   Activates the ¦"¦ character as a switch to perform etymological
+%   hyphenation when followed by a letter. Furthermore, the following shorthands are activated:
+%   \begin{shorthands}
+%   	\item[¦""¦] double raised open quotes (the Italian keyboard misses the backtick).
+%   	\item[¦"<¦] open guillemet (looks like <<).
+%   	\item[¦">¦] closing guillemet (looks like >>).
+%   	\item[¦"/¦] a slash that allows for a subsequent line break. As opposed to ¦\slash¦,
+%                hyphenation at the breakpoints preset in the hyphenation patterns is still allowed.
+%   	\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+%                in the hyphenation patterns (as opposed to ¦\-¦).
+%   \end{shorthands}
 % \end{itemize}
 % 
-% \subsection{korean}\label{korean}\new{v1.40.0}
-% The language definition file includes U. S. hyphenation patterns in order to
-% enable hyphenation when writing English within Korean text.
+% \subsection[korean]{korean\new{v1.40.0}}\label{korean}
+% \paragraph*{Options:}
+%   \begin{itemize}
+%   \item \TB{variant} = \textit{plain}, classic or modern:
+%     for spacing before/after CJK punctuations.
+%     `classic' is suitable for text with no interword spaces,
+%     `modern' for text with interword spaces.
+%   \item \TB{captions} = \textit{hangul} or hanja
+%   \end{itemize}
 % 
-% \subsection{lao}\label{lao}\new{v1.2.0}
-% \textbf{Options}:
+% \subsection[kurdish]{kurdish\new{v1.45}}\label{kurdish}
+% Kurdish support includes Sorani Kurdish and Kurmanji Kurdish, both in either Arabic or Latin script.
+% 
+% \paragraph*{Options:}
+% \begin{itemize}
+% 	\item \TB{variant} = kurmanji or \textit{sorani}
+% 	\item \TB{script} = Arabic or Latin. Defaults are ¦Arabic¦ for Sorani and ¦Latin¦ for Kurmanji.
+% 	\item \TB{numerals} = western or eastern. Defaults are ¦western¦ for Latin and ¦eastern¦ for Arabic script, depending on the selection above.
+% 	\item \TB{abjadjimnotail} = \textit{false} or true.
+% 	Set this to true if you want the \textit{abjad} form of the number three to be \textarabic{ج‍} – as in the manuscript tradition – instead of the modern usage \textarabic{ج}.
+% 	\item \TB{locale} (not yet implemented)
+% 	\item \TB{calendar} (not yet implemented)
+% \end{itemize}
+% \paragraph*{Commands:}
+% \begin{itemize}
+% 	\item \Cmd\ontoday: special form of \cmd\today\ which produces a slightly different
+% 	date format as used in prepositional phrases (as in ‘on February 10th’). Only available for Latin script.
+% 	\item \Cmd\abjad (see section \ref{abjad})
+% 	\item \Cmd\aemph (see section \ref{arabic})
+% \end{itemize}
+% 
+% \subsection[lao]{lao\new{v1.2.0}}\label{lao}
+% \paragraph*{Options:}
 % 	\begin{itemize}
 % 	\item \TB{numerals} = lao or \textit{arabic}
 % 	\end{itemize}
 % 
 % \subsection{latin}\label{latin}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
 % 	\item \TB{variant} = classic, medieval or \textit{modern}
 % 	\end{itemize}
 % 
-% \subsection{lsorbian and usorbian}\label{lsorbian}\label{usorbian}
-% \textbf{Commands}:
-% 	\begin{itemize}
-% 	\item \Cmd\oldtoday : see the \pkg{babel} documentation.
-% 	\end{itemize}
+% \subsection{malay}\label{malay}
+% \paragraph*{Options:}
+% \begin{itemize}
+% 	\item \TB{variant}\new{v1.45} = \textit{indonesian} (=~bahasai in \pkg{babel}) or
+% 	malaysian (=~bahasam in \pkg{babel})
+% \end{itemize}
 % 
-% \subsection{magyar}\label{magyar}
-% \textbf{Commands}:
-% 	\begin{itemize}
-% 	\item \Cmd\ontoday\ (= \Cmd\ondatemagyar): special forms of \cmd\today\
-% 		(see the \pkg{babel} documentation).
-% 	\end{itemize}
+% \subsection[mongolian]{mongolian\new{v1.45}}\label{mongolian}
+% Currently, only the Khalkha variety in Cyrillic script is supported.
 % 
+% \paragraph*{Options:}
+% \begin{itemize}
+% 	\item \TB{babelshorthands} = \textit{false} or true.
+% 	If this is turned on, the following shorthands are activated:
+% 	\begin{shorthands}
+%         \item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+% 		           in the hyphenation patterns (as opposed to ¦\-¦).
+% 		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
+% 		           cases where the hyphen should stick at the following syllable.
+% 		\item[¦"|¦] disables a ligature at this position.
+% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
+% 		\item[¦"---¦] Cyrillic emdash in plain text.
+% 		\item[¦"--~¦] Cyrillic emdash in compound names (surnames).
+% 		\item[¦"--*¦] Cyrillic emdash for denoting direct speech.
+% 		\item[¦",¦] thinspace for initials with a breakpoint in following surname.
+% 		\item[¦"‘¦] for German left double quotes (looks like ,,).
+% 		\item[¦"’¦] for German right double quotes (looks like “).
+% 		\item[¦"<¦] for French left double quotes (looks like <<).
+% 		\item[¦">¦] for French right double quotes (looks like >>).
+% 	\end{shorthands}
+% 	\item \TB{numerals} = \textit{arabic} or cyrillic. Uses either Arabic numerals or Cyrillic
+% 	alphanumerical numbering.
+% \end{itemize}
+% ^^A
+% \paragraph*{Commands:}
+% \begin{itemize}
+% 	\item \Cmd\Asbuk: produces uppercased Cyrillic alphanumerals, for
+% 	environments such as ¦enumerate¦. The command takes a counter as argument,
+% 	\eg ¦\textrussian{\Asbuk{page}}¦ produces \textrussian{\Asbuk{page}}.
+% 	\item \Cmd\asbuk: same in lowercase
+% \end{itemize}
 % 
+% \subsection{norwegian}\label{norwegian}
+% \paragraph*{Options:}
+% \begin{itemize}
+% 	\item \TB{variant}\new{v1.45} = bokmal (=~`norsk' in \pkg{babel}) or \textit{nynorsk}
+% \end{itemize}
+% 
+% \subsection{persian}\label{persian}
+% \paragraph*{Options:}
+% \begin{itemize}
+% 	\item \TB{numerals} = western or \textit{eastern}
+% 	\item \TB{abjadjimnotail} = \textit{false} or true. \new{v1.0.3}
+% 	Set this to true if you want the \textit{abjad} form of the number three to be \textarabic{ج‍} – as in the manuscript tradition – instead of the modern usage \textarabic{ج}.
+% 	\item \TB{locale} (not yet implemented)
+% 	\item \TB{calendar} (not yet implemented)
+% \end{itemize}
+% \paragraph*{Commands:}
+% \begin{itemize}
+% 	\item \Cmd\abjad (see section \ref{abjad})
+% 	\item \Cmd\aemph (see section \ref{arabic}).
+% \end{itemize}
+% 
+% \subsection{portuguese}\label{portuguese}
+% \paragraph*{Options:}
+% \begin{itemize}
+% 	\item \TB{variant}\new{v1.45} = brazilian or \textit{portuguese}
+% \end{itemize}
+% 
 % \subsection{russian}\label{russian}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
-% 	\item \TB{babelshorthands} = \textit{false} or true. % TODO check and document!
+% 	\item \TB{babelshorthands} = \textit{false} or true.
+% 	If this is turned on, the following shorthands are activated:
+% 	\begin{shorthands}
+% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
+% 		           in the hyphenation patterns (as opposed to ¦\-¦).
+% 		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
+% 		           cases where the hyphen should stick at the following syllable.
+% 		\item[¦"|¦] disables a ligature at this position.
+% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
+% 		\item[¦"---¦] Cyrillic emdash in plain text.
+% 		\item[¦"--~¦] Cyrillic emdash in compound names (surnames).
+% 		\item[¦"--*¦] Cyrillic emdash for denoting direct speech.
+% ^^A These are commented out in gloss-russian
+% ^^A		\item[¦",¦] thinspace for initials with a breakpoint in following surname.
+% ^^A		\item[¦"‘¦] for German left double quotes (looks like ,,).
+% ^^A		\item[¦"’¦] for German right double quotes (looks like “).
+% ^^A		\item[¦"<¦] for French left double quotes (looks like <<).
+% ^^A		\item[¦">¦] for French right double quotes (looks like >>).
+% 	\end{shorthands}
 % 	\item \TB{spelling} = \textit{modern} or old (for captions and date only, not for hyphenation)
+% 	\item \TB{numerals} = \textit{arabic} or cyrillic. Uses either Arabic numerals or Cyrillic
+% 	alphanumerical numbering.
 % 	\end{itemize}
-% 
-% \textbf{Commands}:
+% ^^A
+% \paragraph*{Commands:}
 % 	\begin{itemize}
-% 	\item \Cmd\Asbuk: produces the uppercase Russian alphabet, for
-% 	environments such as ¦enumerate¦
+% 	\item \Cmd\Asbuk: produces uppercased Cyrillic alphanumerals, for
+% 	environments such as ¦enumerate¦. The command takes a counter as argument,
+% 	\eg ¦\textrussian{\Asbuk{page}}¦ produces \textrussian{\Asbuk{page}}.
 % 	\item \Cmd\asbuk: same in lowercase
 % 	\end{itemize}
 % 
+% \subsection[sami]{sami\new{v1.45}}\label{sami}
+% Currently support for Sami is limited to Northern Sami.
+% 
 % \subsection{sanskrit}\label{sanskrit}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
-% 	\item \TB{Script} (default = Devanagari). \new{v1.0.2}
-% 	The value is passed to \pkg{fontspec} in cases where ¦\sanskritfont¦ or
-% 	¦\devanagarifont¦ are not defined. This can be useful if you typeset
-% 	Sanskrit texts in scripts other than Devanagari.
-% ^^ATODO \item Numerals <<<<
+% 	\item \TB{Script} = \textit{Devanagari}\new{v1.0.2}, Gujarati, Malayalam, Bengali, Kannada,
+% 	Telugu or Latin.
+% 	The value is passed to \pkg{fontspec} in cases where the respective ¦\<script>font¦ is not defined.
+% 	This can be useful if you typeset Sanskrit texts in scripts other than Devanagari.
+% 	\item \TB{Numerals} = \textit{Devanagari}\new{v1.45} or Western
 % 	\end{itemize}
-%   \pkg{polyglossia} currently supports the typesetting of Sanskrit in the
-%   following writing systems: Devanagari, Gujarati, Malayalam, Bengali, Kannada,
-%   Telugu, and Latin.  Use the ¦Script=¦ option to select the writing system 
-%   you want, and enter your input in that script.
 %  
 % \subsection{serbian}\label{serbian}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
-% 	\item \TB{script} = \textit{cyrillic} or latin
+% 	\item \TB{Script} = \textit{Cyrillic} or Latin. Will likely go to a variant.
+% 	\item \TB{numerals} = \textit{arabic} or cyrillic. Uses either Arabic numerals or Cyrillic
+% 	      alphanumerical numbering.
 % 	\end{itemize}
+% \paragraph*{Commands:}
+% \begin{itemize}
+% 	\item \Cmd\Asbuk: produces uppercased Cyrillic alphanumerals, for
+% 	environments such as ¦enumerate¦. The command takes a counter as argument,\\
+% 	Example: ¦\textserbian[numerals=cyrillic]{\Asbuk{page}}¦ produces \textserbian[numerals=cyrillic]{\Asbuk{page}}.
+% 	\item \Cmd\asbuk: same in lowercase
+% \end{itemize}
 % 
+% 
 % \subsection{slovenian}\label{slovenian}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
-% 	\item \TB{localaph} = true \textit{false}
+% 	\item \TB{localalph} = true or \textit{false}
 % 	\end{itemize}
 % 
+% \subsection{sorbian}\label{sorbian}
+% \paragraph*{Options:}
+% \begin{itemize}
+% 	\item \TB{variant}\new{v1.45} = lower or \textit{upper}
+% 	\item \TB{olddate}\new{v1.45} = true or \textit{false} (default value = true). If true, ¦\today¦
+% 	      will use traditional Sorbian month names (\ie it will be synonymous to ¦\oldtoday¦ below)
+% \end{itemize}
+% \paragraph*{Commands:}
+% \begin{itemize}
+% 	\item \Cmd\oldtoday: outputs the current date using traditional Sorbian month names, even if \TB{olddate} is false.
+% \end{itemize}
+% 
 % \subsection{syriac}\label{syriac}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
 % 	\item \TB{numerals} = \textit{western} (i.e., 1234567890), eastern
 % 		(for which the Oriental Arabic numerals are used: \textarabic{١٢٣٤٥٦٧٨٩٠}),
 % 		or abjad. \new{v1.0.1}.
 % 	\end{itemize}
-% \textbf{Commands}:
+% \paragraph*{Commands:}
 % 	\begin{itemize}
 % 	\item \Cmd\abjadsyriac (see section \ref{abjad})
 %   \item \Cmd\aemph (see section \ref{arabic}).
@@ -812,17 +1170,23 @@
 % 	\end{itemize}
 % 
 % \subsection{thai}\label{thai}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
 % 	\item \TB{numerals} = thai or \textit{arabic}
 % 	\end{itemize}
-% 
-% To insert the word breaks, you need to use an external processor.
+% ^^A
+% To insert word breaks, you need to use an external processor.
 % See the documentation to \pkg{thai-latex} and the file \file{testthai.tex}
 % that comes with this package.
 % 
-% \subsection{ukrainian}\label{russian}
-% \textbf{Commands}:
+% \subsection{tibetan}\label{tibetan}
+% \paragraph*{Options:}
+% \begin{itemize}
+% 	\item \TB{numerals} = tibetan or \textit{arabic}
+% \end{itemize}
+% 
+% \subsection{ukrainian}\label{ukrainian}
+% \paragraph*{Commands:}
 % 	\begin{itemize}
 % 	\item \Cmd\Asbuk: produces the uppercase Ukrainian alphabet, for
 % 	environments such as ¦enumerate¦
@@ -830,80 +1194,229 @@
 % 	\end{itemize}
 % 
 % \subsection{welsh}\label{welsh}
-% \textbf{Options}:
+% \paragraph*{Options:}
 % 	\begin{itemize}
 % 	\item \TB{date} = long or \textit{short}
 % 	\end{itemize}
 % 
-% \section{Modifying or extending captions and date formats}
 % 
-% To redefine internal macros, you can use the command ¦\gappto¦ from the package
-% \pkg{etoolbox}. For compatibility with \pkg{babel} the command ¦\addto¦ is also available
-% with the same effect. For instance, to change the ¦\chaptername¦ for language ¦lingua¦,
+% \section{Modifying or extending captions, date formats and language settings}
+% 
+% \pkg{Polyglossia} uses the following macros to define language-specific captions
+% (\ie strings such as ``chapter''), date formats and additional language settings
+% (¦⟨lang⟩¦ is to be replaces with the respective language name):
+% 
+% \begin{itemize}
+% 	\item \Cmd{\captions⟨lang⟩} stores definitions of caption strings
+% 	           (such as, in the case of English, ¦\def\chaptername{Chapter}¦)
+% 	\item \Cmd{\date⟨lang⟩} stores definitions of date formats (usually redefinitions
+% 	           of ¦\today¦, in some cases also definitions of additional date commands)
+% 	\item \Cmd{\blockextras⟨lang⟩} stores macros that are to be executed when the language
+%               ⟨lang⟩ is activated via ¦\selectlanguage¦ command or the ¦⟨lang⟩¦ environment
+% 	\item \Cmd{\inlineextras⟨lang⟩} stores macros that are to be executed when the language
+% 	          ⟨lang⟩ is activated locally via ¦\text⟨lang⟩¦ command
+% 	\item \Cmd{\noextras⟨lang⟩} stores macros that are to be executed when the language
+% 	          ¦⟨lang⟩¦ is closed 
+% \end{itemize} 
+% ^^A
+% In order to redefine internal macros, we recommend to use the command ¦\gappto¦.
+% For compatibility with \pkg{babel} the command ¦\addto¦ is also available
+% to the same effect. For instance, to change the ¦\chaptername¦ for language ¦lingua¦,
 % you can do this:
 % \begin{verbatim}
-% \gappto\captionslingua{\renewcommand{\chaptername}{Caput}}
+% \gappto\captionslingua{\def\chaptername{Caput}}
 % \end{verbatim}
+% ^^A
+% Note that this needs to be done after the respective language has been loaded with
+% ¦\setmainlanguage¦ or ¦\setotherlanguage¦.
 % 
-% \section{Non-Western decimal digits}
+% Specifically for package authors, analogous commands are provided which are only executed
+% if a specific language \emph{variety} is used. As opposed to the macros above, these refer
+% to babel names. Other than that, the function is identical:
 % 
-% Several scripts have their own versions of the decimal digits commonly called
-% ‘Arabic numerals’.  With the appropriate language option set, \pkg{polyglossia}
+% \begin{itemize}
+% 	\item \Cmd{\captions at bbl@⟨babelname⟩} 
+% 	\item \Cmd{\date at bbl@⟨babelname⟩}
+% 	\item \Cmd{\blockextras at bbl@⟨babelname⟩}
+% 	\item \Cmd{\inlineextras at bbl@⟨babelname⟩}
+% 	\item \Cmd{\noextras at bbl@⟨babelname⟩} 
+% \end{itemize}
+% ^^A
+% By default, these macros are undefined. If they are defined (\eg by an external package),
+% they will be executed after their respective ¦⟨lang⟩¦ counterpart and thus can be used to
+% overwrite definitions of the former. Again, use ¦\gappto¦ to define\slash modify these macros.
+% For instance, to add a new caption ¦\footnotename¦ to the Swiss variety of German (babel name
+% ¦nswissgerman¦), you can do this:
+% \begin{verbatim}
+% \gappto\captions at bbl@nswissgerman{\def\footnotename{Fussnote}}
+% \end{verbatim}
+% ^^A
+% If you do this in a document preamble rather than in a package, you need to embrace the redefinition
+% by ¦\makeatletter¦ and ¦\makeatother¦ due to the ¦@¦ in the macro names.
+% 
+% \section{Script-specific numbering}
+% 
+% Languages and scripts have specific numbering conventions. Some use decimal digits
+% (\eg Arabic numerals), some use alphabetic or alphanumerical notation (\eg Roman numbering).
+% In some cases, different conventions are available (\eg Mashriq or Maghrib numbering
+% in Arabic script, Arabic or Hebrew [=~alphanumeric] numbering in Hebrew).
+% 
+% If the latter is the case, \pkg{polyglossia} provides language options which allow you to select
+% or switch to the suitable convention. With the appropriate language option set, \pkg{polyglossia}
 % will automatically convert the output of internal \LaTeX\ counters to their
 % localized forms, for instance to display page, chapter and section numbers.
 % 
-% In previous versions this conversion was achieved my means of TECKit fontmappings.
-% If needed they can be activated with the fontspec ¦Mapping¦ option,
+% For manual input of numbers, macros are provided. These convert Arabic numeric input to the respective
+% local decimal digit (see sec.~\ref{sec:decdigit}), alphanumeric representation (see sec.~\ref{abjad})
+% or whatever is appropriate (see sec.~\ref{sec:localnumber}). The possibilities are described in turn.
+% 
+% \subsection{General localization of numbering}\label{sec:localnumber}
+% 
+% As of 1.45,\new{1.45} \pkg{polyglossia} provides a generic macro \Cmd\localnumeral\ which converts numbers
+% to the current local form (which might be script-specific decimal digit, an alphabetic numbering or something else).
+% For instance in an Arabic environment
+% ¦\localnumeral{42}¦ yields \textarabic{\localnumeral{42}}, whereas in an Hebrew environment, it
+% results in \texthebrew[numerals=hebrew]{\localnumeral{42}} with ¦numerals=hebrew¦, and \texthebrew{\localnumeral{42}}
+% with ¦numerals=arabic¦. Note that, as opposed to the various ¦digits¦ macros (described in sec.~\ref{sec:decdigit}),
+% the argument of ¦\localnumeral¦ must consist of numbers only.
+% 
+% For\new{1.45} the conversion of counters, the starred version \Cmd{\localnumeral*} is provided. This takes a counter as argument.
+% For instance in an Arabic environment ¦\localnumeral*{page}¦ yields \textarabic{\localnumeral*{page}}.
+% 
+% For scripts with alphanumeric numbering, the variants \Cmd{\Localnumeral} and \Cmd{\Localnumeral*} provide the uppercased 
+% versions.\medskip
+% 
+% \noindent All these macros provide the following options:
+% 
+% \begin{itemize}
+% 	\item \TB{lang} =\DescribeMacro{[lang=]}\ \textit{local}, main, or <language>.\\
+% 	Output number in the local form of the currently active language for ¦local¦, the main language of the document for ¦main¦,
+%     and any (loaded) language for ¦<language>¦ (\eg ¦\localnumeral[lang=arabic]{42}}¦).
+% \end{itemize}
+% 
+% \subsection{Non-Western decimal digits}\label{sec:decdigit}
+% 
+% In addition\new{v1.1.1} to the generic macros described above, \pkg{polyglossia} provides language-specific conversion macros
+% which can be used if the generic ones do not suit the need.\footnote{%
+% A third method are so-called TECKit fontmappings.
+% Those can be activated with the \pkg{fontspec} ¦Mapping¦ option,
 % using ¦arabicdigits¦, ¦farsidigits¦ or ¦thaidigits¦.
 % For instance if \cmd\arabicfont\ is defined with the option ¦Mapping=arabicdigits¦,
-% then by typing ¦\textarabic{2010}¦ one will obtain \textarabic{٢٠١٠}.
+% typing \cmd{\textarabic\{2010\}} results in \textarabic{٢٠١٠}. Note that this method has some drawbacks, though,
+% for instance when the value of a counter has to be written and read from auxiliary files.
+% So please use this with care.}
+% The macros have the form ¦\<script>digits¦. They convert Arabic numerical input and leave every other input untouched.
+% In an Arabic context, for instance, ¦\arabicdigits{9182/738543-X}¦ yields \textarabic{\arabicdigits{9182/738543-X}}.
 % 
-% With version v1.1.1\new{v1.1.1} the same conversion is achieved directly by
-% simple \TeX\ macros. This prevents some problems that occur when the value of a
-% counter has to be written and read from auxiliary files.\footnote{ %
-%   For instance the package \pkg{lastpage} did not work with \pkg{polyglossia} in situations
-%   where the display of counters was redefined to include a font-switching command.}
-% These macros (currently \Cmd\arabicdigits, \Cmd\farsidigits\ and \Cmd\thaidigits\ are provided)
-% are also available to the users. For instance in an Arabic environment
-% ¦\arabicdigits{9182/738543-X}¦ yields
-% \textarabic{\arabicdigits{9182/738543-X}}.
+% Currently, the following macros are provided:
 % 
-% \section{Alphabetic numbering in Greek, Arabic, Hebrew, Syriac and Farsi}\label{abjad}
+% \begin{itemize}
+% 	\item \Cmd\arabicdigits
+% 	\item \Cmd\bengalidigits
+% 	\item \Cmd\devanagaridigits
+% 	\item \Cmd\farsidigits
+% 	\item \Cmd\kannadadigits
+% 	\item \Cmd\khmerdigits
+% 	\item \Cmd\laodigits
+% 	\item \Cmd\nkodigits
+% 	\item \Cmd\thaidigits
+% 	\item \Cmd\tibetandigits
+% \end{itemize}
 % 
-% In certain languages, numbers can be represented
-% by a special alphanumerical notation.\footnote{ %
-% 	See, e.g., \url{http://en.wikipedia.org/wiki/Greek_numerals},
+% 
+% \subsection{Non-Latin alphabetic numbering}\label{abjad}
+% 
+% For languages which use special (non-Latin) alphanumerical notation\footnote{%
+% 	For instance, see \url{http://en.wikipedia.org/wiki/Greek_numerals},
 % 	\url{http://en.wikipedia.org/wiki/Abjad_numerals},
-% 	and \url{http://en.wikipedia.org/wiki/Hebrew_numerals}.}
-% ^^A \url{http://en.wikipedia.org/wiki/Syriac_alphabet}
+% 	\url{http://en.wikipedia.org/wiki/Hebrew_numerals},
+% 	and \url{http://en.wikipedia.org/wiki/Syriac_alphabet}.}, dedicated macros are provided.
 % 
-% The Greek numerals are obtained with \Cmd\greeknumeral (or \Cmd\Greeknumeral\ in uppercase).
-% Example: ¦\greeknumeral{1863}¦ yields \textgreek{\greeknumeral{1863}}.
+% They work in a similar way than the ¦\<script>digits¦ macros described above: They take Arabic numerical input
+% and output the respective value in the local alphabetic numbering scheme (most of these macros are equivalent
+% to ¦\localnumeral¦ and ¦\Localnumeral¦ in the respective context).
 % 
-% The Arabic \textit{abjad} numbers can be generated with the command \Cmd\abjad.
-% Example: ¦\abjad{1863}¦ yields \textarabic{\abjad{1863}}.
-% In the Maghrib the conventions are somewhat different, and the maghribi forms
-% of the \textit{abjad} numerals are obtained with the \Cmd\abjadmaghribi\ command.
-% Example: ¦\abjadmaghribi{1863}¦ yields \textarabic{\abjadmaghribi{1863}}.
+% The following macros are provided:
 % 
-% The code for Hebrew numerals, which was incorrect in previous versions, was
-% ported from the implementation in \pkg{babel} with v1.1.1\new{v1.1.1}, and the
-% user interface is identical to the one in \pkg{babel}.
-% The commands \Cmd\hebrewnumeral, \Cmd\Hebrewnumeral and \Cmd\Hebrewnumeralfinal\ behave exactly
-% as they do in \pkg{babel}: the second command prints the number with \textit{gereshayim} before
-% the last letter, and the latter uses in addition the final forms of Hebrew letters.
-% Examples:
-% ¦\hebrewnumeral{1750}¦ yields \texthebrew{\hebrewnumeral{1750}},
-% ¦\Hebrewnumeral{1750}¦ yields \texthebrew{\Hebrewnumeral{1750}},
-% and ¦\Hebrewnumeralfinal{1750}¦ yields \texthebrew{\Hebrewnumeralfinal{1750}}.
+% \begin{itemize}
+%     \item \Cmd\abjad outputs Arabic \textit{abjad} numbers according to the Mashriq varieties.
+% 			Example: ¦\abjad{1863}¦ yields \textarabic{\abjad{1863}}.
+% 			
+% 	\item \Cmd\abjadmaghribi outputs Arabic \textit{abjad} numbers according to the Maghrib varieties.
+% 			Example: ¦\abjadmaghribi{1863}¦ yields \textarabic{\abjadmaghribi{1863}}.
+% 			
+% 	\item \Cmd\abjadsyriac outputs Syriac abjad numerals.\footnote{%
+% 				A fine guide to numerals in Syriac can be found at \link{http://www.garzo.co.uk/documents/syriac-numerals.pdf}.}\\
+% 			Example: ¦\abjadsyriac{463}¦ yields \textsyriac{\abjadsyriac{463}}.
+% 	
+% 	\item \Cmd\armeniannumeral produces Armenian alphabetic numbering.
+% 	          Example: ¦\armeniannumeral{1863}¦ yields \textarmenian{\armeniannumeral{1863}}.
 % 
+% 	\item \Cmd\greeknumeral produces Greek alphabetic numbering, \Cmd\Greeknumeral outputs uppercased variants.
+% 			Example: ¦\greeknumeral{1863}¦ yields \textgreek{\greeknumeral{1863}},
+% 			¦\Greeknumeral{1863}¦ results in \textgreek{\Greeknumeral{1863}}.
 % 
-% Support is also provided for Syriac abjad numerals, which can be generated
-% with \Cmd\abjadsyriac.\footnote{ %
-% A fine guide to numerals in Syriac can be found at \link{http://www.garzo.co.uk/documents/syriac-numerals.pdf}.}
-% Example: ¦\abjadsyriac{463}¦ yields \textsyriac{\abjadsyriac{463}}.
+% 	\item \Cmd\hebrewnumeral, \Cmd\Hebrewnumeral and \Cmd\Hebrewnumeralfinal generate variants of Hebrew alphanumeric numerals.
+% 			The commands behave exactly as they do in \pkg{babel}: ¦\hebrewnumeral¦ outputs the numbers without any decoration,
+% 			¦\Hebrewnumeral¦ adds \textit{gereshayim} before the last letter, ¦\Hebrewnumeralfinal¦ uses in addition the final forms of Hebrew letters.
+% 			Examples:
+% 			¦\hebrewnumeral{1750}¦ yields \texthebrew{\hebrewnumeral{1750}},
+% 			¦\Hebrewnumeral{1750}¦ yields \texthebrew{\Hebrewnumeral{1750}},
+% 			and ¦\Hebrewnumeralfinal{1750}¦ yields \texthebrew{\Hebrewnumeralfinal{1750}}.
+% 	
+% 	\item \Cmd\russiannumeral produces Russian numbering, with uppercased variant (for alphanumerical variant) via \Cmd\Russiannumeral.
+% 	        Depending on the ¦numerals¦ option in the Russian language selection, this is either Arabic digit or Cyrillic
+% 	        alphanumercial output.\\
+% 	        Example: With ¦numerals=latin¦ ¦\russiannumeral{19}¦ yields \textrussian{\russiannumeral{19}},
+% 	        with ¦numerals=cyrillic¦ ¦\russiannumeral{19}¦ results in \textrussian[numerals=cyrillic]{\russiannumeral{19}}.
+% 			
+% 	\item \Cmd\serbiannumeral produces Serbian numbering, with uppercased variant (for alphanumerical variant) via \Cmd\Serbiannumeral.
+% 		    Depending on the ¦numerals¦ option in the Serbian language selection, this is either Arabic digit or Cyrillic
+% 		    alphanumercial output.\\
+% 		    Example: With ¦numerals=latin¦ ¦\serbiannumeral{19}¦ yields \textserbian{\serbiannumeral{19}},
+% 			with ¦numerals=cyrillic¦ ¦\serbiannumeral{19}¦ results in \textserbian[numerals=cyrillic]{\serbiannumeral{19}}.
+% \end{itemize}
 % 
 % 
+% \section{Footnotes in right-to-left context}
+% 
+% With languages that use right-to-left scripts, footnote apparatuses are usually placed at the right side of the page bottom.
+% Consequently, the footnote rule also is to be placed right. Things get more tricky, though, if right-to-left and left-to-right
+% scripts are mixed. Then you might want to put the footnotes on some pages left, on some right, or even mix positions on a page.
+% Thus, footnote handling in right-to-left context sometimes needs manual intervention. This is described in what follows.
+% 
+% \subsection{Horizontal footnote position}
+% 
+% When right-to-left languages are used, the ¦\footnote¦ command becomes sensitive to the text directionality. The footnote is
+% always placed on the side that is currently the origin of direction: on the left side of the page in LTR paragraphs and
+% on the right in RTL paragraphs.
+% 
+% For cases where this is not desired, two additional footnote commands are provided: \Cmd\RTLfootnote and \Cmd\LTRfootnote.
+% ¦\LTRfootnote¦ always places the footnote on the left side, notwithstanding the current
+% directionality. Likewise, ¦\RTLfootnote¦ always places it on the right side. Like ¦\footnote¦, ¦\RTLfootnote¦
+% and ¦\LTRfootnote¦ provide an optional argument to customize the number.
+% 
+% 
+% \subsection{Footnote rule length and position}
+% 
+% The default placement of the footnote rule differs in \XeTeX\ and \LuaTeX\ output (this is due to differences in the \textsf{bidi}
+% and \textsf{luabidi} packages). With \XeTeX, footnote rules are always placed left, which is often wrong in RTL context.
+% With \LuaTeX, by contrast, the rule is placed always right if the main language is a right-to-left language, and always left
+% if the main language is a left-to-right language, which is the right thing in many cases.
+% 
+% In both cases, you can change the default behavior as follows:
+% \begin{itemize}
+% 	\item Put \Cmd\leftfootnoterule in the preamble to have all rules left-aligned.
+% 	\item Put \Cmd\rightfootnoterule in the preamble to have all rules right-aligned.
+% 	\item Put \Cmd\autofootnoterule in the preamble to have automatic placement depending on the context (see below for elaboration).
+% 	\item Put \Cmd\textwidthfootnoterule in the preamble to have a rule that spans the whole text width.
+% \end{itemize}
+% With ¦\autofootnoterule¦, the first footnote on the current page determines the placement. Note that this automatic can fail with
+% footnotes at page boundaries that differ in directionality from the first footnote on the page. You can work around such cases by switching to ¦\rightfootnoterule¦ or ¦\leftfootnoterule¦ on these pages.
+% 
+% Note also that the rule switches might interfere in bad ways with packages or classes that redefine footnotes themselves. This is also the reason
+% why ¦\autofootnoterule¦ is not used by default.
+% 
 % \section{Calendars}
 % 
 % \subsection{Hebrew calendar (hebrewcal.sty)}
@@ -925,8 +1438,7 @@
 % \Cmd\Hijritoday\ formats the Hijri date for the current day.
 % This command is now locale-aware\new{v1.1.1}: its output will differ depending on the
 % currently active language. Presently \pkg{polyglossia}’s language definition files
-% for Arabic, Farsi, Urdu, Turkish, Bahasa Indonesia and Bahasa Melayu
-% provide a localized version of ¦\Hijritoday¦.
+% for Arabic, Farsi, Urdu, Turkish and Malay provide a localized version of ¦\Hijritoday¦.
 % If the formatting macro for the current language is undefined, the Hijri date will be formatted
 % in Arabic or in roman transliteration, depending of the current writing direction.
 % You can define a new format or redefine one with the command
@@ -955,38 +1467,69 @@
 % 
 % ^^A\section{Varia}
 % 
+% \section{Accessing language information}
 % 
+% The following is specifically relevant to package authors who need information about the languages in use.
+% 
+% In order to get such information, \pkg{polyglossia} provides the following macros:
+% 
+% \begin{itemize}
+% 	\item \Cmd\languagename\ stores the currently active (polyglossia) language name.
+% 	\item \Cmd\mainlanguagename\ stores the (polyglossia) language name of the main document language.
+% 	\item \Cmd\languagevariant\ stores the language variant if set. The macro is empty if no variant has been set.
+% 	\item \Cmd\mainlanguagevariant\ stores the language variant of the main document language if set.
+% 	       The macro is empty if no variant has been set.
+% 	\item \Cmd\babelname\ stores the corresponding name of the currently active language (variant) in \pkg{babel}.
+% 	      This might not only be useful if you want to support both \pkg{babel} and \pkg{polyglossia}, but also
+% 	      since this name is unique for a given language variety (\eg ngerman, german, swissgerman etc.).
+% 	      Note that this macro is also defined for languages that are not supported in \pkg{babel}. In that
+% 	      case, they are equal to the polyglossia language name.
+% 	\item \Cmd\mainbabelname\ analogously stores the name of document's main language (variant) in \pkg{babel}.
+% \end{itemize}
+% ^^A
+% If you want to have a full list of loaded languages/variants, use the following macros:
+% \begin{itemize}
+% 	\item \Cmd{\xpg at loaded}\ stores a comma-separated list of all loaded languages (polyglossia name)
+% 	\item \Cmd{\xpg at vloaded}\ stores a comma-separated list of all loaded variants
+% 	\item \Cmd{\xpg at bloaded}\ stores a comma-separated list of \pkg{babel} names of all language variants 
+% \end{itemize}
+% ^^A
+% Finally, you can test whether a language is loaded by
+% \displaycmd{\iflanguageloaded\{⟨lang⟩\}\{⟨true⟩\}\{⟨false⟩\}}{\iflanguageloaded}
+% where \texttt{⟨lang⟩} is a \pkg{polyglossia} language name, or
+% \displaycmd{\ifbabellanguageloaded\{⟨lang⟩\}\{⟨true⟩\}\{⟨false⟩\}}{\ifbabellanguageloaded}
+% where \texttt{⟨lang⟩} is a \pkg{babel} language name.
+% 
 % \section{Acknowledgements (by François Charette)}
 % \pkg{Polyglossia} is notable for being a recycle box of previous contributions
 % by other people. I take this opportunity to thank the following individuals,
-% whose splendid work has made my task almost trivial in comparision: Johannes
-% Braams and the numerous contributors to the \pkg{babel}{} package (in particular
-% Boris Lavva and others for its Hebrew support), Alexej Kryukov (\pkg{antomega}), Will
-% Robertson (\pkg{fontspec}), Apostolos Syropoulos (\pkg{xgreek}), Youssef Jabri
-% (\pkg{arabi}), and Vafa Khalighi (\pkg{xepersian} and \pkg{bidi}).
-% The work of Mojca Miklavec and Arthur Reutenauer on hyphenation patterns with their package
+% whose splendid work has made my task almost trivial in comparision: \TA{Johannes
+% Braams} and the numerous contributors to the \pkg{babel} package (in particular
+% \TA{Boris Lavva} and others for its Hebrew support), \TA{Alexej Kryuko}v (\pkg{antomega}),
+% \TA{Will Robertson} (\pkg{fontspec}), \TA{Apostolos Syropoulos} (\pkg{xgreek}), \TA{Youssef Jabri}
+% (\pkg{arabi}), and \TA{Vafa Khalighi} (\pkg{xepersian} and \pkg{bidi}).
+% The work of \TA{Mojca Miklavec} and \TA{Arthur Reutenauer} on hyphenation patterns with their package
 % \pkg{hyph-utf8} is of course invaluable. I should also thank other
-% individuals for their assistance in supporting specific languages: Yves Codet
-% (Sanskrit), Zdenek Wagner (Hindi), Mikhal Oren (Hebrew), Sergey Astanin (Russian),
-% Khaled Hosny (Arabic), Sertaç Ö. Yıldız (Turkish), Kamal Abdali (Urdu),
-% and several other members of the \XeTeX\ user community, notably Enrico Gregorio, who
+% individuals for their assistance in supporting specific languages: \TA{Yves Codet}
+% (Sanskrit), \TA{Zdenĕk Wagner} (Hindi), \TA{Mikhal Oren} (Hebrew), \TA{Sergey Astanin} (Russian),
+% \TA{Khaled Hosny} (Arabic), \TA{Sertaç Ö. Yıldız} (Turkish), \TA{Kamal Abdali} (Urdu),
+% and several other members of the \XeTeX\ user community, notably \TA{Enrico Gregorio}, who
 % has sent me many useful suggestions and corrections and contributed the ¦\newXeTeXintercharclass¦
 % mechanism in xelatex.ini which is now used by polyglossia.
-% More recently, Kevin Godby of the \href{http://ubuntu-manual.org}{Ubuntu Manual} project has
+% More recently, \TA{Kevin Godby} of the \href{http://ubuntu-manual.org}{Ubuntu Manual} project has
 % contributed very useful feedback, bug hunting and, with the help of translators,
 % new language definition files for Asturian, Lithuanian, Occitan, Bengali, Malayalam, Marathi, Tamil, and Telugu.
 % It is particularly heartening to realize that this package is used to typeset a widely-read
 % document in dozens of different languages!
-% Support for Lao was also added thanks to Brian Wilson.
-% I also thank Alan Munn for kindly proof-reading the penultimate version of this documentation.
-% And of course my gratitude also goes to Jonathan Kew, the formidable author of \XeTeX!
+% Support for Lao was also added thanks to \TA{Brian Wilson}.
+% I also thank \TA{Alan Munn} for kindly proof-reading the penultimate version of this documentation.
+% And of course my gratitude also goes to \TA{Jonathan Kew}, the formidable author of \XeTeX!
 % 
 % \section{More acknowledgements (by Arthur Reutenauer)}
 % Many thanks to all the people who have contributed bugfixes and new features to
-% Polyglossia since I took over.  Most of them can be identified from the version
-% control log on \href{https://github.com/reutenauer/polyglossia}{GitHub} and I won’t try to name them
+% Polyglossia since I took over.  Most of them can be identified from the contributor statistics on \href{https://github.com/reutenauer/polyglossia/graphs/contributors}{GitHub} and I won’t try to name them
 % all (maybe, one day ...); among the ones who sent contributions directly to me
-% I would like to especially thank Claudio Beccari, the indefatigable champion of
+% I would like to especially thank \TA{Claudio Beccari}, the indefatigable champion of
 % Romance languages, and beyond!
 % 
 % 
@@ -1005,6 +1548,7 @@
 
 \PolyglossiaSetup{albanian}{
   hyphennames={albanian},
+  langtag=SQI,
   hyphenmins={2,2},
   indentfirst=true,
   fontsetup=true,
@@ -1278,9 +1822,10 @@
   langtag=ARA,
   scripttag=arab,
   hyphennames={nohyphenation},
-  fontsetup=true
+  fontsetup=true,
+  envname=Arabic,
+  localnumeral=arabicnumerals
   %TODO localalph={abjad,abjad}
-  %TODO localnumber=arabicnumber
 }
 
 \newif\ifeastern at numerals
@@ -1400,6 +1945,9 @@
     \fi%
  \fi}}
 
+
+\newcommand{\arabicnumerals}[2]{\arabicnumber{#2}}
+
 \def\arabicnumber#1{%
   \ifeastern at numerals
     \arabicdigits{\number#1}%
@@ -1445,35 +1993,40 @@
   \ifnum#1=\z@\fi\abj at maghribi@num at iii}
 
 \def\arabic at numbers{%
-   \let\@origalph\@alph%
-   \let\@origAlph\@Alph%
    \let\@alph\abjad%
    \let\@Alph\abjad%
 }
+
 \def\noarabic at numbers{%
-  \let\@alph\@origalph%
-  \let\@Alph\@origAlph%
-  }
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
+}
 
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
 \def\arabic at globalnumbers{%
-  \let\orig at arabic\@arabic%
   \let\@arabic\arabicnumber%
-  \renewcommand\thefootnote{\protect\arabicnumber{\c at footnote}}%
-  }
+  \renewcommand\thefootnote{\localnumeral*{footnote}}%
+  \renewcommand\theequation{\localnumeral*{equation}}%
+}
 
-\def\noarabic at globalnumbers{
-   \let\@arabic\orig at arabic%
-   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
-   }
+\def\noarabic at globalnumbers{%
+   \let\@arabic\xpg at save@arabic%
+}
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at arabic{%
-   \let\orig at MakeUppercase\MakeUppercase%
    \def\MakeUppercase##1{##1}%
    % TODO disable \@Roman and \@roman ?
-   }
+}
+
 \def\noextras at arabic{%
-   \let\MakeUppercase\orig at MakeUppercase%
-   }
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase
+}
 
 %    \end{macrocode}
 % \iffalse
@@ -1492,35 +2045,57 @@
   langtag=HYE,
   hyphennames={armenian},
   hyphenmins={2,2},
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=armeniannumerals
 }
 
-%\def\captionsarmenian{%
-%   \def\refname{}%
-%   \def\abstractname{}%
-%   \def\bibname{}%
-%   \def\prefacename{}%
-%   \def\chaptername{}%
-%   \def\appendixname{}%
-%   \def\contentsname{}%
-%   \def\listfigurename{}%
-%   \def\listtablename{}%
-%   \def\indexname{}%
-%   \def\authorname{}%
-%   \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\datearmenian{%
+\newif\if at eastern@armenian
+\@eastern at armenianfalse
+\define at choicekey*+{armenian}{variant}[\val\nr]{western,eastern}[western]{%
+   \ifcase\nr\relax
+      % western:
+      \@eastern at armenianfalse%
+   \or
+      % eastern:
+      \@eastern at armeniantrue%
+   \fi
+   \xpg at info{Option: Armenian, variant=\val}%
+}{\xpg at warning{Unknown Armenian variant `#1'}}
+
+\newif\if at armenian@numerals
+\@armenian at numeralsfalse
+\define at key{armenian}{numerals}[armenian]{%
+  \ifstrequal{#1}{arabic}{\@armenian at numeralsfalse}{\@armenian at numeralstrue}%
+}
+
+% Taken from ArmTeX. Audit!
+\def\captionsarmenian{%
+   \def\refname{Հղումներ}%
+   \def\abstractname{Սեղմագիր}%
+   \def\bibname{Գրականություն}%
+   \def\prefacename{Նախաբան}%
+   \def\chaptername{Գլուխ}%
+   \def\appendixname{Հավելված}%
+   \def\contentsname{Բովանդակություն}%
+   \def\listfigurename{Նկարների ցանկ}%
+   \def\listtablename{Աղյուսակների ցանկ}%
+   \def\indexname{Առարկայական ցանկ}%
+   \def\figurename{Նկար}%
+   \def\tablename{Աղյուսակ}%
+   \def\partname{Մաս}%
+   \def\pagename{էջ}%
+   \def\seename{տե՛ս}%
+   \def\alsoname{տե՛ս նաեւ}%
+   \def\enclname{Կից՝}%
+   \def\ccname{Կրկնօրինակը՝}%
+% The \headtoname is empty: the typesetter should use the dative (trakan
+% holov) of the recipient's name.
+   \def\headtoname{}%
+   \def\proofname{Ապացույց}%
+   \def\glossaryname{Տերմինների ցանկ}%
+}
+
+\def\date at western@armenian{%
    \def\today{\ifcase\month\or
     Յունուար\or
     Փետրուար\or
@@ -1534,7 +2109,103 @@
     Հոկտեմբեր\or
     Նոյեմբեր\or
     Դեկտեմբեր\fi
-    \number\day,\space\number\year}}
+    \number\day,\space\number\year}%
+}
+
+\def\date at eastern@armenian{%
+   \def\today{\ifcase\month\or
+    Հունվար\or
+    Փետրվար\or
+    Մարտ\or
+    Ապրիլ\or
+    Մայիս\or
+    Հունիս\or
+    Հուլիս\or
+    Օգոստոս\or
+    Սեպտեմբեր\or
+    Հոկտեմբեր\or
+    Նոյեմբեր\or
+    Դեկտեմբեր\fi
+    \number\day,\space\number\year}%
+}
+
+\def\datearmenian{%
+  \if at eastern@armenian
+     \date at eastern@armenian%
+  \else
+     \date at western@armenian%
+  \fi
+}
+
+\newcommand{\armeniannumerals}[2]{%
+  \if at armenian@numerals
+     \armeniannumber{#2}%
+  \else
+     #2%
+  \fi%
+}
+
+\def\armenian at numbers{%
+   \if at armenian@numerals
+      \def\armenian at alph##1{\expandafter\armeniannumeral\expandafter{\the##1}}%
+      \let\@alph\armenian at alph%
+   \fi%
+}
+
+\def\noarmenian at numbers{%
+  \let\@alph\latin at alph%
+  \let\armenian at alph\@undefined%
+}
+
+\def\armenian at globalnumbers{%
+  \if at armenian@numerals
+    \let\@arabic\armeniannumber%
+    \renewcommand\thefootnote{\localnumeral*{footnote}}%
+    \renewcommand\theequation{\localnumeral*{equation}}%
+  \fi
+}
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
+\def\noarmenian at globalnumbers{
+   \let\@arabic\xpg at save@arabic%
+}
+
+\protected\def\armeniannumber#1{\expandafter\@armeniannumber\expandafter{\number#1}}
+\def\@armeniannumber#1{%
+  \ifnum#1<\@ne\space\arm at ill@value{#1}%
+  \else
+    \ifnum#1<10\expandafter\arm at num@i\number#1%
+    \else
+      \ifnum#1<100\expandafter\arm at num@ii\number#1%
+      \else
+        \ifnum#1<\@m\expandafter\arm at num@iii\number#1%
+        \else
+          \ifnum#1<\@M\expandafter\arm at num@iv\number#1%
+          \else
+             \space\arm at ill@value{#1}%
+          \fi
+        \fi
+      \fi
+    \fi
+  \fi
+}
+
+\let\armeniannumeral=\armeniannumber
+\def\arm at num@i#1{%
+  \ifcase#1\or Ա\or Բ\or Գ\or Դ\or Ե\or Զ\or Է\or Ը\or Թ\fi}
+\def\arm at num@ii#1{%
+  \ifcase#1\or Ժ\or Ի\or Լ\or Խ\or Ծ\or Կ\or Հ\or Ձ\or Ղ\fi
+  \arm at num@i}
+\def\arm at num@iii#1{%
+  \ifcase#1\or Ճ\or Մ\or Յ\or Ն\or Շ\or Ո\or Չ\or Պ\or Ջ\fi
+  \arm at num@ii}
+\def\arm at num@iv#1{%
+  \ifcase#1\or Ռ\or Ս\or Վ\or Տ\or Ր\or Ց\or Ւ\or Փ\or Ք\fi
+  \arm at num@iii}
+\def\arm at ill@value#1{\xpg at warning{Illegal value (#1) for Armenian numeral}[$#1$]}
+
 %    \end{macrocode}
 % \iffalse
 %</gloss-armenian.ldf>
@@ -1551,6 +2222,7 @@
 \PolyglossiaSetup{asturian}{
   hyphennames={asturian,catalan},
   hyphenmins={2,2},
+  langtag=AST,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,
@@ -1596,49 +2268,24 @@
 % \subsection{gloss-bahasai.ldf}
 %    \begin{macrocode}
 \ProvidesFile{gloss-bahasai.ldf}[polyglossia: module for bahasa indonesia]
-\RequirePackage{hijrical}
 
+% We only provide this gloss for babel compatibility. Since bahasai is 
+% a malay variety, we use 'malay' with variant 'indonesian' now.
+
+\input{gloss-malay.ldf}
+
 \PolyglossiaSetup{bahasai}{%
-  language=Bahasa Indonesia,
+  language=Indonesian,
+  langtag=IND,
   hyphennames={indonesian,indon,bahasai,bahasa,bahasam,malay,melayu},
   hyphenmins={2,2},
   fontsetup=true}
 
-\def\captionsbahasai{%
-   \def\refname{Pustaka}%
-   \def\abstractname{Ringkasan}%
-   \def\bibname{Bibliografi}%
-   \def\prefacename{Pendahuluan}%
-   \def\chaptername{Bab}%
-   \def\appendixname{Lampiran}%
-   \def\contentsname{Daftar Isi}%
-   \def\listfigurename{Daftar Gambar}%
-   \def\listtablename{Daftar Tabel}%
-   \def\indexname{Indeks}%
-   \def\figurename{Gambar}%
-   \def\tablename{Tabel}%
-   %\def\thepart{}%
-   \def\partname{Bagian}%
-   \def\pagename{Halaman}%
-   \def\seename{lihat}%
-   \def\alsoname{lihat juga}%
-   \def\enclname{Lampiran}%
-   \def\ccname{cc}%
-   \def\headtoname{Kepada}%
-   \def\proofname{Bukti}%
-   \def\glossaryname{Daftar Istilah}%
-   }
-\def\datebahasai{%
-   \def\today{\number\day~\ifcase\month\or
-    Januari\or Pebruari\or Maret\or April\or Mei\or Juni\or
-    Juli\or Agustus\or September\or Oktober\or Nopember\or Desember\fi
-    \space \number\year}}
+\let\captionsbahasai\captionsmalay at indonesian
+\let\datebahasai\datemalay at indonesian
 
-\def\hijrimonthbahasai#1{\ifcase#1%
-\or Muharram\or Safar\or Rabiul awal\or Rabiul akhir\or Jumadil awal\or Jumadil akhir\or Rajab%
-\or Sya'ban\or Ramadhan\or Syawal\or Dzulkaidah\or Dzulhijjah\fi}
 \DefineFormatHijriDate{bahasai}{%
-\number\value{Hijriday}\space\hijrimonthbahasai{\value{Hijrimonth}}\space\number\value{Hijriyear}}
+  \number\value{Hijriday}\space\hijrimonthmalay at indonesian{\value{Hijrimonth}}\space\number\value{Hijriyear}}
 
 %    \end{macrocode}
 % \iffalse
@@ -1650,57 +2297,24 @@
 % \subsection{gloss-bahasam.ldf}
 %    \begin{macrocode}
 \ProvidesFile{gloss-bahasam.ldf}[polyglossia: module for bahasa melayu]
-\RequirePackage{hijrical}
+
+% We only provide this gloss for babel compatibility. Since bahasai is 
+% a malay variety, we use 'malay' with variant 'indonesian' now.
+
+\input{gloss-malay.ldf}
+
 \PolyglossiaSetup{bahasam}{%
-  language=Bahasa Melayu,
+  language=Malay,
+  langtag=MLY,
   hyphennames={malay,melayu,bahasam,bahasa,bahasai,indonesian,indon},
   hyphenmins={2,2},
   fontsetup=true}
 
-\def\captionsbahasam{%
-   \def\refname{Rujukan}%
-   \def\abstractname{Abstrak}%
-   \def\bibname{Bibliografi}%
-   \def\prefacename{Pendahuluan}%
-   \def\chaptername{Bab}%
-   \def\appendixname{Lampiran}%
-   \def\contentsname{Kandungan}%
-   \def\listfigurename{Senarai Rajah}%
-   \def\listtablename{Senarai Jadual}%
-   \def\indexname{Indeks}%
-   \def\figurename{Rajah}%
-   \def\tablename{Jadual}%
-   \def\thepart{}%
-   \def\partname{Bahagian}%
-   \def\pagename{Halaman}%
-   \def\seename{lihat}%
-   \def\alsoname{lihat juga}%
-   \def\enclname{Lampiran}%
-   \def\ccname{salinan kpd}%
-   \def\headtoname{Kepada}%
-   \def\proofname{Bukti}%
-   \def\glossaryname{Senarai Istilah}%
-   }
-\def\datebahasam{%
-   \def\bahasam at day{%
-      \ifcase\day\or%
-        1hb\or 2hb\or 3hb\or 4hb\or 5hb\or%
-        6hb\or 7hb\or 8hb\or 9hb\or 10hb\or%
-        11hb\or 12hb\or 13hb\or 14hb\or 15hb\or%
-        16hb\or 17hb\or 18hb\or 19hb\or 20hb\or%
-        21hb\or 22hb\or 23hb\or 24hb\or 25hb\or%
-        26hb\or 27hb\or 28hb\or 29hb\or 30hb\or%
-        31hb\fi}%
-   \def\today{\bahasam at day~\ifcase\month\or
-    Januari\or Februari\or Mac\or April\or Mei\or Jun\or
-    Julai\or Ogos\or September\or Oktober\or November\or Disember\fi
-    \space \number\year}}
+\let\captionsbahasam\captionsmalay at malay
+\let\datebahasam\datemalay at malay
 
-\def\hijrimonthbahasam#1{\ifcase#1%
-\or Muharram\or Safar\or Rabiulawal\or Rabiulakhir\or Jamadilawal\or Jamadilakhir\or Rejab%
-\or Syaaban\or Ramadan\or Syawal\or Zulkaedah\or Zulhijah\fi}
 \DefineFormatHijriDate{bahasam}{%
-\number\value{Hijriday}\space\hijrimonthbahasam{\value{Hijrimonth}}\space\number\value{Hijriyear}}
+  \number\value{Hijriday}\space\hijrimonthmalay at malay{\value{Hijrimonth}}\space\number\value{Hijriyear}}
 
 %    \end{macrocode}
 % \iffalse
@@ -1715,6 +2329,7 @@
 \PolyglossiaSetup{basque}{
   hyphennames={basque},
   hyphenmins={2,2},
+  langtag=EUQ,
   indentfirst=true,
   fontsetup=true,
 }
@@ -1779,8 +2394,8 @@
   hyphennames={bengali},
   hyphenmins={2,2},%CHECK
   fontsetup=true,
+  localnumeral=bengalinumerals
   %TODO nouppercase=true,
-  %TODO localnumber=bengalinumber
 }
 
 \def\tmp at western{Western}
@@ -1834,7 +2449,7 @@
 }
 
 \def\captionsbengali{%
-  \def\refname{তথ্যসুত্রসমূহ}%
+  \def\refname{তথ্যসূত্রসমূহ}%
   \def\abstractname{সারসংক্ষেপ}%
   \def\bibname{তথ্যবিবরণ}%
   \def\prefacename{পূর্বকথা}%
@@ -1844,8 +2459,8 @@
   \def\listfigurename{ছবি/নকশা সমূহের তালিকা}%
   \def\listtablename{তালিকাসারণী}%
   \def\indexname{সূচক/নির্দেশক}%
-  \def\figurename{ছবি/নকশা}%
-  \def\tablename{সারনী}%
+  \def\figurename{চিত্র}%
+  \def\tablename{সারণী}%
   %\def\thepart{}% TODO
   \def\partname{খন্ড}%
   \def\pagename{পৃষ্ঠা}%
@@ -1860,14 +2475,14 @@
 \def\datebengali{%
   \def\bengalimonth{%
     \ifcase\month\or
-      জানুয়ারী\or
-      ফেব্রুয়ারী\or
+      জানুয়ারি\or
+      ফেব্রুয়ারি\or
       মার্চ\or
       এপ্রিল\or
       মে\or
       জুন\or
       জুলাই\or
-      আগষ্ট\or
+      আগস্ট\or
       সেপ্টেম্বর\or
       অক্টোবর\or
       নভেম্বর\or
@@ -1875,6 +2490,8 @@
   \def\today{\bengalinumber\day\space\bengalimonth\space\bengalinumber\year}%
 }
 
+\newcommand{\bengalinumerals}[2]{\bengalinumber{#2}}
+
 \def\bengalinumber#1{%
   \ifbengali at devanagari@numerals
     \devanagaridigits{\number#1}%
@@ -1886,9 +2503,20 @@
     \fi
   \fi}
 
-\def\bengalinumber#1{\bengalidigits{\number#1}}% Takes number
-\def\bengalinumeral#1{\bengalinumber{\csname c@#1\endcsname}}% Takes counter
+\def\bengalinumeral#1{\expandafter\bengalinumber\expandafter{\the##1}}% Takes counter
 
+\def\bengali at globalnumbers{%
+   \let\@arabic\bengalinumber%
+   \renewcommand\thefootnote{\localnumeral*{footnote}}%
+}
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
+\def\nobengali at globalnumbers{%
+  \let\@arabic\xpg at save@arabic%
+}
+
 \def\blockextras at bengali{\extras at bengali}
 \def\inlineextras at bengali{\extras at bengali}
 
@@ -1901,44 +2529,29 @@
 % 
 % \subsection{gloss-brazil.ldf}
 %    \begin{macrocode}
-\ProvidesFile{gloss-brazil.ldf}[polyglossia: module for portuguese]
+\ProvidesFile{gloss-brazil.ldf}[polyglossia: module for brazilian portuguese]
+
+% We only provide this gloss for backwards compatibility. The name
+% 'brazil' was selected in accordance with babel.
+% Since brazil is a variety of portuguese, we use 'portuguese' now.
+
+% FIXME: Once we support babel aliases (#112) this gloss can go.
+
+\xpg at warning{The language name 'brazil' is deprectated.\MessageBreak
+             Please use 'portuguese' with variant 'brazilian' instead.}
+
+\input{gloss-portuguese.ldf}
+
 \PolyglossiaSetup{brazil}{
   language=Brazilian Portuguese,
+  langtag=PTG,
   hyphennames={brazil,portuguese,portuges},
   hyphenmins={2,3},
   fontsetup=true,
 }
 
-\def\captionsbrazil{%
-   \def\refname{Referências}%
-   \def\abstractname{Resumo}%
-   \def\bibname{Referências Bibliográficas}%
-   \def\prefacename{Prefácio}%
-   \def\chaptername{Capítulo}%
-   \def\appendixname{Apêndice}%
-   \def\contentsname{Sumário}%
-   \def\listfigurename{Lista de Figuras}%
-   \def\listtablename{Lista de Tabelas}%
-   \def\indexname{Índice Remissivo}%
-   \def\figurename{Figura}%
-   \def\tablename{Tabela}%
-   %\def\thepart{}%
-   \def\partname{Parte}%
-   \def\pagename{Página}%
-   \def\seename{veja}%
-   \def\alsoname{veja também}%
-   \def\enclname{Anexo}%
-   \def\ccname{Cópia para}%
-   \def\headtoname{Para}%
-   \def\proofname{Demonstração}%
-   \def\glossaryname{Glossário}%
-   }
-\def\datebrazil{%   
-   \def\today{\number\day\space de\space\ifcase\month\or
-      janeiro\or fevereiro\or março\or abril\or maio\or junho\or
-      julho\or agosto\or setembro\or outubro\or novembro\or dezembro%
-      \fi\space de\space\number\year}%
-      }
+\let\captionsportuges\captionsportuguese at brazil
+\let\dateportuges\dateportuguese at brazil
      
 %    \end{macrocode}
 % \iffalse
@@ -1953,6 +2566,7 @@
 \PolyglossiaSetup{breton}{
   hyphennames={breton},
   hyphenmins={2,2},
+  langtag=BRE,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,
@@ -2078,8 +2692,6 @@
    \xpg at ill@value{#1}{bulgarian at alph}\fi}%
 
 \def\bulgarian at numbers{%
-   \let\latin at Alph\@Alph%
-   \let\latin at alph\@alph%
    \let\@Alph\bulgarian at Alph%
    \let\@alph\bulgarian at alph%
  }
@@ -2145,6 +2757,7 @@
 \PolyglossiaSetup{catalan}{
   hyphennames={catalan},
   hyphenmins={2,2},
+  langtag=CAT,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,
@@ -2156,9 +2769,11 @@
 \else
   \setkeys{catalan}{babelshorthands=false}
 \fi
+
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 %%% adapted from Babel's catalan.ldf
@@ -2296,172 +2911,6 @@
 %    \end{macrocode}
 % \iffalse
 %</gloss-catalan.ldf>
-%<*gloss-classiclatin.ldf>
-% \fi
-% \clearpage
-% 
-% \subsection{gloss-classiclatin.ldf}
-%    \begin{macrocode}
-%%
-%% This is file `gloss-classiclatin.ldf',
-%% generated with the docstrip utility.
-%%
-%% The original source files were:
-%%
-%% gloss-latin.dtx  (with options: `laclassic')
-%%   ------------------------------------------------------------------
-%%   Latin module for polyglossia
-%%   Copyright (C) Claudio Beccari 2013-2016
-%%   Copyright (C) Élie Roux 2016
-%%   This work is distributed under the MIT License.
-%% 
-%%   See the postamble.
-%%   ------------------------------------------------------------------
-\ProvidesFile{gloss-classiclatin.ldf}
-        [2016/09/10 v.1.03 Latin support from polyglossia]
-%%
-
-
-\PolyglossiaSetup{classiclatin}{%
-      hyphennames={classiclatin},
-      hyphenmins={2,2},
-      frenchspacing=true,
-      fontsetup=true,
-}
-\def\classicuclccodes{\lccode`\V=`\u \uccode`\u=`\V}
-\def\noclassicuclccodes{\lccode`\V=`\v \uccode`\u=`\U}
-\def\classiclatincaptions{%
-   \def\prefacename{Praefatio}%
-   \def\refname{Conspectus librorum}%
-   \def\abstractname{Summarium}%
-   \def\bibname{Conspectus librorum}%
-   \def\chaptername{Caput}%
-   \def\appendixname{Additamentum}%
-   \def\contentsname{Index}%
-   \def\listfigurename{Conspectus descriptionum}%
-   \def\listtablename{Conspectus tabularum}%
-   \def\indexname{Index rerum notabilium}%
-   \def\figurename{Descriptio}%
-   \def\tablename{Tabula}%
-   \def\partname{Pars}%
-   \def\enclname{Additur}%
-   \def\ccname{Exemplar}%
-   \def\headtoname{\ignorespaces}%
-   \def\pagename{charta}%
-   \def\seename{cfr.}%
-   \def\alsoname{cfr.}%
-   \def\proofname{Demonstratio}%
-   \def\glossaryname{Glossarium}%
-   }
-
-\def\classiclatindate{%
-   \def\today{\uppercase\expandafter{\romannumeral\day}%
-      \space \ifcase\month
-      \or Januarii\or Februarii\or Martii\or Aprilis\or Maii\or Junii\or
-      Julii\or Augusti\or Septembris\or Octobris\or Nouembris\or
-      Decembris\fi
-      \space \uppercase\expandafter{\romannumeral\year}}}
-
-\define at boolkey{classiclatin}[classiclatin@]{babelshorthands}[true]{}
-
-\ifsystem at babelshorthands
-  \setkeys{classiclatin}{babelshorthands=true}
-\else
-  \setkeys{classiclatin}{babelshorthands=false}
-\fi
-
-\ifcsundef{initiate at active@char}{%
-    \input{babelsh.def}\initiate at active@char{"}}{}
-
-\def\classiclatin at shorthands{%
-  \def\language at group{classiclatin}%
-  \bbl at activate{"}%
-  \declare at shorthand{classiclatin}{"}{\relax
-    \ifmmode
-      \def\xpgcla at next{''}%
-    \else
-      \def\xpgcla at nextdq{\futurelet\xpgla at temp\xpgla at cwm}%
-    \fi
-  \xpgcla at nextdq}%
-}
-
-\def\xpgcla at allowhyphens{\bbl at allowhyphens\discretionary{-}{}{}\bbl at allowhyphens}
-\newcommand*{\xpgcla at cwm}{\let\xpgcla@@nextdq\relax
-  \ifcat\noexpand\xpgcla at temp a%
-    \let\xpgcla@@nextdq\xpgcla at allowhyphens
-  \else
-    \ifx\xpgcla at temp\ae
-        \let\xpgcla@@nextdq\xpgcla at allowhyphens
-    \else
-        \ifx\xpgcla at temp\oe
-           \let\xpgcla@@nextdq\xpgcla at allowhyphens
-        \else
-           \if\noexpand\xpgla at temp\string|%
-              \def\xpgcla@@nextdq{\xpgcla at allowhyphens\@gobble}%
-           \fi
-        \fi
-    \fi
-  \fi
-  \xpgla@@nextdq}%
-\def\noclassiclatin at shorthands{%
-  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{"}}%
-}
-
-\let\xpgcla at savedvalues\empty
-\AtEndPreamble{%
-  \edef\xpgcla at savedvalues{%
-    \clubpenalty=\the\clubpenalty\space
-    \@clubpenalty=\the\@clubpenalty\space
-    \widowpenalty=\the\widowpenalty\space
-    \finalhyphendemerits=\the\finalhyphendemerits}%
-}
-
-\def\noextras at classiclatin{%
-   \lccode\string"2019=\z@
-   \noclassiclatin at shorthands
-   \noclassicuclccodes
-   \xpgcla at savedvalues
-}
-
-\def\blockextras at classiclatin{%
-   \lccode\string"2019=\string"2019
-   \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000
-   \finalhyphendemerits=50000000
-   \classicuclccodes
-   \ifclassiclatin at babelshorthands\classiclatin at shorthands\fi
-}
-
-\def\inlineextras at classiclatin{%
-   \lccode\string"2019=\string"2019
-   \classicuclccodes
-   \ifclassiclatin at babelshorthands\classiclatin at shorthands\fi
-}
-%%   Copyright (C) Claudio Beccari 2013-2016
-%%   Copyright (C) Élie Roux 2016
-%% 
-%%   Permission is hereby granted, free of charge, to any person obtaining
-%%   a copy of this software and associated documentation files
-%%   (the "Software"), to deal in the Software without restriction, including
-%%   without limitation the rights to use, copy, modify, merge, publish,
-%%   distribute, sublicense, and/or sell copies of the Software, and to permit
-%%   persons to whom the Software is furnished to do so, subject to the following
-%%   conditions:
-%% 
-%%   The above copyright notice and this permission notice shall be included in
-%%   all copies or substantial portions of the Software.
-%% 
-%%   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-%%   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-%%   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-%%   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-%%   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-%%   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-%%   IN THE SOFTWARE.
-%%
-%% End of file `gloss-classiclatin.ldf'.
-%    \end{macrocode}
-% \iffalse
-%</gloss-classiclatin.ldf>
 %<*gloss-coptic.ldf>
 % \fi
 % \clearpage
@@ -2517,8 +2966,10 @@
 %    \begin{macrocode}
 \ProvidesFile{gloss-croatian.ldf}[polyglossia: module for croatian]
 \PolyglossiaSetup{croatian}{
+  langtag=HRV,
   hyphennames={croatian},
   hyphenmins={2,2}, % aligned with https://ctan.org/pkg/hrhyph patterns and http://lebesgue.math.hr/~nenad/Diplomski/Maja_Ribaric_2011.pdf
+  frenchspacing=true, % recommendation from Damir Bralić
   indentfirst=false, % recommendation from Damir Bralić
   fontsetup=true
 }
@@ -2562,13 +3013,169 @@
 % \subsection{gloss-czech.ldf}
 %    \begin{macrocode}
 \ProvidesFile{gloss-czech.ldf}[polyglossia: module for czech]
+
 \PolyglossiaSetup{czech}{
   hyphennames={czech},
   hyphenmins={2,2},
+  langtag=CSY,
   frenchspacing=true,
   fontsetup=true,
 }
 
+\define at boolkey{czech}[czech@]{babelshorthands}[true]{}
+
+\define at boolkey{czech}[czech@]{splithyphens}[true]{}
+
+\define at boolkey{czech}[czech@]{vlna}[true]{}
+
+\ifsystem at babelshorthands
+  \setkeys{czech}{babelshorthands=true}
+\else
+  \setkeys{czech}{babelshorthands=false}
+\fi
+
+\ifcsundef{initiate at active@char}{%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
+}{}
+
+\def\cs@@splithyphen#1{%
+  \kern\z@\discretionary{-}{\char\hyphenchar\the\font}{#1}%
+  \nobreak\hskip\z@%
+}
+
+\def\cs at splithyphen{%
+  \cs@@splithyphen{-}%
+}
+
+\def\czech at shorthands{%
+  \bbl at activate{"}%
+  \def\language at group{czech}%
+  \declare at shorthand{czech}{"=}{\cs at splithyphen}%
+  \declare at shorthand{czech}{"`}{„}%
+  \declare at shorthand{czech}{"'}{“}%
+  \declare at shorthand{czech}{"<}{«}%
+  \declare at shorthand{czech}{">}{»}%
+}
+
+\def\noczech at shorthands{%
+  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{"}}%
+}
+
+\ifxetex
+  % splithyphens
+  \newXeTeXintercharclass\czech at hyphen % -
+  % vlna
+  \newXeTeXintercharclass\czech at openpunctuation
+  \newXeTeXintercharclass\czech at nonsyllabicpreposition
+  \ifdefined\e at alloc@intercharclass at top
+    \chardef\czech at boundary=\e at alloc@intercharclass at top
+  \else
+    \ifdefined\XeTeXinterwordspaceshaping
+      \chardef\czech at boundary=4095 %
+      \def\newXeTeXintercharclass{%
+        \e at alloc\XeTeXcharclass\chardef
+              \xe at alloc@intercharclass\m at ne\@ucharclass at boundary}
+    \else
+      \chardef\czech at boundary=255
+    \fi
+  \fi
+\fi
+
+\def\czech at hyphens{%
+    \ifluatex
+      \xpg at warning{The 'splithyphens' option only works for XeLaTeX.\MessageBreak
+                   Please use the luavlna package to enable the feature for LuaLaTeX}
+    \else
+      \XeTeXinterchartokenstate=1
+      \XeTeXcharclass `\- \czech at hyphen
+      \XeTeXinterchartoks \z@ \czech at hyphen = {\cs@@splithyphen}% "-" -> "\cs@@splithyphen-"
+      % necessary if used together with vlna:
+      \XeTeXinterchartoks \czech at nonsyllabicpreposition \czech at hyphen = {\cs@@splithyphen}% "-" -> "\cs@@splithyphen-"
+    \fi%
+}
+
+\def\noczech at hyphens{%
+    \ifxetex
+      \XeTeXcharclass `\- \z@
+    \fi%
+}
+
+% Add nonbreakable space after single-letter word to
+% prevent them to land at the end of a line
+\def\czech at vlna{%
+    \ifluatex
+       \xpg at warning{The 'vlna' option only works for XeLaTeX.\MessageBreak
+                    Please use the luavlna package to enable the feature for LuaLaTeX}
+    \else
+        % Code taken and adapted from xevlna.sty
+        \XeTeXinterchartokenstate=1
+        \XeTeXcharclass `\( \czech at openpunctuation
+        \XeTeXcharclass `\[ \czech at openpunctuation
+        \XeTeXcharclass `\„ \czech at openpunctuation
+        \XeTeXcharclass `\» \czech at openpunctuation
+        \XeTeXcharclass `\K \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\k \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\S \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\s \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\V \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\v \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\Z \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\z \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\O \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\o \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\U \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\u \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\A \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\a \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\I \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\i \czech at nonsyllabicpreposition
+        \XeTeXinterchartoks \czech at boundary \czech at nonsyllabicpreposition {\czech at interchartoks}
+        \XeTeXinterchartoks \czech at openpunctuation \czech at nonsyllabicpreposition {\czech at interchartoks}
+        \def\czech at nointerchartoks{\let\czech at interchartoks\czech at PreCSpreposition}
+        \def\czech at PreCSpreposition{\def\next{}%
+           \ifnum\catcode`\ =10 % nothing will be done in verbatim
+           \ifmmode % nothing in math
+           \else
+              \let\czech at interchartoks\czech at nointerchartoks
+              \let\next\czech at ExamineCSpreposition
+           \fi \fi
+          \next%
+        }
+        \def\czech at ExamineCSpreposition ##1{##1\futurelet\next\czech at ProcessCSpreposition}
+        \def\czech at ProcessCSpreposition{\ifx\next\czech at XeTeXspace\nobreak\fi}
+        \futurelet\czech at XeTeXspace{ }\czech at nointerchartoks
+    \fi
+}
+
+\def\noczech at vlna{%
+    \ifluatex
+    \else
+        \XeTeXcharclass`\(\z@
+        \XeTeXcharclass`\[\z@
+        \XeTeXcharclass`\„\z@
+        \XeTeXcharclass`\»\z@
+        \XeTeXcharclass`\K\z@
+        \XeTeXcharclass`\k\z@
+        \XeTeXcharclass`\S\z@
+        \XeTeXcharclass`\s\z@
+        \XeTeXcharclass`\V\z@
+        \XeTeXcharclass`\v\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\captionsczech{%
    \def\refname{Reference}%
    \def\abstractname{Abstrakt}%
@@ -2592,14 +3199,35 @@
    \def\headtoname{Komu}%
    \def\proofname{Důkaz}%
    \def\glossaryname{Slovník}%was Glosář
-   }
+}
+
 \def\dateczech{%
    \def\today{\number\day.~\ifcase\month\or
     ledna\or února\or března\or dubna\or května\or
     června\or července\or srpna\or září\or
     října\or listopadu\or prosince\fi
-    \space \number\year}}
+    \space \number\year}%
+}
 
+\def\noextras at czech{%
+  \noczech at shorthands%
+  \noczech at hyphens%
+  \noczech at vlna%
+  \ifxetex\XeTeXinterchartokenstate=0\fi%
+}
+
+\def\blockextras at czech{%
+  \ifczech at babelshorthands\czech at shorthands\fi%
+  \ifczech at vlna\czech at vlna\fi%
+  \ifczech at splithyphens\czech at hyphens\fi%
+}
+
+\def\inlineextras at czech{%
+  \ifczech at babelshorthands\czech at shorthands\fi%
+  \ifczech at vlna\czech at vlna\fi%
+  \ifczech at splithyphens\czech at hyphens\fi%
+}
+
 %    \end{macrocode}
 % \iffalse
 %</gloss-czech.ldf>
@@ -2613,6 +3241,7 @@
 \PolyglossiaSetup{danish}{
   hyphennames={danish},
   hyphenmins={2,3},
+  langtag=DAN,
   frenchspacing=true,
   fontsetup=true,
 }
@@ -2636,13 +3265,16 @@
   \def\headtoname{Til}% in letter
   \def\pagename{Side}%
   \def\seename{Se}%
-  \def\alsoname{Se også}}%
+  \def\alsoname{Se også}%
   \def\proofname{Bevis}%
   \def\glossaryname{Gloseliste}%
+}
+\def\datedanish{%
   \def\today{\number\day.~\ifcase\month\or
     januar\or februar\or marts\or april\or maj\or juni\or
     juli\or august\or september\or oktober\or november\or december\fi
     \space\number\year}
+}
 
 %    \end{macrocode}
 % \iffalse
@@ -2664,6 +3296,7 @@
 \PolyglossiaSetup{divehi}{
   script=Thaana,
   scripttag=thaa,
+  langtag=DIV,% TODO Support DHV as well?
   direction=RL,
   hyphennames={nohyphenation},
   fontsetup=true
@@ -2695,13 +3328,17 @@
 %   }
 %\def\datedivehi{\def\today{<++>}}
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at divehi{%
-   \let\@@MakeUppercase\MakeUppercase%
    \def\MakeUppercase##1{##1}%
-   }
+}
+
 \def\noextras at divehi{%
-   \let\MakeUppercase\@@MakeUppercase%
-   }
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase%
+}
 
 %    \end{macrocode}
 % \iffalse
@@ -2716,6 +3353,7 @@
 \PolyglossiaSetup{dutch}{
   hyphennames={dutch},
   hyphenmins={2,2},
+  langtag=NLD,
   frenchspacing=true,
   fontsetup=true,
 }
@@ -2729,8 +3367,9 @@
 \fi
 
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\dutch at shorthands{%
@@ -2804,67 +3443,125 @@
 \PolyglossiaSetup{english}{
   hyphennames={english,american,usenglish,USenglish},
   hyphenmins={2,3},
+  langtag=ENG,
   fontsetup=true,
 }
 
-\newif\if at british@locale
-\@british at localefalse
-\providebool{@british at hyphen}
+\providebool{british at hyphen}
 \providebool{english at ordinalmonthday}
+\providebool{british at dateformat}
 
+% US English (\l at english) is default
+% Initialize its settings
+\def\english at variant{english}
+\british at hyphenfalse
+\english at ordinalmonthdayfalse
+\british at dateformatfalse
+
+% Option ordinalmonthday
 \define at boolkey{english}[english@]{ordinalmonthday}[true]{}
 
-%% English is a special case in that \l at english is reserved for US English, so
-%% we need to handle it differently
-\define at key{english}{variant}{%
-  %needs to be reset for loop over hyphennames below:
-  \def\do##1{%
-      \xpg at ifdefined{#1}%
-        {\csletcs{l at english}{l@#1}\listbreak}%
-        {}%
-  }%
-  \ifstrequal{#1}{uk}%
-    {\@british at localetrue
-     \xpg at info{Option: english variant=british}}%
-    {\ifstrequal{#1}{british}%
-      {\@british at localetrue
-      \xpg at info{Option: english variant=british}}%
-        {\ifstrequal{#1}{us}% these patterns are the default so we don't need to reset them
-          {\@british at hyphenfalse\english at ordinalmonthdayfalse
-           \xpg at info{Option: english variant=american}}%
-          {\ifstrequal{#1}{american}%
-            {\@british at hyphenfalse\english at ordinalmonthdayfalse
-            \xpg at info{Option: english variant=american}}%
-            {\ifstrequal{#1}{usmax}%
-              {\@british at hyphenfalse\english at ordinalmonthdayfalse
-                \ifluatex\else\setkeys[xpg at setup]{english}{hyphennames={usenglishmax}}\fi
-                \xpg at info{Option: english variant=american (with additional patterns)}%
-                \xpg at ifdefined{usenglishmax}{}%
-                  {\xpg at warning{No hyphenation patterns were loaded for "US English Max"\MessageBreak
-                    I will use the standard patterns for US English instead}%
-                  \adddialect\l at usenglishmax\l at english\relax}%
-                \gdef\english at language{\language=\l at usenglishmax}}%
-                {\ifstrequal{#1}{australian}%
-                  {\@british at hyphentrue\english at ordinalmonthdayfalse
-                  \xpg at info{Option: english variant=australian}}%
-                  {\ifstrequal{#1}{newzealand}%
-                    {\@british at hyphentrue\english at ordinalmonthdayfalse
-                      \xpg at info{Option: english variant=newzealand}}%
-                      {\xpg at warning{Unknown English variant `#1'}}%
-  }}}}}}%
-  \if at british@locale\@british at hyphentrue\english at ordinalmonthdaytrue\fi
-  \if at british@hyphen
-    \ifluatex\else\setkeys[xpg at setup]{english}{hyphennames={ukenglish,british,UKenglish}}\fi
-    \xpg at ifdefined{ukenglish}{}%
-      {\xpg at warning{No hyphenation patterns were loaded for British English\MessageBreak
-         I will use the patterns for US English instead}%
-       \adddialect\l at ukenglish\l at english\relax}%
-    \gdef\english at language{\language=\l at ukenglish\xpg at set@language at luatex@ii{ukenglish}}%
-  \fi
-  % and we reset \do to its previous definition here:
-  \def\do##1{\setotherlanguage{#1}}%
-}
+\define at choicekey*+{english}{variant}[\val\nr]{uk,british,us,american,usmax,australian,newzealand,canadian}{%
+   \ifcase\nr\relax
+      % uk:
+      \british at hyphentrue
+      \british at dateformattrue
+      \english at ordinalmonthdaytrue
+      \SetLanguageKeys{english}{babelname=british}%
+      \xpg at info{Option: English, variant=british}%
+   \or
+      % british:
+      \british at hyphentrue
+      \british at dateformattrue
+      \english at ordinalmonthdaytrue
+      \SetLanguageKeys{english}{babelname=british}%
+      \xpg at info{Option: english variant=british}%
+   \or
+      % us:
+      \british at hyphenfalse
+      \british at dateformatfalse
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=american}%
+      \xpg at info{Option: English, variant=american}%
+   \or
+      % american:
+      \british at hyphenfalse
+      \british at dateformatfalse
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=american}%
+      \xpg at info{Option: English, variant=american}%
+   \or
+      % usmax:
+      \british at hyphenfalse
+      \british at dateformatfalse
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=american}%
+      \xpg at info{Option: english variant=american (with additional patterns)}%
+      \xpg at ifdefined{usenglishmax}{}%
+         {\xpg at warning{No hyphenation patterns were loaded for "US English Max"\MessageBreak
+                       I will use the standard patterns for US English instead}%
+          \adddialect\l at usenglishmax\l at english\relax%
+         }%
+      \def\english at variant{usenglishmax}%
+   \or
+      % australian:
+      % These use the british hyphenation patterns
+      % but date formats without ordinals
+      \british at hyphentrue
+      \british at dateformattrue
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=australian}%
+      \xpg at info{Option: English, variant=australian}%
+   \or
+      % newzealand:
+      % These use the british hyphenation patterns
+      % but date formats without ordinals
+      \british at hyphentrue
+      \british at dateformattrue
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=newzealand}%
+      \xpg at info{Option: English, variant=newzealand}%
+   \or
+      % canadian:
+      % This is currently equivalent to usenglish (as in babel)
+      \british at hyphenfalse
+      \british at dateformatfalse
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=canadian}%
+      \xpg at info{Option: English, variant=american}%
+   \fi
+   \ifbritish at hyphen
+      \xpg at ifdefined{ukenglish}{}%
+         {\xpg at warning{No hyphenation patterns were loaded for British English\MessageBreak
+                       I will use the patterns for US English instead}%
+          \adddialect\l at ukenglish\l at english\relax%
+         }%
+      \def\english at variant{ukenglish}%
+   \fi
+}{\xpg at warning{Unknown English variant `#1'}}
 
+\ifxetex
+   % Check if \l at english is defined. If not, try to set it to some variety
+   % (specific order as in the csv list below), or null language if everything fails
+   \xpg at ifdefined{english}{}{%
+      \def\do##1{%
+         \xpg at ifdefined{#1}%
+            {\csletcs{l at english}{l@#1}\listbreak}%
+            {%
+               \xpg at warning{No hyphenation patterns for English found"\MessageBreak
+                            I will use the 'null' language instead}%
+               \adddialect\l at english0
+            }%
+      }%
+      \docsvlist{british, american, usenglishmax, australian, newzealand}
+      \xpg at ifdefined{english}{}{}
+   }%
+\fi
+
+\def\english at language{%
+   \polyglossia at setup@language at patterns{\english at variant}
+}%
+
 \def\captionsenglish{%
    \def\prefacename{Preface}%
    \def\refname{References}%
@@ -2903,7 +3600,7 @@
       January\or February\or March\or April\or May\or June\or
       July\or August\or September\or October\or November\or December\fi}%
    \def\today{%
-    \if at british@locale
+    \ifbritish at dateformat
       \english at day\space\english at month\space\number\year
     \else
       \english at month\space\english at day,\space\number\year
@@ -2923,6 +3620,7 @@
 \PolyglossiaSetup{esperanto}{
   hyphennames={esperanto},
   hyphenmins={2,2},
+  langtag=NTO,
   fontsetup=true,
   %TODO localalph={esperanto at alph,esperanto at Alph}
 }
@@ -2972,8 +3670,6 @@
      P\or R\or S\or Ŝ\or T\or U\or Ŭ\or V\or Z\else\xpg at ill@value{#1}{esperanto at Alph}\fi}%
 
 \def\esperanto at numbers{%
-   \let\latin at Alph\@Alph%
-   \let\latin at alph\@alph%
    \let\@Alph\esperanto at Alph%
    \let\@alph\esperanto at alph%
  }
@@ -2996,6 +3692,7 @@
 \PolyglossiaSetup{estonian}{
   hyphennames={estonian},
   hyphenmins={2,2},
+  langtag=ETI,
   frenchspacing=true,
   fontsetup=true,
 }
@@ -3040,16 +3737,12 @@
 % \subsection{gloss-farsi.ldf}
 %    \begin{macrocode}
 \ProvidesFile{gloss-farsi.ldf}[polyglossia: module for farsi]
-\ifluatex
-  \xpg at warning{Farsi is not supported with LuaTeX.\MessageBreak
-I will proceed with the compilation, but\MessageBreak
-the output is not guaranteed to be correct\MessageBreak
-and may look very wrong.}
-\fi
-\RequireBidi
-\RequirePackage{arabicnumbers}
-\RequirePackage{farsical}
-\RequirePackage{hijrical}
+
+% We only provide this gloss for babel compatibility.
+% The proper English language name is Persian.
+
+\input{gloss-persian.ldf}
+
 \PolyglossiaSetup{farsi}{
   script=Arabic,
   direction=RL,
@@ -3056,119 +3749,34 @@
   scripttag=arab,
   langtag=FAR,
   hyphennames={nohyphenation},
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=farsinumerals
 }
 
-\newif\if at western@numerals
-\def\tmp at western{western}
 \define at key{farsi}{numerals}[eastern]{%
-  \def\@tmpa{#1}%
-  \ifx\@tmpa\tmp at western\@western at numeralstrue\else%
-    \@western at numeralsfalse%
-  \fi}
+  \setkeys{persian}{numerals=#1}}
 
-%this is needed for \abjad in arabicnumbers.sty
-\def\tmp at true{true}
 \define at key{farsi}{abjadjimnotail}[true]{%
-  \def\@tmpa{#1}%
-  \ifx\@tmpa\tmp at true\abjad at jim@notailtrue%
-  \else
-    \abjad at jim@notailfalse
-  \fi}
+  \setkeys{persian}{abjadjimnotail=#1}}
 
-% NOT YET USED
 \define at key{farsi}{locale}[default]{%
-  \def\@farsi at locale{#1}}
+  \setkeys{persian}{locale=#1}}
 
-%TODO add option for CALENDAR
-
 \setkeys{farsi}{locale,numerals}
 
-\def\farsigregmonth#1{\ifcase#1%
-  \or ژانویه\or فوریه\or مارس\or آوریل\or مه\or ژوئن\or ژوئیه\or اوت\or سپتامبر\or اکتبر\or نوامبر\or دسامبر\fi}
-\def\farsimonth#1{\ifcase#1%
-  \or کانون ثانی\or شباط\or اذار%%or ادار
-    \or نیسان\or ایار\or حزیران\or تموز\or آب\or ایلول\or تشرین اول\or تشرین ثانی\or کانون اول\fi}
-
 %\Hijritoday is now locale-aware and will format the date with this macro:
 \DefineFormatHijriDate{farsi}{\@ensure at RTL{%
-\farsinumber{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\farsinumber{\value{Hijriyear}}}}
+   \farsinumber{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\farsinumber{\value{Hijriyear}}}}
 
-\def\captionsfarsi{%
-\def\prefacename{\@ensure at RTL{پیشگفتار}}%
-\def\refname{\@ensure at RTL{مراجع}}%
-\def\abstractname{\@ensure at RTL{چکیده}}%
-\def\bibname{\@ensure at RTL{کتاب‌نامه}}%
-\def\chaptername{\@ensure at RTL{فصل}}%
-\def\appendixname{\@ensure at RTL{پیوست}}%
-\def\contentsname{\@ensure at RTL{فهرست مطالب}}%
-\def\listfigurename{\@ensure at RTL{لیست تصاویر}}%
-\def\listtablename{\@ensure at RTL{لیست جداول}}%
-\def\indexname{\@ensure at RTL{نمایه}}%
-\def\figurename{\@ensure at RTL{شكل}}%
-\def\tablename{\@ensure at RTL{جدول}}%
-\def\partname{\@ensure at RTL{بخش}}%
-\def\enclname{\@ensure at RTL{پیوست}}%
-\def\ccname{\@ensure at RTL{رونوشت}}%
-\def\headtoname{\@ensure at RTL{به}}%
-\def\pagename{\@ensure at RTL{صفحة}}%
-\def\seename{\@ensure at RTL{ببینید}}%
-\def\alsoname{\@ensure at RTL{نیز ببینید}}%
-\def\proofname{\@ensure at RTL{برهان}}%
-\def\glossaryname{\@ensure at RTL{دانش‌نامه}}%
-}
-\def\datefarsi{%
-   \def\today{\@ensure at RTL{\farsinumber\day\space\farsigregmonth{\month}\space\farsinumber\year}}%
-}
+\let\captionsfarsi\captionspersian
+\let\datefarsi\datepersian
+\let\farsi at numbers\persian at numbers
+\let\nofarsi at numbers\nopersian at numbers
+\let\farsi at globalnumbers\persian at globalnumbers
+\let\nofarsi at globalnumbers\nopersian at globalnumbers
+\let\blockextras at farsi\blockextras at persian
+\let\noextras at farsi\noextras at persian
 
-\def\farsinumber#1{%
-  \if at western@numerals
-    \number#1%
-  \else
-    \ifnum\XeTeXcharglyph"06F0 > 0%
-      \farsidigits{\number#1}%
-      %%{\protect\addfontfeature{Mapping=farsidigits}\number#1}%
-    \else%
-      \arabicdigits{\number#1}%
-      %%{\protect\addfontfeature{Mapping=arabicdigits}\number#1}%
-    \fi
-  \fi}
-
-%\def\farsinum#1{\expandafter\farsinumber\csname c@#1\endcsname}
-%\def\farsibracenum#1{(\expandafter\farsinumber\csname c@#1\endcsname)}
-%\def\farsiornatebracenum#1{\char"FD3E\expandafter\farsinumber\csname c@#1\endcsname\char"FD3F}
-%\def\farsialph#1{\expandafter\@farsialph\csname c@#1\endcsname}
-
-\def\farsi at numbers{%
-   \let\@latinalph\@alph%
-   \let\@latinAlph\@Alph%
-   \let\@alph\abjad%
-   \let\@Alph\abjad%
-}
-\def\nofarsi at numbers{%
-  \let\@alph\@latinalph%
-  \let\@Alph\@latinAlph%
-  }
-
-\def\farsi at globalnumbers{%
-   \let\orig at arabic\@arabic%
-   \let\@arabic\farsinumber%
-   % For some reason \thefootnote needs to be set separately:
-   \renewcommand\thefootnote{\protect\farsinumber{\c at footnote}}%
-   }
-
-\def\nofarsi at globalnumbers{
-   \let\@arabic\orig at arabic%
-   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
-   }
-
-\def\blockextras at farsi{%
-   \let\@@MakeUppercase\MakeUppercase%
-   \def\MakeUppercase##1{##1}%
-   }
-\def\noextras at farsi{%
-   \let\MakeUppercase\@@MakeUppercase%
-   }
 %    \end{macrocode}
 % \iffalse
 %</gloss-farsi.ldf>
@@ -3182,10 +3790,41 @@
 \PolyglossiaSetup{finnish}{
   hyphennames={finnish},
   hyphenmins={2,2},
+  langtag=FIN,
   frenchspacing=true,
   fontsetup=true,
 }
 
+\define at boolkey{finnish}[finnish@]{babelshorthands}[true]{}
+
+\ifsystem at babelshorthands
+  \setkeys{finnish}{babelshorthands=true}
+\else
+  \setkeys{finnish}{babelshorthands=false}
+\fi
+
+\ifcsundef{initiate at active@char}{%
+    \input{babelsh.def}%
+    \initiate at active@char{"}%
+    \shorthandoff{"}%
+}{}
+
+\def\finnish at shorthands{%
+  \bbl at activate{"}%
+  \def\language at group{finnish}%
+  \declare at shorthand{finnish}{"-}{\nobreak-\bbl at allowhyphens}
+  \declare at shorthand{finnish}{"|}{\textormath{\penalty at M\discretionary{-}{}{\kern.03em}}{}}%
+  \declare at shorthand{finnish}{""}{\hskip\z at skip}%
+  \declare at shorthand{finnish}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
+  \declare at shorthand{finnish}{"=}{\penalty at M-\hskip\z at skip}%
+  \declare at shorthand{finnish}{"/}{\textormath
+    {\bbl at allowhyphens\discretionary{/}{}{/}\bbl at allowhyphens}{}}%
+}
+
+\def\nofinnish at shorthands{%
+  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{"}}%
+}
+
 \def\captionsfinnish{%
    \def\refname{Viitteet}%
    \def\abstractname{Tiivistelmä}%
@@ -3209,7 +3848,7 @@
    \def\headtoname{Vastaanottaja}%
    \def\proofname{Todistus}%
    \def\glossaryname{Sanasto}%
-   }
+}
 \def\datefinnish{%
    \def\today{\number\day.~\ifcase\month\or
     tammikuuta\or helmikuuta\or maaliskuuta\or huhtikuuta\or
@@ -3217,6 +3856,18 @@
     syyskuuta\or lokakuuta\or marraskuuta\or joulukuuta\fi
     \space\number\year}}
 
+\def\noextras at finnish{%
+  \nofinnish at shorthands%
+}
+
+\def\blockextras at finnish{%
+  \iffinnish at babelshorthands\finnish at shorthands\fi%
+}
+
+\def\inlineextras at finnish{%
+  \iffinnish at babelshorthands\finnish at shorthands\fi%
+}
+
 %    \end{macrocode}
 % \iffalse
 %</gloss-finnish.ldf>
@@ -3231,6 +3882,7 @@
 \PolyglossiaSetup{french}{%
   language=French,
   script=Latin,
+  langtag=FRA,
   hyphennames={french,francais},
   frenchspacing=true,
   indentfirst=true,
@@ -3237,6 +3889,36 @@
   hyphenmins={2,2},
   fontsetup=true}
 
+\def\french at variant{french}
+\define at choicekey*+{french}{variant}[\val\nr]{french,canadian,acadian}[french]{%
+   \ifcase\nr\relax
+      % french:
+      \def\french at variant{french}%
+   \or
+      % canadian:
+      \def\french at variant{canadien}%
+      \SetLanguageKeys{french}{babelname=canadien}%
+      \xpg at ifdefined{canadien}{}%
+	    {\xpg at warning{No hyphenation patterns were loaded for "French (Canada)"\MessageBreak
+	      I will use the standard patterns for French instead}%
+	    \adddialect\l at canadien\l at french\relax}%
+   \or
+      % acadian:
+      \def\french at variant{acadian}%
+      \SetLanguageKeys{french}{babelname=canadien}%
+      \xpg at ifdefined{acadian}{}%
+	    {\xpg at warning{No hyphenation patterns were loaded for "French (Canada)"\MessageBreak
+	      I will use the standard patterns for French instead}%
+	    \adddialect\l at acadian\l at french\relax}%
+   \fi
+   \xpg at info{Option: French, variant=\val}%
+}{\xpg at warning{Unknown French variant `#1'}}
+
+
+\def\french at language{%
+   \polyglossia at setup@language at patterns{\french at variant}
+}%
+
 \ifluatex
   \newluatexattribute\xpg at frpt %
   \directlua{polyglossia.load_frpt()}%
@@ -3250,36 +3932,77 @@
 \fi
 
 \def\xpg at unskip{\ifhmode\ifdim\lastskip>\z@\unskip\fi\fi}
-\def\xpg at nospace#1{#1}
 
-\ifx\@makefntext\undefined\else
-  \let\nofrench at makefntext\@makefntext
-  \long\def\french at makefntext#1{\parindent1em \noindent\quad\ifx\@thefnmark\empty\else\@thefnmark.\space\fi #1}
-  \let\@makefntext\french at makefntext
-  \define at boolkey{french}[french@]{frenchfootnote}[true]{%
-  	\def\@tmpa{#1}
-    \def\@tmptrue{true}
-    \ifx\@tmpa\@tmptrue
-    	\let\@makefntext\french at makefntext
-		\else 
-			\let\@makefntext\nofrench at makefntext
-    \fi
-  }
-\fi
+% Save original footnote definition
+\let\xpg at orig@makefntext\@makefntext
 
+\define at boolkey{french}[french@]{frenchfootnote}[true]{%
+  \AfterPreamble{%
+    \ifdefstring{\xpg at main@language}{french}{%
+      \iffrench at frenchfootnote
+         \ifx\@makefntext\undefined\else        
+             \long\def\french at makefntext##1{%
+                \parindent1em \noindent\quad%
+                \ifx\@thefnmark\empty\else%
+                \@thefnmark.\space\fi ##1%
+             }
+             \let\@makefntext\french at makefntext
+         \fi
+      \else
+         \let\@makefntext\xpg at orig@makefntext
+      \fi
+    }{\xpg at warning{Option 'frenchfootnote' only supported if French is main language!}}%
+  }%
+}
 
-\newif\iffrench at automaticspacesaroundguillemets
+\define at boolkey{french}[french@]{autospacing}[true]{}
+\french at autospacingtrue
+
+\newif\iffrench at autospaceguillemets
+\define at boolkey{french}[french@]{autospaceguillemets}[true]{}
+\french at autospaceguillemetstrue
+
+% Backwards compatibility
 \define at boolkey{french}[french@]{automaticspacesaroundguillemets}[true]{%
-  %\def\tmp at true{true}%
-  %\def\@tmpa{#1}%
-  %\ifx\@tmpa\tmp at true
+   \iffrench at automaticspacesaroundguillemets
+       \setkeys{french}{autospaceguillemets=true}%
+   \else
+       \setkeys{french}{autospaceguillemets=false}%
+   \fi
 }
-\french at automaticspacesaroundguillemetstrue
 
+% name is for compatibility with babel
+\let\french at ttfamilyORI\ttfamily
+\DeclareRobustCommand\french at ttfamilyFB{\nofrench at punctuation\french at ttfamilyORI}
+
+% Allow to switch on autospacing in ttfamily context
+\define at boolkey{french}[french@]{autospacetypewriter}[true]{}
+\french at autospacetypewriterfalse
+
+% This is how babel-french has it
+\define at boolkey{french}[french@]{OriginalTypewriter}[true]{%
+   \iffrench at OriginalTypewriter
+       \setkeys{french}{autospacetypewriter=false}%
+   \else
+       \setkeys{french}{autospacetypewriter=true}%
+   \fi
+}
+
+\def\french at fontsetup{%
+  \unless\iffrench at autospacetypewriter
+    \let\ttfamily\french at ttfamilyFB
+  \fi
+}
+
+
+\def\nofrench at fontsetup{%
+  \let\ttfamily\french at ttfamilyORI
+}
+
 \def\french at punctuation{%
     \lccode"2019="2019
     \ifluatex
-      \global\xpg at frpt=1\relax %
+      \xpg at frpt=1\relax %
       \directlua{polyglossia.activate_frpt()}%
     \else
       \XeTeXinterchartokenstate=1
@@ -3301,24 +4024,24 @@
       \XeTeXcharclass `\[ \french at closebrackets
       \XeTeXcharclass `\{ \french at openbrackets
       \XeTeXcharclass `\} \french at closebrackets
-      \XeTeXinterchartoks \z@ \french at punctthin = {\nobreak\thinspace}%
+      \XeTeXinterchartoks \z@ \french at punctthin = {\thinspace}%
       \XeTeXinterchartoks \z@ \french at punctthick = {\nobreakspace}%
-      \XeTeXinterchartoks \xpg at boundaryclass \french at punctthin = {\xpg at unskip\nobreak\thinspace}%
+      \XeTeXinterchartoks \xpg at boundaryclass \french at punctthin = {\xpg at unskip\thinspace}%
       \XeTeXinterchartoks \xpg at boundaryclass \french at punctthick = {\xpg at unskip\nobreakspace}%
-      \XeTeXinterchartoks \french at punctguillstart \z@ = {\nobreakspace}% "«a" -> "« a"
-  %   \XeTeXinterchartoks \z@ \french at punctguillstart = {\nobreakspace}% "a«" unchanged?
-  %   \XeTeXinterchartoks \french at punctguillend \z@ = {\nobreakspace}% "»a" unchanged?
-      \XeTeXinterchartoks \z@ \french at punctguillend = {\nobreakspace}% "a»" -> "a »"
-      \iffrench at automaticspacesaroundguillemets
-        \XeTeXinterchartoks \french at punctguillstart \xpg at boundaryclass = {\nobreakspace\xpg at nospace\relax}% "«  " -> "«~"
-        \XeTeXinterchartoks \xpg at boundaryclass \french at punctguillend = {\xpg at unskip\nobreakspace}% "  »" -> "~»"
-      \fi
-      \XeTeXinterchartoks \french at punctguillend \french at punctthin = {\nobreak\thinspace}% "»;" -> "» ;"
-      \XeTeXinterchartoks \french at punctguillend \french at punctthick = {\nobreakspace}% "»:" -> "» :"
-      \XeTeXinterchartoks \french at punctthin \french at punctguillend  = {\nobreakspace}% "?»" -> "? »"
+      \iffrench at autospaceguillemets
+        \XeTeXinterchartoks \french at punctguillstart \z@ = {\thinspace}% "«a" -> "«\,a"
+  %     \XeTeXinterchartoks \z@ \french at punctguillstart = {\nobreakspace}% "a«" unchanged?
+  %     \XeTeXinterchartoks \french at punctguillend \z@ = {\nobreakspace}% "»a" unchanged?
+        \XeTeXinterchartoks \z@ \french at punctguillend = {\thinspace}% "a»" -> "a\,»"
+        \XeTeXinterchartoks \french at punctguillstart \xpg at boundaryclass = {\thinspace\ignorespaces}% "«  " -> "«\,"
+        \XeTeXinterchartoks \xpg at boundaryclass \french at punctguillend = {\xpg at unskip\thinspace}% "  »" -> "\,»"
+     \fi
+     \XeTeXinterchartoks \french at punctguillend \french at punctthin = {\thinspace}% "»;" -> "»\,;"
+     \XeTeXinterchartoks \french at punctguillend \french at punctthick = {\nobreakspace}% "»:" -> "» :"
+     \XeTeXinterchartoks \french at punctthin \french at punctguillend  = {\thinspace}% "?»" -> "?\,»"
      \XeTeXinterchartoks \french at openbrackets \french at punctthin = {\xpg at unskip}% "(?" -> "(?" and not "( ?"      
      \XeTeXinterchartoks \french at punctthin \french at closebrackets = {\xpg at unskip}% "?)" -> "?)" (code not need, just for symetry with previous one)
-     \XeTeXinterchartoks \french at closebrackets \french at punctthin = {\nobreak\thinspace}% ")?" -> ") ?"
+     \XeTeXinterchartoks \french at closebrackets \french at punctthin = {\thinspace}% ")?" -> ")\,?"
      \XeTeXinterchartoks \french at closebrackets \french at punctthick = {\nobreakspace}% "):" -> ") :"
     \fi
     }
@@ -3326,7 +4049,7 @@
 \def\nofrench at punctuation{%
     \lccode"2019=\z@
     \ifluatex
-      \global\xpg at frpt=0\relax %
+      \xpg at frpt=0\relax %
       % Though it would make compilation slightly faster, it is not possible to
       % safely uncomment the following line. Imagine the following case: you start
       % a paragraph by some french text, then, in the same paragraph, you change
@@ -3380,6 +4103,7 @@
    \def\headtoname{}%
    \def\proofname{Démonstration}%
    }
+
 \def\datefrench{%
    \def\today{\ifx\ier\undefined\def\ier{er}\fi
       \ifnum\day=1\relax 1\ier%
@@ -3392,16 +4116,31 @@
 
 \def\noextras at french{%
    \nofrench at punctuation%
-   }
+   \nofrench at fontsetup%
+}
 
 \def\blockextras at french{%
-   \french at punctuation%
-   }
+   \iffrench at autospacing
+      \french at punctuation%
+   \fi
+   \french at fontsetup%
+}
 
 \def\inlineextras at french{%
-   \french at punctuation%
-   }
+   \iffrench at autospacing
+      \french at punctuation%
+   \fi
+   \french at fontsetup%
+}
 
+\def\NoAutoSpacing{%
+  \nofrench at punctuation%
+}
+
+\def\AutoSpacing{%
+  \french at punctuation%
+}
+
 \def\ier{\textsuperscript{er}}
 \def\iers{\textsuperscript{ers}}
 \def\iere{\textsuperscript{re}}
@@ -3430,17 +4169,50 @@
 % \subsection{gloss-friulan.ldf}
 %    \begin{macrocode}
 \ProvidesFile{gloss-friulan.ldf}[polyglossia: module for friulan]
-\makeatletter
+
+% We only provide this gloss for babel compatibility.
+
+\input{gloss-friulian.ldf}
+
 \PolyglossiaSetup{friulan}{%
+  language=Friulian,
   hyphennames={friulan,furlan},
   hyphenmins={2,2},
+  langtag=FRL,
   indentfirst=false,
   fontsetup=true,
   frenchspacing=true,
 }
 
+\let\captionsfriulan\captionsfriulian
+\let\datefriulan\datefriulian
+\let\noextras at friulan\noextras at friulian
+\let\blockextras at friulan\blockextras at friulian
+\let\inlineextras at friulan\inlineextras at friulian
 
-\def\captionsfriulan{%
+%    \end{macrocode}
+% \iffalse
+%</gloss-friulan.ldf>
+%<*gloss-friulian.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-friulian.ldf}
+%    \begin{macrocode}
+\ProvidesFile{gloss-friulian.ldf}[polyglossia: module for friulian]
+
+\PolyglossiaSetup{friulian}{%
+  language=Friulian,
+  babelname=friulan,
+  hyphennames={friulan,furlan},
+  hyphenmins={2,2},
+  langtag=FRL,
+  indentfirst=false,
+  fontsetup=true,
+  frenchspacing=true,
+}
+
+\def\captionsfriulian{%
     \def\prefacename{Prefazion}%
     \def\refname{Riferiments}%
     \def\abstractname{Somari}%
@@ -3464,7 +4236,7 @@
     \def\glossaryname{Glossari}%
   }
   
-\def\datefriulan{%
+\def\datefriulian{%
   \def\today{\number\day\space di\space\ifcase\month\or
       Genâr\or Fevrâr\or Març\or Avril\or Mai\or Jugn\or
       Lui\or Avost\or Setembar\or Otobar\or Novembar\or Dicembar%
@@ -3479,23 +4251,138 @@
 }
 
 
-\def\noextras at friulan{%
+\def\noextras at friulian{%
    \lccode\string"2019=\z@
 }
 
-\def\blockextras at friulan{%
+\def\blockextras at friulian{%
    \lccode\string"2019=\string"2019
    \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000
    \finalhyphendemerits=50000000
 }
 
-\def\inlineextras at friulan{%
+\def\inlineextras at friulian{%
    \lccode\string"2019=\string"2019
 }
 
 %    \end{macrocode}
 % \iffalse
-%</gloss-friulan.ldf>
+%</gloss-friulian.ldf>
+%<*gloss-gaelic.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-gaelic.ldf}
+%    \begin{macrocode}
+\ProvidesFile{gloss-gaelic.ldf}[polyglossia: module for gaelic]
+
+\PolyglossiaSetup{gaelic}{
+  language=Irish,
+  babelname=irish,
+  hyphennames={irish},
+  hyphenmins={2,2},
+  langtag=IRI,
+  fontsetup=true,
+}
+
+\def\gaelic at variant{irish}
+\define at choicekey*+{gaelic}{variant}[\val\nr]{irish,scottish}[irish]{%
+   \ifcase\nr\relax
+      % irish:
+      \gdef\gaelic at variant{irish}%
+      \SetLanguageKeys{gaelic}{language=Irish,langtag=IRI,babelname=irish}%
+      \xpg at fontsetup@latin{gaelic}%
+   \or
+      % scottish:
+      \gdef\gaelic at variant{scottish}%
+      \SetLanguageKeys{gaelic}{language=Gaelic,langtag=GAE,babelname=scottish}%
+      \xpg at fontsetup@latin{gaelic}%
+   \fi
+   \xpg at info{Option: gaelic, variant=\val}%
+}{\xpg at warning{Unknown gaelic variant `#1'}}
+
+\def\captionsgaelic at irish{%
+   \def\refname{Tagairtí}%
+   \def\abstractname{Achoimre}%
+   \def\bibname{Leabharliosta}%
+   \def\prefacename{Réamhrá}%    <-- also "Brollach"
+   \def\refname{Tagairtí}%
+   \def\chaptername{Tagairtí}%
+   \def\appendixname{Aguisín}%
+   \def\contentsname{Clár Ábhair}%
+   \def\listfigurename{Léaráidí}%
+   \def\listtablename{Táblaí}%
+   \def\indexname{Innéacs}%
+   \def\figurename{Léaráid}%
+   \def\tablename{Tábla}%
+   %\def\thepart{}%
+   \def\partname{Cuid}%
+   \def\pagename{Leathanach}%
+   \def\seename{féach}%
+   \def\alsoname{féach freisin}%
+   \def\enclname{faoi iamh}%
+   \def\ccname{cc}%
+   \def\headtoname{Go}%
+   \def\proofname{Cruthúnas}%
+   \def\glossaryname{Glossary}%
+}
+
+\def\captionsgaelic at scottish{%
+   \def\refname{Iomraidh}%
+   \def\abstractname{Brìgh}%
+   \def\bibname{Leabhraichean}%
+   \def\prefacename{Preface}%    <-- needs translation
+   \def\chaptername{Caibideil}%
+   \def\appendixname{Ath-sgr`ıobhadh}%
+   \def\contentsname{Clàr-obrach}%
+   \def\listfigurename{Liosta Dhealbh}%
+   \def\listtablename{Liosta Chlàr}%
+   \def\indexname{Clàr-innse}%
+   \def\figurename{Dealbh}%
+   \def\tablename{Clàr}%
+   %\def\thepart{}%
+   \def\partname{Cuid}%
+   \def\pagename{t.d.}%
+   \def\seename{see}%    <-- needs translation
+   \def\alsoname{see also}%    <-- needs translation
+   \def\enclname{a-staigh}%
+   \def\ccname{lethbhreac gu}%
+   \def\headtoname{gu}%
+   \def\proofname{Proof}%    <-- needs translation 
+   \def\glossaryname{Glossary}%    <-- needs translation
+}
+
+\def\captionsgaelic{%
+  \csname captionsgaelic@\gaelic at variant\endcsname%
+}
+
+\def\dategaelic at irish{%
+   \def\today{%
+    \number\day\space \ifcase\month\or
+    Eanáir\or Feabhra\or Márta\or Aibreán\or
+    Bealtaine\or Meitheamh\or Iúil\or Lúnasa\or
+    Meán Fómhair\or Deireadh Fómhair\or
+    Mí na Samhna\or Mí na Nollag\fi
+    \space \number\year}%
+}
+
+\def\dategaelic at scottish{%
+   \def\today{%
+    \number\day\space \ifcase\month\or
+    am Faoilteach\or an Gearran\or am Màrt\or an Giblean\or
+    an Cèitean\or an t-Òg mhios\or an t-Iuchar\or
+    Lùnasdal\or an Sultuine\or an Dàmhar\or
+    an t-Samhainn\or an Dubhlachd\fi
+    \space \number\year}%
+}
+
+\def\dategaelic{%
+  \csname dategaelic@\gaelic at variant\endcsname%
+}
+
+%    \end{macrocode}
+% \iffalse
+%</gloss-gaelic.ldf>
 %<*gloss-galician.ldf>
 % \fi
 % \clearpage
@@ -3506,6 +4393,7 @@
 \PolyglossiaSetup{galician}{
   hyphennames={galician},
   hyphenmins={2,2},
+  langtag=GAL,
   indentfirst=true,
   fontsetup=true,
 }
@@ -3554,63 +4442,86 @@
   hyphenmins={2,2},
   frenchspacing=true,
   fontsetup=true,
+  langtag=DEU,
+  babelname=ngerman
 }
 
-\def\tmp at old{old}
-\def\tmp at oldyr{1901}
 \newif\if at german@oldspelling
 \@german at oldspellingfalse
-\define at key{german}{spelling}[new]{%
-  \def\@tmpa{#1}%
-  \ifx\@tmpa\tmp at oldyr\def\@tmpa{old}\fi
-  \ifx\@tmpa\tmp at old
-    \xpg at ifdefined{german}{}{%
-      \xpg at nopatterns{german}%
-      \adddialect\l at german\l at nohyphenation
-    }
-    \@german at oldspellingtrue
-  \else % try ngerman
-    \xpg at ifdefined{ngerman}{%
+\define at choicekey*+{german}{spelling}[\val\nr]{new,old,1901}[new]{%
+   \ifcase\nr\relax
+      % new:
       \@german at oldspellingfalse
-    }{% fall back to german
-      \xpg at ifdefined{german}{%
-        \xpg at warning{You asked for `ngerman' but only `german' hyphenation is available!}%
-        \@german at oldspellingtrue
-      }{%
-        \xpg at nopatterns{ngerman}%
-        \adddialect\l at ngerman\l at nohyphenation
-      }%
-    }%
-  \fi
-}
+   \or
+      % old:
+      \@german at oldspellingtrue
+   \or
+      % 1901:
+      \@german at oldspellingtrue
+   \fi
+   \german at set@babelname%
+   \xpg at info{Option: German, spelling=\val}%
+}{\xpg at warning{Unknown German spelling `#1'}}
 
 \newif\if at austrian@locale
 \@austrian at localefalse
 \newif\if at swiss@locale
 \@swiss at localefalse
-\def\tmp at austrian{austrian}
-\def\tmp at swiss{swiss}
-\define at key{german}{variant}[german]{%
-	\def\@tmpa{#1}%
-	\ifx\@tmpa\tmp at austrian\@austrian at localetrue\else
-	  \@austrian at localefalse%
-	\fi
-	\ifx\@tmpa\tmp at swiss\@swiss at localetrue
-	  \xpg at ifdefined{swissgerman}{}%
-	    {\xpg at warning{No hyphenation patterns were loaded for "Swiss German (Old Spelling)"\MessageBreak
-	      I will use the standard patterns for German (old spelling) instead}%
-	    \adddialect\l at swissgerman\l at german\relax}%
-	\else
-	  \@swiss at localefalse%
-	\fi}
+\define at choicekey*+{german}{variant}[\val\nr]{german,austrian,swiss}[german]{%
+   \ifcase\nr\relax
+      % german:
+      \@swiss at localefalse%
+      \@austrian at localefalse%
+   \or
+      % austrian:
+      \@austrian at localetrue%
+      \@swiss at localefalse%
+   \or
+      % swiss:
+      \@swiss at localetrue%
+      \@austrian at localefalse%
+      \xpg at ifdefined{swissgerman}{}%
+         {%
+           \xpg at warning{No hyphenation patterns were loaded for "Swiss German (Old Spelling)"\MessageBreak
+	                I will use the standard patterns for German (old spelling) instead}%
+	                \adddialect\l at swissgerman\l at german\relax%
+         }%
+   \fi
+   \german at set@babelname%
+   \xpg at info{Option: German, variant=\val}%
+}{\xpg at warning{Unknown German variant `#1'}}
 
+\def\german at set@babelname{%
+  \if at german@oldspelling
+     \if at swiss@locale
+         \SetLanguageKeys{german}{babelname=swissgerman}%
+     \else
+     \if at austrian@locale
+         \SetLanguageKeys{german}{babelname=austrian}%
+     \else
+         \SetLanguageKeys{german}{babelname=german}%
+     \fi\fi
+  \else
+     \if at swiss@locale
+         \SetLanguageKeys{german}{babelname=nswissgerman}%
+     \fi
+     \if at austrian@locale
+         \SetLanguageKeys{german}{babelname=naustrian}%
+     \fi
+  \fi
+}
+
 \newif\if at german@fraktur
-\def\tmp at fraktur{fraktur}
-\define at key{german}{script}[latin]{%
-	\def\@tmpa{#1}%
-	\ifx\@tmpa\tmp at fraktur\@german at frakturtrue\else
-	  \@german at frakturfalse%
-	\fi}
+\define at choicekey*+{german}{script}[\val\nr]{latin,fraktur}[latin]{%
+   \ifcase\nr\relax
+      % latin:
+      \@german at frakturfalse%
+   \or
+      % fraktur:
+      \@german at frakturtrue%
+   \fi
+   \xpg at info{Option: German, script=\val}%
+}{\xpg at warning{Unknown German script `#1'}}
 
 \define at boolkey{german}[german@]{latesthyphen}[false]{}
 
@@ -3625,8 +4536,9 @@
 \fi
 
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\german at shorthands{%
@@ -3741,43 +4653,28 @@
   \if at german@fraktur\date at german@fraktur\else\date at german\fi
 }
 
-\def\german at language{\ifxetex\language=%
-  \csname l@%
-    \if at swiss@locale
-       \if at german@oldspelling
-           swissgerman%
-       \else
-            ngerman%
-            \ifgerman at latesthyphen
-                -x-latest
-            \fi
-        \fi
-    \else% (german, austrian)
-      \if at german@oldspelling\else n\fi german\ifgerman at latesthyphen -x-latest\fi
-    \fi
-  \endcsname\else\ifluatex
-  % LuaTeX
+\def\german at language{%
   \ifgerman at latesthyphen
     \if at german@oldspelling
         \if at swiss@locale
-            \xpg at set@language at luatex@iv{swissgerman}%
+            \polyglossia at setup@language at patterns{swissgerman}%
         \else
-            \xpg at set@language at luatex@iv{german-x-latest}%
+            \polyglossia at setup@language at patterns{german-x-latest}%
         \fi
     \else
-        \xpg at set@language at luatex@iv{ngerman-x-latest}%
+        \polyglossia at setup@language at patterns{ngerman-x-latest}%
     \fi
   \else% (latesthyphen=false)
     \if at german@oldspelling
         \if at swiss@locale
-            \xpg at set@language at luatex@iv{swissgerman}%
+            \polyglossia at setup@language at patterns{swissgerman}%
         \else
-            \xpg at set@language at luatex@iv{german}%
+            \polyglossia at setup@language at patterns{german}%
         \fi
     \else
-        \xpg at set@language at luatex@iv{ngerman}%
+        \polyglossia at setup@language at patterns{ngerman}%
     \fi
-  \fi\fi\fi
+  \fi
 }
 
 \def\noextras at german{%
@@ -3805,9 +4702,12 @@
 \PolyglossiaSetup{greek}{
   script=Greek,
   scripttag=grek,
+  langtag=ELL,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,
+  localnumeral=greeknumerals,
+  Localnumeral=Greeknumerals
   %TODO localalph={greek at alph,greek at Alph}
 }
 
@@ -3819,31 +4719,6 @@
 % this file imported from xgreek fixes the \lccode and \uccode of Greek letters:
 \input{xgreek-fixes.def}
 
-%TODO: set these in \define at key instead:
-\ifx\l at greek\@undefined
-  \ifx\l at polygreek\@undefined
-    \xpg at nopatterns{Greek}%
-    \adddialect\l at greek\l at nohyphenation
-  \else
-    \let\l at greek\l at polygreek
-  \fi
-\fi
-\ifx\l at monogreek\@undefined
-  \xpg at warning{No hyphenation patterns were loaded for Monotonic Greek\MessageBreak
-         I will use the patterns loaded for \string\l at greek instead}
-  \adddialect\l at monogreek\l at greek
-\fi
-\ifx\l at ancientgreek\@undefined
-  \xpg at warning{No hyphenation patterns were loaded for Ancient Greek\MessageBreak
-         I will use the patterns loaded for \string\l at greek instead}
-  \adddialect\l at ancientgreek\l at greek
-\fi
-
-%set monotonic as default
-\def\greek at variant{\l at monogreek}% monotonic
-\def\captionsgreek{\monogreekcaptions}%
-\def\dategreek{\datemonogreek}%
-
 \def\tmp at mono{mono}
 \def\tmp at monotonic{monotonic}
 \def\tmp at poly{poly}
@@ -3851,23 +4726,42 @@
 \def\tmp at ancient{ancient}
 \def\tmp at ancientgreek{ancientgreek}
 
+\def\greek at variant{monogreek}
+
 \define at key{greek}{variant}[monotonic]{%
   \def\@tmpa{#1}%
+  \xpg at ifdefined{greek}{}{%
+      \xpg at nopatterns{greek}%
+      \adddialect\l at greek\l at nohyphenation
+  }
   \ifx\@tmpa\tmp at poly\def\@tmpa{polytonic}\fi
   \ifx\@tmpa\tmp at ancientgreek\def\@tmpa{ancient}\fi
   \ifx\@tmpa\tmp at polytonic%
-    \def\greek at variant{\l at polygreek}%
+    \xpg at ifdefined{polygreek}{}%
+      {\xpg at warning{No hyphenation patterns were loaded for Polytonic Greek\MessageBreak
+	            I will use the patterns loaded for \string\l at greek\space instead}%
+      \adddialect\l at polygreek\l at greek\relax}%
+    \def\greek at variant{polygreek}%
     \def\captionsgreek{\polygreekcaptions}%
     \def\dategreek{\datepolygreek}%
+    \SetLanguageKeys{greek}{babelname=polutonikogreek}%
     \xpg at info{Option: Polytonic Greek}%
   \else
     \ifx\@tmpa\tmp at ancient
-      \def\greek at variant{\l at ancientgreek}%
+      \xpg at ifdefined{ancientgreek}{}%
+        {\xpg at warning{No hyphenation patterns were loaded for Ancient Greek\MessageBreak
+	              I will use the patterns loaded for \string\l at greek\space instead}%
+         \adddialect\l at ancientgreek\l at greek\relax}%
+      \def\greek at variant{ancientgreek}%
       \def\captionsgreek{\ancientgreekcaptions}%
       \def\dategreek{\dateancientgreek}%
       \xpg at info{Option: Ancient Greek}%
     \else %monotonic
-      \def\greek at variant{\l at monogreek}% monotonic
+      \xpg at ifdefined{monogreek}{}%
+        {\xpg at warning{No hyphenation patterns were loaded for Monotonic Greek\MessageBreak
+	              I will use the patterns loaded for \string\l at greek\space instead}%
+         \adddialect\l at monogreek\l at greek\relax}%
+      \def\greek at variant{monogreek}% monotonic
       \def\captionsgreek{\monogreekcaptions}%
       \def\dategreek{\datemonogreek}%
       \xpg at info{Option: Monotonic Greek}%
@@ -3874,16 +4768,20 @@
     \fi
   \fi}
 
-\def\greek at language{\language=\greek at variant}
+\def\greek at language{%
+  \polyglossia at setup@language at patterns{\greek at variant}
+}
 
+
 \newif\if at greek@numerals
 \define at key{greek}{numerals}[greek]{%
-\ifstrequal{#1}{arabic}{\@greek at numeralsfalse}{\@greek at numeralstrue}}
+  \ifstrequal{#1}{arabic}{\@greek at numeralsfalse}{\@greek at numeralstrue}%
+}
 
 \define at boolkey{greek}{attic}[true]{\xpg at warning{Greek option `attic' is no longer required.}}
 
 % This sets the defaults
-\setkeys{greek}{numerals}
+\setkeys{greek}{numerals,variant}
 
 \def\monogreekcaptions{%
    \def\refname{Αναφορές}%
@@ -3997,8 +4895,8 @@
   \def\ccname{Κοινοποίησις}%
   \def\headtoname{Πρὸς}%
   \def\pagename{Σελὶς}%
-  \def\seename{ὃρα}%
-  \def\alsoname{ὃρα ὡσαύτως}%
+  \def\seename{ὅρα}%
+  \def\alsoname{ὅρα ὡσαύτως}%
   \def\proofname{Ἀπόδειξις}%
   \def\glossaryname{Γλωσσάριον}%
   \def\refname{Ἀναφοραὶ}%
@@ -4031,14 +4929,18 @@
       Δεκεμβρίου\fi}}
 
 % the code for alphabetic numbers and attic numerals 
-% is copied verbatim from xgreek.sty
-\DeclareRobustCommand\anw at false{%
-  \DeclareRobustCommand\anw at print{}}
-\DeclareRobustCommand\anw at true{%
-  \DeclareRobustCommand\anw at print{ʹ}}
+\newrobustcmd\anw at print{}
+\newrobustcmd\anw at false{%
+  \renewrobustcmd\anw at print{}}
+\newrobustcmd\anw at true{%
+   \renewrobustcmd\anw at print{ʹ}}
 \anw at true
 
-\def\greeknumber#1{%
+\newcommand{\greeknumerals}[2]{\greeknumber{#2}}
+\newcommand{\Greeknumerals}[2]{\Greeknumber{#2}}
+
+\protected\def\greeknumber#1{\expandafter\@greeknumber\expandafter{\number#1}}
+\def\@greeknumber#1{%
   \ifnum#1<\@ne\space\gr at ill@value{#1}%
   \else
     \ifnum#1<10\expandafter\gr at num@i\number#1%
@@ -4062,8 +4964,31 @@
     \fi
   \fi
 }
-\def\Greeknumber#1{%
-  \expandafter\MakeUppercase\expandafter{\greeknumber{#1}}}
+\protected\def\Greeknumber#1{\expandafter\@Greeknumber\expandafter{\number#1}}
+\def\@Greeknumber#1{%
+  \ifnum#1<\@ne\space\gr at ill@value{#1}%
+  \else
+    \ifnum#1<10\expandafter\gr at Num@i\number#1%
+    \else
+      \ifnum#1<100\expandafter\gr at Num@ii\number#1%
+      \else
+        \ifnum#1<\@m\expandafter\gr at Num@iii\number#1%
+        \else
+          \ifnum#1<\@M\expandafter\gr at Num@iv\number#1%
+          \else
+            \ifnum#1<100000\expandafter\gr at Num@v\number#1%
+            \else
+              \ifnum#1<1000000\expandafter\gr at Num@vi\number#1%
+              \else
+                \space\gr at ill@value{#1}%
+              \fi
+            \fi
+          \fi
+        \fi
+      \fi
+    \fi
+  \fi
+}
 \let\greeknumeral=\greeknumber
 \let\Greeknumeral=\Greeknumber
 \def\gr at num@i#1{%
@@ -4086,6 +5011,27 @@
 \def\gr at num@vi#1{%
   ͵\ifcase#1\or ρ\or σ\or τ\or υ\or φ\or χ\or ψ\or ω\or ϡ\fi
   \gr at num@v}
+\def\gr at Num@i#1{%
+  \ifcase#1 \or Α\or Β\or Γ\or Δ\or Ε\or \MakeUppercase{Ϛ}\or Ζ\or Η\or θ\fi
+  \ifnum#1=\z@\else\anw at true\fi\anw at print}
+\def\gr at Num@ii#1{%
+  \ifcase#1 \or Ι\or Κ\or Λ\or Μ\or Ν\or Ξ\or Ο\or Π\or \MakeUppercase{ϟ}\fi
+  \ifnum#1=\z@\else\anw at true\fi\gr at Num@i}
+\def\gr at Num@iii#1{%
+  \ifcase#1 \or Ρ\or Σ\or Τ\or Υ\or Φ\or Χ\or Ψ\or Ω\or \MakeUppercase{ϡ}\fi
+  \ifnum#1=\z@\anw at false\else\anw at true\fi\gr at Num@ii}
+\def\gr at Num@iv#1{%
+  \ifnum#1=\z@\else ͵\fi
+  \ifcase#1 \or Α\or Β\or Γ\or Δ\or Ε\or \MakeUppercase{Ϛ}\or Ζ\or Η\or θ\fi
+  \gr at Num@iii}
+\def\gr at Num@v#1{%
+  \ifnum#1=\z@\else ͵\fi
+  \ifcase#1 \or Ι\or Κ\or Λ\or Μ\or Ν\or Ξ\or Ο\or Π\or \MakeUppercase{ϟ}\fi
+\gr at Num@iv}
+  \def\gr at Num@vi#1{%
+͵ \ifcase#1 \or Ρ\or Σ\or Τ\or Υ\or Φ\or Χ\or Ψ\or Ω\or \MakeUppercase{ϡ}\fi
+  \gr at Num@v}
+\def\gr at ill@value#1{\xpg at warning{Illegal value (#1) for Greek numeral}[$#1$]}
 
 %%%% Attic numerals (no longer optional)
 \newcount\@attic at num
@@ -4129,11 +5075,9 @@
 \let\atticnum=\atticnumeral
 
 \def\greek at numbers{%
-   \let\latin at alph\@alph%
-   \let\latin at Alph\@Alph%
    \if at greek@numerals
-      \def\greek at alph##1{\protect\greeknumber{##1}}%
-      \def\greek at Alph##1{\protect\Greeknumber{##1}}%
+      \def\greek at alph##1{\expandafter\greeknumeral\expandafter{\the##1}}%
+      \def\greek at Alph##1{\expandafter\Greeknumeral\expandafter{\the##1}}%
       \let\@alph\greek at alph%
       \let\@Alph\greek at Alph%
    \fi}
@@ -4164,14 +5108,14 @@
 \RequireBidi
 \RequirePackage{hebrewcal}
 
-\providebool{@hebrew at marcheshvan}
-
 \PolyglossiaSetup{hebrew}{
   script=Hebrew,
   direction=RL,
   scripttag=hebr,
+  langtag=IWR,
   hyphennames={nohyphenation},
   fontsetup=true,
+  localnumeral=hebrewnumerals
   %TODO localalph={hebrewnumeral,Hebrewnumeral}
   %digits = hebrewnumber
 }
@@ -4187,16 +5131,10 @@
     \@calendar at hebrewfalse%
 	\fi}
 
-\define at boolkey{hebrew}[@xpg at hebrew@]{marcheshvan}[false]{%
-  \def\@tmpa{#1}%
-  \def\@tmptrue{true}%
-  \ifx\@tmpa\@tmptrue
-    \@xpg at hebrew@marcheshvantrue
-  \else
-    \@xpg at hebrew@marcheshvanfalse
-  \fi}
+\newif\if at xpg@hebrew at marcheshvan
+\@xpg at hebrew@marcheshvanfalse
 
-\setkeys{hebrew}{marcheshvan}
+\define at boolkey{hebrew}[@xpg at hebrew@]{marcheshvan}[true]{}
 
 % hebrewcal.sty also defines the boolean key fullyear (default=false)
 
@@ -4256,9 +5194,11 @@
 
 \input{babel-hebrewalph.def}
 
+\newcommand{\hebrewnumerals}[2]{\hebrewnumber{#2}}
+
 \def\hebrewnumber#1{%
    \if at hebrew@numerals
-     \protect\hebrewnumeral{#1}%
+     \hebrewnumeral{#1}%
    \else
      \number#1%
    \fi
@@ -4265,33 +5205,38 @@
 }
 
 \def\hebrew at numbers{%
-   \let\@origalph\@alph%
-   \let\@origAlph\@Alph%
    \let\@alph\hebrewnumeral%
    \let\@Alph\Hebrewnumeral%
 }
+
 \def\nohebrew at numbers{%
-  \let\@alph\@origalph%
-  \let\@Alph\@origAlph%
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
 }
 
 \def\hebrew at globalnumbers{%
-   \let\orig at arabic\@arabic%
    \let\@arabic\hebrewnumber%
-   \renewcommand\thefootnote{\protect\hebrewnumber{\c at footnote}}%
+   \renewcommand\thefootnote{\localnumeral*{footnote}}%
 }
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
 \def\nohebrew at globalnumbers{%
-  \let\@arabic\orig at arabic%
-  \renewcommand\thefootnote{\protect\number{\c at footnote}}%
+  \let\@arabic\xpg at save@arabic%
 }
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at hebrew{%
-   \let\@@MakeUppercase\MakeUppercase%
    \def\MakeUppercase##1{##1}%
-   }
+}
+
 \def\noextras at hebrew{%
-   \let\MakeUppercase\@@MakeUppercase%
-   }
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase%
+}
 
 %    \end{macrocode}
 % \iffalse
@@ -4302,18 +5247,12 @@
 % 
 % \subsection{gloss-hindi.ldf}
 %    \begin{macrocode}
-% UTF-8 strings kindly provided by Zdenek Wagner, 10-03-2008
+% UTF-8 strings kindly provided by Zdenĕk Wagner, 10-03-2008
 % with corrections and additional contributions by Anshuman Pandey
 % TODO: add option for velthuis transliteration with link to
 % Velthuis Devanagari project.
 
 \ProvidesFile{gloss-hindi.ldf}[polyglossia: module for hindi]
-\ifluatex
-  \xpg at warning{Hindi is not supported with LuaTeX.\MessageBreak
-I will proceed with the compilation, but\MessageBreak
-the output is not guaranteed to be correct\MessageBreak
-and may look very wrong.}
-\fi
 \RequirePackage{devanagaridigits}
 \PolyglossiaSetup{hindi}{
   script=Devanagari,
@@ -4320,9 +5259,9 @@
   scripttag=deva,
   langtag=HIN,
 %%  hyphennames={hindi,!sanskrit}, TODO: implement fallback patterns (with ! prefix)
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=hindinumerals
   %TODO nouppercase=true,
-  %TODO localnumber=hindinumber
 }
 
 \ifx\l at hindi\@undefined%
@@ -4336,7 +5275,9 @@
   \fi
 \fi
 
-\def\hindi at language{\language=\l at hindi}
+\def\hindi at language{%
+  \polyglossia at setup@language at patterns{hindi}%
+}
 
 \def\tmp at western{Western}
 \newif\ifhindi at devanagari@numerals
@@ -4348,6 +5289,8 @@
     \hindi at devanagari@numeralsfalse
   \fi}
 
+\newcommand{\hindinumerals}[2]{\hindinumber{#2}}
+
 \def\hindinumber#1{%
   \ifhindi at devanagari@numerals
     \devanagaridigits{\number#1}%
@@ -4358,13 +5301,13 @@
 \def\captionshindi{%
      \def\abstractname{सारांश}%
      \def\appendixname{परिशिष्ट}%
-     \def\bibname{संदर्भ ग्रन्थ}%
+     \def\bibname{संदर्भ ग्रंथ}%
      \def\ccname{}%
      \def\chaptername{अध्याय}%
      \def\contentsname{विषय सूची}%
      \def\enclname{}%
      \def\figurename{चित्र}% रेखाचित्र
-     \def\headpagename{पृषठ}%
+     \def\headpagename{पृष्ठ}%
      \def\headtoname{}%
      \def\indexname{सूची}%
      %              सूचक
@@ -4372,7 +5315,7 @@
      %              अनुक्रमणि
      \def\listfigurename{चित्रों की सूची}%
      \def\listtablename{तालिकाओं की सूची}%
-     \def\pagename{पृषठ}%
+     \def\pagename{पृष्ठ}%
      \def\partname{खणड}%
      \def\prefacename{प्रस्तावना}% प्राक्कथन
      \def\refname{हवाले}%
@@ -4398,17 +5341,110 @@
     \space\hindinumber\year}%
 }
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at hindi{%
-  \let\@@MakeUppercase\MakeUppercase%
   \def\MakeUppercase##1{##1}%
 }
+
 \def\noextras at hindi{%
-  \let\MakeUppercase\@@MakeUppercase%
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase%
 }
 
 %    \end{macrocode}
 % \iffalse
 %</gloss-hindi.ldf>
+%<*gloss-hungarian.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-hungarian.ldf}
+%    \begin{macrocode}
+\ProvidesFile{gloss-hungarian.ldf}[polyglossia: module for hungarian]
+
+\PolyglossiaSetup{hungarian}{
+  babelname=magyar,
+  hyphennames={magyar,hungarian},
+  langtag=HUN,
+  hyphenmins={2,2},
+  fontsetup=true,
+}
+
+\frenchspacing
+
+\def\captionshungarian{%
+   \def\refname{Hivatkozások}%
+   \def\abstractname{Kivonat}%
+   \def\bibname{Irodalomjegyzék}%
+   \def\prefacename{Előszó}%
+   \def\chaptername{fejezet}%
+   \def\appendixname{Függelék}%
+   \def\contentsname{Tartalomjegyzék}%
+   \def\listfigurename{Ábrák jegyzéke}%
+   \def\listtablename{Táblázatok jegyzéke}%
+   \def\indexname{Tárgymutató}%
+   \def\figurename{ábra}%
+   \def\tablename{táblázat}%
+   %\def\thepart{}%
+   \def\partname{rész}%
+   \def\pagename{oldal}%
+   \def\seename{lásd}%
+   \def\alsoname{lásd még}%
+   \def\enclname{Melléklet}%
+   \def\ccname{Körlevél–címzettek}%
+   \def\headtoname{Címzett}%
+   \def\proofname{Bizonyítás}%
+   \def\glossaryname{Szójegyzék}%
+}
+
+\def\datehungarian{%   
+   \def\today{%
+    \number\year.\nobreakspace\ifcase\month\or
+    január\or február\or március\or
+    április\or május\or június\or
+    július\or augusztus\or szeptember\or
+    október\or november\or december\fi
+    \space\number\day.}%
+   \def\ondatehungarian{%
+    \number\year.\nobreakspace\ifcase\month\or
+    január\or február\or március\or
+    április\or május\or június\or
+    július\or augusztus\or szeptember\or
+    október\or november\or december\fi
+      \space\ifcase\day\or
+      1-jén\or  2-án\or  3-án\or  4-én\or  5-én\or
+      6-án\or  7-én\or  8-án\or  9-én\or 10-én\or
+     11-én\or 12-én\or 13-án\or 14-én\or 15-én\or
+     16-án\or 17-én\or 18-án\or 19-én\or 20-án\or
+     21-én\or 22-én\or 23-án\or 24-én\or 25-én\or
+     26-án\or 27-én\or 28-án\or 29-én\or 30-án\or
+     31-én\fi}%
+   \let\ontoday\ondatehungarian}
+
+% change 'táblázat x.x' to 'x.x. táblázat'
+\def\xpg at hungarian@fnum at table{\thetable.~\tablename}
+\let\xpg at save@fnum at table\fnum at table
+
+% change 'ábra x.x' to 'x.x. ábra'
+\def\xpg at hungarian@fnum at figure{\thefigure.~\figurename}
+\let\xpg at save@fnum at figure\fnum at figure
+
+\def\blockextras at hungarian{%
+   \let\fnum at table\xpg at hungarian@fnum at table
+   \let\fnum at figure\xpg at hungarian@fnum at figure
+}
+
+\def\noextras at hungarian{%
+   \let\fnum at table\xpg at save@fnum at table
+   \let\fnum at figure\xpg at save@fnum at figure
+   \let\ontoday\@undefined
+}
+
+%    \end{macrocode}
+% \iffalse
+%</gloss-hungarian.ldf>
 %<*gloss-icelandic.ldf>
 % \fi
 % \clearpage
@@ -4419,6 +5455,7 @@
 \PolyglossiaSetup{icelandic}{
   hyphennames={icelandic},
   hyphenmins={2,2},
+  langtag=ISL,
   fontsetup=true,
 }
 
@@ -4468,6 +5505,7 @@
 \PolyglossiaSetup{interlingua}{
   hyphennames={interlingua},
   hyphenmins={2,2},
+  langtag=INA,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,
@@ -4514,45 +5552,21 @@
 % \subsection{gloss-irish.ldf}
 %    \begin{macrocode}
 \ProvidesFile{gloss-irish.ldf}[polyglossia: module for irish]
+
+% We only provide this gloss for babel compatibility. Since irish is 
+% a gaelic variety, we use 'gaelic' with variant 'irish' now.
+
+\input{gloss-gaelic.ldf}
+
 \PolyglossiaSetup{irish}{
   hyphennames={irish},
   hyphenmins={2,2},
+  langtag=IRI,
   fontsetup=true,
 }
 
-\def\captionsirish{%
-   \def\refname{Tagairtí}%
-   \def\abstractname{Achoimre}%
-   \def\bibname{Leabharliosta}%
-   \def\prefacename{Réamhrá}%    <-- also "Brollach"
-   \def\refname{Tagairtí}%
-   \def\chaptername{Tagairtí}%
-   \def\appendixname{Aguisín}%
-   \def\contentsname{Clár Ábhair}%
-   \def\listfigurename{Léaráidí}%
-   \def\listtablename{Táblaí}%
-   \def\indexname{Innéacs}%
-   \def\figurename{Léaráid}%
-   \def\tablename{Tábla}%
-   %\def\thepart{}%
-   \def\partname{Cuid}%
-   \def\pagename{Leathanach}%
-   \def\seename{féach}%
-   \def\alsoname{féach freisin}%
-   \def\enclname{faoi iamh}%
-   \def\ccname{cc}%
-   \def\headtoname{Go}%
-   \def\proofname{Cruthúnas}%
-   \def\glossaryname{Glossary}%
-   }
-\def\dateirish{%
-   \def\today{%
-    \number\day\space \ifcase\month\or
-    Eanáir\or Feabhra\or Márta\or Aibreán\or
-    Bealtaine\or Meitheamh\or Iúil\or Lúnasa\or
-    Meán Fómhair\or Deireadh Fómhair\or
-    Mí na Samhna\or Mí na Nollag\fi
-    \space \number\year}}
+\let\captionsirish\captionsgaelic at irish
+\let\dateirish\dategaelic at irish
 
 %    \end{macrocode}
 % \iffalse
@@ -4568,6 +5582,7 @@
 \PolyglossiaSetup{italian}{
   hyphennames={italian},
   hyphenmins={2,2},
+  langtag=ITA,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,
@@ -4584,8 +5599,9 @@
 \fi
 
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\italian at shorthands{%
@@ -4955,10 +5971,11 @@
 \PolyglossiaSetup{kannada}{
   script=Kannada,
   scripttag=knda,
-  langtag=KNDA,
+  langtag=KAN,
   hyphennames={kannada},
   hyphenmins={2,2}, 
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=kannadanumerals
 }
 
 %% Defining Kannada digits equivalents to english
@@ -5026,7 +6043,9 @@
   \def\today{\kannadanumber\day\space\kannadamonth\space\kannadanumber\year}%
 }
 
-%% Based on the settings displays rrespective numbers
+\newcommand{\kannadanumerals}[2]{\kannadanumber{#2}}
+
+%% Based on the settings displays respective numbers
 \def\kannadanumber#1{%
   \ifkannada at numerals
   \kannadadigits{\number#1}%
@@ -5044,162 +6063,163 @@
 % 
 % \subsection{gloss-khmer.ldf}
 %    \begin{macrocode}
-\ProvidesFile{gloss-khmer.ldf}[polyglossia: module for Khmer]
-\PolyglossiaSetup{khmer}{
-	script=Khmer,%
-	scripttag=khmr,%
-	langtag=KHM,%
-	hyphennames={nohyphenation},%
-	fontsetup=true%
-}
-\newif\if at khmer@numerals
-\def\tmp at khmer{khmer}
-\define at key{khmer}{numerals}[arabic]{%
-	\def\@tmpa{#1}%
-	\ifx\@tmpa\tmp at khmer\@khmer at numeralstrue%
-	\else\@khmer at numeralsfalse\fi%
-}
-\setkeys{khmer}{numerals}
-\def\captionskhmer{%
-	\def\prefacename{អារម្ភកថា}%
-	\def\refname{ឯកសារយោង}%
-	\def\abstractname{សង្ខេប}%
-	\def\bibname{គន្ថនិទ្ទេស}%
-	\def\chaptername{ជំពូក}%
-	\def\appendixname{សេចក្ដីបន្ថែម}%
-	\def\contentsname{មាតិការ}%
-	\def\listfigurename{បញ្ជីរូបភាព}%
-	\def\listtablename{បញ្ជីតារាង}%
-	\def\indexname{សន្ទស្សន៍}%
-	\def\figurename{រូប}%
-	\def\tablename{តារាង}%
-	\def\partname{ផ្នែក}%
-	\def\pagename{ទំព័រ}%
-	\def\seename{មើល}%
-	\def\alsoname{មើលបន្ថែម}%
-	\def\enclname{ឯកសារភ្ជាប់}%
-	\def\ccname{ចម្លងជួន}%
-	\def\headtoname{ផ្ញើរទៅ}%
-	\def\proofname{សម្រាយ}%
-	\def\glossaryname{សទានុក្រម}%
-}
-\def\datekhmer{%
-	\def\khmer at month{%
-		\ifcase\month\or%
-		មករា\or%
-		កុម្ភៈ\or%
-		មិនា\or%
-		មេសា\or%
-		ឧសភា\or%
-		មិថុនា\or%
-		កក្កដា\or%
-		សីហា\or%
-		កញ្ញា\or%
-		តុលា\or%
-		វិច្ឆិកា\or%
-		ធ្នូ\fi}%
-	\def\today{\khmernumber\day\space\khmer at month\space\khmernumber\year}%
-}
-\def\khmerdigits#1{\expandafter\@khmer at digits #1@}
-\def\@khmer at digits#1{%
-	\ifx @#1% then terminate
-	\else\ifx0#1០%
-	\else\ifx1#1១%
-	\else\ifx2#1២%
-	\else\ifx3#1៣%
-	\else\ifx4#1៤%
-	\else\ifx5#1៥%
-	\else\ifx6#1៦%
-	\else\ifx7#1៧%
-	\else\ifx8#1៨%
-	\else\ifx9#1៩%
-	\else#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
-    \expandafter\@khmer at digits%
-    \fi
-}
-\def\khmernumber#1{%
-	\if at khmer@numerals%
-		\khmerdigits{\number#1}%
-	\else%
-		\number#1%
-	\fi}
-\def\khmer at globalnumbers{%
-	\let\orig at arabic\@arabic%
-	\let\@arabic\khmernumber%
-	\renewcommand{\thefootnote}{\protect\khmernumber{\c at footnote}}%
-}
-\def\nokhmer at globalnumbers{%
-	\let\@arabic\orig at arabic%
-	\renewcommand\thefootnote{\protect\number{\c at footnote}}%
-}
-\def\thepart{\arabic{part}}
-\def\@khmeralph#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 ល\or វ\or ស\or ហ\or ឡ\or អ%
-\else\xpg at ill@value{#1}{@khmeralph}\fi}
-\def\khmerAlph#1{\expandafter\@khmerAlph\csname c@#1\endcsname}
-\def\@khmerAlph#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 ល\or វ\or ស\or ហ\or ឡ\or អ%
-\else\xpg at ill@value{#1}{@khmeralph}\fi}
-\def\khmer at numbers{%
-	\let\@latinalph\@alph%
-	\let\@latinAlph\@Alph%
-	\if at khmer@numerals
-		\let\@alph\@khmeralph%
-		\let\@Alph\@khmerAlph%
-	\fi%
-}
-\def\nokhmer at numbers{%
-	\let\@alph\@latinalph%
-	\let\@Alph\@latinAlph%
-}
-\def\blockextras at khmer{%
-	\XeTeXlinebreaklocale "kh" % 
-	\XeTeXlinebreakskip = 0pt plus 1pt minus 1pt
-%	\let\orig at baselinestretch\baselinestretch%
-%	\renewcommand{\baselinestretch}{1.2}% not work
-}
-\def\noblockextras at khmer{% 
-	\XeTeXlinebreaklocale "en"%
-%	\let\baselinestretch\orig at baselinestretch%
-}
-\@ifclassloaded{beamer}{%
-	\usefonttheme{professionalfonts}%
-	\def\factname{ស្វ័យសត្យ}%
-	\def\lemmaname{បទគន្លិះ}%
-	\def\theoremname{ទ្រឹស្ដីបទ}%
-	\def\corollaryname{អនុសាធ្យ}%
-	\def\problemname{ចំណោទ}%
-	\def\solutionname{ដំណោះស្រាយ}%
-	\def\definitionname{និយមន័យ}%
-	\def\examplename{ឧទាហរណ៏}%
-	\uselanguage{khmer}%
-	\languagepath{khmer}%
-	\deftranslation[to=khmer]{Fact}{\factname}%
-	\deftranslation[to=khmer]{Lemma}{\lemmaname}%
-	\deftranslation[to=khmer]{Theorem}{\theoremname}%
-	\deftranslation[to=khmer]{Corollary}{\corollaryname}%
-	\deftranslation[to=khmer]{Problem}{\problemname}%
-	\deftranslation[to=khmer]{Solution}{\solutionname}%
-	\deftranslation[to=khmer]{Definition}{\definitionname}%
-	\deftranslation[to=khmer]{Definitions}{\definitionname}%
-	\deftranslation[to=khmer]{Example}{\examplename}%
-	\deftranslation[to=khmer]{Examples}{\examplename}%
-	\AtEndDocument{\immediate\write\@auxout{\string\@writefile{nav}%
-		{\noexpand\headcommand{\noexpand\def\noexpand%
-		\inserttotalframenumber{\khmernumber{\the\c at framenumber}}}}}}%
-}{}
+\ProvidesFile{gloss-khmer.ldf}[polyglossia: module for Khmer]
+\PolyglossiaSetup{khmer}{
+	script=Khmer,%
+	scripttag=khmr,%
+	langtag=KHM,%
+	hyphennames={nohyphenation},%
+	fontsetup=true,%
+	localnumeral=khmernumerals%
+}
+\newif\if at khmer@numerals
+\def\tmp at khmer{khmer}
+\define at key{khmer}{numerals}[arabic]{%
+	\def\@tmpa{#1}%
+	\ifx\@tmpa\tmp at khmer\@khmer at numeralstrue%
+	\else\@khmer at numeralsfalse\fi%
+}
+\setkeys{khmer}{numerals}
+\def\captionskhmer{%
+	\def\prefacename{អារម្ភកថា}%
+	\def\refname{ឯកសារយោង}%
+	\def\abstractname{សង្ខេប}%
+	\def\bibname{គន្ថនិទ្ទេស}%
+	\def\chaptername{ជំពូក}%
+	\def\appendixname{សេចក្ដីបន្ថែម}%
+	\def\contentsname{មាតិការ}%
+	\def\listfigurename{បញ្ជីរូបភាព}%
+	\def\listtablename{បញ្ជីតារាង}%
+	\def\indexname{សន្ទស្សន៍}%
+	\def\figurename{រូប}%
+	\def\tablename{តារាង}%
+	\def\partname{ផ្នែក}%
+	\def\pagename{ទំព័រ}%
+	\def\seename{មើល}%
+	\def\alsoname{មើលបន្ថែម}%
+	\def\enclname{ឯកសារភ្ជាប់}%
+	\def\ccname{ចម្លងជួន}%
+	\def\headtoname{ផ្ញើរទៅ}%
+	\def\proofname{សម្រាយ}%
+	\def\glossaryname{សទានុក្រម}%
+}
+\def\datekhmer{%
+	\def\khmer at month{%
+		\ifcase\month\or%
+		មករា\or%
+		កុម្ភៈ\or%
+		មិនា\or%
+		មេសា\or%
+		ឧសភា\or%
+		មិថុនា\or%
+		កក្កដា\or%
+		សីហា\or%
+		កញ្ញា\or%
+		តុលា\or%
+		វិច្ឆិកា\or%
+		ធ្នូ\fi}%
+	\def\today{\khmernumber\day\space\khmer at month\space\khmernumber\year}%
+}
+\def\khmerdigits#1{\expandafter\@khmer at digits #1@}
+\def\@khmer at digits#1{%
+	\ifx @#1% then terminate
+	\else\ifx0#1០%
+	\else\ifx1#1១%
+	\else\ifx2#1២%
+	\else\ifx3#1៣%
+	\else\ifx4#1៤%
+	\else\ifx5#1៥%
+	\else\ifx6#1៦%
+	\else\ifx7#1៧%
+	\else\ifx8#1៨%
+	\else\ifx9#1៩%
+	\else#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
+    \expandafter\@khmer at digits%
+    \fi
+}
+
+\newcommand{\khmernumerals}[2]{\khmernumber{#2}}
+
+\def\khmernumber#1{%
+	\if at khmer@numerals%
+		\khmerdigits{\number#1}%
+	\else%
+		\number#1%
+	\fi}
+\def\khmer at globalnumbers{%
+	\let\orig at arabic\@arabic%
+	\let\@arabic\khmernumber%
+	\renewcommand{\thefootnote}{\localnumeral*{footnote}}%
+}
+\def\nokhmer at globalnumbers{%
+	\let\@arabic\orig at arabic%
+}
+\def\thepart{\arabic{part}}
+\def\@khmeralph#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 ល\or វ\or ស\or ហ\or ឡ\or អ%
+\else\xpg at ill@value{#1}{@khmeralph}\fi}
+\def\khmerAlph#1{\expandafter\@khmerAlph\csname c@#1\endcsname}
+\def\@khmerAlph#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 ល\or វ\or ស\or ហ\or ឡ\or អ%
+\else\xpg at ill@value{#1}{@khmeralph}\fi}
+\def\khmer at numbers{%
+	\if at khmer@numerals
+		\let\@alph\@khmeralph%
+		\let\@Alph\@khmerAlph%
+	\fi%
+}
+\def\nokhmer at numbers{%
+	\let\@alph\latin at alph%
+	\let\@Alph\latin at Alph%
+}
+\def\blockextras at khmer{%
+	\XeTeXlinebreaklocale "kh" % 
+	\XeTeXlinebreakskip = 0pt plus 1pt minus 1pt
+%	\let\orig at baselinestretch\baselinestretch%
+%	\renewcommand{\baselinestretch}{1.2}% not work
+}
+\def\noblockextras at khmer{% 
+	\XeTeXlinebreaklocale "en"%
+%	\let\baselinestretch\orig at baselinestretch%
+}
+\@ifclassloaded{beamer}{%
+	\usefonttheme{professionalfonts}%
+	\def\factname{ស្វ័យសត្យ}%
+	\def\lemmaname{បទគន្លិះ}%
+	\def\theoremname{ទ្រឹស្ដីបទ}%
+	\def\corollaryname{អនុសាធ្យ}%
+	\def\problemname{ចំណោទ}%
+	\def\solutionname{ដំណោះស្រាយ}%
+	\def\definitionname{និយមន័យ}%
+	\def\examplename{ឧទាហរណ៏}%
+	\uselanguage{khmer}%
+	\languagepath{khmer}%
+	\deftranslation[to=khmer]{Fact}{\factname}%
+	\deftranslation[to=khmer]{Lemma}{\lemmaname}%
+	\deftranslation[to=khmer]{Theorem}{\theoremname}%
+	\deftranslation[to=khmer]{Corollary}{\corollaryname}%
+	\deftranslation[to=khmer]{Problem}{\problemname}%
+	\deftranslation[to=khmer]{Solution}{\solutionname}%
+	\deftranslation[to=khmer]{Definition}{\definitionname}%
+	\deftranslation[to=khmer]{Definitions}{\definitionname}%
+	\deftranslation[to=khmer]{Example}{\examplename}%
+	\deftranslation[to=khmer]{Examples}{\examplename}%
+	\AtEndDocument{\immediate\write\@auxout{\string\@writefile{nav}%
+		{\noexpand\headcommand{\noexpand\def\noexpand%
+		\inserttotalframenumber{\localnumeral*{framenumber}}}}}}%
+}{}
 %    \end{macrocode}
 % \iffalse
 %</gloss-khmer.ldf>
@@ -5216,8 +6236,7 @@
     scripttag=hang,
     language=Korean,
     langtag=KOR,
-    hyphennames={english,USenglish},
-    hyphenmins={2,3},
+    hyphennames={nohyphenation},
     frenchspacing=true,
     fontsetup=true
 }
@@ -5238,8 +6257,8 @@
     \else
         \captions at korean@hanja
     \fi
-    \def\seename{$rightarrow$}%
-    \def\alsoname{$Rightarrow$}%
+    \def\seename{$\rightarrow$}%
+    \def\alsoname{$\Rightarrow$}%
 }
 \def\captions at korean@hangul{%
     \def\koreanTHEname{제}%
@@ -5305,14 +6324,12 @@
 }
 
 \def\korean at numbers{%
-    \let\@orig at alph\@alph
-    \let\@orig at Alph\@Alph
     \let\@alph\@koreanalph
     \let\@Alph\@koreanAlph
 }
 \def\nokorean at numbers{%
-    \let\@alph\@orig at alph
-    \let\@Alph\@orig at Alph
+    \let\@alph\latin at alph
+    \let\@Alph\latin at Alph
 }
 \let\nokorean at globalnumbers\nokorean at numbers
 
@@ -5346,7 +6363,7 @@
         \XeTeXinterchartokenstate\z@
         \XeTeXlinebreakpenalty\z@
         \XeTeXlinebreakskip\z at skip
-        \XeTeXlinebreaklocale ""
+        \XeTeXlinebreaklocale "en"
         \noextras at korean@common
     }
 \else % luatex
@@ -5366,435 +6383,435 @@
             \def\@chapapp##1##2{\koreanTHEname ##1##2##1\chaptername}%
         \fi
     \fi
-    \ifdefined\baselinestretch
-        \let\xpg at orig@linestretch\baselinestretch
-        \def\baselinestretch{1.3888}\selectfont
-    \fi
-    \ifdefined\footnotesep
-        \edef\xpg at orig@footnotesep{\noexpand\footnotesep=\the\footnotesep\relax}%
-        \footnotesep=1.3888\footnotesep
-    \fi
 }
 
 \def\noextras at korean@common{%
-    \ifdefined\xpg at orig@footnotesep \xpg at orig@footnotesep \fi
-    \ifdefined\xpg at orig@linestretch \let\baselinestretch\xpg at orig@linestretch \fi
-    \ifdefined\xpg at orig@@chapapp    \let\@chapapp\xpg at orig@@chapapp \fi
+    \ifdefined\xpg at orig@@chapapp \let\@chapapp\xpg at orig@@chapapp \fi
 }
 
-\ifxetex % XeTeX
+\ifluatex % luatex
+\protected\def\inhibitglue{\hskip\z at skip}
+\ifdefined\newattribute\else
+    \let\newattribute\newluatexattribute
+    \let\unsetattribute\unsetluatexattribute
+\fi
+\newattribute\xpg at attr@korean
+\newattribute\xpg at attr@autojosa
 % user commands for Josa
 % Josa : particles in Korean grammar that immediately follow a noun or pronoun.
 %        Josa might vary depending on previous character.
-\protected\def\jong {\global\let\XPGKO at let@josa=0}\jong
-\protected\def\rieul{\global\let\XPGKO at let@josa=1}
-\protected\def\jung {\global\let\XPGKO at let@josa=2}
-\protected\def\가{\xpg at make@josa 가이}
-\protected\def\이{\futurelet\@let at token\xpg at make@josa at I}
-\protected\def\은{\xpg at make@josa 는은} \let\는\은
-\protected\def\을{\xpg at make@josa 를을} \let\를\을
-\protected\def\와{\xpg at make@josa 와과} \let\과\와
-\protected\def\으{\xpg at make@josa \empty 으}
+\protected\def\rieul{\global\let\xpg at josa@zwang\@ne}
+\protected\def\jung {\global\let\xpg at josa@zwang\tw@}
+\protected\def\jong {\global\let\xpg at josa@zwang\thr@@}
+\protected\def\은{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 은\endgroup\xpg at reset@josa}
+\let\는\은
+\protected\def\을{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 을\endgroup\xpg at reset@josa}
+\let\를\을
+\protected\def\와{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 와\endgroup\xpg at reset@josa}
+\let\과\와
+\protected\def\가{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 가\endgroup\xpg at reset@josa}
+\protected\def\이{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 이\endgroup\xpg at reset@josa}
+\protected\def\라{\이 라}
+\protected\def\으{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 으\endgroup\xpg at reset@josa}
 \protected\def\로{\으 로}
-\protected\def\라{\xpg at make@josa 라{이라}}
-\def\xpg at make@josa at II{\xpg at make@josa\relax 이}
-\def\xpg at make@josa at I{%
-    \ifcat\@let at token\xpg at catcode@letter
-        \expandafter\expandafter\expandafter\count@\expandafter
-        \xpg at letter@to at num\meaning\@let at token\relax
-        \ifnum 0\ifnum\count@>"ABFF \ifnum\count@<"D7A4 1\fi\fi>\z@
-            \expandafter\expandafter\expandafter\xpg at make@josa at II
+\def\xpg at reset@josa {\global\let\xpg at josa@zwang\z@}\xpg at reset@josa
+% load lua file for korean
+\directlua{ require "polyglossia-korean" }
+%    \end{macrocode}
+% \iffalse
+%</gloss-korean.ldf>
+%<*gloss-kurdish.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-kurdish.ldf}
+%    \begin{macrocode}
+% Created on September 1, 2019
+% Sina Ahmadi (https://sinaahmadi.github.io/)
+\ProvidesFile{gloss-kurdish.ldf}[polyglossia: module for Kurdish]
+
+\RequireBidi
+\RequirePackage{arabicnumbers}
+\RequirePackage{farsical}
+\RequirePackage{hijrical}
+
+\PolyglossiaSetup{kurdish}{
+  script=Arabic,
+  direction=RL,
+  scripttag=arab,
+  langtag=KUR,
+  hyphennames={nohyphenation},
+  fontsetup=true,
+  localnumeral=kurdishnumerals
+}
+
+\newif\if at kurdish@kurmanji
+\def\kurdish at variant{sorani}
+\define at choicekey*+{kurdish}{variant}[\val\nr]{sorani,kurmanji}[sorani]{%
+   \ifcase\nr\relax
+      % sorani:
+      \def\kurdish at variant{sorani}%
+      \@kurdish at kurmanjifalse%
+   \or
+      % kurmanji:
+      \def\kurdish at variant{kurmanji}%
+      \@kurdish at kurmanjitrue%
+   \fi
+   \kurdish at set@variety%
+   \xpg at info{Option: kurdish, variant=\val}%
+}{\xpg at warning{Unknown Kurdish variant `#1'}}
+
+\newif\if at kurdish@latin
+\newif\if at kurdish@arabic
+\define at choicekey*+{kurdish}{script}[\val\nr]{Arabic,Latin}{%
+   \ifcase\nr\relax
+      % Arabic:
+      \@kurdish at latinfalse%
+      \@kurdish at arabictrue%
+   \or
+      % Latin:
+      \@kurdish at latintrue%
+      \@kurdish at arabicfalse%
+   \fi
+   \kurdish at set@variety%
+   \xpg at info{Option: kurdish, script=\val}%
+}{\xpg at warning{Unknown Kurdish script `#1'}}
+
+
+\newif\if at western@numerals
+\newif\if at force@western at numerals
+\def\kurdish at script{arabic}
+\def\kurdish at pattern{nohyphenation}
+
+\def\kurdish at set@variety{%
+  \if at kurdish@latin% Latin explicitly set
+     \@western at numeralstrue%
+     \if at kurdish@kurmanji
+         \def\kurdish at pattern{kurmanji}%
+         \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurmanji}%
+     \else
+         \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurdish}%
+     \fi
+     \def\kurdish at script{latin}
+     \xpg at fontsetup@latin{kurdish}%
+  \else
+     \if at kurdish@arabic% Arabic explicitly set
+        \if at kurdish@kurmanji
+            \if at force@western at numerals\else\@western at numeralsfalse\fi%
+            \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurmanji}%
+            \def\kurdish at script{arabic}%
         \else
-            \expandafter\expandafter\expandafter\가
+            \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurdish}%
         \fi
-    \else
-        \expandafter\가
-    \fi
+        \xpg at fontsetup@nonlatin{kurdish}%
+     \else% sorani=Arabic, kurmanji=Latin
+        \if at kurdish@kurmanji
+            \@western at numeralstrue%
+            \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurmanji}%
+            \xpg at fontsetup@latin{kurdish}%
+            \def\kurdish at script{latin}
+        \else
+            \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurdish}%
+            \xpg at fontsetup@nonlatin{kurdish}%
+        \fi
+     \fi
+  \fi
 }
-\def\xpg at make@josa#1#2{%
-    \ifcat\xpg at catcode@letter\XPGKO at let@josa
-        \expandafter\expandafter\expandafter\count@\expandafter
-        \xpg at letter@to at num\meaning\XPGKO at let@josa\relax
-    \else\ifcat\xpg at catcode@other\XPGKO at let@josa
-        \expandafter\expandafter\expandafter\count@\expandafter
-        \xpg at character@to at num\meaning\XPGKO at let@josa\relax
+
+\def\tmp at western{western}
+\define at key{kurdish}{numerals}[eastern]{%
+  \def\@tmpa{#1}%
+  \ifx\@tmpa\tmp at western\@western at numeralstrue\@force at western@numeralstrue\else%
+    \@western at numeralsfalse%
+  \fi%
+}
+
+%this is needed for \abjad in arabicnumbers.sty
+\def\tmp at true{true}
+\define at key{kurdish}{abjadjimnotail}[true]{%
+  \def\@tmpa{#1}%
+  \ifx\@tmpa\tmp at true\abjad at jim@notailtrue%
+  \else
+    \abjad at jim@notailfalse
+  \fi%
+}
+
+% NOT YET USED
+\define at key{kurdish}{locale}[default]{%
+  \def\@kurdish at locale{#1}}
+
+
+%TODO add option for CALENDAR
+
+\setkeys{kurdish}{variant,locale}
+
+\def\kurdish at language{%
+   \polyglossia at setup@language at patterns{\kurdish at pattern}%
+}%
+
+\def\kurdishNativemonth#1{\ifcase#1%
+  \or رێبه‌ندان\or ره‌شه‌مێ\or خاكه‌لێوه‌\or گوڵان\or جۆزه‌ردان\or پووشپه‌ڕ\or خه‌رمانان\or گه‌لاوێژ\or ره‌زبه‌ر\or گه‌ڵارێزان\or سه‌رماوه‌ز\or به‌فرانبار\fi}
+\def\kurdishmonth#1{\ifcase#1%
+  \or کانونی دووەم\or شوبات\or ئازار\or نیسان\or ئایار\or حوزه‌یران\or ته‌ممووز\or ئاب\or ئه‌یلوول\or تشرینی یه‌كه‌م\or تشرینی دووهه‌م\or كانوونی یه‌كه‌م\fi}
+
+%\Hijritoday is now locale-aware and will format the date with this macro:
+\DefineFormatHijriDate{kurdish}{%
+  \@ensure at RTL{%
+    \kurdishnumber{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\kurdishnumber{\value{Hijriyear}}%
+  }%
+}
+
+\def\captionskurdish at sorani@arabic{%
+  \def\prefacename{\@ensure at RTL{پێشه‌كی}}%
+  \def\refname{\@ensure at RTL{سه‌رچاوه‌کان}}%
+  \def\abstractname{\@ensure at RTL{پوخته‌}}%
+  \def\bibname{\@ensure at RTL{کتێبنامه‌}}%
+  \def\chaptername{\@ensure at RTL{به‌ندی}}%
+  \def\appendixname{\@ensure at RTL{پاشکۆ}}%
+  \def\contentsname{\@ensure at RTL{نێوه‌ڕۆک}}%
+  \def\listfigurename{\@ensure at RTL{لیستی وێنه‌کان}}%
+  \def\listtablename{\@ensure at RTL{لیستی خشته‌کان}}%
+  \def\indexname{\@ensure at RTL{پێنوێن}}%
+  \def\figurename{\@ensure at RTL{وێنه‌}}%
+  \def\tablename{\@ensure at RTL{خشتە}}%
+  \def\partname{\@ensure at RTL{به‌شی}}%
+  \def\enclname{\@ensure at RTL{هاوپێچ}}%
+  \def\ccname{\@ensure at RTL{روونووس}}%
+  \def\headtoname{\@ensure at RTL{بۆ}}%
+  \def\pagename{\@ensure at RTL{لاپه‌ڕه‌}}%
+  \def\seename{\@ensure at RTL{چاو لێکه‌ن}}%
+  \def\alsoname{\@ensure at RTL{هه‌روه‌ها چاو لێکه‌ن}}%
+  \def\proofname{\@ensure at RTL{سەلماندن}}%
+  \def\glossaryname{\@ensure at RTL{فه‌رهه‌نگۆک}}%
+}
+
+\def\captionskurdish at sorani@latin{%
+  \def\prefacename{Pêşekî}%
+  \def\refname{Serçawekan}%
+  \def\abstractname{Puxte}%
+  \def\bibname{Kitêbname}%
+  \def\chaptername{Bendî}%
+  \def\appendixname{Paşko}%
+  \def\contentsname{Nêwerrok}%
+  \def\listfigurename{Lîstî Wênekan}%
+  \def\listtablename{Lîstî Xiştekan}%
+  \def\indexname{Pêrrist}%
+  \def\figurename{Wêney}%
+  \def\tablename{Xiştey}%
+  \def\partname{Beşî}%
+  \def\enclname{Hawpêç}%
+  \def\ccname{Rûnûs}%
+  \def\headtoname{Bo}%
+  \def\pagename{Laperre}%
+  \def\seename{Çaw lêken}%
+  \def\alsoname{Herweha çaw lêken}%
+  \def\proofname{Selmandin}%
+  \def\glossaryname{Ferhengok}%
+}
+
+\def\captionskurdish at kurmanji@latin{%
+  \def\prefacename{Peşgotin}%
+  \def\refname{Pirtuken bijartî}%
+  \def\abstractname{Kurtebîr}%
+  \def\bibname{Çavkanîya Pirtukan}%
+  \def\chaptername{Serê}%
+  \def\appendixname{Tebînîya}%
+  \def\contentsname{Navêrok}%
+  \def\listfigurename{Hejmara Dimena}%
+  \def\listtablename{Hejmara Kevalen}%
+  \def\indexname{Endeks}%
+  \def\figurename{Dimenê}%
+  \def\tablename{Kevala}%
+  \def\partname{Bêşa}%
+  \def\enclname{Dumahik}%
+  \def\ccname{Belavker}%
+  \def\headtoname{Ji bo}%
+  \def\pagename{Rûpelê}%
+  \def\seename{binêra}%
+  \def\alsoname{le vêya ji binêra}%
+  \def\proofname{Delîl}%
+  \def\glossaryname{Çavkanîya lêkolînê}%
+}
+
+\def\captionskurdish at kurmanji@arabic{%
+  \def\prefacename{\@ensure at RTL{پێشگۆتن}}%
+  \def\refname{\@ensure at RTL{پرتووکێن بژارتی}}%
+  \def\abstractname{\@ensure at RTL{کورتەبیر}}%
+  \def\bibname{\@ensure at RTL{چاڤکانییا پرتووکان}}%
+  \def\chaptername{\@ensure at RTL{سەرێ}}%
+  \def\appendixname{\@ensure at RTL{پاشکۆ}}%
+  \def\contentsname{\@ensure at RTL{ناڤێرۆک}}%
+  \def\listfigurename{\@ensure at RTL{هەژمارا دیمەنا}}%
+  \def\listtablename{\@ensure at RTL{هەژمارا کەڤالێن}}%
+  \def\indexname{\@ensure at RTL{پێرست}}%
+  \def\figurename{\@ensure at RTL{دیمەنێ}}%
+  \def\tablename{\@ensure at RTL{کەڤالا}}%
+  \def\partname{\@ensure at RTL{بەشا}}%
+  \def\enclname{\@ensure at RTL{دوماهک}}%
+  \def\ccname{\@ensure at RTL{بەلاڤکەر}}%
+  \def\headtoname{\@ensure at RTL{ژ بۆ}}%
+  \def\pagename{\@ensure at RTL{رووپەلێ}}%
+  \def\seename{\@ensure at RTL{بنێرا}}%
+  \def\alsoname{\@ensure at RTL{لە ڤێیا ژ بنێرا}}%
+  \def\proofname{\@ensure at RTL{دەلیل}}%
+  \def\glossaryname{\@ensure at RTL{چاڤکانییا لێکۆلینێ}}%
+}
+
+\def\captionskurdish{%
+  \csname captionskurdish@\kurdish at variant @\kurdish at script\endcsname%
+}
+
+\def\datekurdish at sorani@arabic{%
+   \def\today{\@ensure at RTL{\kurdishnumber\day{ی}\space\kurdishmonth{\month}{ی}\space\kurdishnumber\year}}%
+}
+
+\def\datekurdish at sorani@latin{%
+  \def\today{%
+     \number\day.~\ifcase\month\or
+      \januaryname\or \februaryname\or \marchname\or \aprilname\or
+      \mayname\or \junename\or \julyname\or \augustname\or
+      \septembername\or \octobername\or \novembername\or
+      \decembername\or \@ctrerr\fi~\number\year}%
+  \def\ontoday{%
+      \number\day’ê~\ifcase\month\or
+      \januaryname\or \februaryname\or \marchname\or \aprilname\or
+      \mayname\or \junename\or \julyname\or \augustname\or
+      \septembername\or \octobername\or \novembername\or
+      \decembername\or \@ctrerr\fi ê~\number\year}%
+  \def\januaryname{Kanûnî Yekem}%
+  \def\februaryname{Şubat}%
+  \def\marchname{Azar}%
+  \def\aprilname{Nîsan}%
+  \def\mayname{Ayar}%
+  \def\junename{Huzeyran}%
+  \def\julyname{Temmûz}%
+  \def\augustname{Ab}%
+  \def\septembername{Eylûl}%
+  \def\octobername{Tişrînî Yekem}%
+  \def\novembername{Tişrînî Dûhem}%
+  \def\decembername{Kanûnî Dûhem}%
+}
+
+\def\datekurdish at kurmanji@latin{%
+  \def\today{%
+     \number\day.~\ifcase\month\or
+      \januaryname\or \februaryname\or \marchname\or \aprilname\or
+      \mayname\or \junename\or \julyname\or \augustname\or
+      \septembername\or \octobername\or \novembername\or
+      \decembername\or \@ctrerr\fi~\number\year}%
+  \def\ontoday{%
+      \number\day’ê~\ifcase\month\or
+      \januaryname\or \februaryname\or \marchname\or \aprilname\or
+      \mayname\or \junename\or \julyname\or \augustname\or
+      \septembername\or \octobername\or \novembername\or
+      \decembername\or \@ctrerr\fi ê~\number\year}%
+  \def\januaryname{Çileya Paşîn}%
+  \def\februaryname{Sibat}%
+  \def\marchname{Adar}%
+  \def\aprilname{Nîsan}%
+  \def\mayname{Gulan}%
+  \def\junename{Hezîran}%
+  \def\julyname{Tîrmeh}%
+  \def\augustname{Tebax}%
+  \def\septembername{Îlon}%
+  \def\octobername{Çiriya Pêşîn}%
+  \def\novembername{Çiriya Paşîn}%
+  \def\decembername{Çileya Pêşîn}%
+}
+
+\def\datekurdish at kurmanji@arabic{%
+   \datekurdish at sorani@arabic% FIXME: correct?
+}
+
+% TODO: babel-kurmanji has these "alternative" month names
+% How to integrate them ("montnames=alternative" is not really good)?
+% It seems the month name question is all but straightforward:
+% https://en.wikipedia.org/wiki/Kurdish_calendar#Names
+%\def\datekurdish at kurmanji@alternate{%
+%  \datekurdish at kurmanji
+%  \def\januaryname{Rêbendan}%
+%  \def\februaryname{Reşemih}%
+%  \def\aprilname{Cotan}%           % Avrêl
+%  \def\junename{Pûşper}%
+%  \def\augustname{Gelavêj}%
+%  \def\septembername{Gelarezan}%   % Rezber
+%  \def\octobername{Kewçêr}%
+%  \def\novembername{Sermawez}%
+%  \def\decembername{Berfandar}%
+%}
+
+\def\datekurdish{%
+  \csname datekurdish@\kurdish at variant @\kurdish at script\endcsname%
+}
+
+\newcommand{\kurdishnumerals}[2]{\kurdishnumber{#2}}
+
+\def\kurdishnumber#1{%
+  \if at western@numerals
+    \number#1%
+  \else
+    \ifxetex
+      \ifnum\XeTeXcharglyph"06F0 > 0\relax
+        \farsidigits{\number#1}%
+      \else%
+         \arabicdigits{\number#1}%
+      \fi
+    \else\ifluatex
+      \expandafter\ifnum\directlua{polyglossia.check_char(0x6F0)} > 0\relax
+        \farsidigits{\number#1}%
+      \else%
+         \arabicdigits{\number#1}%
+      \fi
     \fi\fi
-    \ifnum\count@<"3260
-    \else\ifnum\count@<"3280 \advance\count at -"60
-    \else\ifnum\count@<"AC00
-    \else\ifnum\count@<"D7A4 % Hangul syllables
-        \advance\count at -"AC00
-        \@tempcnta\count@ \divide\@tempcnta28 \multiply\@tempcnta28
-        \advance\count at -\@tempcnta \advance\count@"11A7
-    \else\ifnum\count@<"FF00
-    \else\ifnum\count@<"FF5B \advance\count at -"FEE0
-    \fi\fi\fi\fi\fi \fi
-    \ifnum\count@<"11A8
-        \ifnum      "30=\count@ \count@\z@  % 0
-        \else\ifnum "31=\count@ \count@\@ne % 1
-        \else\ifnum "33=\count@ \count@\z@  % 3
-        \else\ifnum "36=\count@ \count@\z@  % 6
-        \else\ifnum "37=\count@ \count@\@ne % 7
-        \else\ifnum "38=\count@ \count@\@ne % 8
-        \else\ifnum "4C=\count@ \count@\@ne % L
-        \else\ifnum "4D=\count@ \count@\z@  % M
-        \else\ifnum "4E=\count@ \count@\z@  % N
-        \else\ifnum "6C=\count@ \count@\@ne % l
-        \else\ifnum "6D=\count@ \count@\z@  % m
-        \else\ifnum "6E=\count@ \count@\z@  % n
-        \fi\fi\fi\fi\fi \fi\fi\fi\fi\fi \fi\fi
-    \else\ifnum\count@<"1200
-        \ifnum\count@="11AF \count@\@ne \else \count@\z@ \fi
-    \else\ifnum\count@<"3131
-    \else\ifnum\count@<"318F
-        \ifnum     \count@="3139 \count@\@ne
-        \else\ifnum\count@<"314F \count@\z@
-        \else\ifnum\count@>"3164
-             \ifnum\count@<"3187 \count@\z@ \fi
-        \fi\fi\fi
-    \else\ifnum\count@<"3200
-    \else\ifnum\count@<"321F
-        \ifnum     \count@="3203 \count@\@ne
-        \else\ifnum\count@<"320E \count@\z@
-        \fi\fi
-    \else\ifnum\count@<"D7CB
-    \else\ifnum\count@<"D7FC \count@\z@
-    \fi\fi\fi\fi\fi \fi\fi\fi
-    \ifcase\count@ #2% jong
-    \or \ifx#1\empty\else#2\fi% rieul
-    \else #1% jung
-    \fi
+  \fi
 }
-\expandafter\def\expandafter\xpg at character@to at num\detokenize{the character} #1#2\relax{`#1\relax}
-\expandafter\def\expandafter\xpg at letter@to at num\detokenize{the letter} #1#2\relax{`#1\relax}
-\begingroup
-\catcode`A=11 \catcode`0=12
-\global\let\xpg at catcode@letter=A \global\let\xpg at catcode@other=0
-\endgroup
-% macros for interchartoks (Josa selection)
-\def\XPGKOstartID{\global\futurelet\XPGKO at let@josa\XPGKO at skipID}
-\def\XPGKOstartAA{\global\futurelet\XPGKO at let@josa\XPGKO at skipAA}
-\def\XPGKO at skipID{\XeTeXinterchartoks\XeTeXcharclassBoundary\XeTeXcharclassID{\empty}}
-\def\XPGKO at skipAA{\XeTeXinterchartoks\XeTeXcharclassBoundary\XPGKOcharclassAA{\empty}}
-\def\XPGKOstopID {\XeTeXinterchartoks\XeTeXcharclassBoundary\XeTeXcharclassID{\XPGKOstartID}}
-\def\XPGKOstopAA {\XeTeXinterchartoks\XeTeXcharclassBoundary\XPGKOcharclassAA{\XPGKOstartAA}}
-% macros for interchartoks (CJK punctuations)
-\def\XPGKOstartOP{\leavevmode\hbox to.5em\bgroup\hss}%
-\def\XPGKOstopOP {\egroup}%
-\def\XPGKOstartCL{\leavevmode\hbox to.5em\bgroup}%
-\def\XPGKOstopCL {\hss\egroup}%
-\let\XPGKOstartFS\XPGKOstartCL \let\XPGKOstopFS\XPGKOstopCL
-\let\XPGKOstartMD\XPGKOstartOP \let\XPGKOstopMD\XPGKOstopCL
-\let\XPGKOnobreak          \nobreak
-\def\XPGKOhalfzero         {\hskip   \XPGKOhalfdim \relax}%
-\def\XPGKOhalfhalf         {\hskip   \XPGKOhalfdim minus  \XPGKOhalfdim \relax}%
-\def\XPGKOhalfquarter      {\hskip   \XPGKOhalfdim minus.5\XPGKOhalfdim \relax}%
-\def\XPGKOquarterquarter   {\hskip .5\XPGKOhalfdim minus.5\XPGKOhalfdim \relax}%
-\def\XPGKOiiiquarterquarter{\hskip1.5\XPGKOhalfdim minus.5\XPGKOhalfdim \relax}%
-\def\XPGKOlatincjk         {\hskip .5\XPGKOhalfdim plus.25\XPGKOhalfdim minus.125\XPGKOhalfdim}%
-% user macro to force zero skip
-\let\inhibitglue\relax
-% initialize interchartoks and classes
-\ifdim\the\XeTeXversion\XeTeXrevision pt<0.99994pt
-    \let\XeTeXcharclassIgnore  \@cclvi
-    \let\XeTeXcharclassBoundary\@cclv
-\else
-    \chardef\XeTeXcharclassIgnore  =4096
-    \chardef\XeTeXcharclassBoundary=4095
-\fi
-\ifdefined\XeTeXcharclassID\else
-    \ifdefined\xtxHanGlue
-        \let\XeTeXcharclassID\@ne
-        \let\XeTeXcharclassOP\tw@
-        \let\XeTeXcharclassCL\thr@@
-    \else % email from JW
-        \newXeTeXintercharclass\XeTeXcharclassID
-        \newXeTeXintercharclass\XeTeXcharclassOP
-        \newXeTeXintercharclass\XeTeXcharclassCL
-        \global\let\XeTeXcharclassCJ\XeTeXcharclassID
-        \global\let\XeTeXcharclassEX\XeTeXcharclassCL
-        \global\let\XeTeXcharclassIS\XeTeXcharclassCL
-        \global\let\XeTeXcharclassNS\XeTeXcharclassCL
-        \global\let\XeTeXcharclassCM\XeTeXcharclassIgnore
-        \input load-unicode-xetex-classes %
-    \fi
-\fi
-% assign Hangul
-\count@="AC00 \loop
-    \XeTeXcharclass\count@\XeTeXcharclassID
-    \ifnum\count@<"D7A3
-    \advance\count@\@ne
-    \repeat
-\count@="1100 \loop
-    \XeTeXcharclass\count@\XeTeXcharclassID
-    \ifnum\count@<"11FF
-    \advance\count@\@ne
-    \repeat
-\count@="A960 \loop
-    \XeTeXcharclass\count@\XeTeXcharclassID
-    \ifnum\count@<"A97C
-    \advance\count@\@ne
-    \repeat
-\count@="D7B0 \loop
-    \XeTeXcharclass\count@\XeTeXcharclassID
-    \ifnum\count@<"D7FB
-    \advance\count@\@ne
-    \repeat
-% more classes
-\newXeTeXintercharclass\XPGKOcharclassMD % ・ : ;
-\newXeTeXintercharclass\XPGKOcharclassFS % 。 .
-\newXeTeXintercharclass\XPGKOcharclassLD % ― … ‥
-\newXeTeXintercharclass\XPGKOcharclassEX % ? !
-\newXeTeXintercharclass\XPGKOcharclassAO % ascii (
-\newXeTeXintercharclass\XPGKOcharclassAC % ascii )
-\newXeTeXintercharclass\XPGKOcharclassAA % ascii letters/numbers
-% unset all interchartoks
-\def\unsetvariantkoreaninterchartoks{%
-    \@tfor\@tmpa :=\XeTeXcharclassID\XeTeXcharclassOP\XeTeXcharclassCL\XPGKOcharclassMD\XPGKOcharclassFS
-                   \XPGKOcharclassLD\XPGKOcharclassEX\XPGKOcharclassAO\XPGKOcharclassAC\XPGKOcharclassAA
-    \do{\count@\XeTeXcharclassBoundary \loop
-            \XeTeXinterchartoks\@tmpa\count@{}%
-            \XeTeXinterchartoks\count@\@tmpa{}%
-            \ifnum\count@=\XeTeXcharclassBoundary \count@\m at ne \fi
-            \ifnum\count@<\xe at alloc@intercharclass
-            \advance\count@\@ne
-            \repeat
-    }%
+
+%\def\kurdishnum#1{\expandafter\kurdishnumber\csname c@#1\endcsname}
+%\def\kurdishbracenum#1{(\expandafter\kurdishnumber\csname c@#1\endcsname)}
+%\def\kurdishornatebracenum#1{\char"FD3E\expandafter\kurdishnumber\csname c@#1\endcsname\char"FD3F}
+%\def\kurdishalph#1{\expandafter\@farsialph\csname c@#1\endcsname}
+
+\def\kurdish at numbers{%
+  \if at western@numerals%
+  \else%
+     \let\@alph\abjad%
+     \let\@Alph\abjad%
+  \fi%
 }
-% interchartoks for classic/modern variants
-\def\setvariantkoreaninterchartoks{%
-    \count@\XeTeXcharclassBoundary \loop
-        \ifnum\count@=\XeTeXcharclassID\else
-        \ifnum\count@=\XeTeXcharclassOP\else
-        \ifnum\count@=\XeTeXcharclassCL\else
-        \ifnum\count@=\XPGKOcharclassMD\else
-        \ifnum\count@=\XPGKOcharclassFS\else
-        \ifnum\count@=\XPGKOcharclassAA\else
-            \XeTeXinterchartoks\count@\XeTeXcharclassID{\XPGKOstartID}%
-            \XeTeXinterchartoks\count@\XeTeXcharclassOP{\XPGKOstartOP}%
-            \XeTeXinterchartoks\count@\XeTeXcharclassCL{\XPGKOstartCL}%
-            \XeTeXinterchartoks\count@\XPGKOcharclassMD{\XPGKOstartMD}%
-            \XeTeXinterchartoks\count@\XPGKOcharclassFS{\XPGKOstartFS}%
-            \XeTeXinterchartoks\count@\XPGKOcharclassAA{\XPGKOstartAA}%
-            \XeTeXinterchartoks\XeTeXcharclassID\count@{\XPGKOstopID}%
-            \XeTeXinterchartoks\XeTeXcharclassOP\count@{\XPGKOstopOP}%
-            \XeTeXinterchartoks\XeTeXcharclassCL\count@{\XPGKOstopCL}%
-            \XeTeXinterchartoks\XPGKOcharclassMD\count@{\XPGKOstopMD}%
-            \XeTeXinterchartoks\XPGKOcharclassFS\count@{\XPGKOstopFS}%
-            \XeTeXinterchartoks\XPGKOcharclassAA\count@{\XPGKOstopAA}%
-        \fi\fi\fi\fi\fi\fi
-        \ifnum\count@=\XeTeXcharclassBoundary \count@\m at ne \fi
-        \ifnum\count@<\xe at alloc@intercharclass
-        \advance\count@\@ne
-        \repeat
-    %
-    \XeTeXinterchartoks\XPGKOcharclassAA\XeTeXcharclassID{\XPGKOstopAA\XPGKOlatincjk\XPGKOstartID}%
-    \XeTeXinterchartoks\XPGKOcharclassAA\XeTeXcharclassOP{\XPGKOstopAA\XPGKOhalfhalf\XPGKOstartOP}%
-    \XeTeXinterchartoks\XPGKOcharclassAA\XeTeXcharclassCL{\XPGKOstopAA\XPGKOstartCL}%
-    \XeTeXinterchartoks\XPGKOcharclassAA\XPGKOcharclassMD{\XPGKOstopAA\XPGKOnobreak\XPGKOquarterquarter\XPGKOstartMD}%
-    \XeTeXinterchartoks\XPGKOcharclassAA\XPGKOcharclassFS{\XPGKOstopAA\XPGKOstartFS}%
-    \XeTeXinterchartoks\XPGKOcharclassAA\XPGKOcharclassAA{\XPGKOstartAA}%
-    %
-    \XeTeXinterchartoks\XeTeXcharclassID\XeTeXcharclassID{\XPGKOstartID}%
-    \XeTeXinterchartoks\XeTeXcharclassID\XeTeXcharclassOP{\XPGKOstopID\XPGKOhalfhalf\XPGKOstartOP}%
-    \XeTeXinterchartoks\XeTeXcharclassID\XeTeXcharclassCL{\XPGKOstopID\XPGKOstartCL}%
-    \XeTeXinterchartoks\XeTeXcharclassID\XPGKOcharclassMD{\XPGKOstopID\XPGKOnobreak\XPGKOquarterquarter\XPGKOstartMD}%
-    \XeTeXinterchartoks\XeTeXcharclassID\XPGKOcharclassFS{\XPGKOstopID\XPGKOstartFS}%
-    \XeTeXinterchartoks\XeTeXcharclassID\XPGKOcharclassAO{\XPGKOstopID\XPGKOlatincjk}%
-    \XeTeXinterchartoks\XeTeXcharclassID\XPGKOcharclassAA{\XPGKOstopID\XPGKOlatincjk\XPGKOstartAA}%
-    %
-    \XeTeXinterchartoks\XeTeXcharclassOP\XeTeXcharclassID{\XPGKOstopOP\XPGKOstartID}%
-    \XeTeXinterchartoks\XeTeXcharclassOP\XeTeXcharclassOP{\XPGKOstopOP\XPGKOstartOP}%
-    \XeTeXinterchartoks\XeTeXcharclassOP\XeTeXcharclassCL{\XPGKOstopOP\XPGKOstartCL}%
-    \XeTeXinterchartoks\XeTeXcharclassOP\XPGKOcharclassMD{\XPGKOstopOP\XPGKOnobreak\XPGKOquarterquarter\XPGKOstartMD}%
-    \XeTeXinterchartoks\XeTeXcharclassOP\XPGKOcharclassFS{\XPGKOstopOP\XPGKOstartFS}%
-    \XeTeXinterchartoks\XeTeXcharclassOP\XPGKOcharclassAA{\XPGKOstopOP\XPGKOstartAA}%
-    %
-    \XeTeXinterchartoks\XeTeXcharclassCL\XeTeXcharclassID{\XPGKOstopCL\XPGKOhalfhalf\XPGKOstartID}%
-    \XeTeXinterchartoks\XeTeXcharclassCL\XeTeXcharclassOP{\XPGKOstopCL\XPGKOhalfhalf\XPGKOstartOP}%
-    \XeTeXinterchartoks\XeTeXcharclassCL\XeTeXcharclassCL{\XPGKOstopCL\XPGKOstartCL}%
-    \XeTeXinterchartoks\XeTeXcharclassCL\XPGKOcharclassMD{\XPGKOstopCL\XPGKOnobreak\XPGKOquarterquarter\XPGKOstartMD}%
-    \XeTeXinterchartoks\XeTeXcharclassCL\XPGKOcharclassFS{\XPGKOstopCL\XPGKOstartFS}%
-    \XeTeXinterchartoks\XeTeXcharclassCL\XPGKOcharclassLD{\XPGKOstopCL\XPGKOnobreak\XPGKOhalfhalf}%
-    \XeTeXinterchartoks\XeTeXcharclassCL\XPGKOcharclassEX{\XPGKOstopCL\XPGKOnobreak\XPGKOhalfhalf}%
-    \XeTeXinterchartoks\XeTeXcharclassCL\XPGKOcharclassAO{\XPGKOstopCL\XPGKOhalfhalf}%
-    \XeTeXinterchartoks\XeTeXcharclassCL\XPGKOcharclassAC{\XPGKOstopCL\XPGKOnobreak\XPGKOhalfhalf}%
-    \XeTeXinterchartoks\XeTeXcharclassCL\XPGKOcharclassAA{\XPGKOstopCL\XPGKOhalfhalf\XPGKOstartAA}%
-    %
-    \XeTeXinterchartoks\XPGKOcharclassMD\XeTeXcharclassID{\XPGKOstopMD\XPGKOquarterquarter\XPGKOstartID}%
-    \XeTeXinterchartoks\XPGKOcharclassMD\XeTeXcharclassOP{\XPGKOstopMD\XPGKOquarterquarter\XPGKOstartOP}%
-    \XeTeXinterchartoks\XPGKOcharclassMD\XeTeXcharclassCL{\XPGKOstopMD\XPGKOnobreak\XPGKOquarterquarter\XPGKOstartCL}%
-    \XeTeXinterchartoks\XPGKOcharclassMD\XPGKOcharclassMD{\XPGKOstopMD\XPGKOnobreak\XPGKOhalfquarter\XPGKOstartMD}%
-    \XeTeXinterchartoks\XPGKOcharclassMD\XPGKOcharclassFS{\XPGKOstopMD\XPGKOnobreak\XPGKOquarterquarter\XPGKOstartFS}%
-    \XeTeXinterchartoks\XPGKOcharclassMD\XPGKOcharclassLD{\XPGKOstopMD\XPGKOnobreak\XPGKOquarterquarter}%
-    \XeTeXinterchartoks\XPGKOcharclassMD\XPGKOcharclassEX{\XPGKOstopMD\XPGKOnobreak\XPGKOquarterquarter}%
-    \XeTeXinterchartoks\XPGKOcharclassMD\XPGKOcharclassAO{\XPGKOstopMD\XPGKOquarterquarter}%
-    \XeTeXinterchartoks\XPGKOcharclassMD\XPGKOcharclassAC{\XPGKOstopMD\XPGKOnobreak\XPGKOquarterquarter}%
-    \XeTeXinterchartoks\XPGKOcharclassMD\XPGKOcharclassAA{\XPGKOstopMD\XPGKOquarterquarter\XPGKOstartAA}%
-    %
-    \XeTeXinterchartoks\XPGKOcharclassFS\XeTeXcharclassID{\XPGKOstopFS\XPGKOhalfzero\XPGKOstartID}%
-    \XeTeXinterchartoks\XPGKOcharclassFS\XeTeXcharclassOP{\XPGKOstopFS\XPGKOhalfzero\XPGKOstartOP}%
-    \XeTeXinterchartoks\XPGKOcharclassFS\XeTeXcharclassCL{\XPGKOstopFS\XPGKOstartCL}%
-    \XeTeXinterchartoks\XPGKOcharclassFS\XPGKOcharclassMD{\XPGKOstopFS\XPGKOnobreak\XPGKOiiiquarterquarter\XPGKOstartMD}%
-    \XeTeXinterchartoks\XPGKOcharclassFS\XPGKOcharclassFS{\XPGKOstopFS\XPGKOstartFS}%
-    \XeTeXinterchartoks\XPGKOcharclassFS\XPGKOcharclassLD{\XPGKOstopFS\XPGKOnobreak\XPGKOhalfzero}%
-    \XeTeXinterchartoks\XPGKOcharclassFS\XPGKOcharclassEX{\XPGKOstopFS\XPGKOnobreak\XPGKOhalfzero}%
-    \XeTeXinterchartoks\XPGKOcharclassFS\XPGKOcharclassAO{\XPGKOstopFS\XPGKOhalfzero}%
-    \XeTeXinterchartoks\XPGKOcharclassFS\XPGKOcharclassAC{\XPGKOstopFS\XPGKOnobreak\XPGKOhalfzero}%
-    \XeTeXinterchartoks\XPGKOcharclassFS\XPGKOcharclassAA{\XPGKOstopFS\XPGKOhalfzero\XPGKOstartAA}%
-    %
-    \XeTeXinterchartoks\XPGKOcharclassLD\XeTeXcharclassOP{\XPGKOhalfhalf\XPGKOstartOP}%
-    \XeTeXinterchartoks\XPGKOcharclassLD\XPGKOcharclassMD{\XPGKOnobreak\XPGKOquarterquarter\XPGKOstartMD}%
-    %
-    \XeTeXinterchartoks\XPGKOcharclassEX\XeTeXcharclassID{\XPGKOhalfhalf\XPGKOstartID}%
-    \XeTeXinterchartoks\XPGKOcharclassEX\XeTeXcharclassOP{\XPGKOhalfhalf\XPGKOstartOP}%
-    \XeTeXinterchartoks\XPGKOcharclassEX\XPGKOcharclassMD{\XPGKOnobreak\XPGKOquarterquarter\XPGKOstartMD}%
-    \XeTeXinterchartoks\XPGKOcharclassEX\XPGKOcharclassAO{\XPGKOhalfhalf}%
-    \XeTeXinterchartoks\XPGKOcharclassEX\XPGKOcharclassAC{\XPGKOnobreak\XPGKOhalfhalf}%
-    \XeTeXinterchartoks\XPGKOcharclassEX\XPGKOcharclassAA{\XPGKOhalfhalf\XPGKOstartAA}%
-    %
-    \XeTeXinterchartoks\XPGKOcharclassAO\XeTeXcharclassOP{\XPGKOnobreak\XPGKOhalfhalf\XPGKOstartOP}%
-    \XeTeXinterchartoks\XPGKOcharclassAO\XPGKOcharclassMD{\XPGKOnobreak\XPGKOquarterquarter\XPGKOstartMD}%
-    %
-    \XeTeXinterchartoks\XPGKOcharclassAC\XeTeXcharclassID{\XPGKOlatincjk\XPGKOstartID}%
-    \XeTeXinterchartoks\XPGKOcharclassAC\XeTeXcharclassOP{\XPGKOhalfhalf\XPGKOstartOP}%
-    \XeTeXinterchartoks\XPGKOcharclassAC\XPGKOcharclassMD{\XPGKOnobreak\XPGKOquarterquarter\XPGKOstartMD}%
+
+\def\nokurdish at numbers{%
+  \let\@alph\@latinalph%
+  \let\@Alph\@latinAlph%
 }
-% char classes for classic/modern variants
-\def\setvariantkoreancharclasses{}
-\def\unsetvariantkoreancharclasses{}
-\def\@tmpa#1=#2{%
-    \edef\setvariantkoreancharclasses{%
-        \unexpanded\expandafter{\setvariantkoreancharclasses
-            \XeTeXcharclass#1=#2}}%
-    \edef\unsetvariantkoreancharclasses{%
-        \noexpand\XeTeXcharclass#1=\the\XeTeXcharclass#1\relax
-        \unexpanded\expandafter{\unsetvariantkoreancharclasses}}%
+
+\def\kurdish at globalnumbers{%
+   \let\@arabic\kurdishnumber%
+   \renewcommand\thefootnote{\localnumeral*{footnote}}%
+   \renewcommand\theequation{\localnumeral*{equation}}%
 }
-\count@"30 \loop % 0 .. 9
-    \expandafter\@tmpa\the\count@=\XPGKOcharclassAA
-    \ifnum\count@<"39
-    \advance\count@\@ne
-    \repeat
-\count@"41 \loop % A .. Z
-    \expandafter\@tmpa\the\count@=\XPGKOcharclassAA
-    \ifnum\count@<"5A
-    \advance\count@\@ne
-    \repeat
-\count@"61 \loop % a .. z
-    \expandafter\@tmpa\the\count@=\XPGKOcharclassAA
-    \ifnum\count@<"7A
-    \advance\count@\@ne
-    \repeat
-% NS
-\@tmpa "3005=\XeTeXcharclassID % 々 IDEOGRAPHIC ITERATION MARK
-\@tmpa "301C=\XeTeXcharclassID % 〜 WAVE DASH
-\@tmpa "303B=\XeTeXcharclassID % 〻 VERTICAL IDEOGRAPHIC ITERATION MARK
-\@tmpa "303C=\XeTeXcharclassID % 〼 MASU MARK
-\@tmpa "309B=\XeTeXcharclassID % ゛ KATAKANA-HIRAGANA VOICED SOUND MARK
-\@tmpa "309C=\XeTeXcharclassID % ゜ KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
-\@tmpa "309D=\XeTeXcharclassID % ゝ HIRAGANA ITERATION MARK
-\@tmpa "309E=\XeTeXcharclassID % ゞ HIRAGANA VOICED ITERATION MARK
-\@tmpa "30A0=\XeTeXcharclassID % ゠ KATAKANA-HIRAGANA DOUBLE HYPHEN
-\@tmpa "30FD=\XeTeXcharclassID % ヽ KATAKANA ITERATION MARK
-\@tmpa "30FE=\XeTeXcharclassID % ヾ KATAKANA VOICED ITERATION MARK
-\@tmpa "A015=\XeTeXcharclassID % ꀕ YI SYLLABLE ITERATION MARK
-\@tmpa "FF9E=\XeTeXcharclassID % ゙ HALFWIDTH KATAKANA VOICED SOUND MARK
-\@tmpa "FF9F=\XeTeXcharclassID % ゚ HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK
-% IS
-\@tmpa "FE13=\XeTeXcharclassID % ︓ PRESENTATION FORM FOR VERTICAL COLON
-\@tmpa "FE14=\XeTeXcharclassID % ︔ PRESENTATION FORM FOR VERTICAL SEMICOLON
-% CJ
-\ifnum\the\XeTeXcharclass"3041=\XeTeXcharclassID \else
-    \@tmpa "3041=\XeTeXcharclassID % ぁ HIRAGANA LETTER SMALL A
-    \@tmpa "3043=\XeTeXcharclassID % ぃ HIRAGANA LETTER SMALL I
-    \@tmpa "3045=\XeTeXcharclassID % ぅ HIRAGANA LETTER SMALL U
-    \@tmpa "3047=\XeTeXcharclassID % ぇ HIRAGANA LETTER SMALL E
-    \@tmpa "3049=\XeTeXcharclassID % ぉ HIRAGANA LETTER SMALL O
-    \@tmpa "3063=\XeTeXcharclassID % っ HIRAGANA LETTER SMALL TU
-    \@tmpa "3083=\XeTeXcharclassID % ゃ HIRAGANA LETTER SMALL YA
-    \@tmpa "3085=\XeTeXcharclassID % ゅ HIRAGANA LETTER SMALL YU
-    \@tmpa "3087=\XeTeXcharclassID % ょ HIRAGANA LETTER SMALL YO
-    \@tmpa "308E=\XeTeXcharclassID % ゎ HIRAGANA LETTER SMALL WA
-    \@tmpa "3095=\XeTeXcharclassID % ゕ HIRAGANA LETTER SMALL KA
-    \@tmpa "3096=\XeTeXcharclassID % ゖ HIRAGANA LETTER SMALL KE
-    \@tmpa "30A1=\XeTeXcharclassID % ァ KATAKANA LETTER SMALL A
-    \@tmpa "30A3=\XeTeXcharclassID % ィ KATAKANA LETTER SMALL I
-    \@tmpa "30A5=\XeTeXcharclassID % ゥ KATAKANA LETTER SMALL U
-    \@tmpa "30A7=\XeTeXcharclassID % ェ KATAKANA LETTER SMALL E
-    \@tmpa "30A9=\XeTeXcharclassID % ォ KATAKANA LETTER SMALL O
-    \@tmpa "30C3=\XeTeXcharclassID % ッ KATAKANA LETTER SMALL TU
-    \@tmpa "30E3=\XeTeXcharclassID % ャ KATAKANA LETTER SMALL YA
-    \@tmpa "30E5=\XeTeXcharclassID % ュ KATAKANA LETTER SMALL YU
-    \@tmpa "30E7=\XeTeXcharclassID % ョ KATAKANA LETTER SMALL YO
-    \@tmpa "30EE=\XeTeXcharclassID % ヮ KATAKANA LETTER SMALL WA
-    \@tmpa "30F5=\XeTeXcharclassID % ヵ KATAKANA LETTER SMALL KA
-    \@tmpa "30F6=\XeTeXcharclassID % ヶ KATAKANA LETTER SMALL KE
-    \@tmpa "30FC=\XeTeXcharclassID % ー KATAKANA-HIRAGANA PROLONGED SOUND MARK
-    \count@"31F0 \loop
-        \expandafter\@tmpa\the\count@=\XeTeXcharclassID
-        \ifnum\count@<"31FF
-        \advance\count@\@ne
-        \repeat
-    \count@"FF67 \loop
-        \expandafter\@tmpa\the\count@=\XeTeXcharclassID
-        \ifnum\count@<"FF70
-        \advance\count@\@ne
-        \repeat
-\fi
-%
-\@tmpa "28=\XPGKOcharclassAO % ( LEFT PARENTHESIS
-\@tmpa "5B=\XPGKOcharclassAO % [ LEFT SQUARE BRACKET
-\@tmpa "60=\XPGKOcharclassAO % ` GRAVE ACCENT
-\@tmpa "7B=\XPGKOcharclassAO % { LEFT CURLY BRACKET
-\@tmpa "AB=\XPGKOcharclassAO % « LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
-%
-\@tmpa "21=\XPGKOcharclassAC % ! EXCLAMATION MARK
-\@tmpa "27=\XPGKOcharclassAC % ' APOSTROPHE
-\@tmpa "29=\XPGKOcharclassAC % ) RIGHT PARENTHESIS
-\@tmpa "2C=\XPGKOcharclassAC % , COMMA
-\@tmpa "2E=\XPGKOcharclassAC % . FULL STOP
-\@tmpa "3B=\XPGKOcharclassAC % ; SEMICOLON
-\@tmpa "3F=\XPGKOcharclassAC % ? QUESTION MARK
-\@tmpa "5D=\XPGKOcharclassAC % ] RIGHT SQUARE BRACKET
-\@tmpa "7D=\XPGKOcharclassAC % } RIGHT CURLY BRACKET
-\@tmpa "BB=\XPGKOcharclassAC % » RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
-%
-\@tmpa "2018=\XeTeXcharclassOP % ‘ LEFT SINGLE QUOTATION MARK
-\@tmpa "201C=\XeTeXcharclassOP % “ LEFT DOUBLE QUOTATION MARK
-%
-\@tmpa "2019=\XeTeXcharclassCL % ’ RIGHT SINGLE QUOTATION MARK
-\@tmpa "201D=\XeTeXcharclassCL % ” RIGHT DOUBLE QUOTATION MARK
-% NS
-\@tmpa "00B7=\XPGKOcharclassMD % · MIDDLE DOT
-\@tmpa "30FB=\XPGKOcharclassMD % ・ KATAKANA MIDDLE DOT
-\@tmpa "FE54=\XPGKOcharclassMD % ﹔ SMALL SEMICOLON
-\@tmpa "FE55=\XPGKOcharclassMD % ﹕ SMALL COLON
-\@tmpa "FF1A=\XPGKOcharclassMD % : FULLWIDTH COLON
-\@tmpa "FF1B=\XPGKOcharclassMD % ; FULLWIDTH SEMICOLON
-\@tmpa "FF65=\XPGKOcharclassMD % ・ HALFWIDTH KATAKANA MIDDLE DOT
-%
-\@tmpa "3002=\XPGKOcharclassFS % 。 IDEOGRAPHIC FULL STOP
-\@tmpa "FE12=\XPGKOcharclassFS % ︒ PRESENTATION FORM FOR VERTICAL IDEOGRAPHIC FULL STOP
-\@tmpa "FE52=\XPGKOcharclassFS % ﹒ SMALL FULL STOP
-\@tmpa "FF0E=\XPGKOcharclassFS % . FULLWIDTH FULL STOP
-\@tmpa "FF61=\XPGKOcharclassFS % 。 HALFWIDTH IDEOGRAPHIC FULL STOP
-%
-\@tmpa "2014=\XPGKOcharclassLD % — EM DASH
-\@tmpa "2015=\XPGKOcharclassLD % ― HORIZONTAL BAR
-\@tmpa "2025=\XPGKOcharclassLD % ‥ TWO DOT LEADER
-\@tmpa "2026=\XPGKOcharclassLD % … HORIZONTAL ELLIPSIS
-% EX
-\@tmpa "FE15=\XPGKOcharclassEX % ︕ PRESENTATION FORM FOR VERTICAL EXCLAMATION MARK
-\@tmpa "FE16=\XPGKOcharclassEX % ︖ PRESENTATION FORM FOR VERTICAL QUESTION MARK
-\@tmpa "FE56=\XPGKOcharclassEX % ﹖ SMALL QUESTION MARK
-\@tmpa "FE57=\XPGKOcharclassEX % ﹗ SMALL EXCLAMATION MARK
-\@tmpa "FF01=\XPGKOcharclassEX % ! FULLWIDTH EXCLAMATION MARK
-\@tmpa "FF1F=\XPGKOcharclassEX % ? FULLWIDTH QUESTION MARK
 
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
+\def\nokurdish at globalnumbers{
+   \let\@arabic\xpg at save@arabic%
+   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
+}
+
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
+\def\blockextras at kurdish{%
+   \def\MakeUppercase##1{##1}%
+}
+
+\def\noextras at kurdish{%
+   \let\MakeUppercase\xpg at save@MakeUppercase%
+}
+
 %    \end{macrocode}
 % \iffalse
-%</gloss-korean.ldf>
+%</gloss-kurdish.ldf>
 %<*gloss-lao.ldf>
 % \fi
 % \clearpage
@@ -5811,9 +6828,11 @@
 \PolyglossiaSetup{lao}{
   script=Lao,
   scripttag=lao,
+  langtag=LAO,
   hyphennames={lao},
   hyphenmins={1,1},
   fontsetup=true,
+  localnumeral=laonumerals
   %TODO localalph={xxx at alph,xxx at Alph}
   %TODO localdigits=laonumber
 }
@@ -5879,6 +6898,8 @@
   \fi
 }
 
+\newcommand{\laonumerals}[2]{\laonumber{#2}}
+
 \def\laonumber#1{%
   \if at lao@numerals
     \laodigits{\number#1}%
@@ -5889,16 +6910,56 @@
 \def\lao at globalnumbers{%
    \let\orig at arabic\@arabic%
    \let\@arabic\laonumber%
-   \renewcommand{\thefootnote}{\protect\laonumber{\c at footnote}}%
+   \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
 }
 \def\nolao at globalnumbers{%
    \let\@arabic\orig at arabic%
-   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
 }
 
 %    \end{macrocode}
 % \iffalse
 %</gloss-lao.ldf>
+%<*gloss-latex.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-latex.ldf}
+%    \begin{macrocode}
+\ProvidesFile{gloss-latex.ldf}[polyglossia: module for default language]
+
+\PolyglossiaSetup{latex}{
+  hyphennames={english},
+  hyphenmins={2,3},
+  langtag=ENG,
+  fontsetup=true,
+}
+
+\def\captionslatex{%
+   \def\prefacename{Preface}%
+   \def\refname{References}%
+   \def\abstractname{Abstract}%
+   \def\bibname{Bibliography}%
+   \def\chaptername{Chapter}%
+   \def\appendixname{Appendix}%
+   \def\contentsname{Contents}%
+   \def\listfigurename{List of Figures}%
+   \def\listtablename{List of Tables}%
+   \def\indexname{Index}%
+   \def\figurename{Figure}%
+   \def\tablename{Table}%
+   \def\partname{Part}%
+   \def\enclname{encl}%
+   \def\ccname{cc}%
+   \def\headtoname{To}%
+   \def\pagename{Page}%
+   \def\seename{see}%
+   \def\alsoname{see also}%
+   \def\proofname{Proof}%
+}
+
+%    \end{macrocode}
+% \iffalse
+%</gloss-latex.ldf>
 %<*gloss-latin.ldf>
 % \fi
 % \clearpage
@@ -5928,6 +6989,7 @@
 \PolyglossiaSetup{latin}{%
       hyphennames={latin},
       hyphenmins={2,2},
+      langtag=LAT,
       frenchspacing=true,
       fontsetup=true,
 }
@@ -5958,7 +7020,6 @@
   \let\latin at variant\l at latin
   \xpg at set@language at luatex@ii{latin}
   \medievaltrue \classictrue
-  \classicuclccodes
   \xpg at info{Option: Medieval Latin}%
 \else
   \ifx\@tempa\tmp at classic
@@ -5971,7 +7032,7 @@
          \let\latin at variant\l at classiclatin
       \fi
     \fi
-    \medievalfalse\classictrue\classicuclccodes
+    \medievalfalse\classictrue
     \xpg at info{Option: Classic Latin}%
   \else
    \ifx\@tempa\tmp at liturgical\unless\ifluatex
@@ -6181,6 +7242,7 @@
    \lccode\string"2019=\string"2019
    \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000
    \finalhyphendemerits=50000000
+   \ifclassic\classicuclccodes\fi
    \iflatin at babelshorthands\latin at shorthands\fi
    \iflatin at ecclesiastic\unless\ifluatex\ecclesiasticlatin at punctuation
    \let\@makefntext\latin at ecclesiastic@makefntext\fi
@@ -6189,6 +7251,7 @@
 
 \def\inlineextras at latin{%
    \lccode\string"2019=\string"2019
+   \ifclassic\classicuclccodes\fi
    \iflatin at babelshorthands\latin at shorthands\fi
    \iflatin at ecclesiastic
       \unless\ifluatex\ecclesiasticlatin at punctuation
@@ -6231,6 +7294,7 @@
 \PolyglossiaSetup{latvian}{
   hyphennames={latvian},
   hyphenmins={2,2},
+  langtag=LVI,
   fontsetup=true,
 }
 
@@ -6281,15 +7345,17 @@
 \PolyglossiaSetup{lithuanian}{
   hyphennames={lithuanian},
   hyphenmins={2,2},
+  langtag=LTH,
+  indentfirst=true, % TODO Dokumentų rengimo taisyklių, patvirtintų Lietuvos vyriausiojo archyvaro 2011 m. liepos 4 d. įsakymu Nr. V-117, 29.1 punktą
   fontsetup=true
 }
 
 \def\captionslithuanian{%
+   \def\prefacename{Pratarmė}%
    \def\refname{Literatūra}%
    \def\abstractname{Santrauka}%
    \def\bibname{Literatūra}%
-   \def\prefacename{Pratarmė}%
-   \def\chaptername{Skyrius}%
+   \def\chaptername{Skyrius}% TODO letter case
    \def\appendixname{Priedas}%
    \def\contentsname{Turinys}%
    \def\listfigurename{Iliustracijų sąrašas}%
@@ -6296,16 +7362,16 @@
    \def\listtablename{Lentelių sąrašas}%
    \def\indexname{Rodyklė}%
    \def\figurename{pav.}%
-   \def\tablename{lentelė}%
+   \def\tablename{lentelė}% TODO any special reason for \protect in babel?
    \def\partname{Dalis}%
+   \def\enclname{Įdėta}%
+   \def\ccname{Kopijos}%
+   \def\headtoname{Kam}% TODO empty in babel?
    \def\pagename{puslapis}%
    \def\seename{žiūrėk}%
-   \def\alsoname{taip pat}%
-   \def\enclname{Įdėta}%
-   \def\ccname{Kopijos}%
-   \def\headtoname{Kam}%
+   \def\alsoname{taip pat}% TODO some other variants are considered in babel?
    \def\proofname{Įrodymas}%
-   \def\glossaryname{Terminų žodynas}%
+   \def\glossaryname{Terminų žodynas}% TODO some other variants are considered in babel?
 }
 
 \def\datelithuanian{%
@@ -6340,249 +7406,30 @@
 %    \end{macrocode}
 % \iffalse
 %</gloss-lithuanian.ldf>
-%<*gloss-liturgicallatin.ldf>
+%<*gloss-lsorbian.ldf>
 % \fi
 % \clearpage
 % 
-% \subsection{gloss-liturgicallatin.ldf}
+% \subsection{gloss-lsorbian.ldf}
 %    \begin{macrocode}
-%%
-%% This is file `gloss-liturgicallatin.ldf',
-%% generated with the docstrip utility.
-%%
-%% The original source files were:
-%%
-%% gloss-latin.dtx  (with options: `laliturgic')
-%%   ------------------------------------------------------------------
-%%   Latin module for polyglossia
-%%   Copyright (C) Claudio Beccari 2013-2016
-%%   Copyright (C) Élie Roux 2016
-%%   This work is distributed under the MIT License.
-%% 
-%%   See the postamble.
-%%   ------------------------------------------------------------------
-\ProvidesFile{gloss-liturgiclatin.ldf}
-        [2016/09/10 v.1.03 Latin support from polyglossia]
-%%
+\ProvidesFile{gloss-lsorbian.ldf}[polyglossia: module for lower sorbian]
 
+% We only provide this gloss for babel compatibility. Since lsorbian is 
+% a sorbian variety, we use 'sorbian' with variant 'lower' now.
 
-\PolyglossiaSetup{liturgicallatin}{%
-      hyphennames={liturgicallatin},
-      hyphenmins={2,2},
-      frenchspacing=true,
-      fontsetup=true,
-}
-\def\liturgicallatincaptions{%
-   \def\prefacename{Præfatio}%
-   \def\refname{Conspectus librorum}%
-   \def\abstractname{Summarium}%
-   \def\bibname{Conspectus librorum}%
-   \def\chaptername{Caput}%
-   \def\appendixname{Additamentum}%
-   \def\contentsname{Index}%
-   \def\listfigurename{Conspectus descriptionum}%
-   \def\listtablename{Conspectus tabularum}%
-   \def\indexname{Index rerum notabilium}%
-   \def\figurename{Descriptio}%
-   \def\tablename{Tabula}%
-   \def\partname{Pars}%
-   \def\enclname{Additur}%
-   \def\ccname{Exemplar}%
-   \def\headtoname{\ignorespaces}%
-   \def\pagename{charta}%
-   \def\seename{cfr.}%
-   \def\alsoname{cfr.}%
-   \def\proofname{Demonstratio}%
-   \def\glossaryname{Glossarium}%
-   }
+\input{gloss-sorbian.ldf}
 
-\def\liturgicallatindate{%
-   \def\today{\uppercase\expandafter{\romannumeral\day}%
-      \space \ifcase\month%
-      \or Januarii\or Februarii\or Martii\or Aprilis\or Maji\or Junii\or%
-      Julii\or Augusti\or Septembris\or Octobris\or Novembris\or%
-      Decembris\fi%
-      \space \uppercase\expandafter{\romannumeral\year}}}
-
-\define at boolkey{liturgicallatin}[liturgicallatin@]{babelshorthands}[true]{}
-
-\ifsystem at babelshorthands
-  \setkeys{liturgicallatin}{babelshorthands=true}
-\else
-  \setkeys{liturgicallatin}{babelshorthands=false}
-\fi
-
-\ifcsundef{initiate at active@char}{%
-    \input{babelsh.def}%
-    \initiate at active@char{"}%
-    \initiate at active@char{'}%
-}{}
-
-\def\liturgicallatin at shorthands{%
-  \def\language at group{liturgicallatin}%
-  \bbl at activate{"}%
-  \declare at shorthand{liturgicallatin}{"}{\relax
-    \ifmmode
-      \def\xpglla at next{''}%
-    \else
-      \def\xpglla at nextdq{\futurelet\xpglla at temp\xpglla at cwm}%
-    \fi
-  \xpglla at nextdq}%
-  \bbl at activate{'}%
-  \declare at shorthand{liturgicallatin}{'}{\relax
-    \ifmmode
-      \def\xpglla at nextsq{'}%
-    \else
-      \def\xpglla at nextsq{\futurelet\temp at A\xpglla at putacute}%
-    \fi
-  \xpgla at nextsq}%
-}
-
-\def\xpglla at allowhyphens{\bbl at allowhyphens
-     \discretionary{-}{}{}\bbl at allowhyphens}
-
-\newcommand*{\xpglla at cwm}{\let\xpglla@@nextdq\relax
-  \ifcat\noexpand\xpglla at temp a%
-    \let\xpglla@@nextdq\xpglla at allowhyphens
-  \else
-    \ifx\xpglla at temp\ae
-        \let\xpglla@@nextdq\xpglla at allowhyphens
-    \else
-        \ifx\xpglla at temp\oe
-           \let\xpglla@@nextdq\xpglla at allowhyphens
-        \else
-           \if\noexpand\xpglla at temp\string|%
-              \def\xpglla@@nextdq{\xpglla at allowhyphens\@gobble}%
-           \fi
-        \fi
-    \fi
-  \fi
-  \xpglla@@nextdq}%
-
-\def\xpglla at putacute#1{\let\xpglla at nextsq\relax%
-\if a\xpglla at temp@A
-  æ\kern-0.175em^^^^0301\kern0.175em\xpglla at allowhyphens
-\else
-\if o\xpglla at temp@A
-  œ\kern-0.175em^^^^0301\kern0.175em\xpglla at allowhyphens
-\else
-  \if æ\xpglla at temp@A
-    æ^^^^0301%
-  \else
-    \if œ\xpglla at temp@A
-      œ^^^^0301%
-    \else
-      \string'%
-    \fi
-  \fi
-\fi
-\fi}%
-\def\noliturgicallatin at shorthands{%
-  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{"}}%
-  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{'}}%
-}
-
-\let\xpglla at savedvalues\empty
-\AtEndPreamble{%
-  \edef\xpglla at savedvalues{%
-    \clubpenalty=\the\clubpenalty\space
-    \@clubpenalty=\the\@clubpenalty\space
-    \widowpenalty=\the\widowpenalty\space
-    \finalhyphendemerits=\the\finalhyphendemerits}%
-}
-
-\def\noextras at liturgicallatin{%
-   \lccode\string"2019=\z@
-   \noliturgicallatin at shorthands
-   \xpglla at savedvalues
-}
-
-\def\blockextras at liturgicallatin{%
-   \lccode\string"2019=\string"2019
-   \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000
-   \finalhyphendemerits=50000000
-   \ifliturgicallatin at babelshorthands\liturgicallatin at shorthands\fi
-}
-
-\def\inlineextras at liturgicallatin{%
-   \lccode\string"2019=\string"2019
-   \ifliturgicallatin at babelshorthands\liturgicallatin at shorthands\fi
-}
-%%   Copyright (C) Claudio Beccari 2013-2016
-%%   Copyright (C) Élie Roux 2016
-%% 
-%%   Permission is hereby granted, free of charge, to any person obtaining
-%%   a copy of this software and associated documentation files
-%%   (the "Software"), to deal in the Software without restriction, including
-%%   without limitation the rights to use, copy, modify, merge, publish,
-%%   distribute, sublicense, and/or sell copies of the Software, and to permit
-%%   persons to whom the Software is furnished to do so, subject to the following
-%%   conditions:
-%% 
-%%   The above copyright notice and this permission notice shall be included in
-%%   all copies or substantial portions of the Software.
-%% 
-%%   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-%%   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-%%   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-%%   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-%%   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-%%   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-%%   IN THE SOFTWARE.
-%%
-%% End of file `gloss-liturgicallatin.ldf'.
-%    \end{macrocode}
-% \iffalse
-%</gloss-liturgicallatin.ldf>
-%<*gloss-lsorbian.ldf>
-% \fi
-% \clearpage
-% 
-% \subsection{gloss-lsorbian.ldf}
-%    \begin{macrocode}
-\ProvidesFile{gloss-lsorbian.ldf}[polyglossia: module for lower sorbian]
 \PolyglossiaSetup{lsorbian}{
+  language=Lower Sorbian,
+  babelname=lowersorbian,
   hyphennames={lsorbian,lowersorbian,Lsorbian},
+  langtag=LSB,
   hyphenmins={2,2},
   fontsetup=true,
 }
 
-\def\captionslsorbian{%
-   \def\refname{Referency}%
-   \def\abstractname{Abstrakt}%
-   \def\bibname{Literatura}%
-   \def\prefacename{Zawod}%
-   \def\chaptername{Kapitl}%
-   \def\appendixname{Dodawki}%
-   \def\contentsname{Wopśimjeśe}%
-   \def\listfigurename{Zapis wobrazow}%
-   \def\listtablename{Zapis tabulkow}%
-   \def\indexname{Indeks}%
-   \def\figurename{Wobraz}%
-   \def\tablename{Tabulka}%
-   %\def\thepart{}%
-   \def\partname{Źěl}%
-   \def\pagename{Strona}%
-   \def\seename{gl.}%
-   \def\alsoname{gl.~teke}%
-   \def\enclname{Pśiłoga}%
-   \def\ccname{CC}%
-   \def\headtoname{Komu}%
-   \def\proofname{Proof}%
-   \def\glossaryname{Glossary}%
-   }
-\def\datelsorbian{%
-    \def\today{\number\day.~\ifcase\month\or
-    januara\or februara\or měrca\or apryla\or maja\or
-    junija\or julija\or awgusta\or septembra\or oktobra\or
-    nowembra\or decembra\fi
-    \space \number\year}%
-    \def\oldtoday{\textlsorbian{\number\day.~\ifcase\month\or
-    wjelikego rožka\or małego rožka\or nalětnika\or
-    jatšownika\or rožownika\or smažnika\or pražnika\or
-    žnjeńca\or požnjeńca\or winowca\or nazymnika\or 
-    godownika\fi\space \number\year}}%
-    }
+\let\captionslsorbian\captionssorbian at lsorbian
+\let\datelsorbian\datesorbian at lsorbian
 
 %    \end{macrocode}
 % \iffalse
@@ -6623,8 +7470,6 @@
    \xpg at ill@value{#1}{macedonian at alph}\fi}%
 
 \def\macedonian at numbers{%
-   \let\latin at Alph\@Alph%
-   \let\latin at alph\@alph%
    \let\@Alph\macedonian at Alph%
    \let\@alph\macedonian at alph%
  }
@@ -6687,77 +7532,206 @@
 % \subsection{gloss-magyar.ldf}
 %    \begin{macrocode}
 \ProvidesFile{gloss-magyar.ldf}[polyglossia: module for magyar]
+
+% We only provide this gloss for babel compatibility.
+
+\input{gloss-hungarian.ldf}
+
 \PolyglossiaSetup{magyar}{
   hyphennames={magyar,hungarian},
+  langtag=HUN,
   hyphenmins={2,2},
   fontsetup=true,
 }
 
-\frenchspacing
+\let\captionsmagyar\captionshungarian
+\let\datemagyar\datehungarian
+\let\ondatemagyar\ondatehungarian
+\let\blockextras at magyar\blockextras at hungarian
+\let\noextras at magyar\noextras at hungarian
 
-% change 'táblázat x.x' to 'x.x. táblázat'
-\newcommand{\@magyar at fnum@table}{\thetable.~\tablename}
-\let\fnum at table\@magyar at fnum@table
+%    \end{macrocode}
+% \iffalse
+%</gloss-magyar.ldf>
+%<*gloss-malay.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-malay.ldf}
+%    \begin{macrocode}
+\ProvidesFile{gloss-malay.ldf}[polyglossia: module for malay]
 
-% change 'ábra x.x' to 'x.x. ábra'
-\newcommand{\@magyar at fnum@figure}{\thefigure.~\figurename}
-\let\fnum at figure\@magyar at fnum@figure
+\RequirePackage{hijrical}
 
-\def\captionsmagyar{%
-   \def\refname{Hivatkozások}%
-   \def\abstractname{Kivonat}%
-   \def\bibname{Irodalomjegyzék}%
-   \def\prefacename{Előszó}%
-   \def\chaptername{fejezet}%
-   \def\appendixname{Függelék}%
-   \def\contentsname{Tartalomjegyzék}%
-   \def\listfigurename{Ábrák jegyzéke}%
-   \def\listtablename{Táblázatok jegyzéke}%
-   \def\indexname{Tárgymutató}%
-   \def\figurename{ábra}%
-   \def\tablename{táblázat}%
+\PolyglossiaSetup{malay}{%
+  language=Malay,
+  langtag=MLY,
+  hyphennames={malay,melayu,bahasam,bahasai,indonesian,indon,bahasa},
+  hyphenmins={2,2},
+  fontsetup=true}
+
+\providebool{malay at melayu}
+\malay at melayufalse
+\def\malay at variant{malay}
+\define at choicekey*+{malay}{variant}[\val\nr]{indonesian,malaysian}[malaysian]{%
+   \ifcase\nr\relax
+      % indonesian:
+      \def\malay at variant{indonesian}%
+      \malay at melayufalse
+   \or
+      % malaysian:
+      \def\malay at variant{malay}%
+      \malay at melayutrue
+   \fi
+   \ifmalay at melayu
+      \SetLanguageKeys{malay}{language=Malay,langtag=MLY,babelname=bahasam}%
+      \xpg at fontsetup@latin{malay}%
+      % Check if \l at malay is defined. If not, try to set it to some variety
+      % (specific order as in the csv list below), or null language if everything fails
+      \xpg at ifdefined{malay}{}{%
+        \def\do##1{%
+            \xpg at ifdefined{##1}%
+              {\csletcs{l at malay}{l@##1}\listbreak}%
+              {}%
+        }%
+        \docsvlist{melayu,bahasam,bahasai,indonesian,indon,bahasa}
+        \xpg at ifdefined{malay}{}{%
+                 \xpg at warning{No hyphenation patterns for Malay (Malaysian) found\MessageBreak
+                              I will use the 'null' language instead}%
+                 \adddialect\l at malay0%
+        }%
+      }%
+   \else
+      \SetLanguageKeys{malay}{language=Indonesian,langtag=IND,babelname=bahasa}%
+      \xpg at fontsetup@latin{malay}%
+      % Check if \l at indonesian is defined. If not, try to set it to some variety
+      % (specific order as in the csv list below), or null language if everything fails
+      \xpg at ifdefined{indonesian}{}{%
+        \def\do##1{%
+           \xpg at ifdefined{##1}%
+              {\csletcs{l at indonesian}{l@##1}\listbreak}%
+              {}%
+        }%
+        \docsvlist{indon,bahasai,bahasam,malay,melayu,bahasa}
+        \xpg at ifdefined{indonesian}{}{%
+                 \xpg at warning{No hyphenation patterns for Malay (Indonesian) found\MessageBreak
+                              I will use the 'null' language instead}%
+                 \adddialect\l at indonesian0
+        }%
+      }%
+   \fi
+   \xpg at info{Option: malay, variant=\val}%
+}{\xpg at warning{Unknown malay variant `#1'}}
+
+
+\def\malay at language{%
+   \polyglossia at setup@language at patterns{\malay at variant}%
+}%
+
+
+\def\captionsmalay at indonesian{%
+   \def\refname{Pustaka}%
+   \def\abstractname{Ringkasan}%
+   \def\bibname{Bibliografi}%
+   \def\prefacename{Pendahuluan}%
+   \def\chaptername{Bab}%
+   \def\appendixname{Lampiran}%
+   \def\contentsname{Daftar Isi}%
+   \def\listfigurename{Daftar Gambar}%
+   \def\listtablename{Daftar Tabel}%
+   \def\indexname{Indeks}%
+   \def\figurename{Gambar}%
+   \def\tablename{Tabel}%
    %\def\thepart{}%
-   \def\partname{rész}%
-   \def\pagename{oldal}%
-   \def\seename{lásd}%
-   \def\alsoname{lásd még}%
-   \def\enclname{Melléklet}%
-   \def\ccname{Körlevél–címzettek}%
-   \def\headtoname{Címzett}%
-   \def\proofname{Bizonyítás}%
-   \def\glossaryname{Szójegyzék}%
-   }
-\def\datemagyar{%   
-   \def\today{%
-    \number\year.\nobreakspace\ifcase\month\or
-    január\or február\or március\or
-    április\or május\or június\or
-    július\or augusztus\or szeptember\or
-    október\or november\or december\fi
-    \space\number\day.}%
-   \def\ondatemagyar{%
-    \number\year.\nobreakspace\ifcase\month\or
-    január\or február\or március\or
-    április\or május\or június\or
-    július\or augusztus\or szeptember\or
-    október\or november\or december\fi
-      \space\ifcase\day\or
-      1-jén\or  2-án\or  3-án\or  4-én\or  5-én\or
-      6-án\or  7-én\or  8-án\or  9-én\or 10-én\or
-     11-én\or 12-én\or 13-án\or 14-én\or 15-én\or
-     16-án\or 17-én\or 18-án\or 19-én\or 20-án\or
-     21-én\or 22-én\or 23-án\or 24-én\or 25-én\or
-     26-án\or 27-én\or 28-án\or 29-én\or 30-án\or
-     31-én\fi}%
-   \let\ontoday\ondatemagyar}
+   \def\partname{Bagian}%
+   \def\pagename{Halaman}%
+   \def\seename{lihat}%
+   \def\alsoname{lihat juga}%
+   \def\enclname{Lampiran}%
+   \def\ccname{cc}%
+   \def\headtoname{Kepada}%
+   \def\proofname{Bukti}%
+   \def\glossaryname{Daftar Istilah}%
+}
 
-\def\noextras at magyar{%
-   \let\ontoday\@undefined
+\def\captionsmalay at malay{%
+   \def\refname{Rujukan}%
+   \def\abstractname{Abstrak}%
+   \def\bibname{Bibliografi}%
+   \def\prefacename{Pendahuluan}%
+   \def\chaptername{Bab}%
+   \def\appendixname{Lampiran}%
+   \def\contentsname{Kandungan}%
+   \def\listfigurename{Senarai Rajah}%
+   \def\listtablename{Senarai Jadual}%
+   \def\indexname{Indeks}%
+   \def\figurename{Rajah}%
+   \def\tablename{Jadual}%
+   \def\thepart{}%
+   \def\partname{Bahagian}%
+   \def\pagename{Halaman}%
+   \def\seename{lihat}%
+   \def\alsoname{lihat juga}%
+   \def\enclname{Lampiran}%
+   \def\ccname{salinan kpd}%
+   \def\headtoname{Kepada}%
+   \def\proofname{Bukti}%
+   \def\glossaryname{Senarai Istilah}%
 }
 
+\def\captionsmalay{%
+  \csname captionsmalay@\malay at variant\endcsname%
+}
+
+\def\datemalay at indonesian{%
+   \def\today{\number\day~\ifcase\month\or
+    Januari\or Pebruari\or Maret\or April\or Mei\or Juni\or
+    Juli\or Agustus\or September\or Oktober\or Nopember\or Desember\fi
+    \space \number\year}}
+
+\def\datemalay at malay{%
+   \def\bahasam at day{%
+      \ifcase\day\or%
+        1hb\or 2hb\or 3hb\or 4hb\or 5hb\or%
+        6hb\or 7hb\or 8hb\or 9hb\or 10hb\or%
+        11hb\or 12hb\or 13hb\or 14hb\or 15hb\or%
+        16hb\or 17hb\or 18hb\or 19hb\or 20hb\or%
+        21hb\or 22hb\or 23hb\or 24hb\or 25hb\or%
+        26hb\or 27hb\or 28hb\or 29hb\or 30hb\or%
+        31hb\fi}%
+   \def\today{\bahasam at day~\ifcase\month\or
+    Januari\or Februari\or Mac\or April\or Mei\or Jun\or
+    Julai\or Ogos\or September\or Oktober\or November\or Disember\fi
+    \space \number\year}}
+
+\def\datemalay{%
+  \csname datemalay@\malay at variant\endcsname%
+}
+
+% Hijri calendar localizations
+\def\hijrimonthmalay at indonesian#1{%
+  \ifcase#1%
+  \or Muharram\or Safar\or Rabiul awal\or Rabiul akhir\or Jumadil awal\or Jumadil akhir\or Rajab%
+  \or Sya'ban\or Ramadhan\or Syawal\or Dzulkaidah\or Dzulhijjah\fi%
+}
+
+\def\hijrimonthmalay at malay#1{%
+  \ifcase#1%
+  \or Muharram\or Safar\or Rabiulawal\or Rabiulakhir\or Jamadilawal\or Jamadilakhir\or Rejab%
+  \or Syaaban\or Ramadan\or Syawal\or Zulkaedah\or Zulhijah\fi%
+}
+
+\def\hijrimonthmalay{%
+  \csname hijrimonthmalay@\malay at variant\endcsname%
+}
+
+%\Hijritoday is now locale-aware and will format the date with this macro:
+\DefineFormatHijriDate{malay}{%
+  \number\value{Hijriday}\space\hijrimonthmalay{\value{Hijrimonth}}\space\number\value{Hijriyear}}
+
 %    \end{macrocode}
 % \iffalse
-%</gloss-magyar.ldf>
+%</gloss-malay.ldf>
 %<*gloss-malayalam.ldf>
 % \fi
 % \clearpage
@@ -6850,8 +7824,8 @@
   hyphennames={marathi},
   hyphenmins={2,2},%CHECK
   fontsetup=true,
+  localnumeral=marathinumerals
   %TODO nouppercase=true,
-  %TODO localnumber=marathinumber
 }
 
 \def\tmp at western{Western}
@@ -6864,6 +7838,8 @@
     \marathi at devanagari@numeralsfalse
   \fi}
 
+\newcommand{\marathinumerals}[2]{\marathinumber{#2}}
+
 \def\marathinumber#1{%
   \ifmarathi at devanagari@numerals
     \devanagaridigits{\number#1}%
@@ -6880,9 +7856,9 @@
    \def\appendixname{परिशिष्ट}%
    \def\contentsname{अनुक्रमणिका}%
    \def\listfigurename{आकृत्यांची यादी}%
-   \def\listtablename{कॊष्टकांची यादी}%
+   \def\listtablename{कोष्टकांची यादी}%
    \def\indexname{सूची}%
-   \def\figurename{आक्रुती}%
+   \def\figurename{आकृती}%
    \def\tablename{कोष्टक}%
    %\def\thepart{}% TODO
    \def\partname{भाग}%
@@ -6894,6 +7870,7 @@
    \def\headtoname{प्रति}%
    \def\proofname{सिद्धता}%
    \def\glossaryname{स्पष्टीकरणांची यादी}%
+   \def\authorsand{आणि}%
 }
 \def\datemarathi{%
    \def\marathimonth{%
@@ -6917,6 +7894,207 @@
 %    \end{macrocode}
 % \iffalse
 %</gloss-marathi.ldf>
+%<*gloss-mongolian.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-mongolian.ldf}
+%    \begin{macrocode}
+\ProvidesFile{gloss-mongolian.ldf}[polyglossia: module for mongolian]
+
+\RequirePackage{cyrillicnumbers}
+
+\PolyglossiaSetup{mongolian}{
+  script=Cyrillic,
+  scripttag=cyrl,
+  langtag=MNG,
+  hyphennames={mongolian},
+  hyphenmins={2,2},
+  frenchspacing=true,
+  fontsetup,
+  localnumeral=mongoliannumerals,
+  Localnumeral=Mongoliannumerals
+}
+
+% This file is derived from mongolian-babel. which
+% provides support for Mongolian (Khalkha variety)
+% with Cyrillic script
+% TODO: Implement script=mongolian and maybe other
+%       variants of Mongolian
+
+\newif\ifcyrillic at numerals
+\define at key{mongolian}{numerals}[arabic]{%
+   \ifstrequal{#1}{cyrillic}%
+      {\cyrillic at numeralstrue}%
+      {\cyrillic at numeralsfalse}%
+}
+
+\define at boolkey{mongolian}[mongolian@]{babelshorthands}[false]{}
+
+\setkeys{mongolian}{numerals}
+
+\ifsystem at babelshorthands
+  \setkeys{mongolian}{babelshorthands=true}
+\else
+  \setkeys{mongolian}{babelshorthands=false}
+\fi
+
+\ifcsundef{initiate at active@char}{%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
+}{}
+
+\def\mongolian at shorthands{%
+  \bbl at activate{"}%
+  \def\language at group{mongolian}%
+  \declare at shorthand{mongolian}{"`}{„}%
+  \declare at shorthand{mongolian}{"'}{“}%
+  \declare at shorthand{mongolian}{"<}{«}%
+  \declare at shorthand{mongolian}{">}{»}%
+  \declare at shorthand{mongolian}{""}{\hskip\z at skip}%
+  \declare at shorthand{mongolian}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
+  \declare at shorthand{mongolian}{"=}{\nobreak-\hskip\z at skip}%
+  \declare at shorthand{mongolian}{"|}{\textormath{\nobreak\discretionary{-}{}{\kern.03em}\allowhyphens}{}}%
+  \declare at shorthand{mongolian}{"-}{%
+     \def\mongolian at sh@tmp{%
+       \if\mongolian at sh@next-\expandafter\mongolian at sh@emdash%
+       \else\expandafter\mongolian at sh@hyphen\fi%
+     }%
+     \futurelet\mongolian at sh@next\mongolian at sh@tmp%
+  }%
+  \def\mongolian at sh@hyphen{%
+    \nobreak\-\bbl at allowhyphens}%
+  \def\mongolian at sh@emdash##1##2{\cdash-##1##2}%
+  \def\cdash##1##2##3{\def\tempx@{##3}%
+  \def\tempa@{-}\def\tempb@{~}\def\tempc@{*}%
+   \ifx\tempx@\tempa@\@Acdash\else
+    \ifx\tempx@\tempb@\@Bcdash\else
+     \ifx\tempx@\tempc@\@Ccdash\else
+      \errmessage{Wrong usage of cdash}\fi\fi\fi}%
+  \def\@Acdash{\ifdim\lastskip>\z@\unskip\nobreak\hskip.2em\fi
+    \cyrdash\hskip.2em\ignorespaces}%
+  \def\@Bcdash{\leavevmode\ifdim\lastskip>\z@\unskip\fi
+   \nobreak\cyrdash\penalty\exhyphenpenalty\hskip\z at skip\ignorespaces}%
+  \def\@Ccdash{\leavevmode
+   \nobreak\cyrdash\nobreak\hskip.35em\ignorespaces}%
+  \ifx\cyrdash\undefined
+    \def\cyrdash{\hbox to.8em{--\hss--}}%
+  \fi
+  \declare at shorthand{mongolian}{",}{\nobreak\hskip.2em\ignorespaces}%
+}
+
+\def\nomongolian at shorthands{%
+  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{"}}%
+}
+
+% Taken from babel-mongolian
+\def\captionsmongolian{%
+   \def\prefacename{Өмнөх үг}%
+   \def\refname{Ашигласан ном}%
+   \def\abstractname{Удиртгал}%
+   \def\bibname{Номзүй}%
+   \def\chaptername{Бүлэг}%
+   \def\appendixname{Хавсралт}%
+   \ifcsundef{thechapter}%
+     {\def\contentsname{Агуулга}}%
+     {\def\contentsname{Гарчиг}}%
+   \def\listfigurename{Зургийн жагсаалт}%
+   \def\listtablename{Хүснэгтийн жагсаалт}%
+   \def\indexname{Товъёг}%
+   \def\authorname{Нэрийн хэлхээ}%
+   \def\figurename{Зураг}%
+   \def\tablename{Хүснэгт}%
+   \def\partname{Хэсэг}%
+   \def\enclname{Ишлэл}%
+   \def\ccname{э.с.}%
+   \def\headtoname{}%
+   \def\pagename{тал}%
+   \def\seename{талд үз}%
+   \def\alsoname{мөн талд үз}%
+   \def\proofname{Баталгаа}%
+}
+
+\def\datemongolian{%
+  \def\today{\number\year~оны \ifcase\month\or
+  1-р\or 2-р\or 3-р\or 4-р\or 5-р\or 6-р\or
+  7-р\or 8-р\or 9-р\or 10-р\or 11-р\or 12-р\fi
+  ~сарын \number\day}}
+
+\newcommand{\mongoliannumerals}[2]{\mongoliannumber{#2}}
+\newcommand{\Mongoliannumerals}[2]{\Mongoliannumber{#2}}
+
+\def\mongoliannumber#1{%
+  \ifcyrillic at numerals
+    \cyr at alph{#1}%
+  \else
+    \number#1%
+  \fi%
+}
+
+\def\Mongoliannumber#1{%
+  \ifcyrillic at numerals
+    \cyr at Alph{#1}%
+  \else
+    \number#1%
+  \fi%
+}
+
+\let\mongoliannumeral=\mongoliannumber
+\let\Mongoliannumeral=\Mongoliannumber
+
+\def\Asbuk#1{\expandafter\cyr at Alph\csname c@#1\endcsname}
+
+\def\asbuk#1{\expandafter\cyr at alph\csname c@#1\endcsname}
+
+% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
+% thus ends at 30. We now use proper cyrillic numbering.
+
+%\def\mongolian at 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 at ill@value{#1}{mongolian at Alph}\fi}
+
+%\def\mongolian at 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 at ill@value{#1}{mongolian at alph}\fi}
+
+\def\mongolian at numbers{%
+   \let\latin at alph\@alph
+   \let\latin at Alph\@Alph
+   \ifcyrillic at numerals%
+     \def\mongolian at alph##1{\expandafter\mongoliannumeral\expandafter{\the##1}}%
+     \def\mongolian at Alph##1{\expandafter\Mongoliannumeral\expandafter{\the##1}}%
+      \let\@alph\mongolian at alph%
+      \let\@Alph\mongolian at Alph%
+   \fi
+}
+
+\def\nomongolian at numbers{%
+   \let\@alph\latin at alph%
+   \let\@Alph\latin at Alph%
+}
+
+\def\noextras at mongolian{%
+   \ifcyrillic at numerals\nomongolian at numbers\fi%
+   \nomongolian at shorthands%
+}
+
+\def\blockextras at mongolian{%
+   \ifcyrillic at numerals\mongolian at numbers\fi%
+   \ifmongolian at babelshorthands\mongolian at shorthands\fi%
+}
+
+\def\inlineextras at mongolian{%
+   \ifmongolian at babelshorthands\mongolian at shorthands\fi%
+}
+
+%    \end{macrocode}
+% \iffalse
+%</gloss-mongolian.ldf>
 %<*gloss-nko.ldf>
 % \fi
 % \clearpage
@@ -6927,12 +8105,16 @@
 \PolyglossiaSetup{nko}{%
   script=N'ko,
   scripttag=nko~,
+  langtag=NKO,
   fontsetup=true,
   hyphennames={nohyphenation},
-  direction=RL
+  direction=RL,
+  localnumeral=nkonumerals
 }
 \RequirePackage{nkonumbers}%
 
+\newcommand{\nkonumerals}[2]{\nkonumber{#2}}
+
 \def\captionsnko{%
   \def\prefacename{ߢߍߛߓߍ}%
   \def\refname{ߞߐߡߊߛߙߋ}%
@@ -6961,30 +8143,30 @@
 % ߂߀߁߃ ߞߏ߲ߞߏߜߍ ߕߟߋ߬ ߁߈ (RTL)
 % ( 18 February 2013 )
 % The word "ߕߟߋ߬" is mandatory between month name and day number.
+% Replace "ߕߟߋ߬" by "ߕߋ߬ߟߋ߫" if and only if day = 2 or day = 3 or day = 9 
+% or (day >= 20 and day <= 29).
 
+\newcommand*\nkodayprefix[1]{%
+  \ifnum\numexpr#1=2 ߕߋ߬ߟߋ߫\else%
+     \ifnum\numexpr#1=3 ߕߋ߬ߟߋ߫\else%
+        \ifnum\numexpr#1=9 ߕߋ߬ߟߋ߫\else%
+           \ifnum\numexpr#1>19\ifnum\numexpr#1<30 ߕߋ߬ߟߋ߫\else ߕߟߋ߬\fi\else ߕߟߋ߬\fi%
+        \fi%
+     \fi%
+  \fi%
+}
+
+\newcommand*\nkoday[1]{%
+  % If day = 1, put above "߁", NKO_COMBINING_SHORT_RISING_TONE
+  \ifnum\numexpr#1=1 ߁߭\else%
+    \nkonumber{#1}
+  \fi
+}
+
 \def\datenko{%
   \def\today{%
     \nkonumber{\year}\space
     \ifcase\month
-    \orߓߌ߲ߠߊߥߎߟߋ߲%
-    \orߞߏ߲ߞߏߜߍ%
-    \orߕߙߊߓߊ
-    \orߞߏ߲ߞߏߘߌ߬ߓߌ%
-    \orߘߓߊ߬ߕߊ%
-    \orߥߊ߬ߛߌߥߊ߬ߙߊ%
-    \orߞߊ߬ߙߌߝߐ߭%
-    \orߘߓߊ߬ߓߌߟߊ%
-    \orߕߎߟߊߝߌ߲%
-    \orߞߏ߲ߓߌߕߌ߮%
-    \orߣߍߣߍߓߊ%
-    \orߞߏ߬ߟߌ߲߬ߞߏߟߌ߲\fi
-    \spaceߕߟߋ߬
-    \space\nkonumber{\day}
-  }%
-
-  \def\today{%
-    \nkonumber{\year}\space
-    \ifcase\month
     \or ߓߌ߲ߠߊߥߎߟߋ߲%
     \or ߞߏ߲ߞߏߜߍ%
     \or ߕߙߊߓߊ%
@@ -6997,8 +8179,8 @@
     \or ߞߏ߲ߓߌߕߌ߮%
     \or ߣߍߣߍߓߊ%
     \or ߞߏ߬ߟߌ߲߬ߞߏߟߌ߲\fi
-    \space ߕߟߋ߬
-    \space\nkonumber{\day}
+    \space\nkodayprefix{\number\day}
+    \space\nkoday{\day}
   }%
 }%
 
@@ -7011,15 +8193,89 @@
 % 
 % \subsection{gloss-norsk.ldf}
 %    \begin{macrocode}
-\ProvidesFile{gloss-norsk.ldf}[polyglossia: module for norwegian]
+\ProvidesFile{gloss-norsk.ldf}[polyglossia: module for norwegian (bokmal)]
+
+% We only provide this gloss for babel compatibility. Since norsk is 
+% actually norwegian bokmal, we use 'norwegian' with variant 'bokmal' now.
+
+\input{gloss-norwegian.ldf}
+
 \PolyglossiaSetup{norsk}{
   hyphennames={norsk},
   hyphenmins={2,2},
+  langtag=NOR,
   frenchspacing=true,
   fontsetup=true,
 }
 
-\def\captionsnorsk{%
+\let\captionsnorsk\captionsnorwegian at norsk
+\let\datenorsk\datenorwegian at norsk
+
+%    \end{macrocode}
+% \iffalse
+%</gloss-norsk.ldf>
+%<*gloss-norwegian.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-norwegian.ldf}
+%    \begin{macrocode}
+\ProvidesFile{gloss-norwegian.ldf}[polyglossia: module for norwegian]
+\PolyglossiaSetup{norwegian}{
+  hyphennames={nynorsk},
+  langtag=NYN,
+  hyphenmins={2,2},
+  frenchspacing=true,
+  fontsetup=false,
+}
+
+\def\norwegian at variant{nynorsk}
+\define at choicekey*+{norwegian}{variant}[\val\nr]{nynorsk,bokmal}[nynorsk]{%
+   \ifcase\nr\relax
+      % nynorsk:
+      \def\norwegian at variant{nynorsk}%
+      \SetLanguageKeys{norwegian}{langtag=NYN,babelname=nynorsk}%
+      \xpg at fontsetup@latin{norwegian}%
+   \or
+      % bokmal:
+      \def\norwegian at variant{norsk}%
+      \SetLanguageKeys{norwegian}{langtag=NOR,babelname=norsk}%
+      \xpg at fontsetup@latin{norwegian}%
+   \fi
+   \xpg at info{Option: norwegian, variant=\val}%
+}{\xpg at warning{Unknown norwegian variant `#1'}}
+
+
+\def\norwegian at language{%
+   \polyglossia at setup@language at patterns{\norwegian at variant}
+}%
+
+\def\captionsnorwegian at nynorsk{%
+   \def\refname{Referansar}%
+   \def\abstractname{Sammendrag}%
+   \def\bibname{Litteratur}%
+   \def\prefacename{Forord}%
+   \def\chaptername{Kapittel}%
+   \def\appendixname{Tillegg}%
+   \def\contentsname{Innhald}%
+   \def\listfigurename{Figurar}%
+   \def\listtablename{Tabellar}%
+   \def\indexname{Register}%
+   \def\figurename{Figur}%
+   \def\tablename{Tabell}%
+   %\def\thepart{}% <<<
+   \def\partname{Del}%
+   \def\pagename{Side}%
+   \def\seename{Sjå}%
+   \def\alsoname{Sjå òg}%
+   \def\enclname{Vedlegg}%
+   \def\ccname{Kopi til}%
+   \def\headtoname{Til}%
+   \def\proofname{Bevis}%
+   \def\glossaryname{Ordliste}%
+}
+
+\def\captionsnorwegian at norsk{%
    \def\refname{Referanser}%
    \def\abstractname{Sammendrag}%
    \def\bibname{Bibliografi}%
@@ -7042,18 +8298,33 @@
    \def\headtoname{Til}%
    \def\proofname{Bevis}%
    \def\glossaryname{Ordliste}%
-   }
+}
 
-\def\datenorsk{%   
+\def\captionsnorwegian{%
+  \csname captionsnorwegian@\norwegian at variant\endcsname%
+}
+
+\def\datenorwegian at nynorsk{%   
    \def\today{\number\day.~\ifcase\month\or
     januar\or februar\or mars\or april\or mai\or juni\or
     juli\or august\or september\or oktober\or november\or desember
     \fi\space\number\year}%
-    }
+}
 
+\def\datenorwegian at norsk{%   
+   \def\today{\number\day.~\ifcase\month\or
+    januar\or februar\or mars\or april\or mai\or juni\or
+    juli\or august\or september\or oktober\or november\or
+    desember\fi\space\number\year}%
+}
+
+\def\datenorwegian{%
+  \csname datenorwegian@\norwegian at variant\endcsname%
+}
+
 %    \end{macrocode}
 % \iffalse
-%</gloss-norsk.ldf>
+%</gloss-norwegian.ldf>
 %<*gloss-nynorsk.ldf>
 % \fi
 % \clearpage
@@ -7061,45 +8332,23 @@
 % \subsection{gloss-nynorsk.ldf}
 %    \begin{macrocode}
 \ProvidesFile{gloss-nynorsk.ldf}[polyglossia: module for norwegian (Nynorsk)]
+
+% We only provide this gloss for babel compatibility. Since nynorsk is 
+% a norwegian variety, we use 'norwegian' with variant 'nynorsk' now.
+
+\input{gloss-norwegian.ldf}
+
 \PolyglossiaSetup{nynorsk}{
   hyphennames={nynorsk},
+  langtag=NYN,
   hyphenmins={2,2},
   frenchspacing=true,
   fontsetup=true,
 }
 
-\def\captionsnynorsk{%
-   \def\refname{Referansar}%
-   \def\abstractname{Sammendrag}%
-   \def\bibname{Litteratur}%
-   \def\prefacename{Forord}%
-   \def\chaptername{Kapittel}%
-   \def\appendixname{Tillegg}%
-   \def\contentsname{Innhald}%
-   \def\listfigurename{Figurar}%
-   \def\listtablename{Tabellar}%
-   \def\indexname{Register}%
-   \def\figurename{Figur}%
-   \def\tablename{Tabell}%
-   %\def\thepart{}% <<<
-   \def\partname{Del}%
-   \def\pagename{Side}%
-   \def\seename{Sjå}%
-   \def\alsoname{Sjå òg}%
-   \def\enclname{Vedlegg}%
-   \def\ccname{Kopi til}%
-   \def\headtoname{Til}%
-   \def\proofname{Bevis}%
-   \def\glossaryname{Ordliste}%
-   }
+\let\captionsnorsk\captionsnorwegian at nynorsk
+\let\datenorsk\datenorwegian at nynorsk
 
-\def\datenynorsk{%   
-   \def\today{\number\day.~\ifcase\month\or
-    januar\or februar\or mars\or april\or mai\or juni\or
-    juli\or august\or september\or oktober\or november\or desember
-    \fi\space\number\year}%
-    }
-
 %    \end{macrocode}
 % \iffalse
 %</gloss-nynorsk.ldf>
@@ -7130,6 +8379,7 @@
      module for Occitan]
 \PolyglossiaSetup{occitan}{
   hyphennames={occitan},
+  langtag=OCI,
   hyphenmins={2,2},
   frenchspacing=true,
   indentfirst=true,
@@ -7142,10 +8392,13 @@
 \else
   \setkeys{occitan}{babelshorthands=false}
 \fi
+
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
+
 \def\occitan at shorthands{%
   \bbl at activate{"}%
   \def\language at group{occitan}%
@@ -7269,6 +8522,165 @@
 %    \end{macrocode}
 % \iffalse
 %</gloss-occitan.ldf>
+%<*gloss-persian.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-persian.ldf}
+%    \begin{macrocode}
+\ProvidesFile{gloss-persian.ldf}[polyglossia: module for persian]
+\ifluatex
+  \xpg at warning{Persian is not supported with LuaTeX.\MessageBreak
+I will proceed with the compilation, but\MessageBreak
+the output is not guaranteed to be correct\MessageBreak
+and may look very wrong.}
+\fi
+\RequireBidi
+\RequirePackage{arabicnumbers}
+\RequirePackage{farsical}
+\RequirePackage{hijrical}
+\PolyglossiaSetup{persian}{
+  babelname=farsi,
+  script=Arabic,
+  direction=RL,
+  scripttag=arab,
+  langtag=FAR,
+  hyphennames={nohyphenation},
+  fontsetup=true,
+  localnumeral=farsinumerals
+}
+
+\newif\if at western@numerals
+\def\tmp at western{western}
+\define at key{persian}{numerals}[eastern]{%
+  \def\@tmpa{#1}%
+  \ifx\@tmpa\tmp at western\@western at numeralstrue\else%
+    \@western at numeralsfalse%
+  \fi}
+
+%this is needed for \abjad in arabicnumbers.sty
+\def\tmp at true{true}
+\define at key{persian}{abjadjimnotail}[true]{%
+  \def\@tmpa{#1}%
+  \ifx\@tmpa\tmp at true\abjad at jim@notailtrue%
+  \else
+    \abjad at jim@notailfalse
+  \fi}
+
+% NOT YET USED
+\define at key{persian}{locale}[default]{%
+  \def\@persian at locale{#1}}
+
+%TODO add option for CALENDAR
+
+\setkeys{persian}{locale,numerals}
+
+\def\farsigregmonth#1{\ifcase#1%
+  \or ژانویه\or فوریه\or مارس\or آوریل\or مه\or ژوئن\or ژوئیه\or اوت\or سپتامبر\or اکتبر\or نوامبر\or دسامبر\fi}
+\def\farsimonth#1{\ifcase#1%
+  \or کانون ثانی\or شباط\or اذار%%or ادار
+    \or نیسان\or ایار\or حزیران\or تموز\or آب\or ایلول\or تشرین اول\or تشرین ثانی\or کانون اول\fi}
+
+%\Hijritoday is now locale-aware and will format the date with this macro:
+\DefineFormatHijriDate{persian}{\@ensure at RTL{%
+\farsinumber{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\farsinumber{\value{Hijriyear}}}}
+
+\def\captionspersian{%
+\def\prefacename{\@ensure at RTL{پیشگفتار}}%
+\def\refname{\@ensure at RTL{مراجع}}%
+\def\abstractname{\@ensure at RTL{چکیده}}%
+\def\bibname{\@ensure at RTL{کتاب‌نامه}}%
+\def\chaptername{\@ensure at RTL{فصل}}%
+\def\appendixname{\@ensure at RTL{پیوست}}%
+\def\contentsname{\@ensure at RTL{فهرست مطالب}}%
+\def\listfigurename{\@ensure at RTL{لیست تصاویر}}%
+\def\listtablename{\@ensure at RTL{لیست جداول}}%
+\def\indexname{\@ensure at RTL{نمایه}}%
+\def\figurename{\@ensure at RTL{شكل}}%
+\def\tablename{\@ensure at RTL{جدول}}%
+\def\partname{\@ensure at RTL{بخش}}%
+\def\enclname{\@ensure at RTL{پیوست}}%
+\def\ccname{\@ensure at RTL{رونوشت}}%
+\def\headtoname{\@ensure at RTL{به}}%
+\def\pagename{\@ensure at RTL{صفحة}}%
+\def\seename{\@ensure at RTL{ببینید}}%
+\def\alsoname{\@ensure at RTL{نیز ببینید}}%
+\def\proofname{\@ensure at RTL{برهان}}%
+\def\glossaryname{\@ensure at RTL{دانش‌نامه}}%
+}
+\def\datepersian{%
+   \def\today{\@ensure at RTL{\farsinumber\day\space\farsigregmonth{\month}\space\farsinumber\year}}%
+}
+
+\newcommand{\farsinumerals}[2]{\farsinumber{#2}}
+
+\newif\ifpersiandigits
+
+\def\farsinumber#1{%
+  \if at western@numerals
+    \number#1%
+  \else
+    \ifxetex
+      \ifnum\XeTeXcharglyph"06F0 > 0\relax
+        \persiandigitstrue
+      \fi
+    \else\ifluatex
+      \expandafter\ifnum\directlua{polyglossia.check_char(0x6F0)} > 0\relax
+        \persiandigitstrue
+      \fi
+    \fi\fi
+    \ifpersiandigits
+      \farsidigits{\number#1}%
+      %%{\protect\addfontfeature{Mapping=farsidigits}\number#1}%
+    \else%
+      \arabicdigits{\number#1}%
+      %%{\protect\addfontfeature{Mapping=arabicdigits}\number#1}%
+    \fi
+  \fi
+}
+
+%\def\farsinum#1{\expandafter\farsinumber\csname c@#1\endcsname}
+%\def\farsibracenum#1{(\expandafter\farsinumber\csname c@#1\endcsname)}
+%\def\farsiornatebracenum#1{\char"FD3E\expandafter\farsinumber\csname c@#1\endcsname\char"FD3F}
+%\def\farsialph#1{\expandafter\@farsialph\csname c@#1\endcsname}
+
+\def\persian at numbers{%
+   \let\@alph\abjad%
+   \let\@Alph\abjad%
+}
+
+\def\nopersian at numbers{%
+  \let\@alph\@latinalph%
+  \let\@Alph\@latinAlph%
+}
+
+\def\persian at globalnumbers{%
+   \let\@arabic\farsinumber%
+   \renewcommand\thefootnote{\localnumeral*{footnote}}%
+   \renewcommand\theequation{\localnumeral*{equation}}%
+}
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
+\def\nopersian at globalnumbers{
+   \let\@arabic\xpg at save@arabic%
+}
+
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
+\def\blockextras at persian{%
+   \def\MakeUppercase##1{##1}%
+}
+
+\def\noextras at persian{%
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase
+}
+%    \end{macrocode}
+% \iffalse
+%</gloss-persian.ldf>
 %<*gloss-piedmontese.ldf>
 % \fi
 % \clearpage
@@ -7281,6 +8693,7 @@
 \PolyglossiaSetup{piedmontese}{
   hyphennames={piedmontese},
   hyphenmins={2,2},
+  langtag=PMS,
   frenchspacing=true,
   fontsetup=true,
 }
@@ -7295,8 +8708,9 @@
 \fi
 
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\piedmontese at shorthands{%
@@ -7401,6 +8815,7 @@
 \PolyglossiaSetup{polish}{
   hyphennames={polish},
   hyphenmins={2,2},
+  langtag=PLK,
   frenchspacing=true,
   fontsetup=true,
 }
@@ -7446,14 +8861,71 @@
 % 
 % \subsection{gloss-portuges.ldf}
 %    \begin{macrocode}
-\ProvidesFile{gloss-portuges.ldf}[polyglossia: module for portuguese]
+\ProvidesFile{gloss-portuges.ldf}[polyglossia: module for portuguese (DEPRECATED!)]
+
+% We only provide this gloss for backwards compatibility. The name
+% 'portuges' was selected in accordance with babel (which probably
+% introduced it in 8.3 filename times). Since polyglossia uses full
+% English language names, we use 'portuguese' now.
+
+% FIXME: Once we support babel aliases (#112) this gloss can go.
+
+\xpg at warning{The language name 'portuges' is deprectated.\MessageBreak
+             Please use 'portuguese' instead.}
+
+\input{gloss-portuguese.ldf}
+
 \PolyglossiaSetup{portuges}{
   hyphennames={portuges,portuguese},
   hyphenmins={2,3},
+  langtag=PTG,
   fontsetup=true,
 }
 
-\def\captionsportuges{%
+\let\captionsportuges\captionsportuguese at portuges
+\let\dateportuges\dateportuguese at portuges
+     
+%    \end{macrocode}
+% \iffalse
+%</gloss-portuges.ldf>
+%<*gloss-portuguese.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-portuguese.ldf}
+%    \begin{macrocode}
+\ProvidesFile{gloss-portuguese.ldf}[polyglossia: module for portuguese]
+\PolyglossiaSetup{portuguese}{
+  babelname=portuges,
+  hyphennames={portuges,portuguese},
+  hyphenmins={2,3},
+  langtag=PTG,
+  fontsetup=true,
+}
+
+\def\portuguese at variant{portuges}
+\define at choicekey*+{portuguese}{variant}[\val\nr]{portuguese,brazilian}[portuguese]{%
+   \ifcase\nr\relax
+      % portuguese:
+      \def\portuguese at variant{portuges}%
+   \or
+      % brazilian:
+      \def\portuguese at variant{brazil}%
+      \SetLanguageKeys{portuguese}{babelname=brazil}%
+      \xpg at ifdefined{brazil}{}%
+	    {\xpg at warning{No hyphenation patterns were loaded for "Portuguese (Brazil)"\MessageBreak
+	      I will use the standard patterns for Portuguese instead}%
+	    \adddialect\l at brazil\l at portuges\relax}%
+   \fi
+   \xpg at info{Option: portuguese, variant=\val}%
+}{\xpg at warning{Unknown portuguese variant `#1'}}
+
+
+\def\portuguese at language{%
+   \polyglossia at setup@language at patterns{\portuguese at variant}
+}%
+
+\def\captionsportuguese at portuges{%
   \def\refname{Referências}%
   \def\abstractname{Resumo}%
   \def\bibname{Bibliografia}%
@@ -7466,7 +8938,6 @@
   \def\indexname{Índice}%
   \def\figurename{Figura}%
   \def\tablename{Tabela}%
-  %\def\thepart{}%
   \def\partname{Parte}%
   \def\pagename{Página}%
   \def\seename{ver}%
@@ -7476,18 +8947,58 @@
   \def\headtoname{Para}%
   \def\proofname{Demonstração}%
   \def\glossaryname{Glossário}%
-  }
+}
 
-\def\dateportuges{%   
+\def\captionsportuguese at brazil{%
+   \def\refname{Referências}%
+   \def\abstractname{Resumo}%
+   \def\bibname{Referências Bibliográficas}%
+   \def\prefacename{Prefácio}%
+   \def\chaptername{Capítulo}%
+   \def\appendixname{Apêndice}%
+   \def\contentsname{Sumário}%
+   \def\listfigurename{Lista de Figuras}%
+   \def\listtablename{Lista de Tabelas}%
+   \def\indexname{Índice Remissivo}%
+   \def\figurename{Figura}%
+   \def\tablename{Tabela}%
+   \def\partname{Parte}%
+   \def\pagename{Página}%
+   \def\seename{veja}%
+   \def\alsoname{veja também}%
+   \def\enclname{Anexo}%
+   \def\ccname{Cópia para}%
+   \def\headtoname{Para}%
+   \def\proofname{Demonstração}%
+   \def\glossaryname{Glossário}%
+}
+
+\def\captionsportuguese{%
+  \csname captionsportuguese@\portuguese at variant\endcsname%
+}
+
+\def\dateportuguese at portuges{%   
   \def\today{\number\day\space de\space\ifcase\month\or
     Janeiro\or Fevereiro\or Março\or Abril\or Maio\or Junho\or
     Julho\or Agosto\or Setembro\or Outubro\or Novembro\or Dezembro\fi
     \space de\space\number\year}%
-  }
+}
+
+
+\def\dateportuguese at brazil{%   
+   \def\today{\number\day\space de\space\ifcase\month\or
+      janeiro\or fevereiro\or março\or abril\or maio\or junho\or
+      julho\or agosto\or setembro\or outubro\or novembro\or dezembro%
+      \fi\space de\space\number\year}%
+}
+
+\def\dateportuguese{%
+  \csname dateportuguese@\portuguese at variant\endcsname%
+}
      
 %    \end{macrocode}
 % \iffalse
-%</gloss-portuges.ldf>
+%</gloss-portuguese.ldf>
 %<*gloss-romanian.ldf>
 % \fi
 % \clearpage
@@ -7499,6 +9010,7 @@
 \PolyglossiaSetup{romanian}{
   hyphennames={romanian},
   hyphenmins={2,2},
+  langtag=ROM,
   fontsetup=true,
 }
 
@@ -7549,6 +9061,7 @@
 \PolyglossiaSetup{romansh}{%
   hyphennames={romansh},
   hyphenmins={2,2},
+  langtag=RMS,
   indentfirst=true,
   fontsetup=true,
 }
@@ -7595,6 +9108,9 @@
 % \subsection{gloss-russian.ldf}
 %    \begin{macrocode}
 \ProvidesFile{gloss-russian.ldf}[polyglossia: module for russian]
+
+\RequirePackage{cyrillicnumbers}
+
 \PolyglossiaSetup{russian}{
   script=Cyrillic,
   scripttag=cyrl,
@@ -7602,22 +9118,30 @@
   hyphennames={russian},
   hyphenmins={2,2},
   frenchspacing=true,
-  fontsetup
-  %TODO localalph={russian at alph,russian at Alph}
+  fontsetup,
+  localnumeral=russiannumerals,
+  Localnumeral=Russiannumerals
 }
 
+\newif\if at russian@modern
 \define at key{russian}{spelling}[modern]{%
   \ifstrequal{#1}{old}%
-    {\def\captionsrussian{\captionsrussian at old}%
-     \def\daterussian{\daterussian at old}}%
-    {\def\captionsrussian{\captionsrussian at modern}%
-     \def\daterussian{\daterussian at modern}}%
+    {\@russian at modernfalse}%
+    {\@russian at moderntrue}%
 }
 
+\def\captionsrussian{%
+   \if at russian@modern\captionsrussian at modern\else\captionsrussian at old\fi%
+}%
+
+\def\daterussian{%
+   \if at russian@modern\daterussian at modern\else\daterussian at old\fi%
+}%
+
 \newif\ifcyrillic at numerals
-\define at key{russian}{numerals}[latin]{%
+\define at key{russian}{numerals}[arabic]{%
    \ifstrequal{#1}{cyrillic}%
-      {\cyrillic at numeralstrue}
+      {\cyrillic at numeralstrue}%
       {\cyrillic at numeralsfalse}%
 }
 
@@ -7634,6 +9158,7 @@
 \ifcsundef{initiate at active@char}{%
   \input{babelsh.def}%
   \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\russian at shorthands{%
@@ -7649,8 +9174,8 @@
   \declare at shorthand{russian}{"|}{\textormath{\nobreak\discretionary{-}{}{\kern.03em}\allowhyphens}{}}%
   \declare at shorthand{russian}{"-}{%
     \def\russian at sh@tmp{%
-      \if\russian at sh@next-\expandafter\russian at sh@emdash
-      \else\expandafter\russian at sh@hyphen\fi
+      \if\russian at sh@next-\expandafter\russian at sh@emdash%
+      \else\expandafter\russian at sh@hyphen\fi%
     }%
     \futurelet\russian at sh@next\russian at sh@tmp}%
   \def\russian at sh@hyphen{%
@@ -7669,7 +9194,7 @@
   \def\@Ccdash{\leavevmode
    \nobreak\cyrdash\nobreak\hskip.35em\ignorespaces}%
   \ifx\cyrdash\undefined
-    \def\cyrdash{\hbox to.8em{--\hss--}}
+    \def\cyrdash{\hbox to.8em{--\hss--}}%
   \fi
   \declare at shorthand{russian}{",}{\nobreak\hskip.2em\ignorespaces}%
 }
@@ -7719,7 +9244,8 @@
       октября\or
       ноября\or
       декабря\fi%
-      \space \number\year\space г.}}
+      \space \number\year\space г.}%
+}
      
 \def\captionsrussian at old{%
    \def\prefacename{Предисловіе}%
@@ -7745,7 +9271,8 @@
    \def\seename{см.}%
    \def\alsoname{см.~также}%
    \def\proofname{Доказательство}%
-}  
+}
+
 \def\daterussian at old{%
       \def\today{\number\day%
       \space\ifcase\month\or%
@@ -7761,7 +9288,8 @@
       октября\or
       ноября\or
       декабря\fi%
-      \space \number\year\space г.}}
+      \space \number\year\space г.}%
+}
 
 % The following is based on some ideas from ruscor.sty
 \def\russian at capsformat{%
@@ -7768,11 +9296,16 @@
    \ifdef{\KOMAScript}{%
       \ifdef{\chapterformat}{%
         \renewcommand{\chapterformat}{\prechapter\thechapter\postchapter}}{}%
-      \renewcommand{\sectionformat}{\presection\thesection\postsection}%
-      \renewcommand{\subsectionformat}{\presubsection\thesubsection\postsubsection}%
-      \renewcommand{\subsubsectionformat}{\presubsubsection\thesubsubsection\postsubsubsection}%
-      \renewcommand{\paragraphformat}{\preparagraph\theparagraph\postparagraph}%
-      \renewcommand{\subparagraphformat}{\presubparagraph\thesubparagraph\postsubparagraph}%
+      \ifdef{\sectionformat}{%
+        \renewcommand{\sectionformat}{\presection\thesection\postsection}}{}%
+      \ifdef{\subsectionformat}{%
+        \renewcommand{\subsectionformat}{\presubsection\thesubsection\postsubsection}}{}%
+      \ifdef{\subsubsectionformat}{%
+        \renewcommand{\subsubsectionformat}{\presubsubsection\thesubsubsection\postsubsubsection}}{}%
+      \ifdef{\paragraphformat}{%
+        \renewcommand{\paragraphformat}{\preparagraph\theparagraph\postparagraph}}{}%
+      \ifdef{\subparagraphformat}{%
+        \renewcommand{\subparagraphformat}{\presubparagraph\thesubparagraph\postsubparagraph}}{}%
    }{%
       \def\@seccntformat##1{\csname pre##1\endcsname%
          \csname the##1\endcsname%
@@ -7790,27 +9323,58 @@
    \def\presubsection{}%
    \def\presubsubsection{}%
    \def\preparagraph{}%
-   \def\presubparagraph{}}
+   \def\presubparagraph{}%
+}
 
-\def\Asbuk#1{\expandafter\russian at Alph\csname c@#1\endcsname}
-\def\russian at 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 at ill@value{#1}{russian at Alph}\fi}
-\def\asbuk#1{\expandafter\russian at alph\csname c@#1\endcsname}
-\def\russian at 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 at ill@value{#1}{russian at alph}\fi}
+\newcommand{\russiannumerals}[2]{\russiannumber{#2}}
+\newcommand{\Russiannumerals}[2]{\Russiannumber{#2}}
 
+\def\russiannumber#1{%
+  \ifcyrillic at numerals
+    \cyr at alph{#1}%
+  \else
+    \number#1%
+  \fi%
+}
+
+\def\Russiannumber#1{%
+  \ifcyrillic at numerals
+    \cyr at Alph{#1}%
+  \else
+    \number#1%
+  \fi%
+}
+
+\let\russiannumeral=\russiannumber
+\let\Russiannumeral=\Russiannumber
+
+\def\Asbuk#1{\expandafter\cyr at Alph\csname c@#1\endcsname}
+
+\def\asbuk#1{\expandafter\cyr at alph\csname c@#1\endcsname}
+
+% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
+% thus ends at 30. We now use proper cyrillic numbering.
+
+%\def\russian at 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 at ill@value{#1}{russian at Alph}\fi}
+
+%\def\russian at 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 at ill@value{#1}{russian at alph}\fi}
+
 \def\russian at numbers{%
-   \let\latin at alph\@alph%
-   \let\latin at Alph\@Alph%
-   \ifcyrillic at numerals
-     \let\@alph\russian at alph%
-     \let\@Alph\russian at Alph%
+   \let\latin at alph\@alph
+   \let\latin at Alph\@Alph
+   \ifcyrillic at numerals%
+     \def\russian at alph##1{\expandafter\russiannumeral\expandafter{\the##1}}%
+     \def\russian at Alph##1{\expandafter\Russiannumeral\expandafter{\the##1}}%
+      \let\@alph\russian at alph%
+      \let\@Alph\russian at Alph%
    \fi
 }
 
@@ -7823,22 +9387,27 @@
    \ifdef{\KOMAScript}{%
       \ifdef{\chapterformat}{%
         \renewcommand{\chapterformat}{\thechapter\autodot\enskip}}{}%
-      \renewcommand{\sectionformat}{\thesection\autodot\enskip}%
-      \renewcommand{\subsectionformat}{\thesubsection\autodot\enskip}%
-      \renewcommand{\subsubsectionformat}{\thesubsubsection\autodot\enskip}%
-      \renewcommand{\paragraphformat}{\theparagraph\autodot\enskip}%
-      \renewcommand{\subparagraphformat}{\thesubparagraph\autodot\enskip}%
+      \ifdef{\sectionformat}{%
+        \renewcommand{\sectionformat}{\thesection\autodot\enskip}}{}%
+      \ifdef{\subsectionformat}{%
+        \renewcommand{\subsectionformat}{\thesubsection\autodot\enskip}}{}%
+      \ifdef{\subsubsectionformat}{%
+        \renewcommand{\subsubsectionformat}{\thesubsubsection\autodot\enskip}}{}%
+      \ifdef{\paragraphformat}{%
+        \renewcommand{\paragraphformat}{\theparagraph\autodot\enskip}}{}%
+      \ifdef{\subparagraphformat}{%
+        \renewcommand{\subparagraphformat}{\thesubparagraph\autodot\enskip}}{}%
    }{%
       \def\@seccntformat##1{\csname the##1\endcsname\quad}% = LaTeX kernel
    }%
-   \ifcyrillic at numerals\norussian at numbers\fi
+   \ifcyrillic at numerals\norussian at numbers\fi%
    \norussian at shorthands%
 }
 
 \def\blockextras at russian{%
    \russian at capsformat%
-   \ifcyrillic at numerals\russian at numbers\fi
-   \ifrussian at babelshorthands\russian at shorthands\fi
+   \ifcyrillic at numerals\russian at numbers\fi%
+   \ifrussian at babelshorthands\russian at shorthands\fi%
 }
 
 \def\inlineextras at russian{%
@@ -7868,21 +9437,46 @@
 %    \end{macrocode}
 % \iffalse
 %</gloss-russian.ldf>
-%<*gloss-samin.ldf>
+%<*gloss-sami.ldf>
 % \fi
 % \clearpage
 % 
-% \subsection{gloss-samin.ldf}
+% \subsection{gloss-sami.ldf}
 %    \begin{macrocode}
-\ProvidesFile{gloss-samin.ldf}[polyglossia: module for samin]
+\ProvidesFile{gloss-sami.ldf}[polyglossia: module for sami]
 
-\PolyglossiaSetup{samin}{
+\PolyglossiaSetup{sami}{
+  babelname=samin,
   hyphennames={samin},
   hyphenmins={2,2},
+  language={Northern Sami},
+  langtag=NSM,
   fontsetup=true,
 }
 
-\def\captionssamin{%
+% TODO: Add other Sami varieties
+\def\sami at variant{northern}
+%\define at choicekey*+{sami}{variant}[\val\nr]{northern}[nothern]{%
+%   \ifcase\nr\relax
+%      % northern:
+%      \def\sami at variant{samin}%
+%      \SetLanguageKeys{sami}{language=Northern Sami,langtag=NSM}%
+%      \xpg at fontsetup@latin{sami}%
+%   \or
+%      % other:
+%      \def\sami at variant{}%
+%      \SetLanguageKeys{sami}{language= Sami,langtag=}%
+%      \xpg at fontsetup@latin{sami}%
+%   \fi
+%   \xpg at info{Option: sami, variant=\val}%
+%}{\xpg at warning{Unknown sami variant `#1'}}
+
+
+%\def\sami at language{%
+%   \polyglossia at setup@language at patterns{\sami at variant}
+%}%
+
+\def\captionssami at northern{%
    \def\refname{Čujuhusat}%
    \def\abstractname{Čoahkkáigeassu}%
    \def\bibname{Girjjálašvuohta}%
@@ -7905,8 +9499,13 @@
    \def\headtoname{Vuostáiváldi}%
    \def\proofname{Duođaštus}%
    \def\glossaryname{Sátnelistu}%
-   }
-\def\datesamin{%
+}
+
+\def\captionssami{%
+  \csname captionssami@\sami at variant\endcsname%
+}
+
+\def\datesami at northern{%
   \def\today{\ifcase\month\or
     ođđajagemánu\or
     guovvamánu\or
@@ -7921,10 +9520,41 @@
     skábmamánu\or
     juovlamánu\fi
     \space\number\day.~b.\space\number\year}%
-  }
+}
 
+\def\datesami{%
+  \csname datesami@\sami at variant\endcsname%
+}
+
 %    \end{macrocode}
 % \iffalse
+%</gloss-sami.ldf>
+%<*gloss-samin.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-samin.ldf}
+%    \begin{macrocode}
+\ProvidesFile{gloss-samin.ldf}[polyglossia: module for samin]
+
+% We only provide this gloss for babel compatibility. Since samin is 
+% a sami variety, we use 'sami' with variant 'northern' now.
+
+\input{gloss-sami.ldf}
+
+\PolyglossiaSetup{samin}{
+  hyphennames={samin},
+  hyphenmins={2,2},
+  language={Northern Sami},
+  langtag=NSM,
+  fontsetup=true,
+}
+
+\let\captionssamin\captionssami at nothern
+\let\datesamin\datesami at nothern
+
+%    \end{macrocode}
+% \iffalse
 %</gloss-samin.ldf>
 %<*gloss-sanskrit.ldf>
 % \fi
@@ -7933,6 +9563,13 @@
 % \subsection{gloss-sanskrit.ldf}
 %    \begin{macrocode}
 \ProvidesFile{gloss-sanskrit.ldf}[polyglossia: module for sanskrit]
+\ifluatex
+  \xpg at warning{Sanskrit is not supported with LuaTeX.\MessageBreak
+I will proceed with the compilation, but\MessageBreak
+the output is not guaranteed to be correct\MessageBreak
+and may look very wrong.}
+\fi
+
 \RequirePackage{devanagaridigits}
 
 \PolyglossiaSetup{sanskrit}{
@@ -7941,11 +9578,10 @@
   hyphenmins={1,3},
   frenchspacing=true,
   fontsetup=false, % will be done below
-  %TODO localnumber=sanskritnumber
+  localnumeral=sanskritnumerals
 }
 
 \define at key{sanskrit}{Script}[Devanagari]{%
-  \setkeys[xpg at setup]{sanskrit}{script=#1}%
   \ifcsdef{fontsetup at sanskrit@#1}%
     {\csname fontsetup at sanskrit@#1\endcsname}%
     {\xpg at error{`#1' is not a valid script for Sanskrit}%
@@ -7953,65 +9589,82 @@
 }
 
 \def\fontsetup at sanskrit@Devanagari{%
-  \def\xpg at scripttag@sanskrit{deva}%
+  \SetLanguageKeys{sanskrit}{scripttag=deva,script=Devanagari}
   \xpg at fontsetup@nonlatin{sanskrit}}
 \def\fontsetup at sanskrit@Gujarati{%
-  \def\xpg at scripttag@sanskrit{gujr}%
+  \SetLanguageKeys{sanskrit}{scripttag=gujr,script=Gujarati}
   \xpg at fontsetup@nonlatin{sanskrit}}
 \def\fontsetup at sanskrit@Malayalam{%
-  \def\xpg at scripttag@sanskrit{mlym}%
+  \SetLanguageKeys{sanskrit}{scripttag=mlym,script=Malayalam}
   \xpg at fontsetup@nonlatin{sanskrit}}
 \def\fontsetup at sanskrit@Bengali{%
-  \def\xpg at scripttag@sanskrit{beng}%
+  \SetLanguageKeys{sanskrit}{scripttag=beng,script=Bengali}
   \xpg at fontsetup@nonlatin{sanskrit}}
 \def\fontsetup at sanskrit@Kannada{%
-  \def\xpg at scripttag@sanskrit{knda}%
+  \SetLanguageKeys{sanskrit}{scripttag=knda,script=Kannada}
   \xpg at fontsetup@nonlatin{sanskrit}}
 \def\fontsetup at sanskrit@Telugu{%
-  \def\xpg at scripttag@sanskrit{telu}%
+  \SetLanguageKeys{sanskrit}{scripttag=telu,script=Telugu}
   \xpg at fontsetup@nonlatin{sanskrit}}
-%% DW
 \def\fontsetup at sanskrit@Latin{%
-    \def\xpg at scripttag@sanskrit{latn}%
-    \xpg at fontsetup@latin{sanskrit}}
-%% DW
+  \SetLanguageKeys{sanskrit}{scripttag=latn,script=Latin}
+  \xpg at fontsetup@latin{sanskrit}}
 
 \setkeys{sanskrit}{Script} %sets the default for Devanagari
 
-%% TODO option for numerals (Devanagari or Western)
-%\def\tmp at western{Western}
-%\newif\ifsanskrit at devanagari@numerals
-%\sanskrit at devanagari@numeralstrue
-%
-%\define at key{sanskrit}{numerals}[Devanagari]{%
-%  \def\@tmpa{#1}%
-%  \ifx\@tmpa\tmp at western
-%    \sanskrit at devanagari@numeralsfalse
-%  \fi}
+\def\tmp at western{Western}
+\newif\ifsanskrit at devanagari@numerals
+\sanskrit at devanagari@numeralstrue
 
-\newXeTeXintercharclass\sanskrit at punctthin % ! ? ; : danda double_danda
+\define at key{sanskrit}{numerals}[Devanagari]{%
+  \def\@tmpa{#1}%
+  \ifx\@tmpa\tmp at western
+    \sanskrit at devanagari@numeralsfalse
+  \fi%
+}
 
+\newcommand{\sanskritnumerals}[2]{\sanskritnumber{#2}}
+
+\def\sanskritnumber#1{%
+  \ifsanskrit at devanagari@numerals
+    \devanagaridigits{\number#1}%
+  \else
+    \number#1%
+  \fi%
+}
+
+% FIXME: Support LuaTeX
+\ifxetex
+  \newXeTeXintercharclass\sanskrit at punctthin % ! ? ; : danda double_danda
+\fi
+
 \def\sanskrit at punctthinspace{{\unskip\thinspace}}
 
 \def\sanskrit at punctuation{%
-  \XeTeXinterchartokenstate=1%
-  \XeTeXcharclass `\! \sanskrit at punctthin
-  \XeTeXcharclass `\? \sanskrit at punctthin
-  \XeTeXcharclass `\; \sanskrit at punctthin
-  \XeTeXcharclass `\: \sanskrit at punctthin
-  \XeTeXcharclass `\। \sanskrit at punctthin
-  \XeTeXcharclass `\॥ \sanskrit at punctthin
-  \XeTeXinterchartoks \z@ \sanskrit at punctthin = \sanskrit at punctthinspace
+  % FIXME: Support LuaTeX
+  \ifxetex
+    \XeTeXinterchartokenstate=1%
+    \XeTeXcharclass `\! \sanskrit at punctthin
+    \XeTeXcharclass `\? \sanskrit at punctthin
+    \XeTeXcharclass `\; \sanskrit at punctthin
+    \XeTeXcharclass `\: \sanskrit at punctthin
+    \XeTeXcharclass `\। \sanskrit at punctthin
+    \XeTeXcharclass `\॥ \sanskrit at punctthin
+    \XeTeXinterchartoks \z@ \sanskrit at punctthin = \sanskrit at punctthinspace
+  \fi
 }
 
 \def\nosanskrit at punctuation{%
-  \XeTeXcharclass `\! \z@
-  \XeTeXcharclass `\? \z@
-  \XeTeXcharclass `\; \z@
-  \XeTeXcharclass `\: \z@
-  \XeTeXcharclass `\। \z@
-  \XeTeXcharclass `\॥ \z@
-  \XeTeXinterchartokenstate=0%
+  % FIXME: Support LuaTeX
+  \ifxetex
+    \XeTeXcharclass `\! \z@
+    \XeTeXcharclass `\? \z@
+    \XeTeXcharclass `\; \z@
+    \XeTeXcharclass `\: \z@
+    \XeTeXcharclass `\। \z@
+    \XeTeXcharclass `\॥ \z@
+    \XeTeXinterchartokenstate=0%
+  \fi
 }
 
 \def\noextras at sanskrit{%
@@ -8033,47 +9686,21 @@
 %    \begin{macrocode}
 \ProvidesFile{gloss-scottish.ldf}[polyglossia: module for scottish]
 
+% We only provide this gloss for babel compatibility. Since scottish is 
+% a gaelic variety, we use 'gaelic' with variant 'scottish' now.
+
+\input{gloss-gaelic.ldf}
+
 \PolyglossiaSetup{scottish}{
   hyphennames={scottish},
   hyphenmins={2,2},
+  langtag=GAE,
   fontsetup=true,
 }
 
-\def\captionsscottish{%
-   \def\refname{Iomraidh}%
-   \def\abstractname{Brìgh}%
-   \def\bibname{Leabhraichean}%
-   \def\prefacename{Preface}%    <-- needs translation
-   \def\chaptername{Caibideil}%
-   \def\appendixname{Ath-sgr`ıobhadh}%
-   \def\contentsname{Clàr-obrach}%
-   \def\listfigurename{Liosta Dhealbh}%
-   \def\listtablename{Liosta Chlàr}%
-   \def\indexname{Clàr-innse}%
-   \def\figurename{Dealbh}%
-   \def\tablename{Clàr}%
-   %\def\thepart{}%
-   \def\partname{Cuid}%
-   \def\pagename{t.d.}%
-   \def\seename{see}%    <-- needs translation
-   \def\alsoname{see also}%    <-- needs translation
-   \def\enclname{a-staigh}%
-   \def\ccname{lethbhreac gu}%
-   \def\headtoname{gu}%
-   \def\proofname{Proof}%    <-- needs translation 
-   \def\glossaryname{Glossary}%    <-- needs translation
-   }
+\let\captionsscottish\captionsgaelic at scottish
+\let\datescottish\dategaelic at scottish
 
-\def\datescottish{%
-   \def\today{%
-    \number\day\space \ifcase\month\or
-    am Faoilteach\or an Gearran\or am Màrt\or an Giblean\or
-    an Cèitean\or an t-Òg mhios\or an t-Iuchar\or
-    Lùnasdal\or an Sultuine\or an Dàmhar\or
-    an t-Samhainn\or an Dubhlachd\fi
-    \space \number\year}%
-    }
-
 %    \end{macrocode}
 % \iffalse
 %</gloss-scottish.ldf>
@@ -8089,29 +9716,33 @@
 %% same thing for all languages that have a "script" key !
 %% BETTER APPROACH: see gloss-sanskrit!
 
+\RequirePackage{cyrillicnumbers}
+
 \PolyglossiaSetup{serbian}{
   langtag=SRB,
   hyphennames={serbian},
   hyphenmins={2,2},
   indentfirst=true,
-  fontsetup=false
+  fontsetup=false,
+  localnumeral=serbiannumerals,
+  Localnumeral=Serbiannumerals
   %TODO localalph
 }
 
 \newif\if at serbian@cyr
 
-\define at key{serbian}{Script}[Cyrillic]{% TODO FIXDOC: keyname is CHANGED: script -> Script !!!
+\define at key{serbian}{Script}[Cyrillic]{%
   \ifstrequal{#1}{Cyrillic}%
     {\@serbian at cyrtrue
-     \setkeys[xpg at setup]{serbian}{script=Cyrillic}%
-     \def\xpg at scripttag@serbian{cyrl}%
+     \SetLanguageKeys{serbian}{scripttag=cyrl,script=Cyrillic,babelname=serbianc}
      \xpg at fontsetup@nonlatin{serbian}%
     }%
     {\ifstrequal{#1}{Latin}%
       {\@serbian at cyrfalse
-      \xpg at fontsetup@latin{serbian}%
-      %TODO \def\serbian at language{\language=\l at serbianlat}%
-      % or should we use Croatian patterns as a fallback for the time being???
+       \SetLanguageKeys{serbian}{scripttag=latn,script=Latin}
+       \xpg at fontsetup@latin{serbian}%
+       %TODO \def\serbian at language{\language=\l at serbianlat}%
+       % or should we use Croatian patterns as a fallback for the time being???
       }%
       {\xpg at error{Unknown script `#1' for Serbian language\MessageBreak
       Valid values are "Cyrillic" and "Latin"}}%
@@ -8119,15 +9750,24 @@
 }
 \define at key{serbian}{script}[Cyrillic]{\setkeys{serbian}{Script=#1}}
 
-\setkeys{serbian}{Script}
+\newif\ifserbian at numerals
+\define at key{serbian}{numerals}[arabic]{%
+   \ifstrequal{#1}{latin}{\serbian at numeralsfalse}{%
+       \ifstrequal{#1}{cyrillic}%
+          {\serbian at numeralstrue}
+          {\serbian at numeralsfalse}%
+   }%
+}
 
+\setkeys{serbian}{Script,numerals}
+
 \def\captionsserbian{%
    \if at serbian@cyr\captionsserbian at cyr\else\captionsserbian at lat\fi
-   }
+}
 
 \def\dateserbian{%
    \if at serbian@cyr\dateserbian at cyr\else\dateserbian at lat\fi
-   }
+}
 
 \def\captionsserbian at lat{%
    \def\refname{Bibliografija}%
@@ -8156,13 +9796,14 @@
    \def\headtoname{Prima}%
    \def\proofname{Dokaz}%
    \def\glossaryname{Rečnik nepoznatih reči}%
-   }
+}
+
 \def\dateserbian at lat{%
    \def\today{\number\day .~\ifcase\month\or
     januar\or februar\or mart\or april\or maj\or
     jun\or jul\or avgust\or septembar\or oktobar\or novembar\or
     decembar\fi \space \number\year.}%
-    }
+}
 
 \def\captionsserbian at cyr{%
    \def\refname{Библиографија}%
@@ -8190,14 +9831,82 @@
    \def\headtoname{Прима}%
    \def\proofname{Доказ}%
    \def\glossaryname{Речник непознатих речи}%
-   }
+}
+
 \def\dateserbian at cyr{%
    \def\today{\number\day .~\ifcase\month\or
     јануар\or фебруар\or март\or април\or мај\or
     јун\or јул\or август\or септембар\or октобар\or новембар\or
     децембар\fi \space \number\year.}%
-    }
+}
 
+
+\newcommand{\serbiannumerals}[2]{\serbiannumber{#2}}
+\newcommand{\Serbiannumerals}[2]{\Serbiannumber{#2}}
+
+\def\serbiannumber#1{%
+  \ifserbian at numerals
+    \cyr at alph{#1}%
+  \else
+    \number#1%
+  \fi
+}
+
+\def\Serbiannumber#1{%
+  \ifserbian at numerals
+    \cyr at Alph{#1}%
+  \else
+    \number#1%
+  \fi
+}
+
+\let\serbiannumeral=\serbiannumber
+\let\Serbiannumeral=\Serbiannumber
+
+\def\serbian at numbers{%
+   \let\latin at alph\@alph
+   \let\latin at Alph\@Alph
+   \ifserbian at numerals
+     \def\serbian at alph##1{\expandafter\serbiannumeral\expandafter{\the##1}}%
+     \def\serbian at Alph##1{\expandafter\Serbiannumeral\expandafter{\the##1}}%
+      \let\@alph\serbian at alph%
+      \let\@Alph\serbian at Alph%
+   \fi
+}
+
+\def\noserbian at numbers{%
+   \let\@alph\latin at alph
+   \let\@Alph\latin at Alph
+}
+
+\def\blockextras at serbian{%
+   \ifserbian at numerals\serbian at numbers\fi
+}
+ 
+\def\noextras at serbian{%
+   \ifserbian at numerals\noserbian at numbers\fi
+}
+
+\def\Asbuk#1{\expandafter\cyr at Alph\csname c@#1\endcsname}
+
+\def\asbuk#1{\expandafter\cyr at alph\csname c@#1\endcsname}
+
+% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
+% thus ends at 30. We now use proper cyrillic numbering.
+
+%\def\cyr at 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 Ч\or Џ\or Ш\else\xpg at ill@value{#1}{cyr at Alph}\fi}
+
+%\def\cyr at 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 ч\or џ\or ш\else\xpg at ill@value{#1}{cyr at alph}\fi}
+
+ 
 %    \end{macrocode}
 % \iffalse
 %</gloss-serbian.ldf>
@@ -8212,6 +9921,7 @@
 \PolyglossiaSetup{slovak}{
   hyphennames={slovak},
   hyphenmins={2,2},
+  langtag=SKY,
   fontsetup=true,
 }
 
@@ -8261,7 +9971,9 @@
 
 \PolyglossiaSetup{slovenian}{
   hyphennames={slovenian,slovene},
+  babelname=slovene,
   hyphenmins={2,2},
+  langtag=SLV,
   fontsetup=true,
 }
 
@@ -8319,15 +10031,189 @@
 \def\Abeceda#1{\expandafter\slovenian at Alph\csname c@#1\endcsname}
 
 \def\setlocalalph{%
-  \def\extras at slovenian{\let\savealph\alph\let\saveAlph\Alph\let\alph\abeceda\let\Alph\Abeceda}
+  \def\extras at slovenian{\let\alph\abeceda\let\Alph\Abeceda}
   \def\blockextras at slovenian{\extras at slovenian}
   \def\inlineextras at slovenian{\extras at slovenian}
-  \def\noextras at slovenian{\let\alph\savealph\let\Alph\saveAlph}
+  \def\noextras at slovenian{\let\alph\latinalph\let\Alph\latinAlph}
 }
 
 %    \end{macrocode}
 % \iffalse
 %</gloss-slovenian.ldf>
+%<*gloss-sorbian.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-sorbian.ldf}
+%    \begin{macrocode}
+\ProvidesFile{gloss-sorbian.ldf}[polyglossia: module for sorbian]
+
+\PolyglossiaSetup{sorbian}{
+  language=Upper Sorbian,
+  babelname=uppersorbian,
+  hyphennames={usorbian,uppersorbian},
+  langtag=USB,
+  hyphenmins={2,2},
+  fontsetup=true,
+}
+
+\def\sorbian at variant{usorbian}
+\define at choicekey*+{sorbian}{variant}[\val\nr]{upper,lower}[upper]{%
+   \ifcase\nr\relax
+      % upper:
+      \def\sorbian at variant{usorbian}%
+      \SetLanguageKeys{sorbian}{language=Upper Sorbian,langtag=USB,babelname=uppersorbian}%
+      \xpg at fontsetup@latin{sorbian}%
+      % Check if \l at usorbian is defined. If not, try to set it to some variety
+      % (specific order as in the csv list below), or null language if everything fails
+      \xpg at ifdefined{usorbian}{}{%
+        \def\do##1{%
+            \xpg at ifdefined{##1}%
+              {\csletcs{l at usorbian}{l@##1}\listbreak}%
+              {}%
+        }%
+        \docsvlist{uppersorbian}
+        \xpg at ifdefined{usorbian}{}{%
+                 \xpg at warning{No hyphenation patterns for Upper Sorbian found\MessageBreak
+                              I will use the 'null' language instead}%
+                 \adddialect\l at usorbian0%
+        }
+      }%
+   \or
+      % lower:
+      \def\sorbian at variant{lsorbian}%
+      \SetLanguageKeys{sorbian}{language=Lower Sorbian,langtag=LSB,babelname=lowersorbian}%
+      \xpg at fontsetup@latin{sorbian}%
+      % Check if \l at lsorbian is defined. If not, try to set it to some variety
+      % (specific order as in the csv list below), or null language if everything fails
+      \xpg at ifdefined{lsorbian}{}{%
+        \def\do##1{%
+           \xpg at ifdefined{##1}%
+              {\csletcs{l at lsorbian}{l@##1}\listbreak}%
+              {}%
+        }%
+        \docsvlist{lowersorbian,Lsorbian,usorbian,uppersorbian}
+        \xpg at ifdefined{lsorbian}{}{%
+                 \xpg at warning{No hyphenation patterns for Lower Sorbian found\MessageBreak
+                              I will use the 'null' language instead}%
+                 \adddialect\l at lsorbian0%
+        }
+     }%
+   \fi
+   \xpg at info{Option: sorbian, variant=\val}%
+}{\xpg at warning{Unknown sorbian variant `#1'}}
+
+
+\define at boolkey{sorbian}[sorbian@]{olddate}[true]{}
+
+\setkeys{sorbian}{variant}
+
+
+\def\sorbian at language{%
+   \polyglossia at setup@language at patterns{\sorbian at variant}%
+}%
+
+
+\def\captionssorbian at lsorbian{%
+   \def\refname{Referency}%
+   \def\abstractname{Abstrakt}%
+   \def\bibname{Literatura}%
+   \def\prefacename{Zawod}%
+   \def\chaptername{Kapitl}%
+   \def\appendixname{Dodawki}%
+   \def\contentsname{Wopśimjeśe}%
+   \def\listfigurename{Zapis wobrazow}%
+   \def\listtablename{Zapis tabulkow}%
+   \def\indexname{Indeks}%
+   \def\figurename{Wobraz}%
+   \def\tablename{Tabulka}%
+   %\def\thepart{}%
+   \def\partname{Źěl}%
+   \def\pagename{Strona}%
+   \def\seename{gl.}%
+   \def\alsoname{gl.~teke}%
+   \def\enclname{Pśiłoga}%
+   \def\ccname{CC}%
+   \def\headtoname{Komu}%
+   \def\proofname{Proof}%
+   \def\glossaryname{Glossary}%
+}
+
+\def\captionssorbian at usorbian{%
+   \def\refname{Referency}%
+   \def\abstractname{Abstrakt}%
+   \def\bibname{Literatura}%
+   \def\prefacename{Zawod}%
+   \def\chaptername{Kapitl}%
+   \def\appendixname{Dodawki}%
+   \def\contentsname{Wobsah}%
+   \def\listfigurename{Zapis wobrazow}%
+   \def\listtablename{Zapis tabulkow}%
+   \def\indexname{Indeks}%
+   \def\figurename{Wobraz}%
+   \def\tablename{Tabulka}%
+   %\def\thepart{}%
+   \def\partname{Dźěl}%
+   \def\pagename{Strona}%
+   \def\seename{hl.}%
+   \def\alsoname{hl.~tež}%
+   \def\enclname{Přłoha}%
+   \def\ccname{CC}%
+   \def\headtoname{Komu}%
+   \def\proofname{Proof}% <-- needs translation
+   \def\glossaryname{Glossary}% <-- needs translation
+}%
+
+\def\captionssorbian{%
+  \csname captionssorbian@\sorbian at variant\endcsname%
+}
+
+\def\datesorbian at lsorbian{%
+    \def\oldtoday{%
+      \number\day.~\ifcase\month\or
+      wjelikego rožka\or małego rožka\or nalětnika\or
+      jatšownika\or rožownika\or smažnika\or pražnika\or
+      žnjeńca\or požnjeńca\or winowca\or nazymnika\or 
+      godownika\fi\space \number\year}%
+    \def\today{%
+      \ifsorbian at olddate
+        \oldtoday%
+      \else
+        \number\day.~\ifcase\month\or
+        januara\or februara\or měrca\or apryla\or maja\or
+        junija\or julija\or awgusta\or septembra\or oktobra\or
+        nowembra\or decembra\fi
+        \space \number\year%
+      \fi
+   }%
+}
+
+\def\datesorbian at usorbian{%
+  \def\oldtoday{\number\day.~\ifcase\month\or
+    wulkeho róžka\or małeho róžka\or nalětnika\or
+    jutrownika\or róžownika\or  smažnika\or pražnika\or
+    žnjenca\or požnjenca\or winowca\or nazymnika\or
+    hodownika\fi \space \number\year}%
+  \def\today{%
+    \ifsorbian at olddate
+      \oldtoday%
+    \else
+      \number\day.~\ifcase\month\or
+      januara\or februara\or měrca\or apryla\or meje\or junija\or
+      julija\or awgusta\or septembra\or oktobra\or
+      nowembra\or decembra\fi
+      \space \number\year%
+    \fi
+  }%
+}
+
+\def\datesorbian{%
+  \csname datesorbian@\sorbian at variant\endcsname%
+}
+
+%    \end{macrocode}
+% \iffalse
+%</gloss-sorbian.ldf>
 %<*gloss-spanish.ldf>
 % \fi
 % \clearpage
@@ -8338,6 +10224,7 @@
 \PolyglossiaSetup{spanish}{
   hyphennames={spanish},
   hyphenmins={2,2},
+  langtag=ESP,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,
@@ -8388,6 +10275,7 @@
 \PolyglossiaSetup{swedish}{
   hyphennames={swedish},
   hyphenmins={2,2},
+  langtag=SVE,
   frenchspacing=true,
   fontsetup=true,
 }
@@ -8452,9 +10340,11 @@
 \PolyglossiaSetup{syriac}{
   script=Syriac,
   scripttag=syrc,
+  langtag=SYR,
   direction=RL,
   hyphennames={syriac,nohyphenation},
   fontsetup=true,
+  localnumeral=syriacnumerals
   %TODO localalph
 }
 
@@ -8556,18 +10446,31 @@
 
 \def\@syriacnumber#1{%
    \if at eastern@numerals
-     \ifnum\XeTeXcharglyph"0661 > 0%
-     %%% we test for the presence of one of ١٢٣٤٥٦٧٨٩٠ in the Syriac font, 
-     %%% else we try \arabicfont if defined (and give a warning), 
-     %%% else we fall back to the Western numerals.
-       %%\protect\addfontfeature{Mapping=arabicdigits}\number#1}%
-       \protect\arabicdigits{\number#1}%
-     \else%
-       \ifcsdef{arabicfont}%
-         {\protect\arabicdigits{\number#1}%
-          \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: I am using \string\arabicfont instead}}%
-         {\number#1%%% <---changed from \RL{\protect\reset at font\protect\number#1}%
-          \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: since \string\arabicfont is not defined, we'll use Western numerals instead}}%
+      %%% we test for the presence of one of ١٢٣٤٥٦٧٨٩٠ in the Syriac font, 
+      %%% else we try \arabicfont if defined (and give a warning), 
+      %%% else we fall back to the Western numerals.
+      \ifxetex
+         \ifnum\XeTeXcharglyph"0661 > 0%
+           %%\protect\addfontfeature{Mapping=arabicdigits}\number#1}%
+           \protect\arabicdigits{\number#1}%
+         \else%
+           \ifcsdef{arabicfont}%
+	     {\protect\arabicdigits{\number#1}%
+	      \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: I am using \string\arabicfont instead}}%
+	     {\number#1%%% <---changed from \RL{\protect\reset at font\protect\number#1}%
+	      \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: since \string\arabicfont is not defined, we'll use Western numerals instead}}%
+         \fi
+     \else% LuaTeX
+         \expandafter\ifnum\directlua{polyglossia.check_char(0x661)} > 0\relax
+           %%\protect\addfontfeature{Mapping=arabicdigits}\number#1}%
+           \protect\arabicdigits{\number#1}%
+         \else%
+           \ifcsdef{arabicfont}%
+	     {\protect\arabicdigits{\number#1}%
+	      \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: I am using \string\arabicfont instead}}%
+	     {\number#1%%% <---changed from \RL{\protect\reset at font\protect\number#1}%
+	      \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: since \string\arabicfont is not defined, we'll use Western numerals instead}}%
+         \fi
      \fi
    \else
      %%\RL{\protect\reset at font\number#1}%
@@ -8575,32 +10478,40 @@
    \fi}
 
 \def\syriac at numbers{%
-   \let\@latinalph\@alph%
-   \let\@latinAlph\@Alph%
    \let\@alph\abjadsyriac%
    \let\@Alph\abjadsyriac%
 }
+
 \def\nosyriac at numbers{%
-  \let\@alph\@latinalph%
-  \let\@Alph\@latinAlph%
-  }
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
+}
+
+\newcommand{\syriacnumerals}[2]{\syriacnumber{#2}}
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
 \def\syriac at globalnumbers{%
-  \let\orig at arabic\@arabic%
   \let\@arabic\syriacnumber%
-  \renewcommand\thefootnote{\protect\syriacnumber{\c at footnote}}%
+  \renewcommand\thefootnote{\localnumeral*{footnote}}%
 }
+
 \def\nosyriac at globalnumbers{%
-  \let\@arabic\orig at arabic%
-  \renewcommand\thefootnote{\protect\number{\c at footnote}}%
-  }
+  \let\@arabic\xpg at save@arabic%
+}
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at syriac{%
-   \let\@@MakeUppercase\MakeUppercase%
    \def\MakeUppercase##1{##1}%
-   }
+}
+
 \def\noextras at syriac{%
-   \let\MakeUppercase\@@MakeUppercase%
-   }
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase%
+}
 
 %    \end{macrocode}
 % \iffalse
@@ -8767,8 +10678,10 @@
 \PolyglossiaSetup{thai}{
   script=Thai,
   scripttag=thai,
+  langtag=THA,
   hyphennames={nohyphenation},
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=thainumerals
   %TODO localalph={xxx at alph,xxx at Alph}
   %TODO localdigits=thainumber
 }
@@ -8834,6 +10747,8 @@
   \fi
 }
 
+\newcommand{\thainumerals}[2]{\thainumber{#2}}
+
 \def\thainumber#1{%
   \if at thai@numerals
     \thaidigits{\number#1}%
@@ -8856,8 +10771,6 @@
      ศ\or ษ\or ส\or ห\or ฬ\or อ\or ฮ\else\xpg at ill@value{#1}{@thaialph}\fi}
      
 \def\thai at numbers{%
-   \let\@latinalph\@alph%
-   \let\@latinAlph\@Alph%
    \if at thai@numerals
      \let\@alph\@thaialph%
      \let\@Alph\@thaiAlph%
@@ -8864,18 +10777,17 @@
    \fi
 }
 \def\nothai at numbers{%
-  \let\@alph\@latinalph%
-  \let\@Alph\@latinAlph%
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
 }
 
 \def\thai at globalnumbers{%
    \let\orig at arabic\@arabic%
    \let\@arabic\thainumber%
-   \renewcommand{\thefootnote}{\protect\thainumber{\c at footnote}}%
+   \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
 }
 \def\nothai at globalnumbers{%
    \let\@arabic\orig at arabic%
-   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
 }
 
 \def\blockextras at thai{%
@@ -8907,10 +10819,11 @@
 \PolyglossiaSetup{tibetan}{
   script=Tibetan,
   scripttag=tibt,
+  langtag=TIB,
   hyphennames={nohyphenation},
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=tibetannumerals
   %TODO localalph={xxx at alph,xxx at Alph}
-  %TODO localdigits=tibetannumber
 }
 
 \newif\if at tibetan@numerals
@@ -9025,10 +10938,10 @@
   \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 ས\or ཧ\or ཨ
  \else\xpg at ill@value{#1}{@tibetanalph}\fi}
-     
+
+\newcommand{\tibetanumerals}[2]{\tibetannumber{#2}}
+
 \def\tibetan at numbers{%
-   \let\@latinalph\@alph%
-   \let\@latinAlph\@Alph%
    \if at tibetan@numerals
      \let\@alph\@tibetanalph%
      \let\@Alph\@tibetanAlph%
@@ -9035,19 +10948,18 @@
    \fi
 }
 \def\notibetan at numbers{%
-  \let\@alph\@latinalph%
-  \let\@Alph\@latinAlph%
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
 }
 
 \def\tibetan at globalnumbers{%
    \let\xpg at orig@arabic\@arabic%
    \let\@arabic\tibetannumber%
-   \renewcommand{\thefootnote}{\protect\tibetannumber{\c at footnote}}%
+   \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
 }
 
 \def\notibetan at globalnumbers{%
    \let\@arabic\xpg at orig@arabic%
-   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
 }
 
 \def\noextras at tibetan{%
@@ -9269,8 +11181,9 @@
 \fi
 
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\ukrainian at shorthands{%
@@ -9389,8 +11302,6 @@
    ц\or ч\or ш\or щ\or ю\or я\else\xpg at ill@value{#1}{ukrainian at alph}\fi}
 
 \def\ukrainian at numbers{%
-   \let\latin at Alph\@Alph%
-   \let\latin at alph\@alph%
    \let\@Alph\ukrainian at Alph%
    \let\@alph\ukrainian at alph%
 }
@@ -9465,9 +11376,9 @@
   scripttag=arab,
   langtag=URD,
   hyphennames={urdu,nohyphenation},
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=urdunumerals
   %TODO localalph={abjad,abjad}
-  %TODO localnumber=urdunumber
 }
 
 \newif\if at western@numerals
@@ -9557,37 +11468,41 @@
   \fi}
 
 \def\urdu at numbers{%
-  \let\@latinalph\@alph%
-  \let\@latinAlph\@Alph%
   \let\@alph\abjad%
   \let\@Alph\abjad%
-  }
+}
 
 \def\nourdu at numbers{%
-  \let\@alph\@latinalph%
-  \let\@Alph\@latinAlph%
-  }
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
+}
 
+\newcommand{\urdunumerals}[2]{\urdunumber{#2}}
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
 \def\urdu at globalnumbers{%
-  \let\orig at arabic\@arabic%
   \let\@arabic\urdunumber%
   % For some reason \thefootnote needs to be set separately:
-  \renewcommand\thefootnote{\protect\urdunumber{\c at footnote}}%
-  }
+  \renewcommand\thefootnote{\localnumeral*{footnote}}%
+}
 
 \def\nourdu at globalnumbers{
-  \let\@arabic\orig at arabic%
-  \renewcommand\thefootnote{\protect\number{\c at footnote}}%
-  }
+  \let\@arabic\xpg at save@arabic%
+}
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at urdu{%
-  \let\@@MakeUppercase\MakeUppercase%
   \def\MakeUppercase##1{##1}%
-  }
+}
 
 \def\noextras at urdu{%
-  \let\MakeUppercase\@@MakeUppercase%
-  }
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase%
+}
 
 %    \end{macrocode}
 % \iffalse
@@ -9600,51 +11515,23 @@
 %    \begin{macrocode}
 \ProvidesFile{gloss-usorbian.ldf}[polyglossia: module for upper sorbian]
 
+% We only provide this gloss for babel compatibility. Since usorbian is 
+% a sorbian variety, we use 'sorbian' with variant 'upper' now.
+
+\input{gloss-sorbian.ldf}
+
 \PolyglossiaSetup{usorbian}{
+  language=Upper Sorbian,
+  babelname=uppersorbian,
   hyphennames={usorbian,uppersorbian},
   hyphenmins={2,2},
+  langtag=USB,
   fontsetup=true,
 }
 
-\def\captionsusorbian{%
-   \def\refname{Referency}%
-   \def\abstractname{Abstrakt}%
-   \def\bibname{Literatura}%
-   \def\prefacename{Zawod}%
-   \def\chaptername{Kapitl}%
-   \def\appendixname{Dodawki}%
-   \def\contentsname{Wobsah}%
-   \def\listfigurename{Zapis wobrazow}%
-   \def\listtablename{Zapis tabulkow}%
-   \def\indexname{Indeks}%
-   \def\figurename{Wobraz}%
-   \def\tablename{Tabulka}%
-   %\def\thepart{}%
-   \def\partname{Dźěl}%
-   \def\pagename{Strona}%
-   \def\seename{hl.}%
-   \def\alsoname{hl.~tež}%
-   \def\enclname{Přłoha}%
-   \def\ccname{CC}%
-   \def\headtoname{Komu}%
-   \def\proofname{Proof}% <-- needs translation
-   \def\glossaryname{Glossary}% <-- needs translation
-   }%
+\let\captionsusorbian\captionssorbian at usorbian
+\let\dateusorbian\datesorbian at usorbian
 
-\def\dateusorbian{%   
-  \def\today{\number\day.~\ifcase\month\or
-    januara\or februara\or měrca\or apryla\or meje\or junija\or
-    julija\or awgusta\or septembra\or oktobra\or
-    nowembra\or decembra\fi
-    \space \number\year}%
-  %TODO implement option olddate:
-    \def\oldtoday{\number\day.~\ifcase\month\or
-    wulkeho róžka\or małeho róžka\or nalětnika\or
-    jutrownika\or róžownika\or  smažnika\or pražnika\or
-    žnjenca\or požnjenca\or winowca\or nazymnika\or
-    hodownika\fi \space \number\year}%
-  }
-
 %    \end{macrocode}
 % \iffalse
 %</gloss-usorbian.ldf>
@@ -9710,6 +11597,7 @@
 \PolyglossiaSetup{welsh}{
   hyphennames={welsh},
   hyphenmins={2,3},
+  langtag=WEL,
   fontsetup=true,
 }
 
@@ -9773,11 +11661,12 @@
     Mai\or Mehefin\or Gorffennaf\or Awst\or
     Medi\or Hydref\or Tachwedd\or Rhagfyr\fi%
     \space\number\year}%
-
   \def\formaltoday{%
-    \expandafter\welsh at article\welsh at ordinal@long\day\space o\space\ifcase\month\or Ionawr\or Chwefror\or Fawrth\or Ebrill\or Fai\or Fehefin\or Orffenaf\or Awst\or Fedi\or Hydref\or Dachwedd\or Ragfyr\fi
+    \expandafter\welsh at article\welsh at ordinal@long\day\space o\space\ifcase\month\or
+    Ionawr\or Chwefror\or Fawrth\or Ebrill\or Fai\or Fehefin\or Orffenaf\or Awst\or
+    Fedi\or Hydref\or Dachwedd\or Ragfyr\fi%
     \space\number\year}%
-  }
+}
 
 %    \end{macrocode}
 % \iffalse
@@ -9929,15 +11818,15 @@
 
 local insert_node_before = node.insert_before
 local insert_node_after  = node.insert_after
-local remove_node        = nodes.remove
+local remove_node        = node.remove
 local has_attribute      = node.has_attribute
 local node_copy          = node.copy
 local new_node           = node.new
 
+local math_code          = nodecodes.math
 local end_of_math        = node.end_of_math
 if not end_of_math then -- luatex < .76
   local traverse_nodes = node.traverse_id
-  local math_code      = nodecodes.math
   local end_of_math = function (n)
     for n in traverse_nodes(math_code, n.next) do
       return n
@@ -10075,10 +11964,10 @@
                         if somespace then
                             local somepenalty = somepenalty(prevprev,10000)
                             if somepenalty then
-                                head = remove_node(head,prev,true)
-                                head = remove_node(head,prevprev,true)
+                                head = remove_node(head,prev)
+                                head = remove_node(head,prevprev)
                             else
-                                head = remove_node(head,prev,true)
+                                head = remove_node(head,prev)
                             end
                         end
                         insert_node_before(head,start,get_penalty_node())
@@ -10092,13 +11981,13 @@
                         if somepenalty then
                             local somespace = somespace(nextnext,true)
                             if somespace then
-                                head = remove_node(head,next,true)
-                                head = remove_node(head,nextnext,true)
+                                head = remove_node(head,next)
+                                head = remove_node(head,nextnext)
                             end
                         else
                             local somespace = somespace(next,true)
                             if somespace then
-                                head = remove_node(head,next,true)
+                                head = remove_node(head,next)
                             end
                         end
                         insert_node_after(head,start,get_kern_node(map[2]*quad))
@@ -10140,6 +12029,618 @@
 %    \end{macrocode}
 % \iffalse
 %</polyglossia-frpt.lua>
+%<*polyglossia-korean.lua>
+% \fi
+% \clearpage
+% 
+% \subsection{polyglossia-korean.lua}
+%    \begin{macrocode}
+--
+-- polyglossia-korean.lua
+--
+
+local glyph_id = node.id"glyph"
+local hbox_id  = node.id"hlist"
+local vbox_id  = node.id"vlist"
+local glue_id  = node.id"glue"
+local penalty_id = node.id"penalty"
+local disc_id  = node.id"disc"
+
+--
+-- attr_korean: variant = plain (0), classic (1), modern (2)
+--
+local attr_korean = luatexbase.attributes["xpg at attr@korean"]
+local attr_josa   = luatexbase.attributes["xpg at attr@autojosa"]
+
+--
+-- characters after which linebreak is not allowed
+--
+local nobr_after = {
+    [0x28] = 1, -- ( LEFT PARENTHESIS
+    [0x3C] = 1, -- < LESS-THAN SIGN
+    [0x5B] = 1, -- [ LEFT SQUARE BRACKET
+    [0x60] = 1, -- ` GRAVE ACCENT
+    [0x7B] = 1, -- { LEFT CURLY BRACKET
+    [0xAB] = 1, -- « LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
+    [0x2018] = 1, -- ‘ LEFT SINGLE QUOTATION MARK
+    [0x201C] = 1, -- “ LEFT DOUBLE QUOTATION MARK
+    [0x2329] = 1, -- 〈 LEFT-POINTING ANGLE BRACKET
+    [0x3008] = 1, -- 〈 LEFT ANGLE BRACKET
+    [0x300A] = 1, -- 《 LEFT DOUBLE ANGLE BRACKET
+    [0x300C] = 1, -- 「 LEFT CORNER BRACKET
+    [0x300E] = 1, -- 『 LEFT WHITE CORNER BRACKET
+    [0x3010] = 1, -- 【 LEFT BLACK LENTICULAR BRACKET
+    [0x3014] = 1, -- 〔 LEFT TORTOISE SHELL BRACKET
+    [0x3016] = 1, -- 〖 LEFT WHITE LENTICULAR BRACKET
+    [0x3018] = 1, -- 〘 LEFT WHITE TORTOISE SHELL BRACKET
+    [0x301A] = 1, -- 〚 LEFT WHITE SQUARE BRACKET
+    [0x301D] = 1, -- 〝 REVERSED DOUBLE PRIME QUOTATION MARK
+    [0xFE17] = 1, -- ︗ PRESENTATION FORM FOR VERTICAL LEFT WHITE LENTICULAR BRACKET
+    [0xFE35] = 1, -- ︵ PRESENTATION FORM FOR VERTICAL LEFT PARENTHESIS
+    [0xFE37] = 1, -- ︷ PRESENTATION FORM FOR VERTICAL LEFT CURLY BRACKET
+    [0xFE39] = 1, -- ︹ PRESENTATION FORM FOR VERTICAL LEFT TORTOISE SHELL BRACKET
+    [0xFE3B] = 1, -- ︻ PRESENTATION FORM FOR VERTICAL LEFT BLACK LENTICULAR BRACKET
+    [0xFE3D] = 1, -- ︽ PRESENTATION FORM FOR VERTICAL LEFT DOUBLE ANGLE BRACKET
+    [0xFE3F] = 1, -- ︿ PRESENTATION FORM FOR VERTICAL LEFT ANGLE BRACKET
+    [0xFE41] = 1, -- ﹁ PRESENTATION FORM FOR VERTICAL LEFT CORNER BRACKET
+    [0xFE43] = 1, -- ﹃ PRESENTATION FORM FOR VERTICAL LEFT WHITE CORNER BRACKET
+    [0xFE47] = 1, -- ﹇ PRESENTATION FORM FOR VERTICAL LEFT SQUARE BRACKET
+    [0xFE59] = 1, -- ﹙ SMALL LEFT PARENTHESIS
+    [0xFE5B] = 1, -- ﹛ SMALL LEFT CURLY BRACKET
+    [0xFE5D] = 1, -- ﹝ SMALL LEFT TORTOISE SHELL BRACKET
+    [0xFF08] = 1, -- ( FULLWIDTH LEFT PARENTHESIS
+    [0xFF3B] = 1, -- [ FULLWIDTH LEFT SQUARE BRACKET
+    [0xFF5B] = 1, -- { FULLWIDTH LEFT CURLY BRACKET
+    [0xFF5F] = 1, -- ⦅ FULLWIDTH LEFT WHITE PARENTHESIS
+    [0xFF62] = 1, -- 「 HALFWIDTH LEFT CORNER BRACKET
+}
+
+--
+-- characters before which linebreak is not allowed
+--   (currently, not much differences among the followings)
+--   1: normal chars
+--   2: hangul jamo vowels and trailing consonants
+--   3: kana small letters
+--   0: dashes (supress visible spacing)
+--
+local nobr_before = setmetatable({
+    [0x21] = 1, -- ! EXCLAMATION MARK
+    [0x22] = 1, -- " QUOTATION MARK
+    [0x27] = 1, -- ' APOSTROPHE
+    [0x29] = 1, -- ) RIGHT PARENTHESIS
+    [0x2C] = 1, -- , COMMA
+    [0x2D] = 0, -- - HYPHEN-MINUS
+    [0x2E] = 1, -- . FULL STOP
+    [0x2F] = 0, -- / SOLIDUS
+    [0x3A] = 0, -- : COLON
+    [0x3B] = 1, -- ; SEMICOLON
+    [0x3E] = 1, -- > GREATER-THAN SIGN
+    [0x3F] = 1, -- ? QUESTION MARK
+    [0x5C] = 0, -- \ REVERSE SOLIDUS
+    [0x5D] = 1, -- ] RIGHT SQUARE BRACKET
+    [0x7D] = 1, -- } RIGHT CURLY BRACKET
+    [0x7E] = 0, -- ~ TILDE
+    [0xB7] = 1, -- · MIDDLE DOT
+    [0xBB] = 1, -- » RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
+    [0x2013] = 0, -- – EN DASH
+    [0x2014] = 0, -- — EM DASH
+    [0x2015] = 1, -- ― HORIZONTAL BAR
+    [0x2019] = 1, -- ’ RIGHT SINGLE QUOTATION MARK
+    [0x201D] = 1, -- ” RIGHT DOUBLE QUOTATION MARK
+    [0x2025] = 1, -- ‥ TWO DOT LEADER
+    [0x2026] = 1, -- … HORIZONTAL ELLIPSIS
+    [0x232A] = 1, -- 〉 RIGHT-POINTING ANGLE BRACKET
+    [0x3001] = 1, -- 、 IDEOGRAPHIC COMMA
+    [0x3002] = 1, -- 。 IDEOGRAPHIC FULL STOP
+    [0x3005] = 1, -- 々 IDEOGRAPHIC ITERATION MARK
+    [0x3009] = 1, -- 〉 RIGHT ANGLE BRACKET
+    [0x300B] = 1, -- 》 RIGHT DOUBLE ANGLE BRACKET
+    [0x300D] = 1, -- 」 RIGHT CORNER BRACKET
+    [0x300F] = 1, -- 』 RIGHT WHITE CORNER BRACKET
+    [0x3011] = 1, -- 】 RIGHT BLACK LENTICULAR BRACKET
+    [0x3015] = 1, -- 〕 RIGHT TORTOISE SHELL BRACKET
+    [0x3017] = 1, -- 〗 RIGHT WHITE LENTICULAR BRACKET
+    [0x3019] = 1, -- 〙 RIGHT WHITE TORTOISE SHELL BRACKET
+    [0x301B] = 1, -- 〛 RIGHT WHITE SQUARE BRACKET
+    [0x301C] = 1, -- 〜 WAVE DASH
+    [0x301E] = 1, -- 〞 DOUBLE PRIME QUOTATION MARK
+    [0x301F] = 1, -- 〟 LOW DOUBLE PRIME QUOTATION MARK
+    [0x3035] = 1, -- 〵 VERTICAL KANA REPEAT MARK LOWER HALF
+    [0x303B] = 1, -- 〻 VERTICAL IDEOGRAPHIC ITERATION MARK
+    [0x303C] = 1, -- 〼 MASU MARK
+    [0x3041] = 3, -- ぁ HIRAGANA LETTER SMALL A
+    [0x3043] = 3, -- ぃ HIRAGANA LETTER SMALL I
+    [0x3045] = 3, -- ぅ HIRAGANA LETTER SMALL U
+    [0x3047] = 3, -- ぇ HIRAGANA LETTER SMALL E
+    [0x3049] = 3, -- ぉ HIRAGANA LETTER SMALL O
+    [0x3063] = 3, -- っ HIRAGANA LETTER SMALL TU
+    [0x3083] = 3, -- ゃ HIRAGANA LETTER SMALL YA
+    [0x3085] = 3, -- ゅ HIRAGANA LETTER SMALL YU
+    [0x3087] = 3, -- ょ HIRAGANA LETTER SMALL YO
+    [0x308E] = 3, -- ゎ HIRAGANA LETTER SMALL WA
+    [0x3095] = 3, -- ゕ HIRAGANA LETTER SMALL KA
+    [0x3096] = 3, -- ゖ HIRAGANA LETTER SMALL KE
+    [0x3099] = 1, --  COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
+    [0x309A] = 1, --  COMBINING KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
+    [0x309B] = 1, -- ゛ KATAKANA-HIRAGANA VOICED SOUND MARK
+    [0x309C] = 1, -- ゜ KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
+    [0x309D] = 1, -- ゝ HIRAGANA ITERATION MARK
+    [0x309E] = 1, -- ゞ HIRAGANA VOICED ITERATION MARK
+    [0x30A0] = 1, -- ゠ KATAKANA-HIRAGANA DOUBLE HYPHEN
+    [0x30A1] = 3, -- ァ KATAKANA LETTER SMALL A
+    [0x30A3] = 3, -- ィ KATAKANA LETTER SMALL I
+    [0x30A5] = 3, -- ゥ KATAKANA LETTER SMALL U
+    [0x30A7] = 3, -- ェ KATAKANA LETTER SMALL E
+    [0x30A9] = 3, -- ォ KATAKANA LETTER SMALL O
+    [0x30C3] = 3, -- ッ KATAKANA LETTER SMALL TU
+    [0x30E3] = 3, -- ャ KATAKANA LETTER SMALL YA
+    [0x30E5] = 3, -- ュ KATAKANA LETTER SMALL YU
+    [0x30E7] = 3, -- ョ KATAKANA LETTER SMALL YO
+    [0x30EE] = 3, -- ヮ KATAKANA LETTER SMALL WA
+    [0x30F5] = 3, -- ヵ KATAKANA LETTER SMALL KA
+    [0x30F6] = 3, -- ヶ KATAKANA LETTER SMALL KE
+    [0x30FB] = 1, -- ・ KATAKANA MIDDLE DOT
+    [0x30FC] = 1, -- ー KATAKANA-HIRAGANA PROLONGED SOUND MARK
+    [0x30FD] = 1, -- ヽ KATAKANA ITERATION MARK
+    [0x30FE] = 1, -- ヾ KATAKANA VOICED ITERATION MARK
+    [0xFE30] = 1, -- ︰ PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
+    [0xFE31] = 1, -- ︱ PRESENTATION FORM FOR VERTICAL EM DASH
+    [0xFE32] = 1, -- ︲ PRESENTATION FORM FOR VERTICAL EN DASH
+    [0xFE36] = 1, -- ︶ PRESENTATION FORM FOR VERTICAL RIGHT PARENTHESIS
+    [0xFE38] = 1, -- ︸ PRESENTATION FORM FOR VERTICAL RIGHT CURLY BRACKET
+    [0xFE3A] = 1, -- ︺ PRESENTATION FORM FOR VERTICAL RIGHT TORTOISE SHELL BRACKET
+    [0xFE3C] = 1, -- ︼ PRESENTATION FORM FOR VERTICAL RIGHT BLACK LENTICULAR BRACKET
+    [0xFE3E] = 1, -- ︾ PRESENTATION FORM FOR VERTICAL RIGHT DOUBLE ANGLE BRACKET
+    [0xFE40] = 1, -- ﹀ PRESENTATION FORM FOR VERTICAL RIGHT ANGLE BRACKET
+    [0xFE42] = 1, -- ﹂ PRESENTATION FORM FOR VERTICAL RIGHT CORNER BRACKET
+    [0xFE44] = 1, -- ﹄ PRESENTATION FORM FOR VERTICAL RIGHT WHITE CORNER BRACKET
+    [0xFE48] = 1, -- ﹈ PRESENTATION FORM FOR VERTICAL RIGHT SQUARE BRACKET
+    [0xFE5A] = 1, -- ﹚ SMALL RIGHT PARENTHESIS
+    [0xFE5C] = 1, -- ﹜ SMALL RIGHT CURLY BRACKET
+    [0xFE5E] = 1, -- ﹞ SMALL RIGHT TORTOISE SHELL BRACKET
+    [0xFF01] = 1, -- ! FULLWIDTH EXCLAMATION MARK
+    [0xFF09] = 1, -- ) FULLWIDTH RIGHT PARENTHESIS
+    [0xFF0C] = 1, -- , FULLWIDTH COMMA
+    [0xFF0E] = 1, -- . FULLWIDTH FULL STOP
+    [0xFF1A] = 1, -- : FULLWIDTH COLON
+    [0xFF1B] = 1, -- ; FULLWIDTH SEMICOLON
+    [0xFF1F] = 1, -- ? FULLWIDTH QUESTION MARK
+    [0xFF3D] = 1, -- ] FULLWIDTH RIGHT SQUARE BRACKET
+    [0xFF5D] = 1, -- } FULLWIDTH RIGHT CURLY BRACKET
+    [0xFF60] = 1, -- ⦆ FULLWIDTH RIGHT WHITE PARENTHESIS
+    [0xFF61] = 1, -- 。 HALFWIDTH IDEOGRAPHIC FULL STOP
+    [0xFF63] = 1, -- 」 HALFWIDTH RIGHT CORNER BRACKET
+    [0xFF64] = 1, -- 、 HALFWIDTH IDEOGRAPHIC COMMA
+    [0xFF65] = 1, -- ・ HALFWIDTH KATAKANA MIDDLE DOT
+    [0xFF9E] = 1, -- ゙ HALFWIDTH KATAKANA VOICED SOUND MARK
+    [0xFF9F] = 1, -- ゚ HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK
+}, { __index = function(_,c)
+        if c >= 0x1160  and c <= 0x11FF  then return 2 end
+        if c >= 0xD7B0  and c <= 0xD7FF  then return 2 end
+        if c >= 0x302A  and c <= 0x302F  then return 1 end
+        if c >= 0x31F0  and c <= 0x31FF  then return 3 end
+        if c >= 0xFF67  and c <= 0xFF70  then return 3 end
+        if c >= 0xFE00  and c <= 0xFE0F  then return 1 end
+        if c >= 0xFE10  and c <= 0xFE19 and not (c == 0xFE17) then return 1 end
+        if c >= 0xFE50  and c <= 0xFE58  then return 1 end
+        if c >= 0xE0100 and c <= 0xE01EF then return 1 end
+    end
+})
+
+--
+-- whether 'c' is a cjk character
+--
+local function is_cjk (c)
+    return c >= 0xAC00  and c <= 0xD7FF
+    or     c >= 0x1100  and c <= 0x11FF
+    or     c >= 0xA960  and c <= 0xA97F
+    or     c >= 0x2E80  and c <= 0x9FFF
+    or     c >= 0xF900  and c <= 0xFAFF
+    or     c >= 0xFE10  and c <= 0xFE1F
+    or     c >= 0xFE30  and c <= 0xFE6F
+    or     c >= 0xFF00  and c <= 0xFFEF
+    or     c >= 0x1F100 and c <= 0x1F2FF
+    or     c >= 0x20000 and c <= 0x2FA1F
+    or     nobr_after[c]  and c > 0x2014
+    or     nobr_before[c] and c > 0x2014
+end
+
+--
+-- classify cjk characters
+--   1: openings
+--   2: closings
+--   3: centered chars
+--   4: full stops
+--   5: ellipses
+--   6: exclamation and question marks
+--   0: all others
+--
+local charclass = setmetatable({
+    [0x2018] = 1, [0x201C] = 1, [0x2329] = 1, [0x3008] = 1,
+    [0x300A] = 1, [0x300C] = 1, [0x300E] = 1, [0x3010] = 1,
+    [0x3014] = 1, [0x3016] = 1, [0x3018] = 1, [0x301A] = 1,
+    [0x301D] = 1, [0xFE17] = 1, [0xFE35] = 1, [0xFE37] = 1,
+    [0xFE39] = 1, [0xFE3B] = 1, [0xFE3D] = 1, [0xFE3F] = 1,
+    [0xFE41] = 1, [0xFE43] = 1, [0xFE47] = 1, [0xFF08] = 1,
+    [0xFF3B] = 1, [0xFF5B] = 1, [0xFF5F] = 1, [0xFF62] = 1,
+    [0x2019] = 2, [0x201D] = 2, [0x232A] = 2, [0x3001] = 2,
+    [0x3009] = 2, [0x300B] = 2, [0x300D] = 2, [0x300F] = 2,
+    [0x3011] = 2, [0x3015] = 2, [0x3017] = 2, [0x3019] = 2,
+    [0x301B] = 2, [0x301E] = 2, [0x301F] = 2, [0xFE10] = 2,
+    [0xFE11] = 2, [0xFE18] = 2, [0xFE36] = 2, [0xFE38] = 2,
+    [0xFE3A] = 2, [0xFE3C] = 2, [0xFE3E] = 2, [0xFE40] = 2,
+    [0xFE42] = 2, [0xFE44] = 2, [0xFE48] = 2, [0xFF09] = 2,
+    [0xFF0C] = 2, [0xFF3D] = 2, [0xFF5D] = 2, [0xFF60] = 2,
+    [0xFF63] = 2, [0xFF64] = 2, [0x00B7] = 3, [0x30FB] = 3,
+    [0xFF1A] = 3, [0xFF1B] = 3, [0xFF65] = 3, [0x3002] = 4,
+    [0xFE12] = 4, [0xFF0E] = 4, [0xFF61] = 4, [0x2015] = 5,
+    [0x2025] = 5, [0x2026] = 5, [0xFE19] = 5, [0xFE30] = 5,
+    [0xFE31] = 5, [0xFE15] = 6, [0xFE16] = 6, [0xFF01] = 6,
+    [0xFF1F] = 6,
+}, { __index = function() return 0 end })
+
+--
+-- table for spacing between char classes
+--   1 stands for 0.5*fontsize when variant=classic
+--
+local intercharclass = { [0] =
+    { [0] = nil,    {1,1},  nil,    {.5,.5} },
+    { [0] = nil,    nil,    nil,    {.5,.5} },
+    { [0] = {1,1},  {1,1},  nil,    {.5,.5}, nil,    {1,1},  {1,1} },
+    { [0] = {.5,.5},{.5,.5},{.5,.5},{1,.5},  {.5,.5},{.5,.5},{.5,.5} },
+    { [0] = {1,0},  {1,0},  nil,    {1.5,.5},nil,    {1,0},  {1,0} },
+    { [0] = nil,    {1,1},  nil,    {.5,.5} },
+    { [0] = {1,1},  {1,1},  nil,    {.5,.5} },
+}
+
+--
+-- get a new penalty node
+--
+local function get_new_penalty (p)
+    local penalty = node.new("penalty")
+    penalty.penalty = p
+    return penalty
+end
+
+--
+-- get a new glue node
+--
+local function get_new_glue (...)
+    local glue = node.new("glue")
+    node.setglue(glue, ...)
+    return glue
+end
+
+--
+-- return 0.5*fontsize of given fontid
+--   space: true if variant=modern; then 0.5*interword_space
+--
+local function get_font_size (fid, space)
+    local size = font.getparameters(fid)
+    if space then
+        size = size and size.space or 196608
+    else
+        size = size and size.quad  or 655360
+    end
+    return size/2
+end
+
+--
+-- charclass 1 thru 4 will be packed in \hbox to 0.5em{\hss? curr \hss?}
+--   when variant=classic/modern
+--
+local function glyph_to_box (head, curr, class)
+    local g, h = curr
+    local size = get_font_size(g.font)
+    head, curr = node.remove(head, curr)
+    g.next, g.prev = nil, nil
+    local hss = get_new_glue(0, 65536, 65536, 2, 2)
+    if class == 1 then
+        h, hss.next, g.prev = hss, g, hss
+    elseif class == 2 or class == 4 then
+        h, g.next, hss.prev = g, hss, g
+    else
+        local hss2 = node.copy(hss)
+        h, hss.next, g.prev, g.next, hss2.prev = hss, g, hss, hss2, g
+    end
+    h = nodes.simple_font_handler(h)
+    local box = node.hpack(h, size, "exactly")
+    if curr then
+        head, curr = node.insert_before(head, curr, box)
+    else
+        head, curr = node.insert_after(head, node.tail(head), box)
+    end
+    return head, curr
+end
+
+--
+-- insert spacing defined as charclass[a][b] between a and b
+--   f:    fontid
+--   var:  variant = plain, classic, modern
+--   cc:   charclass of current char
+--   nc:   charclass of next char
+--   nobr: linebreak is not allowed
+--
+local function insert_cjk_penalty_glue (head, curr, f, var, cc, nc, nobr)
+    if nobr or cc == 1 or nc > 1 then
+        local penalty = get_new_penalty(10000)
+        head, curr = node.insert_after(head, curr, penalty)
+    end
+    local factor = get_font_size(f, var == 2)
+    local t = intercharclass[cc][nc]
+    local glue = get_new_glue(t[1]*factor, nil, t[2]*factor)
+    head, curr = node.insert_after(head, curr, glue)
+    return head, curr
+end
+
+--
+-- insert inter-character spacing in other normal cases
+--   f:   fontid
+--   var: variant = plain, classic, modern
+--   x:   true between cjk and non-cjk (a little more spacing)
+--
+local function insert_penalty_glue (head, curr, f, var, x)
+    if var ~= 1 then
+        local penalty = get_new_penalty(50)
+        head, curr = node.insert_after(head, curr, penalty)
+    end
+    local size, glue = get_font_size(f, x and var == 2)
+    if x then
+        glue = get_new_glue(size/2, size/4, size/8)
+    else
+        glue = get_new_glue(0, size/10, size/50)
+    end
+    head, curr = node.insert_after(head, curr, glue)
+    return head, curr
+end
+
+--
+-- main process for linebreak and inter-character spacing
+--   lb: true if pre_linebreak_filter
+--
+local function korean_break (head, lb)
+    local curr = head
+    while curr do
+        if curr.id == glyph_id then
+            local var = node.has_attribute(curr, attr_korean)
+            if var then
+                local c, f = curr.char or 0, curr.font or 0
+                local cc, cjkc = charclass[c], is_cjk(c)
+
+                -- compress cjk punctuations when charclass is 1 thru 4
+                if var > 0 and cc > 0 and cc < 5 then
+                    head, curr = glyph_to_box(head, curr, cc)
+                end
+
+                local next = curr.next
+                if next and next.id == glyph_id then
+                    local n = next.char or 0
+                    local nc = charclass[n]
+                    local nobr = nobr_before[n] or nobr_after[c]
+
+                    -- insert spacing as of intercharclass
+                    if var > 0 and intercharclass[cc][nc] then
+                        head, curr = insert_cjk_penalty_glue(head, curr, f, var, cc, nc, nobr)
+
+                    -- or insert spacing when linebreak is allowed
+                    elseif not nobr then
+                        local cjkn = is_cjk(n)
+
+                        -- if curr or next is cjk char
+                        if cjkc or cjkn then
+
+                            -- if between cjk and non-cjk
+                            if var > 0 and not (cjkc and cjkn) and nobr_before[c] ~= 0 then
+                                head, curr = insert_penalty_glue(head, curr, f, var, true)
+
+                            -- or under pre_linebreak_filter
+                            elseif lb then
+                                head, curr = insert_penalty_glue(head, curr, f, var)
+                            end
+                        end
+                    end
+                end
+            end
+        end
+        curr = curr.next
+    end
+    return head
+end
+
+--
+-- process for reordering hangul tone marks (U+302E, U+302F)
+--   some hangul fonts (eg. Noto CJK) are so designed that hangul tone marks
+--   should be moved to the first position of a syllable.
+--   Currently, this functionality is not provided by luaotfload.
+--
+local function reorder_tm (head)
+    local curr, tone = node.slide(head)
+    while curr do
+        if curr.id == glyph_id and node.has_attribute(curr, attr_korean) then
+            local c, wd = curr.char or 0, curr.width or 0
+            if (c == 0x302E or c == 0x302F) and wd > 0 then
+                tone = curr
+            elseif tone and not nobr_before[c] then
+                head = node.remove(head, tone)
+                tone.next, tone.prev = nil, nil
+                head, curr = node.insert_before(head, curr, tone)
+                tone = nil
+            end
+        end
+        curr = curr.prev
+    end
+    return head
+end
+
+--
+-- automatic josa selection
+--
+local josa_table = {
+    --          consonant ㄹ, vowel,  other consonants
+    [0xAC00] = {0xC774,       0xAC00, 0xC774}, -- 가 => 이, 가, 이
+    [0xC740] = {0xC740,       0xB294, 0xC740}, -- 은 => 은, 는, 은
+    [0xC744] = {0xC744,       0xB97C, 0xC744}, -- 을 => 을, 를, 을
+    [0xC640] = {0xACFC,       0xC640, 0xACFC}, -- 와 => 과, 와, 과
+    [0xC73C] = {nil,          nil,    0xC73C}, -- 으(로) =>   ,  , 으
+    [0xC774] = {0xC774,       nil,    0xC774}, -- 이(라) => 이,  , 이
+}
+
+--
+-- helper function for number-like characters
+--
+local function josa_char_num (t, c)
+    c = c % 10 + 0x30
+    return t[c] or 2
+end
+
+--
+-- decide josa selection
+--
+local josa_code = setmetatable({
+    [0x30] = 3, [0x31] = 1, [0x33] = 3, [0x36] = 3, [0x37] = 1,
+    [0x38] = 1, [0x4C] = 1, [0x4D] = 3, [0x4E] = 3, [0x6C] = 1,
+    [0x6D] = 3, [0x6E] = 3, [0xFB02] = 1, [0xFB04] = 1,
+},{ __index = function(t,c)
+        if c >= 0xAC00 and c <= 0xD7A3 then
+            c = (c - 0xAC00) % 28 + 0x11A7
+        end
+        if c >= 0x11A8 and c <= 0x11FF then
+            if c == 0x11AF then return 1 end
+            return 3
+        end
+        if c >= 0xD7CB and c <= 0xD7FB then return 3 end
+        if c >= 0x2170 and c <= 0x217F then c = c - 0x10 end
+        if c >= 0x2160 and c <= 0x216F then
+            if c >= 0x216C then return 3 end
+            return josa_char_num(t, c - 0x215F)
+        end
+        if c >= 0x2460 and c <= 0x2473 then return josa_char_num(t, c - 0x245F) end
+        if c >= 0x2474 and c <= 0x2487 then return josa_char_num(t, c - 0x2473) end
+        if c >= 0x2488 and c <= 0x249B then return josa_char_num(t, c - 0x2487) end
+        if c >= 0x249C and c <= 0x24B5 then return t[c - 0x249C + 0x61] or 2 end
+        if c >= 0x24B6 and c <= 0x24CF then return t[c - 0x24B6 + 0x61] or 2 end
+        if c >= 0x24D0 and c <= 0x24E9 then return t[c - 0x24D0 + 0x61] or 2 end
+        if c >= 0x3131 and c <= 0x318E then
+            if c == 0x3139 then return 1 end
+            if c >= 0x314F and c <= 0x3163 or c >= 0x3187 then return 2 end
+            return 3
+        end
+        if c >= 0x3260 and c <= 0x327E then c = c - 0x60 end
+        if c >= 0x3200 and c <= 0x321E then
+            if c == 0x3203 then return 1 end
+            if c >= 0x320E then return 2 end
+            return 3
+        end
+        if c >= 0xFF10 and c <= 0xFF19 then return josa_char_num(t, c - 0xFF10) end
+        if c >= 0xFF21 and c <= 0xFF3A then return t[c - 0xFF21 + 0x61] or 2 end
+        if c >= 0xFF41 and c <= 0xFF5A then return t[c - 0xFF41 + 0x61] or 2 end
+        return 2
+    end
+})
+
+--
+-- obtain char that comes just before the josa
+--
+local function get_prev_char (p)
+    while p do
+        if p.id == glyph_id then
+            local pc = p.char or 0
+            if not nobr_after[pc] then
+                if not nobr_before[pc] or nobr_before[pc] >= 2 then
+                    return pc
+                end
+            end
+        elseif p.id == hbox_id or p.id == vbox_id then
+            local pc = get_prev_char(node.slide(p.head))
+            if pc then return pc end
+        end
+        p = p.prev
+    end
+end
+
+--
+-- main process of josa selection
+--
+local function auto_josa (head)
+    local curr, tofree = head, {}
+    while curr do
+        if curr.id == glyph_id then
+            local josa = node.has_attribute(curr, attr_josa)
+            if josa then
+                local cc = curr.char or 0
+                if josa == 0 then
+                    josa = josa_code[get_prev_char(curr.prev) or 0x30]
+                end
+                if cc == 0xC774 then
+                    local n = curr.next
+                    if n and n.char and n.char >= 0xAC00 and n.char <= 0xD7A3 then
+                    else
+                        cc = 0xAC00
+                    end
+                end
+                local new = josa_table[cc]
+                if new then
+                    cc = new[josa]
+                    if cc then
+                        curr.char = cc
+                    else
+                        head = node.remove(head, curr)
+                        table.insert(tofree, curr)
+                    end
+                end
+                node.unset_attribute(curr, attr_josa)
+            end
+        end
+        curr = curr.next
+    end
+    for _,v in ipairs(tofree) do node.free(v) end
+    return head
+end
+
+--
+-- now register to luatex callbacks
+--   As char value of glyphs can be changed by opentype GSUB process,
+--   we have to occupy the first position among callback functions.
+--
+local prepend_to_callback
+if luatexbase.base_add_to_callback then
+    prepend_to_callback = function(name, func, desc)
+        luatexbase.add_to_callback(name, func, desc, 1)
+    end
+else
+    prepend_to_callback = function(name, func, desc)
+        local t = { {func, desc} }
+        for _,v in ipairs(luatexbase.callback_descriptions(name)) do
+            table.insert(t, {luatexbase.remove_from_callback(name, v)})
+        end
+        for _,v in ipairs(t) do
+            luatexbase.add_to_callback(name, v[1], v[2])
+        end
+    end
+end
+
+prepend_to_callback ("pre_linebreak_filter",
+    function(head)
+        head = auto_josa(head)
+        head = korean_break(head, true)
+        head = reorder_tm(head)
+        return head
+    end,
+    "polyglossia.lang_korean")
+
+prepend_to_callback ("hpack_filter",
+    function(head)
+        head = auto_josa(head)
+        head = korean_break(head)
+        head = reorder_tm(head)
+        return head
+    end,
+    "polyglossia.lang_korean")
+
+-- vim:ft=lua:tw=0:sw=4:ts=4:expandtab
+%    \end{macrocode}
+% \iffalse
+%</polyglossia-korean.lua>
 %<*polyglossia-tibt.lua>
 % \fi
 % \clearpage
@@ -10272,12 +12773,11 @@
 polyglossia = polyglossia or {}
 local polyglossia = polyglossia
 
-local current_language
-local last_language
-local default_language
+-- predefined l at nohyphenation or dummy new language
+local nohyphid = luatexbase.registernumber'l at nohyphenation' or lang.id(lang.new())
+-- key `nohyphenation` is for .sty file when possibly undefined l at nohyphenation
+local newloader_loaded_languages = { nohyphenation = nohyphid }
 
-polyglossia.newloader_loaded_languages = { }
-polyglossia.newloader_max_langid = 0
 local newloader_available_languages = dofile(kpse.find_file('language.dat.lua'))
 -- Suggestion by Dohyun Kim on #129
 local t = { }
@@ -10297,8 +12797,7 @@
 
 local function select_language(lang, id)
   loadlang(lang, id)
-  current_language = lang
-  last_language = lang
+  polyglossia.current_language = lang
 end
 
 local function set_default_language(lang, id)
@@ -10305,18 +12804,6 @@
   polyglossia.default_language = lang
 end
 
-local function falsefun()
-  return false
-end
-
-local function disable_hyphenation()
-  luatexbase.add_to_callback("hyphenate", falsefun, "polyglossia.disable_hyphenation")
-end
-
-local function enable_hyphenation()
-  luatexbase.remove_from_callback("hyphenate", "polyglossia.disable_hyphenation")
-end
-
 local check_char
 
 if luaotfload and luaotfload.aux and luaotfload.aux.font_has_glyph then
@@ -10352,9 +12839,12 @@
     require('polyglossia-tibt')
 end
 
+-- LaTeX's language register is \count19
+local lang_register = 19
+
 -- New hyphenation pattern loader: use language.dat.lua directly and the language identifiers
 local function newloader(langentry)
-    loaded_language = polyglossia.newloader_loaded_languages[langentry]
+    local loaded_language = newloader_loaded_languages[langentry]
     if loaded_language then
         log_info('Language ' .. langentry .. ' already loaded; id is ' .. lang.id(loaded_language))
         -- texio.write_nl('term and log', 'Language ' .. langentry .. ' already loaded with patterns ' .. tostring(loaded_language) .. '; id is ' .. lang.id(loaded_language))
@@ -10361,7 +12851,7 @@
         -- texio.write_nl('term and log', 'Language ' .. langentry .. ' already loaded with patterns ' .. loaded_language['patterns'] .. '; id is ' .. lang.id(loaded_language))
         return lang.id(loaded_language)
     else
-        langdata = newloader_available_languages[langentry]
+        local langdata = newloader_available_languages[langentry]
         if langdata and langdata['special'] == 'language0' then return 0 end
 
         if langdata then
@@ -10369,35 +12859,59 @@
             for k, v in pairs(langdata) do
 				s = s .. "\n" .. k .. "\t" .. tostring(v)
             end
-            polyglossia.newloader_max_langid = polyglossia.newloader_max_langid + 1
-            -- langobject = lang.new(newloader_max_langid)
-            lang.new(); lang.new(); lang.new()
-            langobject = lang.new()
+
+            --
+            -- LaTeX's \newlanguage increases language register (count19),
+            -- whereas LuaTeX's lang.new() increases its own language id.
+            -- So when a user has declared, say, \newlanguage\lang at xyz, then
+            -- these two numbers do not match each other. If we do not consider
+            -- this possible situation, our newloader() function will
+            -- unfortunately overwrite the language \lang at xyz.
+            --
+            -- Threfore here we will compare LaTeX's \newlanguage number with
+            -- LuaTeX's lang.new() id and select the bigger one for our new
+            -- language object. Also we will update LaTeX's language register
+            -- by this new id, so that another possible \newlanguage should not
+            -- overwrite our language object.
+            --
+            -- get next \newlanguage allocation number
+            local langcnt = tex.count[lang_register] + 1
+            -- get new lang object
+            local langobject = lang.new()
+            local langid = lang.id(langobject)
+            -- get bigger one between \newlanguage and new lang obj id
+            local maxlangid = math.max(langcnt, langid)
+            -- set language register for possible \newlanguage
+            tex.setcount('global', lang_register, maxlangid)
+            -- get new lang object if needeed
+            if langid ~= maxlangid then
+              langobject = lang.new(maxlangid)
+            end
 			s = s .. "\npatterns: " .. langdata.patterns
 			log_info(s)
             if langdata.patterns and langdata.patterns ~= '' then
-                pattfilepath = kpse.find_file(langdata.patterns)
+                local pattfilepath = kpse.find_file(langdata.patterns)
                 if pattfilepath then
-                    pattfile = io.open(pattfilepath)
+                    local pattfile = io.open(pattfilepath)
                     lang.patterns(langobject, pattfile:read('*all'))
                     pattfile:close()
                 end
             end
             if langdata.hyphenation and langdata.hyphenation ~= '' then
-                hyphfilepath = kpse.find_file(langdata.hyphenation)
+                local hyphfilepath = kpse.find_file(langdata.hyphenation)
                 if hyphfilepath then
-                    hyphfile = io.open(hyphfilepath)
+                    local hyphfile = io.open(hyphfilepath)
                     lang.hyphenation(langobject, hyphfile:read('*all'))
                     hyphfile:close()
                 end
             end
-            polyglossia.newloader_loaded_languages[langentry] = langobject
+            newloader_loaded_languages[langentry] = langobject
 
             log_info('Language ' .. langentry .. ' was not yet loaded; created with id ' .. lang.id(langobject))
             return lang.id(langobject)
         else
             log_warning('Language ' .. langentry .. ' not found in language.dat.lua')
-            return 255
+            return nohyphid
         end
     end
 end
@@ -10405,14 +12919,14 @@
 polyglossia.loadlang = loadlang
 polyglossia.select_language = select_language
 polyglossia.set_default_language = set_default_language
-polyglossia.current_language = current_language -- doesn't seem to be working well :-(
-polyglossia.default_language = default_language
 polyglossia.check_char = check_char
 polyglossia.load_frpt = load_frpt
 polyglossia.load_tibt_eol = load_tibt_eol
-polyglossia.disable_hyphenation = disable_hyphenation
-polyglossia.enable_hyphenation = enable_hyphenation
 polyglossia.newloader = newloader
+polyglossia.newloader_loaded_languages = newloader_loaded_languages
+-- global variables:
+-- polyglossia.default_language
+-- polyglossia.current_language
 %    \end{macrocode}
 % \iffalse
 %</polyglossia.lua>
@@ -10426,7 +12940,7 @@
 
    ¦----------------------------------------------¦
    ¦                                              ¦
-   ¦       THE POLYGLOSSIA PACKAGE v1.44          ¦
+   ¦       THE POLYGLOSSIA PACKAGE v1.45          ¦
    ¦                                              ¦
    ¦     Modern multilingual typesetting          ¦
    ¦        with XeLaTeX and LuaLaTeX             ¦
@@ -10435,7 +12949,8 @@
 
 This package provides an alternative to Babel for users of XeLaTeX and LuaLaTeX
 (with a few languages incompletely supported for the latter). This version
-includes support for 78 different languages.
+includes support for 75 different languages, some of which in different regional,
+national or scriptal varieties.
 
 Polyglossia makes it possible to automate the following tasks:
 
@@ -10453,7 +12968,8 @@
 * For languages that have their own numeration system, modifying the formatting
   of numbers appropriately.
 * Ensuring the proper directionality if the document contains languages
-  written from right to left (via the package bidi, available separately).
+  written from right to left (via the packages bidi and luabidi, available
+  separately).
 
 LICENSE
 
@@ -10464,18 +12980,129 @@
 LICENCE.txt for the text of the LPPL v1.3c, or
 http://www.latex-project.org/lppl.txt for the latest version.
 
-This work has the LPPL maintenance status ‘maintained’.  The current maintainer is Arthur Reutenauer.
+This work has the LPPL maintenance status ‘maintained’.  The current maintainer is
+Arthur Reutenauer.
 
 BUGS
 
-Polyglossia is full of bugs.  If you run into one, or suspect you do, or you
-have a request or comment, please use the GitHub issue tracker:
-http://github.com/reutenauer/polyglossia/issues
+If you run into a bug, or suspect you do, or you have a request or comment, please
+use the GitHub issue tracker: http://github.com/reutenauer/polyglossia/issues
 
 This is more efficient than contacting me by email as it allows me to track the
 issues and follow progress.
 %</../README>
 %<*Changelog>
+1.45 (27-10-2019)
+
+New features:
+  * Introduce a framework for external packages to access language variants. This fixes,
+    among other things, long-standing problems in the interaction of biblatex and polyglossia.
+  * Add new macros \languagevariant, \mainlanguagevariant, \babelname and \mainbabelname
+    for package authors to access language information.
+  * Add new test \iflanguageloaded{<language>}{<true>}{<false>}, where <language>
+    can be a \polyglossia or babel language name.
+  * Add new macros \localnumeral, \localnumeral*, \Localnumeral and
+    \Localnumeral* that convert Arabic digitals to the local number scheme.
+  * Add new macro \pghyphenation to add language-specific hyphenation exceptions (#18).
+  * Add support form (Khalkha & Cyrillic) Mongolian in line with babel-mongolian (#23).
+  * Add option splithyphens and vlna to Czech (XeTeX only; for LuaTeX, use the package
+    luavlna to get these features) (#32).
+  * Add support for Kurdish, both Kurmanji and Sorani (#277).
+  * Implement proper Cyrillic (alphanumeric) numbering (#285).
+  * Add new language friulian.
+    This deprecates friulan (which is still supported for backwards compatibility).
+  * Add new language malay with variants indonesian and malaysian.
+    This deprecates bahasai and bahasam (which are still supported for
+    backwards compatibility).
+  * Add new language gaelic with variants irish and scottish.
+    This deprecates irish and scottish as own polyglossia languages (which
+    are still supported for backwards compatibility).
+  * Add new language hungarian.
+    This deprecates magyar (which is still supported for backwards compatibility).
+  * Add new language sorbian with variants lower and upper.
+    This deprecates lsorbian and usorbian (which are still supported for
+    backwards compatibility).
+  * Add new language portuguese with variants portuguese and brazilian.
+    This deprecates brazil and portuges (which are still supported for
+    backwards compatibility).
+  * Add new language norwegian with variants nynorsk and bokmal.
+    This deprecates nynorsk and norsk (which are still supported for
+    backwards compatibility).
+  * Add new language persian.
+    This deprecates farsi (which is still supported for backwards compatibility).
+  * Add new language sami. Currently only Northern Sami is supported.
+    This deprecates samin (which is still supported for backwards compatibility).
+  * gloss-serbian: add numerals=cyrillic option. Add \asbuk and \Asbuk (#285).
+  * Implement basic support for (French) canadien and (English) canadian (#22)
+  * Improve support for Armenian (#79): Add captions, Eastern month names
+    (accessible via variant=eastern) and Armenian alphabetic numbering
+    (via numerals=armenian and \armenicnumeral).
+  * Add french option autospacing and commands \AutoSpacing, \NoAutoSpacing
+    This allows to switch off autospacing globally or locally (#113)
+  * Fixup \normalfont (#203)
+  * Fix directionality issues in mixed RTL/LTR paragraphs (#204)
+  * Implement babelshorthands for Finnish (#212) and Czech.
+  * Implement access to current language via Lua (#243).
+  * Introduce french option option autospacetypewriter
+    alias OriginalTypewriter
+  * Support \aemph with lualatex
+  * Rename automaticspacesaroundguillemets to autospaceguillemets 
+    The old option is kept for backwards compatibility.
+
+Bug fixes:
+  * Fix equation number in arabic and farsi (#7).
+  * Simplify and document Hebrew marcheshvan option (#16).
+  * Fix hyphenation of Greek with LuaTeX (#55).
+  * Fix N'ko date format (#63).
+  * Disable the extras of a language when a nested language starts (#66, #169).
+  * Properly implement bengali numbers (#69, #184).
+  * Fix conflicts with other packages caused by premature shorthand activation
+    in preamble (#81, #200).
+  * Fix kerning in math with French (#92).
+  * Fix expansion issue in Hebrew (#93).
+  * Fix numbering expansion issue in Greek (#110).
+  * Postpone \disablehyphenation in preamble until after setting of
+    document language (#125).
+  * Postpone the assignment of defaultfamily to BeginDocument,
+    thus do not overwrite \familydefault redefinitions in the preamble (#127).
+  * Reset number settings when switching language (#133).
+  * hebrew: Properly store \MakeUppercase for later restoration (#152).
+  * Fix whitespace issue in \datewelsh (#158).
+  * When switching language, set the language/script specific font families (#164).
+  * Correct some Bengali captions (#165).
+  * Fix documentation of Serbian (#168).
+  * Reset ucl codes in latin only if the respective variant is used (#172).
+  * Fix \disablehyphenation with LuaTeX (#187).
+  * Fix typos in Hindi captions (#202).
+  * Pass language options to the aux files (#205).
+  * Rewrite and fix English variant handling (#208).
+  * Define magyar caption formats in \blockextras and undef them in \noextras (#209).
+  * Ensure proper direction with arabic digits in Arabic and Farsi (#213).
+  * Fix \linespread with Korean (#218).
+  * Define russian caption before key allocation (#219).
+  * Register current language in polyglossia lua module after selection (#234).
+  * Fix babel language switching commands (#239).
+    \foreignlanguage and the starred otherlanguage* environment are not
+    supposed to change dates.
+  * Fix French spacing leaking beyond French (#270).
+  * Redefine fontfamilies for French only if language is loaded (#270).
+  * gloss-russian: 
+    - check whether command exist before redefining (#280).
+    - Fix some whitespace issues.
+  * Fix and simplify frenchfootnote definition (#294).
+  * Fix footnote numbering in Farsi.
+  * Fix latin footnotes in Arabic documents.
+  * Set the correct main direction with luabidi.
+  * Fix autospaceguillemets option in French.
+  * Fix grouping in gloss-danish.ldf.
+  * Properly store \MakeUppercase and \@arabic for later restoration.
+
+Documentation:
+  * Add documentation about footnotes in RTL context
+  * Document tibetan numerals option (#109)
+  * Improve frenchfootnote documentation.
+  * Mention Japanese support in the docs.
+
 1.44 (04-04-2019)
   * Correction to Russian language file, by Maksim Zholudev (commit d2f383e)
   * Added Macedonian language file, by Stefan Zlatinov (commit cd379e1)

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/babel-hebrewalph.def
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/babel-hebrewalph.def	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/babel-hebrewalph.def	2019-10-28 20:58:49 UTC (rev 52555)
@@ -4,13 +4,22 @@
          Adapted from hebrew.ldf (2005/03/30 v2.3h)]
 \newif\if at gim@apost  % whether we print apostrophes (gereshayim)
 \newif\if at gim@final  % whether we use final or initial letters
-\newrobustcmd*{\hebrewnumeral}[1]      % no apostrophe, no final letters
- {{\@gim at finalfalse\@gim at apostfalse\@hebrew at numeral{#1}}}
-\newrobustcmd*{\Hebrewnumeral}[1]      % apostrophe, no final letters
- {{\@gim at finalfalse\@gim at aposttrue\@hebrew at numeral{#1}}}
-\newrobustcmd*{\Hebrewnumeralfinal}[1] % apostrophe, final letters
- {{\@gim at finaltrue\@gim at aposttrue\@hebrew at numeral{#1}}}
-\newcommand*{\@hebrew at numeral}[1]{%
+\newcommand*\hebrewnumeral[1]{%
+  \expandafter\@hebrew at numeral\expandafter{\the\numexpr#1}%
+}
+\newcommand*\Hebrewnumeral[1]{%
+  \expandafter\@Hebrew at numeral\expandafter{\the\numexpr#1}%
+}
+\newcommand*\Hebrewnumeralfinal[1]{%
+  \expandafter\@Hebrew at numeralfinal\expandafter{\the\numexpr#1}%
+}
+\newrobustcmd*{\@hebrew at numeral}[1]      % no apostrophe, no final letters
+ {{\@gim at finalfalse\@gim at apostfalse\@hebrew@@numeral{#1}}}
+\newrobustcmd*{\@Hebrew at numeral}[1]      % apostrophe, no final letters
+ {{\@gim at finalfalse\@gim at aposttrue\@hebrew@@numeral{#1}}}
+\newrobustcmd*{\@Hebrew at numeralfinal}[1] % apostrophe, final letters
+ {{\@gim at finaltrue\@gim at aposttrue\@hebrew@@numeral{#1}}}
+\newcommand*{\@hebrew@@numeral}[1]{%
   \ifnum#1<\z@\space\xpg at warning{Illegal value (#1) for Hebrew numeral}%
   \else
     \@tempcnta=#1\@tempcntb=#1\relax
@@ -75,5 +84,5 @@
      \else#2\if at gim@apost ׳\fi\fi%
   \else{\@gim at finalfalse#2}\@gim at prevtrue\fi}
 \def\Alphfinal#1{\expandafter\@Alphfinal\csname c@#1\endcsname}%
-\providecommand*{\@Alphfinal}[1]{\protect\Hebrewnumeralfinal{\number#1}}
+\providecommand*{\@Alphfinal}[1]{\Hebrewnumeralfinal{#1}}
 \endinput

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/cyrillicnumbers.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/cyrillicnumbers.sty	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/cyrillicnumbers.sty	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,119 @@
+\ProvidesPackage{cyrillicnumbers}
+        [2019/09/13 v0.1 %
+         Formatting of Cyrillic alphabetic numbers]
+
+%% This follows https://en.wikipedia.org/wiki/Cyrillic_numerals
+
+% Numbers are often distinguished from text by centered dots.
+% The commented code does this. We leave it deactivated until
+% we get some expertise.
+\newrobustcmd\cnw at print{}
+\newrobustcmd\cnw at false{%
+  \renewrobustcmd\cnw at print{}}
+\newrobustcmd\cnw at true{%
+%   \renewrobustcmd\cnw at print{$\cdot$}%
+}
+\cnw at true
+
+\protected\def\cyr at alph#1{\expandafter\@cyr at alph\expandafter{\number#1}}
+\def\@cyr at alph#1{%
+  \ifnum#1<\@ne\space\cyr at ill@value{#1}%
+  \else
+    \cnw at print
+    \ifnum#1<10\expandafter\cyr at num@i\number#1%
+    \else
+      \ifnum#1<100\expandafter\cyr at num@ii\number#1%
+      \else
+        \ifnum#1<\@m\expandafter\cyr at num@iii\number#1%
+        \else
+          \ifnum#1<\@M\expandafter\cyr at num@iv\number#1%
+          \else
+            \ifnum#1<100000\expandafter\cyr at num@v\number#1%
+            \else
+              \ifnum#1<1000000\expandafter\cyr at num@vi\number#1%
+              \else
+                \space\cyr at ill@value{#1}%
+              \fi
+            \fi
+          \fi
+        \fi
+      \fi
+    \fi
+  \fi
+}
+
+\protected\def\cyr at Alph#1{\expandafter\@cyr at Alph\expandafter{\number#1}}
+\def\@cyr at Alph#1{%
+  \ifnum#1<\@ne\space\cyr at ill@value{#1}%
+  \else
+    \cnw at print
+    \ifnum#1<10\expandafter\cyr at Num@i\number#1%
+    \else
+      \ifnum#1<100\expandafter\cyr at Num@ii\number#1%
+      \else
+        \ifnum#1<\@m\expandafter\cyr at Num@iii\number#1%
+        \else
+          \ifnum#1<\@M\expandafter\cyr at Num@iv\number#1%
+          \else
+            \ifnum#1<100000\expandafter\cyr at Num@v\number#1%
+            \else
+              \ifnum#1<1000000\expandafter\cyr at Num@vi\number#1%
+              \else
+                \space\cyr at ill@value{#1}%
+              \fi
+            \fi
+          \fi
+        \fi
+      \fi
+    \fi
+  \fi
+}
+
+% Lowercase
+\def\cyr at num@i#1{%
+  \ifcase#1 \or а\or в\or г\or д\or е\or ѕ\or з\or и\or ѳ\fi
+  \ifnum#1=\z@\else\cnw at true\fi\cnw at print}
+\def\cyr at num@ii#1{%
+  \ifcase#1 \or і\or к\or л\or м\or н\or ѯ\or о\or п\or ч\fi
+  \ifnum#1=\z@\else\cnw at true\fi\cyr at num@i}
+\def\cyr at num@iii#1{%
+  \ifcase#1 \or р\or с\or т\or у\or ф\or х\or ѱ\or ѡ\or ц\fi
+  \ifnum#1=\z@\cnw at false\else\cnw at true\fi\cyr at num@ii}
+\def\cyr at num@iv#1{%
+  \ifnum#1=\z@\else ҂\fi
+  \ifcase#1 \or а\or в\or г\or д\or е\or ѕ\or з\or и\or ѳ\fi
+  \cyr at num@iii}
+\def\cyr at num@v#1{%
+  \ifnum#1=\z@\else ҂\fi
+  \ifcase#1 \or і\or к\or л\or м\or н\or ѯ\or о\or п\or ч\fi
+  \cyr at num@iv}
+\def\cyr at Num@vi#1{%
+  \ifnum#1=\z@\else ҂\fi
+  \ifcase#1 \or р\or с\or т\or у\or ф\or х\or ѱ\or ѡ\or ц\fi
+  \cyr at num@v}
+
+% Uppercase
+\def\cyr at Num@i#1{%
+  \ifcase#1 \or А\or В\or Г\or Д\or Е\or Ѕ\or З\or И\or Ѳ\fi
+  \ifnum#1=\z@\else\cnw at true\fi\cnw at print}
+\def\cyr at Num@ii#1{%
+  \ifcase#1 \or І\or К\or Л\or М\or Н\or Ѯ\or О\or П\or Ч\fi
+  \ifnum#1=\z@\else\cnw at true\fi\cyr at Num@i}
+\def\cyr at Num@iii#1{%
+  \ifcase#1 \or Р\or С\or Т\or У\or Ф\or Х\or Ѱ\or Ѡ\or Ц\fi
+  \ifnum#1=\z@\cnw at false\else\cnw at true\fi\cyr at Num@ii}
+\def\cyr at Num@iv#1{%
+  \ifnum#1=\z@\else ҂\fi
+  \ifcase#1 \or А\or В\or Г\or Д\or Е\or Ѕ\or З\or И\or Ѳ\fi
+  \cyr at Num@iii}
+\def\cyr at Num@v#1{%
+  \ifnum#1=\z@\else ҂\fi
+  \ifcase#1 \or І\or К\or Л\or М\or Н\or Ѯ\or О\or П\or Ч\fi
+  \cyr at Num@iv}
+\def\cyr at Num@vi#1{%
+  \ifnum#1=\z@\else ҂\fi
+  \ifcase#1 \or Р\or С\or Т\or У\or Ф\or Х\or Ѱ\or Ѡ\or Ц\fi
+  \cyr at Num@v}
+\def\cyr at ill@value#1{\xpg at warning{Illegal value (#1) for cyr numeral}[$#1$]}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/cyrillicnumbers.sty
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-albanian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-albanian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-albanian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 
 \PolyglossiaSetup{albanian}{
   hyphennames={albanian},
+  langtag=SQI,
   hyphenmins={2,2},
   indentfirst=true,
   fontsetup=true,

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arabic.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arabic.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arabic.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -15,9 +15,10 @@
   langtag=ARA,
   scripttag=arab,
   hyphennames={nohyphenation},
-  fontsetup=true
+  fontsetup=true,
+  envname=Arabic,
+  localnumeral=arabicnumerals
   %TODO localalph={abjad,abjad}
-  %TODO localnumber=arabicnumber
 }
 
 \newif\ifeastern at numerals
@@ -137,6 +138,9 @@
     \fi%
  \fi}}
 
+
+\newcommand{\arabicnumerals}[2]{\arabicnumber{#2}}
+
 \def\arabicnumber#1{%
   \ifeastern at numerals
     \arabicdigits{\number#1}%
@@ -182,34 +186,39 @@
   \ifnum#1=\z@\fi\abj at maghribi@num at iii}
 
 \def\arabic at numbers{%
-   \let\@origalph\@alph%
-   \let\@origAlph\@Alph%
    \let\@alph\abjad%
    \let\@Alph\abjad%
 }
+
 \def\noarabic at numbers{%
-  \let\@alph\@origalph%
-  \let\@Alph\@origAlph%
-  }
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
+}
 
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
 \def\arabic at globalnumbers{%
-  \let\orig at arabic\@arabic%
   \let\@arabic\arabicnumber%
-  \renewcommand\thefootnote{\protect\arabicnumber{\c at footnote}}%
-  }
+  \renewcommand\thefootnote{\localnumeral*{footnote}}%
+  \renewcommand\theequation{\localnumeral*{equation}}%
+}
 
-\def\noarabic at globalnumbers{
-   \let\@arabic\orig at arabic%
-   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
-   }
+\def\noarabic at globalnumbers{%
+   \let\@arabic\xpg at save@arabic%
+}
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at arabic{%
-   \let\orig at MakeUppercase\MakeUppercase%
    \def\MakeUppercase##1{##1}%
    % TODO disable \@Roman and \@roman ?
-   }
+}
+
 \def\noextras at arabic{%
-   \let\MakeUppercase\orig at MakeUppercase%
-   }
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase
+}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-armenian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-armenian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-armenian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -6,35 +6,57 @@
   langtag=HYE,
   hyphennames={armenian},
   hyphenmins={2,2},
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=armeniannumerals
 }
 
-%\def\captionsarmenian{%
-%   \def\refname{}%
-%   \def\abstractname{}%
-%   \def\bibname{}%
-%   \def\prefacename{}%
-%   \def\chaptername{}%
-%   \def\appendixname{}%
-%   \def\contentsname{}%
-%   \def\listfigurename{}%
-%   \def\listtablename{}%
-%   \def\indexname{}%
-%   \def\authorname{}%
-%   \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\datearmenian{%
+\newif\if at eastern@armenian
+\@eastern at armenianfalse
+\define at choicekey*+{armenian}{variant}[\val\nr]{western,eastern}[western]{%
+   \ifcase\nr\relax
+      % western:
+      \@eastern at armenianfalse%
+   \or
+      % eastern:
+      \@eastern at armeniantrue%
+   \fi
+   \xpg at info{Option: Armenian, variant=\val}%
+}{\xpg at warning{Unknown Armenian variant `#1'}}
+
+\newif\if at armenian@numerals
+\@armenian at numeralsfalse
+\define at key{armenian}{numerals}[armenian]{%
+  \ifstrequal{#1}{arabic}{\@armenian at numeralsfalse}{\@armenian at numeralstrue}%
+}
+
+% Taken from ArmTeX. Audit!
+\def\captionsarmenian{%
+   \def\refname{Հղումներ}%
+   \def\abstractname{Սեղմագիր}%
+   \def\bibname{Գրականություն}%
+   \def\prefacename{Նախաբան}%
+   \def\chaptername{Գլուխ}%
+   \def\appendixname{Հավելված}%
+   \def\contentsname{Բովանդակություն}%
+   \def\listfigurename{Նկարների ցանկ}%
+   \def\listtablename{Աղյուսակների ցանկ}%
+   \def\indexname{Առարկայական ցանկ}%
+   \def\figurename{Նկար}%
+   \def\tablename{Աղյուսակ}%
+   \def\partname{Մաս}%
+   \def\pagename{էջ}%
+   \def\seename{տե՛ս}%
+   \def\alsoname{տե՛ս նաեւ}%
+   \def\enclname{Կից՝}%
+   \def\ccname{Կրկնօրինակը՝}%
+% The \headtoname is empty: the typesetter should use the dative (trakan
+% holov) of the recipient's name.
+   \def\headtoname{}%
+   \def\proofname{Ապացույց}%
+   \def\glossaryname{Տերմինների ցանկ}%
+}
+
+\def\date at western@armenian{%
    \def\today{\ifcase\month\or
     Յունուար\or
     Փետրուար\or
@@ -48,5 +70,101 @@
     Հոկտեմբեր\or
     Նոյեմբեր\or
     Դեկտեմբեր\fi
-    \number\day,\space\number\year}}
+    \number\day,\space\number\year}%
+}
+
+\def\date at eastern@armenian{%
+   \def\today{\ifcase\month\or
+    Հունվար\or
+    Փետրվար\or
+    Մարտ\or
+    Ապրիլ\or
+    Մայիս\or
+    Հունիս\or
+    Հուլիս\or
+    Օգոստոս\or
+    Սեպտեմբեր\or
+    Հոկտեմբեր\or
+    Նոյեմբեր\or
+    Դեկտեմբեր\fi
+    \number\day,\space\number\year}%
+}
+
+\def\datearmenian{%
+  \if at eastern@armenian
+     \date at eastern@armenian%
+  \else
+     \date at western@armenian%
+  \fi
+}
+
+\newcommand{\armeniannumerals}[2]{%
+  \if at armenian@numerals
+     \armeniannumber{#2}%
+  \else
+     #2%
+  \fi%
+}
+
+\def\armenian at numbers{%
+   \if at armenian@numerals
+      \def\armenian at alph##1{\expandafter\armeniannumeral\expandafter{\the##1}}%
+      \let\@alph\armenian at alph%
+   \fi%
+}
+
+\def\noarmenian at numbers{%
+  \let\@alph\latin at alph%
+  \let\armenian at alph\@undefined%
+}
+
+\def\armenian at globalnumbers{%
+  \if at armenian@numerals
+    \let\@arabic\armeniannumber%
+    \renewcommand\thefootnote{\localnumeral*{footnote}}%
+    \renewcommand\theequation{\localnumeral*{equation}}%
+  \fi
+}
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
+\def\noarmenian at globalnumbers{
+   \let\@arabic\xpg at save@arabic%
+}
+
+\protected\def\armeniannumber#1{\expandafter\@armeniannumber\expandafter{\number#1}}
+\def\@armeniannumber#1{%
+  \ifnum#1<\@ne\space\arm at ill@value{#1}%
+  \else
+    \ifnum#1<10\expandafter\arm at num@i\number#1%
+    \else
+      \ifnum#1<100\expandafter\arm at num@ii\number#1%
+      \else
+        \ifnum#1<\@m\expandafter\arm at num@iii\number#1%
+        \else
+          \ifnum#1<\@M\expandafter\arm at num@iv\number#1%
+          \else
+             \space\arm at ill@value{#1}%
+          \fi
+        \fi
+      \fi
+    \fi
+  \fi
+}
+
+\let\armeniannumeral=\armeniannumber
+\def\arm at num@i#1{%
+  \ifcase#1\or Ա\or Բ\or Գ\or Դ\or Ե\or Զ\or Է\or Ը\or Թ\fi}
+\def\arm at num@ii#1{%
+  \ifcase#1\or Ժ\or Ի\or Լ\or Խ\or Ծ\or Կ\or Հ\or Ձ\or Ղ\fi
+  \arm at num@i}
+\def\arm at num@iii#1{%
+  \ifcase#1\or Ճ\or Մ\or Յ\or Ն\or Շ\or Ո\or Չ\or Պ\or Ջ\fi
+  \arm at num@ii}
+\def\arm at num@iv#1{%
+  \ifcase#1\or Ռ\or Ս\or Վ\or Տ\or Ր\or Ց\or Ւ\or Փ\or Ք\fi
+  \arm at num@iii}
+\def\arm at ill@value#1{\xpg at warning{Illegal value (#1) for Armenian numeral}[$#1$]}
+
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-asturian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-asturian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-asturian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -5,6 +5,7 @@
 \PolyglossiaSetup{asturian}{
   hyphennames={asturian,catalan},
   hyphenmins={2,2},
+  langtag=AST,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasai.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasai.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasai.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,46 +1,21 @@
 \ProvidesFile{gloss-bahasai.ldf}[polyglossia: module for bahasa indonesia]
-\RequirePackage{hijrical}
 
+% We only provide this gloss for babel compatibility. Since bahasai is 
+% a malay variety, we use 'malay' with variant 'indonesian' now.
+
+\input{gloss-malay.ldf}
+
 \PolyglossiaSetup{bahasai}{%
-  language=Bahasa Indonesia,
+  language=Indonesian,
+  langtag=IND,
   hyphennames={indonesian,indon,bahasai,bahasa,bahasam,malay,melayu},
   hyphenmins={2,2},
   fontsetup=true}
 
-\def\captionsbahasai{%
-   \def\refname{Pustaka}%
-   \def\abstractname{Ringkasan}%
-   \def\bibname{Bibliografi}%
-   \def\prefacename{Pendahuluan}%
-   \def\chaptername{Bab}%
-   \def\appendixname{Lampiran}%
-   \def\contentsname{Daftar Isi}%
-   \def\listfigurename{Daftar Gambar}%
-   \def\listtablename{Daftar Tabel}%
-   \def\indexname{Indeks}%
-   \def\figurename{Gambar}%
-   \def\tablename{Tabel}%
-   %\def\thepart{}%
-   \def\partname{Bagian}%
-   \def\pagename{Halaman}%
-   \def\seename{lihat}%
-   \def\alsoname{lihat juga}%
-   \def\enclname{Lampiran}%
-   \def\ccname{cc}%
-   \def\headtoname{Kepada}%
-   \def\proofname{Bukti}%
-   \def\glossaryname{Daftar Istilah}%
-   }
-\def\datebahasai{%
-   \def\today{\number\day~\ifcase\month\or
-    Januari\or Pebruari\or Maret\or April\or Mei\or Juni\or
-    Juli\or Agustus\or September\or Oktober\or Nopember\or Desember\fi
-    \space \number\year}}
+\let\captionsbahasai\captionsmalay at indonesian
+\let\datebahasai\datemalay at indonesian
 
-\def\hijrimonthbahasai#1{\ifcase#1%
-\or Muharram\or Safar\or Rabiul awal\or Rabiul akhir\or Jumadil awal\or Jumadil akhir\or Rajab%
-\or Sya'ban\or Ramadhan\or Syawal\or Dzulkaidah\or Dzulhijjah\fi}
 \DefineFormatHijriDate{bahasai}{%
-\number\value{Hijriday}\space\hijrimonthbahasai{\value{Hijrimonth}}\space\number\value{Hijriyear}}
+  \number\value{Hijriday}\space\hijrimonthmalay at indonesian{\value{Hijrimonth}}\space\number\value{Hijriyear}}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasam.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasam.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasam.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,54 +1,21 @@
 \ProvidesFile{gloss-bahasam.ldf}[polyglossia: module for bahasa melayu]
-\RequirePackage{hijrical}
+
+% We only provide this gloss for babel compatibility. Since bahasai is 
+% a malay variety, we use 'malay' with variant 'indonesian' now.
+
+\input{gloss-malay.ldf}
+
 \PolyglossiaSetup{bahasam}{%
-  language=Bahasa Melayu,
+  language=Malay,
+  langtag=MLY,
   hyphennames={malay,melayu,bahasam,bahasa,bahasai,indonesian,indon},
   hyphenmins={2,2},
   fontsetup=true}
 
-\def\captionsbahasam{%
-   \def\refname{Rujukan}%
-   \def\abstractname{Abstrak}%
-   \def\bibname{Bibliografi}%
-   \def\prefacename{Pendahuluan}%
-   \def\chaptername{Bab}%
-   \def\appendixname{Lampiran}%
-   \def\contentsname{Kandungan}%
-   \def\listfigurename{Senarai Rajah}%
-   \def\listtablename{Senarai Jadual}%
-   \def\indexname{Indeks}%
-   \def\figurename{Rajah}%
-   \def\tablename{Jadual}%
-   \def\thepart{}%
-   \def\partname{Bahagian}%
-   \def\pagename{Halaman}%
-   \def\seename{lihat}%
-   \def\alsoname{lihat juga}%
-   \def\enclname{Lampiran}%
-   \def\ccname{salinan kpd}%
-   \def\headtoname{Kepada}%
-   \def\proofname{Bukti}%
-   \def\glossaryname{Senarai Istilah}%
-   }
-\def\datebahasam{%
-   \def\bahasam at day{%
-      \ifcase\day\or%
-        1hb\or 2hb\or 3hb\or 4hb\or 5hb\or%
-        6hb\or 7hb\or 8hb\or 9hb\or 10hb\or%
-        11hb\or 12hb\or 13hb\or 14hb\or 15hb\or%
-        16hb\or 17hb\or 18hb\or 19hb\or 20hb\or%
-        21hb\or 22hb\or 23hb\or 24hb\or 25hb\or%
-        26hb\or 27hb\or 28hb\or 29hb\or 30hb\or%
-        31hb\fi}%
-   \def\today{\bahasam at day~\ifcase\month\or
-    Januari\or Februari\or Mac\or April\or Mei\or Jun\or
-    Julai\or Ogos\or September\or Oktober\or November\or Disember\fi
-    \space \number\year}}
+\let\captionsbahasam\captionsmalay at malay
+\let\datebahasam\datemalay at malay
 
-\def\hijrimonthbahasam#1{\ifcase#1%
-\or Muharram\or Safar\or Rabiulawal\or Rabiulakhir\or Jamadilawal\or Jamadilakhir\or Rejab%
-\or Syaaban\or Ramadan\or Syawal\or Zulkaedah\or Zulhijah\fi}
 \DefineFormatHijriDate{bahasam}{%
-\number\value{Hijriday}\space\hijrimonthbahasam{\value{Hijrimonth}}\space\number\value{Hijriyear}}
+  \number\value{Hijriday}\space\hijrimonthmalay at malay{\value{Hijrimonth}}\space\number\value{Hijriyear}}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-basque.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-basque.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-basque.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{basque}{
   hyphennames={basque},
   hyphenmins={2,2},
+  langtag=EUQ,
   indentfirst=true,
   fontsetup=true,
 }

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bengali.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bengali.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bengali.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -18,8 +18,8 @@
   hyphennames={bengali},
   hyphenmins={2,2},%CHECK
   fontsetup=true,
+  localnumeral=bengalinumerals
   %TODO nouppercase=true,
-  %TODO localnumber=bengalinumber
 }
 
 \def\tmp at western{Western}
@@ -73,7 +73,7 @@
 }
 
 \def\captionsbengali{%
-  \def\refname{তথ্যসুত্রসমূহ}%
+  \def\refname{তথ্যসূত্রসমূহ}%
   \def\abstractname{সারসংক্ষেপ}%
   \def\bibname{তথ্যবিবরণ}%
   \def\prefacename{পূর্বকথা}%
@@ -83,8 +83,8 @@
   \def\listfigurename{ছবি/নকশা সমূহের তালিকা}%
   \def\listtablename{তালিকাসারণী}%
   \def\indexname{সূচক/নির্দেশক}%
-  \def\figurename{ছবি/নকশা}%
-  \def\tablename{সারনী}%
+  \def\figurename{চিত্র}%
+  \def\tablename{সারণী}%
   %\def\thepart{}% TODO
   \def\partname{খন্ড}%
   \def\pagename{পৃষ্ঠা}%
@@ -99,14 +99,14 @@
 \def\datebengali{%
   \def\bengalimonth{%
     \ifcase\month\or
-      জানুয়ারী\or
-      ফেব্রুয়ারী\or
+      জানুয়ারি\or
+      ফেব্রুয়ারি\or
       মার্চ\or
       এপ্রিল\or
       মে\or
       জুন\or
       জুলাই\or
-      আগষ্ট\or
+      আগস্ট\or
       সেপ্টেম্বর\or
       অক্টোবর\or
       নভেম্বর\or
@@ -114,6 +114,8 @@
   \def\today{\bengalinumber\day\space\bengalimonth\space\bengalinumber\year}%
 }
 
+\newcommand{\bengalinumerals}[2]{\bengalinumber{#2}}
+
 \def\bengalinumber#1{%
   \ifbengali at devanagari@numerals
     \devanagaridigits{\number#1}%
@@ -125,9 +127,20 @@
     \fi
   \fi}
 
-\def\bengalinumber#1{\bengalidigits{\number#1}}% Takes number
-\def\bengalinumeral#1{\bengalinumber{\csname c@#1\endcsname}}% Takes counter
+\def\bengalinumeral#1{\expandafter\bengalinumber\expandafter{\the##1}}% Takes counter
 
+\def\bengali at globalnumbers{%
+   \let\@arabic\bengalinumber%
+   \renewcommand\thefootnote{\localnumeral*{footnote}}%
+}
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
+\def\nobengali at globalnumbers{%
+  \let\@arabic\xpg at save@arabic%
+}
+
 \def\blockextras at bengali{\extras at bengali}
 \def\inlineextras at bengali{\extras at bengali}
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-brazil.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-brazil.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-brazil.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,40 +1,25 @@
-\ProvidesFile{gloss-brazil.ldf}[polyglossia: module for portuguese]
+\ProvidesFile{gloss-brazil.ldf}[polyglossia: module for brazilian portuguese]
+
+% We only provide this gloss for backwards compatibility. The name
+% 'brazil' was selected in accordance with babel.
+% Since brazil is a variety of portuguese, we use 'portuguese' now.
+
+% FIXME: Once we support babel aliases (#112) this gloss can go.
+
+\xpg at warning{The language name 'brazil' is deprectated.\MessageBreak
+             Please use 'portuguese' with variant 'brazilian' instead.}
+
+\input{gloss-portuguese.ldf}
+
 \PolyglossiaSetup{brazil}{
   language=Brazilian Portuguese,
+  langtag=PTG,
   hyphennames={brazil,portuguese,portuges},
   hyphenmins={2,3},
   fontsetup=true,
 }
 
-\def\captionsbrazil{%
-   \def\refname{Referências}%
-   \def\abstractname{Resumo}%
-   \def\bibname{Referências Bibliográficas}%
-   \def\prefacename{Prefácio}%
-   \def\chaptername{Capítulo}%
-   \def\appendixname{Apêndice}%
-   \def\contentsname{Sumário}%
-   \def\listfigurename{Lista de Figuras}%
-   \def\listtablename{Lista de Tabelas}%
-   \def\indexname{Índice Remissivo}%
-   \def\figurename{Figura}%
-   \def\tablename{Tabela}%
-   %\def\thepart{}%
-   \def\partname{Parte}%
-   \def\pagename{Página}%
-   \def\seename{veja}%
-   \def\alsoname{veja também}%
-   \def\enclname{Anexo}%
-   \def\ccname{Cópia para}%
-   \def\headtoname{Para}%
-   \def\proofname{Demonstração}%
-   \def\glossaryname{Glossário}%
-   }
-\def\datebrazil{%   
-   \def\today{\number\day\space de\space\ifcase\month\or
-      janeiro\or fevereiro\or março\or abril\or maio\or junho\or
-      julho\or agosto\or setembro\or outubro\or novembro\or dezembro%
-      \fi\space de\space\number\year}%
-      }
+\let\captionsportuges\captionsportuguese at brazil
+\let\dateportuges\dateportuguese at brazil
      
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-breton.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-breton.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-breton.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{breton}{
   hyphennames={breton},
   hyphenmins={2,2},
+  langtag=BRE,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bulgarian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bulgarian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bulgarian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -29,8 +29,6 @@
    \xpg at ill@value{#1}{bulgarian at alph}\fi}%
 
 \def\bulgarian at numbers{%
-   \let\latin at Alph\@Alph%
-   \let\latin at alph\@alph%
    \let\@Alph\bulgarian at Alph%
    \let\@alph\bulgarian at alph%
  }

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-catalan.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-catalan.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-catalan.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{catalan}{
   hyphennames={catalan},
   hyphenmins={2,2},
+  langtag=CAT,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,
@@ -13,9 +14,11 @@
 \else
   \setkeys{catalan}{babelshorthands=false}
 \fi
+
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 %%% adapted from Babel's catalan.ldf

Deleted: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-classiclatin.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-classiclatin.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-classiclatin.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,157 +0,0 @@
-%%
-%% This is file `gloss-classiclatin.ldf',
-%% generated with the docstrip utility.
-%%
-%% The original source files were:
-%%
-%% gloss-latin.dtx  (with options: `laclassic')
-%%   ------------------------------------------------------------------
-%%   Latin module for polyglossia
-%%   Copyright (C) Claudio Beccari 2013-2016
-%%   Copyright (C) Élie Roux 2016
-%%   This work is distributed under the MIT License.
-%% 
-%%   See the postamble.
-%%   ------------------------------------------------------------------
-\ProvidesFile{gloss-classiclatin.ldf}
-        [2016/09/10 v.1.03 Latin support from polyglossia]
-%%
-
-
-\PolyglossiaSetup{classiclatin}{%
-      hyphennames={classiclatin},
-      hyphenmins={2,2},
-      frenchspacing=true,
-      fontsetup=true,
-}
-\def\classicuclccodes{\lccode`\V=`\u \uccode`\u=`\V}
-\def\noclassicuclccodes{\lccode`\V=`\v \uccode`\u=`\U}
-\def\classiclatincaptions{%
-   \def\prefacename{Praefatio}%
-   \def\refname{Conspectus librorum}%
-   \def\abstractname{Summarium}%
-   \def\bibname{Conspectus librorum}%
-   \def\chaptername{Caput}%
-   \def\appendixname{Additamentum}%
-   \def\contentsname{Index}%
-   \def\listfigurename{Conspectus descriptionum}%
-   \def\listtablename{Conspectus tabularum}%
-   \def\indexname{Index rerum notabilium}%
-   \def\figurename{Descriptio}%
-   \def\tablename{Tabula}%
-   \def\partname{Pars}%
-   \def\enclname{Additur}%
-   \def\ccname{Exemplar}%
-   \def\headtoname{\ignorespaces}%
-   \def\pagename{charta}%
-   \def\seename{cfr.}%
-   \def\alsoname{cfr.}%
-   \def\proofname{Demonstratio}%
-   \def\glossaryname{Glossarium}%
-   }
-
-\def\classiclatindate{%
-   \def\today{\uppercase\expandafter{\romannumeral\day}%
-      \space \ifcase\month
-      \or Januarii\or Februarii\or Martii\or Aprilis\or Maii\or Junii\or
-      Julii\or Augusti\or Septembris\or Octobris\or Nouembris\or
-      Decembris\fi
-      \space \uppercase\expandafter{\romannumeral\year}}}
-
-\define at boolkey{classiclatin}[classiclatin@]{babelshorthands}[true]{}
-
-\ifsystem at babelshorthands
-  \setkeys{classiclatin}{babelshorthands=true}
-\else
-  \setkeys{classiclatin}{babelshorthands=false}
-\fi
-
-\ifcsundef{initiate at active@char}{%
-    \input{babelsh.def}\initiate at active@char{"}}{}
-
-\def\classiclatin at shorthands{%
-  \def\language at group{classiclatin}%
-  \bbl at activate{"}%
-  \declare at shorthand{classiclatin}{"}{\relax
-    \ifmmode
-      \def\xpgcla at next{''}%
-    \else
-      \def\xpgcla at nextdq{\futurelet\xpgla at temp\xpgla at cwm}%
-    \fi
-  \xpgcla at nextdq}%
-}
-
-\def\xpgcla at allowhyphens{\bbl at allowhyphens\discretionary{-}{}{}\bbl at allowhyphens}
-\newcommand*{\xpgcla at cwm}{\let\xpgcla@@nextdq\relax
-  \ifcat\noexpand\xpgcla at temp a%
-    \let\xpgcla@@nextdq\xpgcla at allowhyphens
-  \else
-    \ifx\xpgcla at temp\ae
-        \let\xpgcla@@nextdq\xpgcla at allowhyphens
-    \else
-        \ifx\xpgcla at temp\oe
-           \let\xpgcla@@nextdq\xpgcla at allowhyphens
-        \else
-           \if\noexpand\xpgla at temp\string|%
-              \def\xpgcla@@nextdq{\xpgcla at allowhyphens\@gobble}%
-           \fi
-        \fi
-    \fi
-  \fi
-  \xpgla@@nextdq}%
-\def\noclassiclatin at shorthands{%
-  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{"}}%
-}
-
-\let\xpgcla at savedvalues\empty
-\AtEndPreamble{%
-  \edef\xpgcla at savedvalues{%
-    \clubpenalty=\the\clubpenalty\space
-    \@clubpenalty=\the\@clubpenalty\space
-    \widowpenalty=\the\widowpenalty\space
-    \finalhyphendemerits=\the\finalhyphendemerits}%
-}
-
-\def\noextras at classiclatin{%
-   \lccode\string"2019=\z@
-   \noclassiclatin at shorthands
-   \noclassicuclccodes
-   \xpgcla at savedvalues
-}
-
-\def\blockextras at classiclatin{%
-   \lccode\string"2019=\string"2019
-   \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000
-   \finalhyphendemerits=50000000
-   \classicuclccodes
-   \ifclassiclatin at babelshorthands\classiclatin at shorthands\fi
-}
-
-\def\inlineextras at classiclatin{%
-   \lccode\string"2019=\string"2019
-   \classicuclccodes
-   \ifclassiclatin at babelshorthands\classiclatin at shorthands\fi
-}
-%%   Copyright (C) Claudio Beccari 2013-2016
-%%   Copyright (C) Élie Roux 2016
-%% 
-%%   Permission is hereby granted, free of charge, to any person obtaining
-%%   a copy of this software and associated documentation files
-%%   (the "Software"), to deal in the Software without restriction, including
-%%   without limitation the rights to use, copy, modify, merge, publish,
-%%   distribute, sublicense, and/or sell copies of the Software, and to permit
-%%   persons to whom the Software is furnished to do so, subject to the following
-%%   conditions:
-%% 
-%%   The above copyright notice and this permission notice shall be included in
-%%   all copies or substantial portions of the Software.
-%% 
-%%   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-%%   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-%%   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-%%   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-%%   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-%%   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-%%   IN THE SOFTWARE.
-%%
-%% End of file `gloss-classiclatin.ldf'.

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-croatian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-croatian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-croatian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,7 +1,9 @@
 \ProvidesFile{gloss-croatian.ldf}[polyglossia: module for croatian]
 \PolyglossiaSetup{croatian}{
+  langtag=HRV,
   hyphennames={croatian},
   hyphenmins={2,2}, % aligned with https://ctan.org/pkg/hrhyph patterns and http://lebesgue.math.hr/~nenad/Diplomski/Maja_Ribaric_2011.pdf
+  frenchspacing=true, % recommendation from Damir Bralić
   indentfirst=false, % recommendation from Damir Bralić
   fontsetup=true
 }

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-czech.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-czech.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-czech.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,11 +1,167 @@
 \ProvidesFile{gloss-czech.ldf}[polyglossia: module for czech]
+
 \PolyglossiaSetup{czech}{
   hyphennames={czech},
   hyphenmins={2,2},
+  langtag=CSY,
   frenchspacing=true,
   fontsetup=true,
 }
 
+\define at boolkey{czech}[czech@]{babelshorthands}[true]{}
+
+\define at boolkey{czech}[czech@]{splithyphens}[true]{}
+
+\define at boolkey{czech}[czech@]{vlna}[true]{}
+
+\ifsystem at babelshorthands
+  \setkeys{czech}{babelshorthands=true}
+\else
+  \setkeys{czech}{babelshorthands=false}
+\fi
+
+\ifcsundef{initiate at active@char}{%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
+}{}
+
+\def\cs@@splithyphen#1{%
+  \kern\z@\discretionary{-}{\char\hyphenchar\the\font}{#1}%
+  \nobreak\hskip\z@%
+}
+
+\def\cs at splithyphen{%
+  \cs@@splithyphen{-}%
+}
+
+\def\czech at shorthands{%
+  \bbl at activate{"}%
+  \def\language at group{czech}%
+  \declare at shorthand{czech}{"=}{\cs at splithyphen}%
+  \declare at shorthand{czech}{"`}{„}%
+  \declare at shorthand{czech}{"'}{“}%
+  \declare at shorthand{czech}{"<}{«}%
+  \declare at shorthand{czech}{">}{»}%
+}
+
+\def\noczech at shorthands{%
+  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{"}}%
+}
+
+\ifxetex
+  % splithyphens
+  \newXeTeXintercharclass\czech at hyphen % -
+  % vlna
+  \newXeTeXintercharclass\czech at openpunctuation
+  \newXeTeXintercharclass\czech at nonsyllabicpreposition
+  \ifdefined\e at alloc@intercharclass at top
+    \chardef\czech at boundary=\e at alloc@intercharclass at top
+  \else
+    \ifdefined\XeTeXinterwordspaceshaping
+      \chardef\czech at boundary=4095 %
+      \def\newXeTeXintercharclass{%
+        \e at alloc\XeTeXcharclass\chardef
+              \xe at alloc@intercharclass\m at ne\@ucharclass at boundary}
+    \else
+      \chardef\czech at boundary=255
+    \fi
+  \fi
+\fi
+
+\def\czech at hyphens{%
+    \ifluatex
+      \xpg at warning{The 'splithyphens' option only works for XeLaTeX.\MessageBreak
+                   Please use the luavlna package to enable the feature for LuaLaTeX}
+    \else
+      \XeTeXinterchartokenstate=1
+      \XeTeXcharclass `\- \czech at hyphen
+      \XeTeXinterchartoks \z@ \czech at hyphen = {\cs@@splithyphen}% "-" -> "\cs@@splithyphen-"
+      % necessary if used together with vlna:
+      \XeTeXinterchartoks \czech at nonsyllabicpreposition \czech at hyphen = {\cs@@splithyphen}% "-" -> "\cs@@splithyphen-"
+    \fi%
+}
+
+\def\noczech at hyphens{%
+    \ifxetex
+      \XeTeXcharclass `\- \z@
+    \fi%
+}
+
+% Add nonbreakable space after single-letter word to
+% prevent them to land at the end of a line
+\def\czech at vlna{%
+    \ifluatex
+       \xpg at warning{The 'vlna' option only works for XeLaTeX.\MessageBreak
+                    Please use the luavlna package to enable the feature for LuaLaTeX}
+    \else
+        % Code taken and adapted from xevlna.sty
+        \XeTeXinterchartokenstate=1
+        \XeTeXcharclass `\( \czech at openpunctuation
+        \XeTeXcharclass `\[ \czech at openpunctuation
+        \XeTeXcharclass `\„ \czech at openpunctuation
+        \XeTeXcharclass `\» \czech at openpunctuation
+        \XeTeXcharclass `\K \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\k \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\S \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\s \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\V \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\v \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\Z \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\z \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\O \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\o \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\U \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\u \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\A \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\a \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\I \czech at nonsyllabicpreposition
+        \XeTeXcharclass `\i \czech at nonsyllabicpreposition
+        \XeTeXinterchartoks \czech at boundary \czech at nonsyllabicpreposition {\czech at interchartoks}
+        \XeTeXinterchartoks \czech at openpunctuation \czech at nonsyllabicpreposition {\czech at interchartoks}
+        \def\czech at nointerchartoks{\let\czech at interchartoks\czech at PreCSpreposition}
+        \def\czech at PreCSpreposition{\def\next{}%
+           \ifnum\catcode`\ =10 % nothing will be done in verbatim
+           \ifmmode % nothing in math
+           \else
+              \let\czech at interchartoks\czech at nointerchartoks
+              \let\next\czech at ExamineCSpreposition
+           \fi \fi
+          \next%
+        }
+        \def\czech at ExamineCSpreposition ##1{##1\futurelet\next\czech at ProcessCSpreposition}
+        \def\czech at ProcessCSpreposition{\ifx\next\czech at XeTeXspace\nobreak\fi}
+        \futurelet\czech at XeTeXspace{ }\czech at nointerchartoks
+    \fi
+}
+
+\def\noczech at vlna{%
+    \ifluatex
+    \else
+        \XeTeXcharclass`\(\z@
+        \XeTeXcharclass`\[\z@
+        \XeTeXcharclass`\„\z@
+        \XeTeXcharclass`\»\z@
+        \XeTeXcharclass`\K\z@
+        \XeTeXcharclass`\k\z@
+        \XeTeXcharclass`\S\z@
+        \XeTeXcharclass`\s\z@
+        \XeTeXcharclass`\V\z@
+        \XeTeXcharclass`\v\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\captionsczech{%
    \def\refname{Reference}%
    \def\abstractname{Abstrakt}%
@@ -29,12 +185,33 @@
    \def\headtoname{Komu}%
    \def\proofname{Důkaz}%
    \def\glossaryname{Slovník}%was Glosář
-   }
+}
+
 \def\dateczech{%
    \def\today{\number\day.~\ifcase\month\or
     ledna\or února\or března\or dubna\or května\or
     června\or července\or srpna\or září\or
     října\or listopadu\or prosince\fi
-    \space \number\year}}
+    \space \number\year}%
+}
 
+\def\noextras at czech{%
+  \noczech at shorthands%
+  \noczech at hyphens%
+  \noczech at vlna%
+  \ifxetex\XeTeXinterchartokenstate=0\fi%
+}
+
+\def\blockextras at czech{%
+  \ifczech at babelshorthands\czech at shorthands\fi%
+  \ifczech at vlna\czech at vlna\fi%
+  \ifczech at splithyphens\czech at hyphens\fi%
+}
+
+\def\inlineextras at czech{%
+  \ifczech at babelshorthands\czech at shorthands\fi%
+  \ifczech at vlna\czech at vlna\fi%
+  \ifczech at splithyphens\czech at hyphens\fi%
+}
+
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-danish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-danish.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-danish.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{danish}{
   hyphennames={danish},
   hyphenmins={2,3},
+  langtag=DAN,
   frenchspacing=true,
   fontsetup=true,
 }
@@ -25,12 +26,15 @@
   \def\headtoname{Til}% in letter
   \def\pagename{Side}%
   \def\seename{Se}%
-  \def\alsoname{Se også}}%
+  \def\alsoname{Se også}%
   \def\proofname{Bevis}%
   \def\glossaryname{Gloseliste}%
+}
+\def\datedanish{%
   \def\today{\number\day.~\ifcase\month\or
     januar\or februar\or marts\or april\or maj\or juni\or
     juli\or august\or september\or oktober\or november\or december\fi
     \space\number\year}
+}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-divehi.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-divehi.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-divehi.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -9,6 +9,7 @@
 \PolyglossiaSetup{divehi}{
   script=Thaana,
   scripttag=thaa,
+  langtag=DIV,% TODO Support DHV as well?
   direction=RL,
   hyphennames={nohyphenation},
   fontsetup=true
@@ -40,12 +41,16 @@
 %   }
 %\def\datedivehi{\def\today{<++>}}
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at divehi{%
-   \let\@@MakeUppercase\MakeUppercase%
    \def\MakeUppercase##1{##1}%
-   }
+}
+
 \def\noextras at divehi{%
-   \let\MakeUppercase\@@MakeUppercase%
-   }
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase%
+}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dutch.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dutch.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dutch.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{dutch}{
   hyphennames={dutch},
   hyphenmins={2,2},
+  langtag=NLD,
   frenchspacing=true,
   fontsetup=true,
 }
@@ -15,8 +16,9 @@
 \fi
 
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\dutch at shorthands{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-english.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-english.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-english.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,67 +2,125 @@
 \PolyglossiaSetup{english}{
   hyphennames={english,american,usenglish,USenglish},
   hyphenmins={2,3},
+  langtag=ENG,
   fontsetup=true,
 }
 
-\newif\if at british@locale
-\@british at localefalse
-\providebool{@british at hyphen}
+\providebool{british at hyphen}
 \providebool{english at ordinalmonthday}
+\providebool{british at dateformat}
 
+% US English (\l at english) is default
+% Initialize its settings
+\def\english at variant{english}
+\british at hyphenfalse
+\english at ordinalmonthdayfalse
+\british at dateformatfalse
+
+% Option ordinalmonthday
 \define at boolkey{english}[english@]{ordinalmonthday}[true]{}
 
-%% English is a special case in that \l at english is reserved for US English, so
-%% we need to handle it differently
-\define at key{english}{variant}{%
-  %needs to be reset for loop over hyphennames below:
-  \def\do##1{%
-      \xpg at ifdefined{#1}%
-        {\csletcs{l at english}{l@#1}\listbreak}%
-        {}%
-  }%
-  \ifstrequal{#1}{uk}%
-    {\@british at localetrue
-     \xpg at info{Option: english variant=british}}%
-    {\ifstrequal{#1}{british}%
-      {\@british at localetrue
-      \xpg at info{Option: english variant=british}}%
-        {\ifstrequal{#1}{us}% these patterns are the default so we don't need to reset them
-          {\@british at hyphenfalse\english at ordinalmonthdayfalse
-           \xpg at info{Option: english variant=american}}%
-          {\ifstrequal{#1}{american}%
-            {\@british at hyphenfalse\english at ordinalmonthdayfalse
-            \xpg at info{Option: english variant=american}}%
-            {\ifstrequal{#1}{usmax}%
-              {\@british at hyphenfalse\english at ordinalmonthdayfalse
-                \ifluatex\else\setkeys[xpg at setup]{english}{hyphennames={usenglishmax}}\fi
-                \xpg at info{Option: english variant=american (with additional patterns)}%
-                \xpg at ifdefined{usenglishmax}{}%
-                  {\xpg at warning{No hyphenation patterns were loaded for "US English Max"\MessageBreak
-                    I will use the standard patterns for US English instead}%
-                  \adddialect\l at usenglishmax\l at english\relax}%
-                \gdef\english at language{\language=\l at usenglishmax}}%
-                {\ifstrequal{#1}{australian}%
-                  {\@british at hyphentrue\english at ordinalmonthdayfalse
-                  \xpg at info{Option: english variant=australian}}%
-                  {\ifstrequal{#1}{newzealand}%
-                    {\@british at hyphentrue\english at ordinalmonthdayfalse
-                      \xpg at info{Option: english variant=newzealand}}%
-                      {\xpg at warning{Unknown English variant `#1'}}%
-  }}}}}}%
-  \if at british@locale\@british at hyphentrue\english at ordinalmonthdaytrue\fi
-  \if at british@hyphen
-    \ifluatex\else\setkeys[xpg at setup]{english}{hyphennames={ukenglish,british,UKenglish}}\fi
-    \xpg at ifdefined{ukenglish}{}%
-      {\xpg at warning{No hyphenation patterns were loaded for British English\MessageBreak
-         I will use the patterns for US English instead}%
-       \adddialect\l at ukenglish\l at english\relax}%
-    \gdef\english at language{\language=\l at ukenglish\xpg at set@language at luatex@ii{ukenglish}}%
-  \fi
-  % and we reset \do to its previous definition here:
-  \def\do##1{\setotherlanguage{#1}}%
-}
+\define at choicekey*+{english}{variant}[\val\nr]{uk,british,us,american,usmax,australian,newzealand,canadian}{%
+   \ifcase\nr\relax
+      % uk:
+      \british at hyphentrue
+      \british at dateformattrue
+      \english at ordinalmonthdaytrue
+      \SetLanguageKeys{english}{babelname=british}%
+      \xpg at info{Option: English, variant=british}%
+   \or
+      % british:
+      \british at hyphentrue
+      \british at dateformattrue
+      \english at ordinalmonthdaytrue
+      \SetLanguageKeys{english}{babelname=british}%
+      \xpg at info{Option: english variant=british}%
+   \or
+      % us:
+      \british at hyphenfalse
+      \british at dateformatfalse
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=american}%
+      \xpg at info{Option: English, variant=american}%
+   \or
+      % american:
+      \british at hyphenfalse
+      \british at dateformatfalse
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=american}%
+      \xpg at info{Option: English, variant=american}%
+   \or
+      % usmax:
+      \british at hyphenfalse
+      \british at dateformatfalse
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=american}%
+      \xpg at info{Option: english variant=american (with additional patterns)}%
+      \xpg at ifdefined{usenglishmax}{}%
+         {\xpg at warning{No hyphenation patterns were loaded for "US English Max"\MessageBreak
+                       I will use the standard patterns for US English instead}%
+          \adddialect\l at usenglishmax\l at english\relax%
+         }%
+      \def\english at variant{usenglishmax}%
+   \or
+      % australian:
+      % These use the british hyphenation patterns
+      % but date formats without ordinals
+      \british at hyphentrue
+      \british at dateformattrue
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=australian}%
+      \xpg at info{Option: English, variant=australian}%
+   \or
+      % newzealand:
+      % These use the british hyphenation patterns
+      % but date formats without ordinals
+      \british at hyphentrue
+      \british at dateformattrue
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=newzealand}%
+      \xpg at info{Option: English, variant=newzealand}%
+   \or
+      % canadian:
+      % This is currently equivalent to usenglish (as in babel)
+      \british at hyphenfalse
+      \british at dateformatfalse
+      \english at ordinalmonthdayfalse
+      \SetLanguageKeys{english}{babelname=canadian}%
+      \xpg at info{Option: English, variant=american}%
+   \fi
+   \ifbritish at hyphen
+      \xpg at ifdefined{ukenglish}{}%
+         {\xpg at warning{No hyphenation patterns were loaded for British English\MessageBreak
+                       I will use the patterns for US English instead}%
+          \adddialect\l at ukenglish\l at english\relax%
+         }%
+      \def\english at variant{ukenglish}%
+   \fi
+}{\xpg at warning{Unknown English variant `#1'}}
 
+\ifxetex
+   % Check if \l at english is defined. If not, try to set it to some variety
+   % (specific order as in the csv list below), or null language if everything fails
+   \xpg at ifdefined{english}{}{%
+      \def\do##1{%
+         \xpg at ifdefined{#1}%
+            {\csletcs{l at english}{l@#1}\listbreak}%
+            {%
+               \xpg at warning{No hyphenation patterns for English found"\MessageBreak
+                            I will use the 'null' language instead}%
+               \adddialect\l at english0
+            }%
+      }%
+      \docsvlist{british, american, usenglishmax, australian, newzealand}
+      \xpg at ifdefined{english}{}{}
+   }%
+\fi
+
+\def\english at language{%
+   \polyglossia at setup@language at patterns{\english at variant}
+}%
+
 \def\captionsenglish{%
    \def\prefacename{Preface}%
    \def\refname{References}%
@@ -101,7 +159,7 @@
       January\or February\or March\or April\or May\or June\or
       July\or August\or September\or October\or November\or December\fi}%
    \def\today{%
-    \if at british@locale
+    \ifbritish at dateformat
       \english at day\space\english at month\space\number\year
     \else
       \english at month\space\english at day,\space\number\year

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-esperanto.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-esperanto.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-esperanto.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{esperanto}{
   hyphennames={esperanto},
   hyphenmins={2,2},
+  langtag=NTO,
   fontsetup=true,
   %TODO localalph={esperanto at alph,esperanto at Alph}
 }
@@ -51,8 +52,6 @@
      P\or R\or S\or Ŝ\or T\or U\or Ŭ\or V\or Z\else\xpg at ill@value{#1}{esperanto at Alph}\fi}%
 
 \def\esperanto at numbers{%
-   \let\latin at Alph\@Alph%
-   \let\latin at alph\@alph%
    \let\@Alph\esperanto at Alph%
    \let\@alph\esperanto at alph%
  }

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-estonian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-estonian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-estonian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{estonian}{
   hyphennames={estonian},
   hyphenmins={2,2},
+  langtag=ETI,
   frenchspacing=true,
   fontsetup=true,
 }

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-farsi.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-farsi.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-farsi.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,14 +1,10 @@
 \ProvidesFile{gloss-farsi.ldf}[polyglossia: module for farsi]
-\ifluatex
-  \xpg at warning{Farsi is not supported with LuaTeX.\MessageBreak
-I will proceed with the compilation, but\MessageBreak
-the output is not guaranteed to be correct\MessageBreak
-and may look very wrong.}
-\fi
-\RequireBidi
-\RequirePackage{arabicnumbers}
-\RequirePackage{farsical}
-\RequirePackage{hijrical}
+
+% We only provide this gloss for babel compatibility.
+% The proper English language name is Persian.
+
+\input{gloss-persian.ldf}
+
 \PolyglossiaSetup{farsi}{
   script=Arabic,
   direction=RL,
@@ -15,117 +11,32 @@
   scripttag=arab,
   langtag=FAR,
   hyphennames={nohyphenation},
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=farsinumerals
 }
 
-\newif\if at western@numerals
-\def\tmp at western{western}
 \define at key{farsi}{numerals}[eastern]{%
-  \def\@tmpa{#1}%
-  \ifx\@tmpa\tmp at western\@western at numeralstrue\else%
-    \@western at numeralsfalse%
-  \fi}
+  \setkeys{persian}{numerals=#1}}
 
-%this is needed for \abjad in arabicnumbers.sty
-\def\tmp at true{true}
 \define at key{farsi}{abjadjimnotail}[true]{%
-  \def\@tmpa{#1}%
-  \ifx\@tmpa\tmp at true\abjad at jim@notailtrue%
-  \else
-    \abjad at jim@notailfalse
-  \fi}
+  \setkeys{persian}{abjadjimnotail=#1}}
 
-% NOT YET USED
 \define at key{farsi}{locale}[default]{%
-  \def\@farsi at locale{#1}}
+  \setkeys{persian}{locale=#1}}
 
-%TODO add option for CALENDAR
-
 \setkeys{farsi}{locale,numerals}
 
-\def\farsigregmonth#1{\ifcase#1%
-  \or ژانویه\or فوریه\or مارس\or آوریل\or مه\or ژوئن\or ژوئیه\or اوت\or سپتامبر\or اکتبر\or نوامبر\or دسامبر\fi}
-\def\farsimonth#1{\ifcase#1%
-  \or کانون ثانی\or شباط\or اذار%%or ادار
-    \or نیسان\or ایار\or حزیران\or تموز\or آب\or ایلول\or تشرین اول\or تشرین ثانی\or کانون اول\fi}
-
 %\Hijritoday is now locale-aware and will format the date with this macro:
 \DefineFormatHijriDate{farsi}{\@ensure at RTL{%
-\farsinumber{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\farsinumber{\value{Hijriyear}}}}
+   \farsinumber{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\farsinumber{\value{Hijriyear}}}}
 
-\def\captionsfarsi{%
-\def\prefacename{\@ensure at RTL{پیشگفتار}}%
-\def\refname{\@ensure at RTL{مراجع}}%
-\def\abstractname{\@ensure at RTL{چکیده}}%
-\def\bibname{\@ensure at RTL{کتاب‌نامه}}%
-\def\chaptername{\@ensure at RTL{فصل}}%
-\def\appendixname{\@ensure at RTL{پیوست}}%
-\def\contentsname{\@ensure at RTL{فهرست مطالب}}%
-\def\listfigurename{\@ensure at RTL{لیست تصاویر}}%
-\def\listtablename{\@ensure at RTL{لیست جداول}}%
-\def\indexname{\@ensure at RTL{نمایه}}%
-\def\figurename{\@ensure at RTL{شكل}}%
-\def\tablename{\@ensure at RTL{جدول}}%
-\def\partname{\@ensure at RTL{بخش}}%
-\def\enclname{\@ensure at RTL{پیوست}}%
-\def\ccname{\@ensure at RTL{رونوشت}}%
-\def\headtoname{\@ensure at RTL{به}}%
-\def\pagename{\@ensure at RTL{صفحة}}%
-\def\seename{\@ensure at RTL{ببینید}}%
-\def\alsoname{\@ensure at RTL{نیز ببینید}}%
-\def\proofname{\@ensure at RTL{برهان}}%
-\def\glossaryname{\@ensure at RTL{دانش‌نامه}}%
-}
-\def\datefarsi{%
-   \def\today{\@ensure at RTL{\farsinumber\day\space\farsigregmonth{\month}\space\farsinumber\year}}%
-}
+\let\captionsfarsi\captionspersian
+\let\datefarsi\datepersian
+\let\farsi at numbers\persian at numbers
+\let\nofarsi at numbers\nopersian at numbers
+\let\farsi at globalnumbers\persian at globalnumbers
+\let\nofarsi at globalnumbers\nopersian at globalnumbers
+\let\blockextras at farsi\blockextras at persian
+\let\noextras at farsi\noextras at persian
 
-\def\farsinumber#1{%
-  \if at western@numerals
-    \number#1%
-  \else
-    \ifnum\XeTeXcharglyph"06F0 > 0%
-      \farsidigits{\number#1}%
-      %%{\protect\addfontfeature{Mapping=farsidigits}\number#1}%
-    \else%
-      \arabicdigits{\number#1}%
-      %%{\protect\addfontfeature{Mapping=arabicdigits}\number#1}%
-    \fi
-  \fi}
-
-%\def\farsinum#1{\expandafter\farsinumber\csname c@#1\endcsname}
-%\def\farsibracenum#1{(\expandafter\farsinumber\csname c@#1\endcsname)}
-%\def\farsiornatebracenum#1{\char"FD3E\expandafter\farsinumber\csname c@#1\endcsname\char"FD3F}
-%\def\farsialph#1{\expandafter\@farsialph\csname c@#1\endcsname}
-
-\def\farsi at numbers{%
-   \let\@latinalph\@alph%
-   \let\@latinAlph\@Alph%
-   \let\@alph\abjad%
-   \let\@Alph\abjad%
-}
-\def\nofarsi at numbers{%
-  \let\@alph\@latinalph%
-  \let\@Alph\@latinAlph%
-  }
-
-\def\farsi at globalnumbers{%
-   \let\orig at arabic\@arabic%
-   \let\@arabic\farsinumber%
-   % For some reason \thefootnote needs to be set separately:
-   \renewcommand\thefootnote{\protect\farsinumber{\c at footnote}}%
-   }
-
-\def\nofarsi at globalnumbers{
-   \let\@arabic\orig at arabic%
-   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
-   }
-
-\def\blockextras at farsi{%
-   \let\@@MakeUppercase\MakeUppercase%
-   \def\MakeUppercase##1{##1}%
-   }
-\def\noextras at farsi{%
-   \let\MakeUppercase\@@MakeUppercase%
-   }
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-finnish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-finnish.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-finnish.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,10 +2,41 @@
 \PolyglossiaSetup{finnish}{
   hyphennames={finnish},
   hyphenmins={2,2},
+  langtag=FIN,
   frenchspacing=true,
   fontsetup=true,
 }
 
+\define at boolkey{finnish}[finnish@]{babelshorthands}[true]{}
+
+\ifsystem at babelshorthands
+  \setkeys{finnish}{babelshorthands=true}
+\else
+  \setkeys{finnish}{babelshorthands=false}
+\fi
+
+\ifcsundef{initiate at active@char}{%
+    \input{babelsh.def}%
+    \initiate at active@char{"}%
+    \shorthandoff{"}%
+}{}
+
+\def\finnish at shorthands{%
+  \bbl at activate{"}%
+  \def\language at group{finnish}%
+  \declare at shorthand{finnish}{"-}{\nobreak-\bbl at allowhyphens}
+  \declare at shorthand{finnish}{"|}{\textormath{\penalty at M\discretionary{-}{}{\kern.03em}}{}}%
+  \declare at shorthand{finnish}{""}{\hskip\z at skip}%
+  \declare at shorthand{finnish}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
+  \declare at shorthand{finnish}{"=}{\penalty at M-\hskip\z at skip}%
+  \declare at shorthand{finnish}{"/}{\textormath
+    {\bbl at allowhyphens\discretionary{/}{}{/}\bbl at allowhyphens}{}}%
+}
+
+\def\nofinnish at shorthands{%
+  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{"}}%
+}
+
 \def\captionsfinnish{%
    \def\refname{Viitteet}%
    \def\abstractname{Tiivistelmä}%
@@ -29,7 +60,7 @@
    \def\headtoname{Vastaanottaja}%
    \def\proofname{Todistus}%
    \def\glossaryname{Sanasto}%
-   }
+}
 \def\datefinnish{%
    \def\today{\number\day.~\ifcase\month\or
     tammikuuta\or helmikuuta\or maaliskuuta\or huhtikuuta\or
@@ -37,6 +68,18 @@
     syyskuuta\or lokakuuta\or marraskuuta\or joulukuuta\fi
     \space\number\year}}
 
+\def\noextras at finnish{%
+  \nofinnish at shorthands%
+}
+
+\def\blockextras at finnish{%
+  \iffinnish at babelshorthands\finnish at shorthands\fi%
+}
+
+\def\inlineextras at finnish{%
+  \iffinnish at babelshorthands\finnish at shorthands\fi%
+}
+
 \endinput
 
 % TODO ? this is set in babel:
@@ -45,4 +88,4 @@
   \babel at savevariable\exhyphenpenalty\exhyphenpenalty=30%
   \babel at savevariable\doublehyphendemerits\doublehyphendemerits=5000%
   \babel at savevariable\finalhyphendemerits\finalhyphendemerits=5000%
-  }
+}

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-french.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-french.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-french.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -3,6 +3,7 @@
 \PolyglossiaSetup{french}{%
   language=French,
   script=Latin,
+  langtag=FRA,
   hyphennames={french,francais},
   frenchspacing=true,
   indentfirst=true,
@@ -9,6 +10,36 @@
   hyphenmins={2,2},
   fontsetup=true}
 
+\def\french at variant{french}
+\define at choicekey*+{french}{variant}[\val\nr]{french,canadian,acadian}[french]{%
+   \ifcase\nr\relax
+      % french:
+      \def\french at variant{french}%
+   \or
+      % canadian:
+      \def\french at variant{canadien}%
+      \SetLanguageKeys{french}{babelname=canadien}%
+      \xpg at ifdefined{canadien}{}%
+	    {\xpg at warning{No hyphenation patterns were loaded for "French (Canada)"\MessageBreak
+	      I will use the standard patterns for French instead}%
+	    \adddialect\l at canadien\l at french\relax}%
+   \or
+      % acadian:
+      \def\french at variant{acadian}%
+      \SetLanguageKeys{french}{babelname=canadien}%
+      \xpg at ifdefined{acadian}{}%
+	    {\xpg at warning{No hyphenation patterns were loaded for "French (Canada)"\MessageBreak
+	      I will use the standard patterns for French instead}%
+	    \adddialect\l at acadian\l at french\relax}%
+   \fi
+   \xpg at info{Option: French, variant=\val}%
+}{\xpg at warning{Unknown French variant `#1'}}
+
+
+\def\french at language{%
+   \polyglossia at setup@language at patterns{\french at variant}
+}%
+
 \ifluatex
   \newluatexattribute\xpg at frpt %
   \directlua{polyglossia.load_frpt()}%
@@ -22,36 +53,77 @@
 \fi
 
 \def\xpg at unskip{\ifhmode\ifdim\lastskip>\z@\unskip\fi\fi}
-\def\xpg at nospace#1{#1}
 
-\ifx\@makefntext\undefined\else
-  \let\nofrench at makefntext\@makefntext
-  \long\def\french at makefntext#1{\parindent1em \noindent\quad\ifx\@thefnmark\empty\else\@thefnmark.\space\fi #1}
-  \let\@makefntext\french at makefntext
-  \define at boolkey{french}[french@]{frenchfootnote}[true]{%
-  	\def\@tmpa{#1}
-    \def\@tmptrue{true}
-    \ifx\@tmpa\@tmptrue
-    	\let\@makefntext\french at makefntext
-		\else 
-			\let\@makefntext\nofrench at makefntext
-    \fi
-  }
-\fi
+% Save original footnote definition
+\let\xpg at orig@makefntext\@makefntext
 
+\define at boolkey{french}[french@]{frenchfootnote}[true]{%
+  \AfterPreamble{%
+    \ifdefstring{\xpg at main@language}{french}{%
+      \iffrench at frenchfootnote
+         \ifx\@makefntext\undefined\else        
+             \long\def\french at makefntext##1{%
+                \parindent1em \noindent\quad%
+                \ifx\@thefnmark\empty\else%
+                \@thefnmark.\space\fi ##1%
+             }
+             \let\@makefntext\french at makefntext
+         \fi
+      \else
+         \let\@makefntext\xpg at orig@makefntext
+      \fi
+    }{\xpg at warning{Option 'frenchfootnote' only supported if French is main language!}}%
+  }%
+}
 
-\newif\iffrench at automaticspacesaroundguillemets
+\define at boolkey{french}[french@]{autospacing}[true]{}
+\french at autospacingtrue
+
+\newif\iffrench at autospaceguillemets
+\define at boolkey{french}[french@]{autospaceguillemets}[true]{}
+\french at autospaceguillemetstrue
+
+% Backwards compatibility
 \define at boolkey{french}[french@]{automaticspacesaroundguillemets}[true]{%
-  %\def\tmp at true{true}%
-  %\def\@tmpa{#1}%
-  %\ifx\@tmpa\tmp at true
+   \iffrench at automaticspacesaroundguillemets
+       \setkeys{french}{autospaceguillemets=true}%
+   \else
+       \setkeys{french}{autospaceguillemets=false}%
+   \fi
 }
-\french at automaticspacesaroundguillemetstrue
 
+% name is for compatibility with babel
+\let\french at ttfamilyORI\ttfamily
+\DeclareRobustCommand\french at ttfamilyFB{\nofrench at punctuation\french at ttfamilyORI}
+
+% Allow to switch on autospacing in ttfamily context
+\define at boolkey{french}[french@]{autospacetypewriter}[true]{}
+\french at autospacetypewriterfalse
+
+% This is how babel-french has it
+\define at boolkey{french}[french@]{OriginalTypewriter}[true]{%
+   \iffrench at OriginalTypewriter
+       \setkeys{french}{autospacetypewriter=false}%
+   \else
+       \setkeys{french}{autospacetypewriter=true}%
+   \fi
+}
+
+\def\french at fontsetup{%
+  \unless\iffrench at autospacetypewriter
+    \let\ttfamily\french at ttfamilyFB
+  \fi
+}
+
+
+\def\nofrench at fontsetup{%
+  \let\ttfamily\french at ttfamilyORI
+}
+
 \def\french at punctuation{%
     \lccode"2019="2019
     \ifluatex
-      \global\xpg at frpt=1\relax %
+      \xpg at frpt=1\relax %
       \directlua{polyglossia.activate_frpt()}%
     \else
       \XeTeXinterchartokenstate=1
@@ -73,24 +145,24 @@
       \XeTeXcharclass `\[ \french at closebrackets
       \XeTeXcharclass `\{ \french at openbrackets
       \XeTeXcharclass `\} \french at closebrackets
-      \XeTeXinterchartoks \z@ \french at punctthin = {\nobreak\thinspace}%
+      \XeTeXinterchartoks \z@ \french at punctthin = {\thinspace}%
       \XeTeXinterchartoks \z@ \french at punctthick = {\nobreakspace}%
-      \XeTeXinterchartoks \xpg at boundaryclass \french at punctthin = {\xpg at unskip\nobreak\thinspace}%
+      \XeTeXinterchartoks \xpg at boundaryclass \french at punctthin = {\xpg at unskip\thinspace}%
       \XeTeXinterchartoks \xpg at boundaryclass \french at punctthick = {\xpg at unskip\nobreakspace}%
-      \XeTeXinterchartoks \french at punctguillstart \z@ = {\nobreakspace}% "«a" -> "« a"
-  %   \XeTeXinterchartoks \z@ \french at punctguillstart = {\nobreakspace}% "a«" unchanged?
-  %   \XeTeXinterchartoks \french at punctguillend \z@ = {\nobreakspace}% "»a" unchanged?
-      \XeTeXinterchartoks \z@ \french at punctguillend = {\nobreakspace}% "a»" -> "a »"
-      \iffrench at automaticspacesaroundguillemets
-        \XeTeXinterchartoks \french at punctguillstart \xpg at boundaryclass = {\nobreakspace\xpg at nospace\relax}% "«  " -> "«~"
-        \XeTeXinterchartoks \xpg at boundaryclass \french at punctguillend = {\xpg at unskip\nobreakspace}% "  »" -> "~»"
-      \fi
-      \XeTeXinterchartoks \french at punctguillend \french at punctthin = {\nobreak\thinspace}% "»;" -> "» ;"
-      \XeTeXinterchartoks \french at punctguillend \french at punctthick = {\nobreakspace}% "»:" -> "» :"
-      \XeTeXinterchartoks \french at punctthin \french at punctguillend  = {\nobreakspace}% "?»" -> "? »"
+      \iffrench at autospaceguillemets
+        \XeTeXinterchartoks \french at punctguillstart \z@ = {\thinspace}% "«a" -> "«\,a"
+  %     \XeTeXinterchartoks \z@ \french at punctguillstart = {\nobreakspace}% "a«" unchanged?
+  %     \XeTeXinterchartoks \french at punctguillend \z@ = {\nobreakspace}% "»a" unchanged?
+        \XeTeXinterchartoks \z@ \french at punctguillend = {\thinspace}% "a»" -> "a\,»"
+        \XeTeXinterchartoks \french at punctguillstart \xpg at boundaryclass = {\thinspace\ignorespaces}% "«  " -> "«\,"
+        \XeTeXinterchartoks \xpg at boundaryclass \french at punctguillend = {\xpg at unskip\thinspace}% "  »" -> "\,»"
+     \fi
+     \XeTeXinterchartoks \french at punctguillend \french at punctthin = {\thinspace}% "»;" -> "»\,;"
+     \XeTeXinterchartoks \french at punctguillend \french at punctthick = {\nobreakspace}% "»:" -> "» :"
+     \XeTeXinterchartoks \french at punctthin \french at punctguillend  = {\thinspace}% "?»" -> "?\,»"
      \XeTeXinterchartoks \french at openbrackets \french at punctthin = {\xpg at unskip}% "(?" -> "(?" and not "( ?"      
      \XeTeXinterchartoks \french at punctthin \french at closebrackets = {\xpg at unskip}% "?)" -> "?)" (code not need, just for symetry with previous one)
-     \XeTeXinterchartoks \french at closebrackets \french at punctthin = {\nobreak\thinspace}% ")?" -> ") ?"
+     \XeTeXinterchartoks \french at closebrackets \french at punctthin = {\thinspace}% ")?" -> ")\,?"
      \XeTeXinterchartoks \french at closebrackets \french at punctthick = {\nobreakspace}% "):" -> ") :"
     \fi
     }
@@ -98,7 +170,7 @@
 \def\nofrench at punctuation{%
     \lccode"2019=\z@
     \ifluatex
-      \global\xpg at frpt=0\relax %
+      \xpg at frpt=0\relax %
       % Though it would make compilation slightly faster, it is not possible to
       % safely uncomment the following line. Imagine the following case: you start
       % a paragraph by some french text, then, in the same paragraph, you change
@@ -152,6 +224,7 @@
    \def\headtoname{}%
    \def\proofname{Démonstration}%
    }
+
 \def\datefrench{%
    \def\today{\ifx\ier\undefined\def\ier{er}\fi
       \ifnum\day=1\relax 1\ier%
@@ -164,16 +237,31 @@
 
 \def\noextras at french{%
    \nofrench at punctuation%
-   }
+   \nofrench at fontsetup%
+}
 
 \def\blockextras at french{%
-   \french at punctuation%
-   }
+   \iffrench at autospacing
+      \french at punctuation%
+   \fi
+   \french at fontsetup%
+}
 
 \def\inlineextras at french{%
-   \french at punctuation%
-   }
+   \iffrench at autospacing
+      \french at punctuation%
+   \fi
+   \french at fontsetup%
+}
 
+\def\NoAutoSpacing{%
+  \nofrench at punctuation%
+}
+
+\def\AutoSpacing{%
+  \french at punctuation%
+}
+
 \def\ier{\textsuperscript{er}}
 \def\iers{\textsuperscript{ers}}
 \def\iere{\textsuperscript{re}}

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulan.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulan.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulan.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,64 +1,22 @@
 \ProvidesFile{gloss-friulan.ldf}[polyglossia: module for friulan]
-\makeatletter
+
+% We only provide this gloss for babel compatibility.
+
+\input{gloss-friulian.ldf}
+
 \PolyglossiaSetup{friulan}{%
+  language=Friulian,
   hyphennames={friulan,furlan},
   hyphenmins={2,2},
+  langtag=FRL,
   indentfirst=false,
   fontsetup=true,
   frenchspacing=true,
 }
 
+\let\captionsfriulan\captionsfriulian
+\let\datefriulan\datefriulian
+\let\noextras at friulan\noextras at friulian
+\let\blockextras at friulan\blockextras at friulian
+\let\inlineextras at friulan\inlineextras at friulian
 
-\def\captionsfriulan{%
-    \def\prefacename{Prefazion}%
-    \def\refname{Riferiments}%
-    \def\abstractname{Somari}%
-    \def\bibname{Bibliografie}%
-    \def\chaptername{Cjapitul}%
-    \def\appendixname{Zonte}%
-    \def\contentsname{Tabele gjenerâl}%
-    \def\listfigurename{Liste des figuris}%
-    \def\listtablename{Liste des tabelis}%
-    \def\indexname{Tabele analitiche}%
-    \def\figurename{Figure}%
-    \def\tablename{Tabele}%
-    \def\partname{Part}%
-    \def\enclname{Zonte(is)}%
-    \def\ccname{Cun copie a}%
-    \def\headtoname{Par}%
-    \def\pagename{Pagjine}%
-    \def\seename{cjale}%
-    \def\alsoname{cjale ancje}%
-    \def\proofname{Dimostrazion}%
-    \def\glossaryname{Glossari}%
-  }
-  
-\def\datefriulan{%
-  \def\today{\number\day\space di\space\ifcase\month\or
-      Genâr\or Fevrâr\or Març\or Avril\or Mai\or Jugn\or
-      Lui\or Avost\or Setembar\or Otobar\or Novembar\or Dicembar%
-      \fi\space dal\space\number\year}}
-
-\AtEndPreamble{% the user or the class might define different values
-  \edef\xpgfu at savedvalues{%
-    \clubpenalty=\the\clubpenalty\space
-    \@clubpenalty=\the\@clubpenalty\space
-    \widowpenalty=\the\widowpenalty\space
-    \finalhyphendemerits=\the\finalhyphendemerits}
-}
-
-
-\def\noextras at friulan{%
-   \lccode\string"2019=\z@
-}
-
-\def\blockextras at friulan{%
-   \lccode\string"2019=\string"2019
-   \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000
-   \finalhyphendemerits=50000000
-}
-
-\def\inlineextras at friulan{%
-   \lccode\string"2019=\string"2019
-}
-

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulian.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,66 @@
+\ProvidesFile{gloss-friulian.ldf}[polyglossia: module for friulian]
+
+\PolyglossiaSetup{friulian}{%
+  language=Friulian,
+  babelname=friulan,
+  hyphennames={friulan,furlan},
+  hyphenmins={2,2},
+  langtag=FRL,
+  indentfirst=false,
+  fontsetup=true,
+  frenchspacing=true,
+}
+
+\def\captionsfriulian{%
+    \def\prefacename{Prefazion}%
+    \def\refname{Riferiments}%
+    \def\abstractname{Somari}%
+    \def\bibname{Bibliografie}%
+    \def\chaptername{Cjapitul}%
+    \def\appendixname{Zonte}%
+    \def\contentsname{Tabele gjenerâl}%
+    \def\listfigurename{Liste des figuris}%
+    \def\listtablename{Liste des tabelis}%
+    \def\indexname{Tabele analitiche}%
+    \def\figurename{Figure}%
+    \def\tablename{Tabele}%
+    \def\partname{Part}%
+    \def\enclname{Zonte(is)}%
+    \def\ccname{Cun copie a}%
+    \def\headtoname{Par}%
+    \def\pagename{Pagjine}%
+    \def\seename{cjale}%
+    \def\alsoname{cjale ancje}%
+    \def\proofname{Dimostrazion}%
+    \def\glossaryname{Glossari}%
+  }
+  
+\def\datefriulian{%
+  \def\today{\number\day\space di\space\ifcase\month\or
+      Genâr\or Fevrâr\or Març\or Avril\or Mai\or Jugn\or
+      Lui\or Avost\or Setembar\or Otobar\or Novembar\or Dicembar%
+      \fi\space dal\space\number\year}}
+
+\AtEndPreamble{% the user or the class might define different values
+  \edef\xpgfu at savedvalues{%
+    \clubpenalty=\the\clubpenalty\space
+    \@clubpenalty=\the\@clubpenalty\space
+    \widowpenalty=\the\widowpenalty\space
+    \finalhyphendemerits=\the\finalhyphendemerits}
+}
+
+
+\def\noextras at friulian{%
+   \lccode\string"2019=\z@
+}
+
+\def\blockextras at friulian{%
+   \lccode\string"2019=\string"2019
+   \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000
+   \finalhyphendemerits=50000000
+}
+
+\def\inlineextras at friulian{%
+   \lccode\string"2019=\string"2019
+}
+


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulian.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gaelic.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gaelic.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gaelic.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,107 @@
+\ProvidesFile{gloss-gaelic.ldf}[polyglossia: module for gaelic]
+
+\PolyglossiaSetup{gaelic}{
+  language=Irish,
+  babelname=irish,
+  hyphennames={irish},
+  hyphenmins={2,2},
+  langtag=IRI,
+  fontsetup=true,
+}
+
+\def\gaelic at variant{irish}
+\define at choicekey*+{gaelic}{variant}[\val\nr]{irish,scottish}[irish]{%
+   \ifcase\nr\relax
+      % irish:
+      \gdef\gaelic at variant{irish}%
+      \SetLanguageKeys{gaelic}{language=Irish,langtag=IRI,babelname=irish}%
+      \xpg at fontsetup@latin{gaelic}%
+   \or
+      % scottish:
+      \gdef\gaelic at variant{scottish}%
+      \SetLanguageKeys{gaelic}{language=Gaelic,langtag=GAE,babelname=scottish}%
+      \xpg at fontsetup@latin{gaelic}%
+   \fi
+   \xpg at info{Option: gaelic, variant=\val}%
+}{\xpg at warning{Unknown gaelic variant `#1'}}
+
+\def\captionsgaelic at irish{%
+   \def\refname{Tagairtí}%
+   \def\abstractname{Achoimre}%
+   \def\bibname{Leabharliosta}%
+   \def\prefacename{Réamhrá}%    <-- also "Brollach"
+   \def\refname{Tagairtí}%
+   \def\chaptername{Tagairtí}%
+   \def\appendixname{Aguisín}%
+   \def\contentsname{Clár Ábhair}%
+   \def\listfigurename{Léaráidí}%
+   \def\listtablename{Táblaí}%
+   \def\indexname{Innéacs}%
+   \def\figurename{Léaráid}%
+   \def\tablename{Tábla}%
+   %\def\thepart{}%
+   \def\partname{Cuid}%
+   \def\pagename{Leathanach}%
+   \def\seename{féach}%
+   \def\alsoname{féach freisin}%
+   \def\enclname{faoi iamh}%
+   \def\ccname{cc}%
+   \def\headtoname{Go}%
+   \def\proofname{Cruthúnas}%
+   \def\glossaryname{Glossary}%
+}
+
+\def\captionsgaelic at scottish{%
+   \def\refname{Iomraidh}%
+   \def\abstractname{Brìgh}%
+   \def\bibname{Leabhraichean}%
+   \def\prefacename{Preface}%    <-- needs translation
+   \def\chaptername{Caibideil}%
+   \def\appendixname{Ath-sgr`ıobhadh}%
+   \def\contentsname{Clàr-obrach}%
+   \def\listfigurename{Liosta Dhealbh}%
+   \def\listtablename{Liosta Chlàr}%
+   \def\indexname{Clàr-innse}%
+   \def\figurename{Dealbh}%
+   \def\tablename{Clàr}%
+   %\def\thepart{}%
+   \def\partname{Cuid}%
+   \def\pagename{t.d.}%
+   \def\seename{see}%    <-- needs translation
+   \def\alsoname{see also}%    <-- needs translation
+   \def\enclname{a-staigh}%
+   \def\ccname{lethbhreac gu}%
+   \def\headtoname{gu}%
+   \def\proofname{Proof}%    <-- needs translation 
+   \def\glossaryname{Glossary}%    <-- needs translation
+}
+
+\def\captionsgaelic{%
+  \csname captionsgaelic@\gaelic at variant\endcsname%
+}
+
+\def\dategaelic at irish{%
+   \def\today{%
+    \number\day\space \ifcase\month\or
+    Eanáir\or Feabhra\or Márta\or Aibreán\or
+    Bealtaine\or Meitheamh\or Iúil\or Lúnasa\or
+    Meán Fómhair\or Deireadh Fómhair\or
+    Mí na Samhna\or Mí na Nollag\fi
+    \space \number\year}%
+}
+
+\def\dategaelic at scottish{%
+   \def\today{%
+    \number\day\space \ifcase\month\or
+    am Faoilteach\or an Gearran\or am Màrt\or an Giblean\or
+    an Cèitean\or an t-Òg mhios\or an t-Iuchar\or
+    Lùnasdal\or an Sultuine\or an Dàmhar\or
+    an t-Samhainn\or an Dubhlachd\fi
+    \space \number\year}%
+}
+
+\def\dategaelic{%
+  \csname dategaelic@\gaelic at variant\endcsname%
+}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gaelic.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-galician.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-galician.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-galician.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{galician}{
   hyphennames={galician},
   hyphenmins={2,2},
+  langtag=GAL,
   indentfirst=true,
   fontsetup=true,
 }

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-german.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-german.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-german.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -3,63 +3,86 @@
   hyphenmins={2,2},
   frenchspacing=true,
   fontsetup=true,
+  langtag=DEU,
+  babelname=ngerman
 }
 
-\def\tmp at old{old}
-\def\tmp at oldyr{1901}
 \newif\if at german@oldspelling
 \@german at oldspellingfalse
-\define at key{german}{spelling}[new]{%
-  \def\@tmpa{#1}%
-  \ifx\@tmpa\tmp at oldyr\def\@tmpa{old}\fi
-  \ifx\@tmpa\tmp at old
-    \xpg at ifdefined{german}{}{%
-      \xpg at nopatterns{german}%
-      \adddialect\l at german\l at nohyphenation
-    }
-    \@german at oldspellingtrue
-  \else % try ngerman
-    \xpg at ifdefined{ngerman}{%
+\define at choicekey*+{german}{spelling}[\val\nr]{new,old,1901}[new]{%
+   \ifcase\nr\relax
+      % new:
       \@german at oldspellingfalse
-    }{% fall back to german
-      \xpg at ifdefined{german}{%
-        \xpg at warning{You asked for `ngerman' but only `german' hyphenation is available!}%
-        \@german at oldspellingtrue
-      }{%
-        \xpg at nopatterns{ngerman}%
-        \adddialect\l at ngerman\l at nohyphenation
-      }%
-    }%
-  \fi
-}
+   \or
+      % old:
+      \@german at oldspellingtrue
+   \or
+      % 1901:
+      \@german at oldspellingtrue
+   \fi
+   \german at set@babelname%
+   \xpg at info{Option: German, spelling=\val}%
+}{\xpg at warning{Unknown German spelling `#1'}}
 
 \newif\if at austrian@locale
 \@austrian at localefalse
 \newif\if at swiss@locale
 \@swiss at localefalse
-\def\tmp at austrian{austrian}
-\def\tmp at swiss{swiss}
-\define at key{german}{variant}[german]{%
-	\def\@tmpa{#1}%
-	\ifx\@tmpa\tmp at austrian\@austrian at localetrue\else
-	  \@austrian at localefalse%
-	\fi
-	\ifx\@tmpa\tmp at swiss\@swiss at localetrue
-	  \xpg at ifdefined{swissgerman}{}%
-	    {\xpg at warning{No hyphenation patterns were loaded for "Swiss German (Old Spelling)"\MessageBreak
-	      I will use the standard patterns for German (old spelling) instead}%
-	    \adddialect\l at swissgerman\l at german\relax}%
-	\else
-	  \@swiss at localefalse%
-	\fi}
+\define at choicekey*+{german}{variant}[\val\nr]{german,austrian,swiss}[german]{%
+   \ifcase\nr\relax
+      % german:
+      \@swiss at localefalse%
+      \@austrian at localefalse%
+   \or
+      % austrian:
+      \@austrian at localetrue%
+      \@swiss at localefalse%
+   \or
+      % swiss:
+      \@swiss at localetrue%
+      \@austrian at localefalse%
+      \xpg at ifdefined{swissgerman}{}%
+         {%
+           \xpg at warning{No hyphenation patterns were loaded for "Swiss German (Old Spelling)"\MessageBreak
+	                I will use the standard patterns for German (old spelling) instead}%
+	                \adddialect\l at swissgerman\l at german\relax%
+         }%
+   \fi
+   \german at set@babelname%
+   \xpg at info{Option: German, variant=\val}%
+}{\xpg at warning{Unknown German variant `#1'}}
 
+\def\german at set@babelname{%
+  \if at german@oldspelling
+     \if at swiss@locale
+         \SetLanguageKeys{german}{babelname=swissgerman}%
+     \else
+     \if at austrian@locale
+         \SetLanguageKeys{german}{babelname=austrian}%
+     \else
+         \SetLanguageKeys{german}{babelname=german}%
+     \fi\fi
+  \else
+     \if at swiss@locale
+         \SetLanguageKeys{german}{babelname=nswissgerman}%
+     \fi
+     \if at austrian@locale
+         \SetLanguageKeys{german}{babelname=naustrian}%
+     \fi
+  \fi
+}
+
 \newif\if at german@fraktur
-\def\tmp at fraktur{fraktur}
-\define at key{german}{script}[latin]{%
-	\def\@tmpa{#1}%
-	\ifx\@tmpa\tmp at fraktur\@german at frakturtrue\else
-	  \@german at frakturfalse%
-	\fi}
+\define at choicekey*+{german}{script}[\val\nr]{latin,fraktur}[latin]{%
+   \ifcase\nr\relax
+      % latin:
+      \@german at frakturfalse%
+   \or
+      % fraktur:
+      \@german at frakturtrue%
+   \fi
+   \xpg at info{Option: German, script=\val}%
+}{\xpg at warning{Unknown German script `#1'}}
 
 \define at boolkey{german}[german@]{latesthyphen}[false]{}
 
@@ -74,8 +97,9 @@
 \fi
 
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\german at shorthands{%
@@ -190,43 +214,28 @@
   \if at german@fraktur\date at german@fraktur\else\date at german\fi
 }
 
-\def\german at language{\ifxetex\language=%
-  \csname l@%
-    \if at swiss@locale
-       \if at german@oldspelling
-           swissgerman%
-       \else
-            ngerman%
-            \ifgerman at latesthyphen
-                -x-latest
-            \fi
-        \fi
-    \else% (german, austrian)
-      \if at german@oldspelling\else n\fi german\ifgerman at latesthyphen -x-latest\fi
-    \fi
-  \endcsname\else\ifluatex
-  % LuaTeX
+\def\german at language{%
   \ifgerman at latesthyphen
     \if at german@oldspelling
         \if at swiss@locale
-            \xpg at set@language at luatex@iv{swissgerman}%
+            \polyglossia at setup@language at patterns{swissgerman}%
         \else
-            \xpg at set@language at luatex@iv{german-x-latest}%
+            \polyglossia at setup@language at patterns{german-x-latest}%
         \fi
     \else
-        \xpg at set@language at luatex@iv{ngerman-x-latest}%
+        \polyglossia at setup@language at patterns{ngerman-x-latest}%
     \fi
   \else% (latesthyphen=false)
     \if at german@oldspelling
         \if at swiss@locale
-            \xpg at set@language at luatex@iv{swissgerman}%
+            \polyglossia at setup@language at patterns{swissgerman}%
         \else
-            \xpg at set@language at luatex@iv{german}%
+            \polyglossia at setup@language at patterns{german}%
         \fi
     \else
-        \xpg at set@language at luatex@iv{ngerman}%
+        \polyglossia at setup@language at patterns{ngerman}%
     \fi
-  \fi\fi\fi
+  \fi
 }
 
 \def\noextras at german{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-greek.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-greek.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-greek.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,9 +2,12 @@
 \PolyglossiaSetup{greek}{
   script=Greek,
   scripttag=grek,
+  langtag=ELL,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,
+  localnumeral=greeknumerals,
+  Localnumeral=Greeknumerals
   %TODO localalph={greek at alph,greek at Alph}
 }
 
@@ -16,31 +19,6 @@
 % this file imported from xgreek fixes the \lccode and \uccode of Greek letters:
 \input{xgreek-fixes.def}
 
-%TODO: set these in \define at key instead:
-\ifx\l at greek\@undefined
-  \ifx\l at polygreek\@undefined
-    \xpg at nopatterns{Greek}%
-    \adddialect\l at greek\l at nohyphenation
-  \else
-    \let\l at greek\l at polygreek
-  \fi
-\fi
-\ifx\l at monogreek\@undefined
-  \xpg at warning{No hyphenation patterns were loaded for Monotonic Greek\MessageBreak
-         I will use the patterns loaded for \string\l at greek instead}
-  \adddialect\l at monogreek\l at greek
-\fi
-\ifx\l at ancientgreek\@undefined
-  \xpg at warning{No hyphenation patterns were loaded for Ancient Greek\MessageBreak
-         I will use the patterns loaded for \string\l at greek instead}
-  \adddialect\l at ancientgreek\l at greek
-\fi
-
-%set monotonic as default
-\def\greek at variant{\l at monogreek}% monotonic
-\def\captionsgreek{\monogreekcaptions}%
-\def\dategreek{\datemonogreek}%
-
 \def\tmp at mono{mono}
 \def\tmp at monotonic{monotonic}
 \def\tmp at poly{poly}
@@ -48,23 +26,42 @@
 \def\tmp at ancient{ancient}
 \def\tmp at ancientgreek{ancientgreek}
 
+\def\greek at variant{monogreek}
+
 \define at key{greek}{variant}[monotonic]{%
   \def\@tmpa{#1}%
+  \xpg at ifdefined{greek}{}{%
+      \xpg at nopatterns{greek}%
+      \adddialect\l at greek\l at nohyphenation
+  }
   \ifx\@tmpa\tmp at poly\def\@tmpa{polytonic}\fi
   \ifx\@tmpa\tmp at ancientgreek\def\@tmpa{ancient}\fi
   \ifx\@tmpa\tmp at polytonic%
-    \def\greek at variant{\l at polygreek}%
+    \xpg at ifdefined{polygreek}{}%
+      {\xpg at warning{No hyphenation patterns were loaded for Polytonic Greek\MessageBreak
+	            I will use the patterns loaded for \string\l at greek\space instead}%
+      \adddialect\l at polygreek\l at greek\relax}%
+    \def\greek at variant{polygreek}%
     \def\captionsgreek{\polygreekcaptions}%
     \def\dategreek{\datepolygreek}%
+    \SetLanguageKeys{greek}{babelname=polutonikogreek}%
     \xpg at info{Option: Polytonic Greek}%
   \else
     \ifx\@tmpa\tmp at ancient
-      \def\greek at variant{\l at ancientgreek}%
+      \xpg at ifdefined{ancientgreek}{}%
+        {\xpg at warning{No hyphenation patterns were loaded for Ancient Greek\MessageBreak
+	              I will use the patterns loaded for \string\l at greek\space instead}%
+         \adddialect\l at ancientgreek\l at greek\relax}%
+      \def\greek at variant{ancientgreek}%
       \def\captionsgreek{\ancientgreekcaptions}%
       \def\dategreek{\dateancientgreek}%
       \xpg at info{Option: Ancient Greek}%
     \else %monotonic
-      \def\greek at variant{\l at monogreek}% monotonic
+      \xpg at ifdefined{monogreek}{}%
+        {\xpg at warning{No hyphenation patterns were loaded for Monotonic Greek\MessageBreak
+	              I will use the patterns loaded for \string\l at greek\space instead}%
+         \adddialect\l at monogreek\l at greek\relax}%
+      \def\greek at variant{monogreek}% monotonic
       \def\captionsgreek{\monogreekcaptions}%
       \def\dategreek{\datemonogreek}%
       \xpg at info{Option: Monotonic Greek}%
@@ -71,16 +68,20 @@
     \fi
   \fi}
 
-\def\greek at language{\language=\greek at variant}
+\def\greek at language{%
+  \polyglossia at setup@language at patterns{\greek at variant}
+}
 
+
 \newif\if at greek@numerals
 \define at key{greek}{numerals}[greek]{%
-\ifstrequal{#1}{arabic}{\@greek at numeralsfalse}{\@greek at numeralstrue}}
+  \ifstrequal{#1}{arabic}{\@greek at numeralsfalse}{\@greek at numeralstrue}%
+}
 
 \define at boolkey{greek}{attic}[true]{\xpg at warning{Greek option `attic' is no longer required.}}
 
 % This sets the defaults
-\setkeys{greek}{numerals}
+\setkeys{greek}{numerals,variant}
 
 \def\monogreekcaptions{%
    \def\refname{Αναφορές}%
@@ -194,8 +195,8 @@
   \def\ccname{Κοινοποίησις}%
   \def\headtoname{Πρὸς}%
   \def\pagename{Σελὶς}%
-  \def\seename{ὃρα}%
-  \def\alsoname{ὃρα ὡσαύτως}%
+  \def\seename{ὅρα}%
+  \def\alsoname{ὅρα ὡσαύτως}%
   \def\proofname{Ἀπόδειξις}%
   \def\glossaryname{Γλωσσάριον}%
   \def\refname{Ἀναφοραὶ}%
@@ -228,14 +229,18 @@
       Δεκεμβρίου\fi}}
 
 % the code for alphabetic numbers and attic numerals 
-% is copied verbatim from xgreek.sty
-\DeclareRobustCommand\anw at false{%
-  \DeclareRobustCommand\anw at print{}}
-\DeclareRobustCommand\anw at true{%
-  \DeclareRobustCommand\anw at print{ʹ}}
+\newrobustcmd\anw at print{}
+\newrobustcmd\anw at false{%
+  \renewrobustcmd\anw at print{}}
+\newrobustcmd\anw at true{%
+   \renewrobustcmd\anw at print{ʹ}}
 \anw at true
 
-\def\greeknumber#1{%
+\newcommand{\greeknumerals}[2]{\greeknumber{#2}}
+\newcommand{\Greeknumerals}[2]{\Greeknumber{#2}}
+
+\protected\def\greeknumber#1{\expandafter\@greeknumber\expandafter{\number#1}}
+\def\@greeknumber#1{%
   \ifnum#1<\@ne\space\gr at ill@value{#1}%
   \else
     \ifnum#1<10\expandafter\gr at num@i\number#1%
@@ -259,8 +264,31 @@
     \fi
   \fi
 }
-\def\Greeknumber#1{%
-  \expandafter\MakeUppercase\expandafter{\greeknumber{#1}}}
+\protected\def\Greeknumber#1{\expandafter\@Greeknumber\expandafter{\number#1}}
+\def\@Greeknumber#1{%
+  \ifnum#1<\@ne\space\gr at ill@value{#1}%
+  \else
+    \ifnum#1<10\expandafter\gr at Num@i\number#1%
+    \else
+      \ifnum#1<100\expandafter\gr at Num@ii\number#1%
+      \else
+        \ifnum#1<\@m\expandafter\gr at Num@iii\number#1%
+        \else
+          \ifnum#1<\@M\expandafter\gr at Num@iv\number#1%
+          \else
+            \ifnum#1<100000\expandafter\gr at Num@v\number#1%
+            \else
+              \ifnum#1<1000000\expandafter\gr at Num@vi\number#1%
+              \else
+                \space\gr at ill@value{#1}%
+              \fi
+            \fi
+          \fi
+        \fi
+      \fi
+    \fi
+  \fi
+}
 \let\greeknumeral=\greeknumber
 \let\Greeknumeral=\Greeknumber
 \def\gr at num@i#1{%
@@ -283,6 +311,27 @@
 \def\gr at num@vi#1{%
   ͵\ifcase#1\or ρ\or σ\or τ\or υ\or φ\or χ\or ψ\or ω\or ϡ\fi
   \gr at num@v}
+\def\gr at Num@i#1{%
+  \ifcase#1 \or Α\or Β\or Γ\or Δ\or Ε\or \MakeUppercase{Ϛ}\or Ζ\or Η\or θ\fi
+  \ifnum#1=\z@\else\anw at true\fi\anw at print}
+\def\gr at Num@ii#1{%
+  \ifcase#1 \or Ι\or Κ\or Λ\or Μ\or Ν\or Ξ\or Ο\or Π\or \MakeUppercase{ϟ}\fi
+  \ifnum#1=\z@\else\anw at true\fi\gr at Num@i}
+\def\gr at Num@iii#1{%
+  \ifcase#1 \or Ρ\or Σ\or Τ\or Υ\or Φ\or Χ\or Ψ\or Ω\or \MakeUppercase{ϡ}\fi
+  \ifnum#1=\z@\anw at false\else\anw at true\fi\gr at Num@ii}
+\def\gr at Num@iv#1{%
+  \ifnum#1=\z@\else ͵\fi
+  \ifcase#1 \or Α\or Β\or Γ\or Δ\or Ε\or \MakeUppercase{Ϛ}\or Ζ\or Η\or θ\fi
+  \gr at Num@iii}
+\def\gr at Num@v#1{%
+  \ifnum#1=\z@\else ͵\fi
+  \ifcase#1 \or Ι\or Κ\or Λ\or Μ\or Ν\or Ξ\or Ο\or Π\or \MakeUppercase{ϟ}\fi
+\gr at Num@iv}
+  \def\gr at Num@vi#1{%
+͵ \ifcase#1 \or Ρ\or Σ\or Τ\or Υ\or Φ\or Χ\or Ψ\or Ω\or \MakeUppercase{ϡ}\fi
+  \gr at Num@v}
+\def\gr at ill@value#1{\xpg at warning{Illegal value (#1) for Greek numeral}[$#1$]}
 
 %%%% Attic numerals (no longer optional)
 \newcount\@attic at num
@@ -326,11 +375,9 @@
 \let\atticnum=\atticnumeral
 
 \def\greek at numbers{%
-   \let\latin at alph\@alph%
-   \let\latin at Alph\@Alph%
    \if at greek@numerals
-      \def\greek at alph##1{\protect\greeknumber{##1}}%
-      \def\greek at Alph##1{\protect\Greeknumber{##1}}%
+      \def\greek at alph##1{\expandafter\greeknumeral\expandafter{\the##1}}%
+      \def\greek at Alph##1{\expandafter\Greeknumeral\expandafter{\the##1}}%
       \let\@alph\greek at alph%
       \let\@Alph\greek at Alph%
    \fi}

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hebrew.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hebrew.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hebrew.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -8,14 +8,14 @@
 \RequireBidi
 \RequirePackage{hebrewcal}
 
-\providebool{@hebrew at marcheshvan}
-
 \PolyglossiaSetup{hebrew}{
   script=Hebrew,
   direction=RL,
   scripttag=hebr,
+  langtag=IWR,
   hyphennames={nohyphenation},
   fontsetup=true,
+  localnumeral=hebrewnumerals
   %TODO localalph={hebrewnumeral,Hebrewnumeral}
   %digits = hebrewnumber
 }
@@ -31,16 +31,10 @@
     \@calendar at hebrewfalse%
 	\fi}
 
-\define at boolkey{hebrew}[@xpg at hebrew@]{marcheshvan}[false]{%
-  \def\@tmpa{#1}%
-  \def\@tmptrue{true}%
-  \ifx\@tmpa\@tmptrue
-    \@xpg at hebrew@marcheshvantrue
-  \else
-    \@xpg at hebrew@marcheshvanfalse
-  \fi}
+\newif\if at xpg@hebrew at marcheshvan
+\@xpg at hebrew@marcheshvanfalse
 
-\setkeys{hebrew}{marcheshvan}
+\define at boolkey{hebrew}[@xpg at hebrew@]{marcheshvan}[true]{}
 
 % hebrewcal.sty also defines the boolean key fullyear (default=false)
 
@@ -100,9 +94,11 @@
 
 \input{babel-hebrewalph.def}
 
+\newcommand{\hebrewnumerals}[2]{\hebrewnumber{#2}}
+
 \def\hebrewnumber#1{%
    \if at hebrew@numerals
-     \protect\hebrewnumeral{#1}%
+     \hebrewnumeral{#1}%
    \else
      \number#1%
    \fi
@@ -109,32 +105,37 @@
 }
 
 \def\hebrew at numbers{%
-   \let\@origalph\@alph%
-   \let\@origAlph\@Alph%
    \let\@alph\hebrewnumeral%
    \let\@Alph\Hebrewnumeral%
 }
+
 \def\nohebrew at numbers{%
-  \let\@alph\@origalph%
-  \let\@Alph\@origAlph%
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
 }
 
 \def\hebrew at globalnumbers{%
-   \let\orig at arabic\@arabic%
    \let\@arabic\hebrewnumber%
-   \renewcommand\thefootnote{\protect\hebrewnumber{\c at footnote}}%
+   \renewcommand\thefootnote{\localnumeral*{footnote}}%
 }
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
 \def\nohebrew at globalnumbers{%
-  \let\@arabic\orig at arabic%
-  \renewcommand\thefootnote{\protect\number{\c at footnote}}%
+  \let\@arabic\xpg at save@arabic%
 }
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at hebrew{%
-   \let\@@MakeUppercase\MakeUppercase%
    \def\MakeUppercase##1{##1}%
-   }
+}
+
 \def\noextras at hebrew{%
-   \let\MakeUppercase\@@MakeUppercase%
-   }
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase%
+}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hindi.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hindi.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hindi.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,15 +1,9 @@
-% UTF-8 strings kindly provided by Zdenek Wagner, 10-03-2008
+% UTF-8 strings kindly provided by Zdenĕk Wagner, 10-03-2008
 % with corrections and additional contributions by Anshuman Pandey
 % TODO: add option for velthuis transliteration with link to
 % Velthuis Devanagari project.
 
 \ProvidesFile{gloss-hindi.ldf}[polyglossia: module for hindi]
-\ifluatex
-  \xpg at warning{Hindi is not supported with LuaTeX.\MessageBreak
-I will proceed with the compilation, but\MessageBreak
-the output is not guaranteed to be correct\MessageBreak
-and may look very wrong.}
-\fi
 \RequirePackage{devanagaridigits}
 \PolyglossiaSetup{hindi}{
   script=Devanagari,
@@ -16,9 +10,9 @@
   scripttag=deva,
   langtag=HIN,
 %%  hyphennames={hindi,!sanskrit}, TODO: implement fallback patterns (with ! prefix)
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=hindinumerals
   %TODO nouppercase=true,
-  %TODO localnumber=hindinumber
 }
 
 \ifx\l at hindi\@undefined%
@@ -32,7 +26,9 @@
   \fi
 \fi
 
-\def\hindi at language{\language=\l at hindi}
+\def\hindi at language{%
+  \polyglossia at setup@language at patterns{hindi}%
+}
 
 \def\tmp at western{Western}
 \newif\ifhindi at devanagari@numerals
@@ -44,6 +40,8 @@
     \hindi at devanagari@numeralsfalse
   \fi}
 
+\newcommand{\hindinumerals}[2]{\hindinumber{#2}}
+
 \def\hindinumber#1{%
   \ifhindi at devanagari@numerals
     \devanagaridigits{\number#1}%
@@ -54,13 +52,13 @@
 \def\captionshindi{%
      \def\abstractname{सारांश}%
      \def\appendixname{परिशिष्ट}%
-     \def\bibname{संदर्भ ग्रन्थ}%
+     \def\bibname{संदर्भ ग्रंथ}%
      \def\ccname{}%
      \def\chaptername{अध्याय}%
      \def\contentsname{विषय सूची}%
      \def\enclname{}%
      \def\figurename{चित्र}% रेखाचित्र
-     \def\headpagename{पृषठ}%
+     \def\headpagename{पृष्ठ}%
      \def\headtoname{}%
      \def\indexname{सूची}%
      %              सूचक
@@ -68,7 +66,7 @@
      %              अनुक्रमणि
      \def\listfigurename{चित्रों की सूची}%
      \def\listtablename{तालिकाओं की सूची}%
-     \def\pagename{पृषठ}%
+     \def\pagename{पृष्ठ}%
      \def\partname{खणड}%
      \def\prefacename{प्रस्तावना}% प्राक्कथन
      \def\refname{हवाले}%
@@ -94,12 +92,16 @@
     \space\hindinumber\year}%
 }
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at hindi{%
-  \let\@@MakeUppercase\MakeUppercase%
   \def\MakeUppercase##1{##1}%
 }
+
 \def\noextras at hindi{%
-  \let\MakeUppercase\@@MakeUppercase%
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase%
 }
 
 \endinput

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hungarian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hungarian.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hungarian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,81 @@
+\ProvidesFile{gloss-hungarian.ldf}[polyglossia: module for hungarian]
+
+\PolyglossiaSetup{hungarian}{
+  babelname=magyar,
+  hyphennames={magyar,hungarian},
+  langtag=HUN,
+  hyphenmins={2,2},
+  fontsetup=true,
+}
+
+\frenchspacing
+
+\def\captionshungarian{%
+   \def\refname{Hivatkozások}%
+   \def\abstractname{Kivonat}%
+   \def\bibname{Irodalomjegyzék}%
+   \def\prefacename{Előszó}%
+   \def\chaptername{fejezet}%
+   \def\appendixname{Függelék}%
+   \def\contentsname{Tartalomjegyzék}%
+   \def\listfigurename{Ábrák jegyzéke}%
+   \def\listtablename{Táblázatok jegyzéke}%
+   \def\indexname{Tárgymutató}%
+   \def\figurename{ábra}%
+   \def\tablename{táblázat}%
+   %\def\thepart{}%
+   \def\partname{rész}%
+   \def\pagename{oldal}%
+   \def\seename{lásd}%
+   \def\alsoname{lásd még}%
+   \def\enclname{Melléklet}%
+   \def\ccname{Körlevél–címzettek}%
+   \def\headtoname{Címzett}%
+   \def\proofname{Bizonyítás}%
+   \def\glossaryname{Szójegyzék}%
+}
+
+\def\datehungarian{%   
+   \def\today{%
+    \number\year.\nobreakspace\ifcase\month\or
+    január\or február\or március\or
+    április\or május\or június\or
+    július\or augusztus\or szeptember\or
+    október\or november\or december\fi
+    \space\number\day.}%
+   \def\ondatehungarian{%
+    \number\year.\nobreakspace\ifcase\month\or
+    január\or február\or március\or
+    április\or május\or június\or
+    július\or augusztus\or szeptember\or
+    október\or november\or december\fi
+      \space\ifcase\day\or
+      1-jén\or  2-án\or  3-án\or  4-én\or  5-én\or
+      6-án\or  7-én\or  8-án\or  9-én\or 10-én\or
+     11-én\or 12-én\or 13-án\or 14-én\or 15-én\or
+     16-án\or 17-én\or 18-án\or 19-én\or 20-án\or
+     21-én\or 22-én\or 23-án\or 24-én\or 25-én\or
+     26-án\or 27-én\or 28-án\or 29-én\or 30-án\or
+     31-én\fi}%
+   \let\ontoday\ondatehungarian}
+
+% change 'táblázat x.x' to 'x.x. táblázat'
+\def\xpg at hungarian@fnum at table{\thetable.~\tablename}
+\let\xpg at save@fnum at table\fnum at table
+
+% change 'ábra x.x' to 'x.x. ábra'
+\def\xpg at hungarian@fnum at figure{\thefigure.~\figurename}
+\let\xpg at save@fnum at figure\fnum at figure
+
+\def\blockextras at hungarian{%
+   \let\fnum at table\xpg at hungarian@fnum at table
+   \let\fnum at figure\xpg at hungarian@fnum at figure
+}
+
+\def\noextras at hungarian{%
+   \let\fnum at table\xpg at save@fnum at table
+   \let\fnum at figure\xpg at save@fnum at figure
+   \let\ontoday\@undefined
+}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hungarian.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-icelandic.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-icelandic.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-icelandic.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{icelandic}{
   hyphennames={icelandic},
   hyphenmins={2,2},
+  langtag=ISL,
   fontsetup=true,
 }
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-interlingua.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-interlingua.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-interlingua.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{interlingua}{
   hyphennames={interlingua},
   hyphenmins={2,2},
+  langtag=INA,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-irish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-irish.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-irish.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,42 +1,18 @@
 \ProvidesFile{gloss-irish.ldf}[polyglossia: module for irish]
+
+% We only provide this gloss for babel compatibility. Since irish is 
+% a gaelic variety, we use 'gaelic' with variant 'irish' now.
+
+\input{gloss-gaelic.ldf}
+
 \PolyglossiaSetup{irish}{
   hyphennames={irish},
   hyphenmins={2,2},
+  langtag=IRI,
   fontsetup=true,
 }
 
-\def\captionsirish{%
-   \def\refname{Tagairtí}%
-   \def\abstractname{Achoimre}%
-   \def\bibname{Leabharliosta}%
-   \def\prefacename{Réamhrá}%    <-- also "Brollach"
-   \def\refname{Tagairtí}%
-   \def\chaptername{Tagairtí}%
-   \def\appendixname{Aguisín}%
-   \def\contentsname{Clár Ábhair}%
-   \def\listfigurename{Léaráidí}%
-   \def\listtablename{Táblaí}%
-   \def\indexname{Innéacs}%
-   \def\figurename{Léaráid}%
-   \def\tablename{Tábla}%
-   %\def\thepart{}%
-   \def\partname{Cuid}%
-   \def\pagename{Leathanach}%
-   \def\seename{féach}%
-   \def\alsoname{féach freisin}%
-   \def\enclname{faoi iamh}%
-   \def\ccname{cc}%
-   \def\headtoname{Go}%
-   \def\proofname{Cruthúnas}%
-   \def\glossaryname{Glossary}%
-   }
-\def\dateirish{%
-   \def\today{%
-    \number\day\space \ifcase\month\or
-    Eanáir\or Feabhra\or Márta\or Aibreán\or
-    Bealtaine\or Meitheamh\or Iúil\or Lúnasa\or
-    Meán Fómhair\or Deireadh Fómhair\or
-    Mí na Samhna\or Mí na Nollag\fi
-    \space \number\year}}
+\let\captionsirish\captionsgaelic at irish
+\let\dateirish\dategaelic at irish
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-italian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-italian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-italian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -3,6 +3,7 @@
 \PolyglossiaSetup{italian}{
   hyphennames={italian},
   hyphenmins={2,2},
+  langtag=ITA,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,
@@ -19,8 +20,9 @@
 \fi
 
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\italian at shorthands{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kannada.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kannada.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kannada.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -26,10 +26,11 @@
 \PolyglossiaSetup{kannada}{
   script=Kannada,
   scripttag=knda,
-  langtag=KNDA,
+  langtag=KAN,
   hyphennames={kannada},
   hyphenmins={2,2}, 
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=kannadanumerals
 }
 
 %% Defining Kannada digits equivalents to english
@@ -97,7 +98,9 @@
   \def\today{\kannadanumber\day\space\kannadamonth\space\kannadanumber\year}%
 }
 
-%% Based on the settings displays rrespective numbers
+\newcommand{\kannadanumerals}[2]{\kannadanumber{#2}}
+
+%% Based on the settings displays respective numbers
 \def\kannadanumber#1{%
   \ifkannada at numerals
   \kannadadigits{\number#1}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-khmer.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-khmer.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-khmer.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -4,7 +4,8 @@
 	scripttag=khmr,%
 	langtag=KHM,%
 	hyphennames={nohyphenation},%
-	fontsetup=true%
+	fontsetup=true,%
+	localnumeral=khmernumerals%
 }
 \newif\if at khmer@numerals
 \def\tmp at khmer{khmer}
@@ -71,6 +72,9 @@
     \expandafter\@khmer at digits%
     \fi
 }
+
+\newcommand{\khmernumerals}[2]{\khmernumber{#2}}
+
 \def\khmernumber#1{%
 	\if at khmer@numerals%
 		\khmerdigits{\number#1}%
@@ -80,11 +84,10 @@
 \def\khmer at globalnumbers{%
 	\let\orig at arabic\@arabic%
 	\let\@arabic\khmernumber%
-	\renewcommand{\thefootnote}{\protect\khmernumber{\c at footnote}}%
+	\renewcommand{\thefootnote}{\localnumeral*{footnote}}%
 }
 \def\nokhmer at globalnumbers{%
 	\let\@arabic\orig at arabic%
-	\renewcommand\thefootnote{\protect\number{\c at footnote}}%
 }
 \def\thepart{\arabic{part}}
 \def\@khmeralph#1{%
@@ -107,8 +110,6 @@
 \or យ\or រ\or ល\or វ\or ស\or ហ\or ឡ\or អ%
 \else\xpg at ill@value{#1}{@khmeralph}\fi}
 \def\khmer at numbers{%
-	\let\@latinalph\@alph%
-	\let\@latinAlph\@Alph%
 	\if at khmer@numerals
 		\let\@alph\@khmeralph%
 		\let\@Alph\@khmerAlph%
@@ -115,8 +116,8 @@
 	\fi%
 }
 \def\nokhmer at numbers{%
-	\let\@alph\@latinalph%
-	\let\@Alph\@latinAlph%
+	\let\@alph\latin at alph%
+	\let\@Alph\latin at Alph%
 }
 \def\blockextras at khmer{%
 	\XeTeXlinebreaklocale "kh" % 
@@ -152,6 +153,6 @@
 	\deftranslation[to=khmer]{Examples}{\examplename}%
 	\AtEndDocument{\immediate\write\@auxout{\string\@writefile{nav}%
 		{\noexpand\headcommand{\noexpand\def\noexpand%
-		\inserttotalframenumber{\khmernumber{\the\c at framenumber}}}}}}%
+		\inserttotalframenumber{\localnumeral*{framenumber}}}}}}%
 }{}
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-korean.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-korean.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-korean.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -5,8 +5,7 @@
     scripttag=hang,
     language=Korean,
     langtag=KOR,
-    hyphennames={english,USenglish},
-    hyphenmins={2,3},
+    hyphennames={nohyphenation},
     frenchspacing=true,
     fontsetup=true
 }
@@ -27,8 +26,8 @@
     \else
         \captions at korean@hanja
     \fi
-    \def\seename{$rightarrow$}%
-    \def\alsoname{$Rightarrow$}%
+    \def\seename{$\rightarrow$}%
+    \def\alsoname{$\Rightarrow$}%
 }
 \def\captions at korean@hangul{%
     \def\koreanTHEname{제}%
@@ -94,14 +93,12 @@
 }
 
 \def\korean at numbers{%
-    \let\@orig at alph\@alph
-    \let\@orig at Alph\@Alph
     \let\@alph\@koreanalph
     \let\@Alph\@koreanAlph
 }
 \def\nokorean at numbers{%
-    \let\@alph\@orig at alph
-    \let\@Alph\@orig at Alph
+    \let\@alph\latin at alph
+    \let\@Alph\latin at Alph
 }
 \let\nokorean at globalnumbers\nokorean at numbers
 
@@ -135,7 +132,7 @@
         \XeTeXinterchartokenstate\z@
         \XeTeXlinebreakpenalty\z@
         \XeTeXlinebreakskip\z at skip
-        \XeTeXlinebreaklocale ""
+        \XeTeXlinebreaklocale "en"
         \noextras at korean@common
     }
 \else % luatex
@@ -155,26 +152,44 @@
             \def\@chapapp##1##2{\koreanTHEname ##1##2##1\chaptername}%
         \fi
     \fi
-    \ifdefined\baselinestretch
-        \let\xpg at orig@linestretch\baselinestretch
-        \def\baselinestretch{1.3888}\selectfont
-    \fi
-    \ifdefined\footnotesep
-        \edef\xpg at orig@footnotesep{\noexpand\footnotesep=\the\footnotesep\relax}%
-        \footnotesep=1.3888\footnotesep
-    \fi
 }
 
 \def\noextras at korean@common{%
-    \ifdefined\xpg at orig@footnotesep \xpg at orig@footnotesep \fi
-    \ifdefined\xpg at orig@linestretch \let\baselinestretch\xpg at orig@linestretch \fi
-    \ifdefined\xpg at orig@@chapapp    \let\@chapapp\xpg at orig@@chapapp \fi
+    \ifdefined\xpg at orig@@chapapp \let\@chapapp\xpg at orig@@chapapp \fi
 }
 
-\ifxetex % XeTeX
+\ifluatex % luatex
+\protected\def\inhibitglue{\hskip\z at skip}
+\ifdefined\newattribute\else
+    \let\newattribute\newluatexattribute
+    \let\unsetattribute\unsetluatexattribute
+\fi
+\newattribute\xpg at attr@korean
+\newattribute\xpg at attr@autojosa
 % user commands for Josa
 % Josa : particles in Korean grammar that immediately follow a noun or pronoun.
 %        Josa might vary depending on previous character.
+\protected\def\rieul{\global\let\xpg at josa@zwang\@ne}
+\protected\def\jung {\global\let\xpg at josa@zwang\tw@}
+\protected\def\jong {\global\let\xpg at josa@zwang\thr@@}
+\protected\def\은{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 은\endgroup\xpg at reset@josa}
+\let\는\은
+\protected\def\을{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 을\endgroup\xpg at reset@josa}
+\let\를\을
+\protected\def\와{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 와\endgroup\xpg at reset@josa}
+\let\과\와
+\protected\def\가{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 가\endgroup\xpg at reset@josa}
+\protected\def\이{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 이\endgroup\xpg at reset@josa}
+\protected\def\라{\이 라}
+\protected\def\으{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 으\endgroup\xpg at reset@josa}
+\protected\def\로{\으 로}
+\def\xpg at reset@josa {\global\let\xpg at josa@zwang\z@}\xpg at reset@josa
+% load lua file for korean
+\directlua{ require "polyglossia-korean" }
+\endinput\fi
+
+% XeTeX
+% user commands for Josa
 \protected\def\jong {\global\let\XPGKO at let@josa=0}\jong
 \protected\def\rieul{\global\let\XPGKO at let@josa=1}
 \protected\def\jung {\global\let\XPGKO at let@josa=2}
@@ -581,553 +596,4 @@
 \@tmpa "FF01=\XPGKOcharclassEX % ! FULLWIDTH EXCLAMATION MARK
 \@tmpa "FF1F=\XPGKOcharclassEX % ? FULLWIDTH QUESTION MARK
 
-\endinput\fi % end of XeTeX
-
-% luatex
-\protected\def\inhibitglue{\hskip\z at skip}
-\ifdefined\newattribute\else
-    \let\newattribute\newluatexattribute
-    \let\unsetattribute\unsetluatexattribute
-\fi
-\newattribute\xpg at attr@korean
-\newattribute\xpg at attr@autojosa
-\protected\def\rieul{\global\let\xpg at josa@zwang\@ne}
-\protected\def\jung {\global\let\xpg at josa@zwang\tw@}
-\protected\def\jong {\global\let\xpg at josa@zwang\thr@@}
-\protected\def\은{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 은\endgroup\xpg at reset@josa}
-\let\는\은
-\protected\def\을{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 을\endgroup\xpg at reset@josa}
-\let\를\을
-\protected\def\와{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 와\endgroup\xpg at reset@josa}
-\let\과\와
-\protected\def\가{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 가\endgroup\xpg at reset@josa}
-\protected\def\이{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 이\endgroup\xpg at reset@josa}
-\protected\def\라{\이 라}
-\protected\def\으{\begingroup\xpg at attr@autojosa\xpg at josa@zwang 으\endgroup\xpg at reset@josa}
-\protected\def\로{\으 로}
-\def\xpg at reset@josa {\global\let\xpg at josa@zwang\z@}\xpg at reset@josa
-\directlua{
-local glyph_id = node.id("glyph")
-local hbox_id  = node.id("hlist")
-local vbox_id  = node.id("vlist")
-local glue_id  = node.id("glue")
-local penalty_id = node.id("penalty")
-local disc_id  = node.id("disc")
-local attr_korean = luatexbase.attributes["xpg at attr@korean"]
-local attr_josa   = luatexbase.attributes["xpg at attr@autojosa"]
-local nobr_after = {
-    [0x28] = 1, % ( LEFT PARENTHESIS
-    [0x3C] = 1, % < LESS-THAN SIGN
-    [0x5B] = 1, % [ LEFT SQUARE BRACKET
-    [0x60] = 1, % ` GRAVE ACCENT
-    [0x7B] = 1, % { LEFT CURLY BRACKET
-    [0xAB] = 1, % « LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
-    [0x2018] = 1, % ‘ LEFT SINGLE QUOTATION MARK
-    [0x201C] = 1, % “ LEFT DOUBLE QUOTATION MARK
-    [0x2329] = 1, % 〈 LEFT-POINTING ANGLE BRACKET
-    [0x3008] = 1, % 〈 LEFT ANGLE BRACKET
-    [0x300A] = 1, % 《 LEFT DOUBLE ANGLE BRACKET
-    [0x300C] = 1, % 「 LEFT CORNER BRACKET
-    [0x300E] = 1, % 『 LEFT WHITE CORNER BRACKET
-    [0x3010] = 1, % 【 LEFT BLACK LENTICULAR BRACKET
-    [0x3014] = 1, % 〔 LEFT TORTOISE SHELL BRACKET
-    [0x3016] = 1, % 〖 LEFT WHITE LENTICULAR BRACKET
-    [0x3018] = 1, % 〘 LEFT WHITE TORTOISE SHELL BRACKET
-    [0x301A] = 1, % 〚 LEFT WHITE SQUARE BRACKET
-    [0x301D] = 1, % 〝 REVERSED DOUBLE PRIME QUOTATION MARK
-    [0xFE17] = 1, % ︗ PRESENTATION FORM FOR VERTICAL LEFT WHITE LENTICULAR BRACKET
-    [0xFE35] = 1, % ︵ PRESENTATION FORM FOR VERTICAL LEFT PARENTHESIS
-    [0xFE37] = 1, % ︷ PRESENTATION FORM FOR VERTICAL LEFT CURLY BRACKET
-    [0xFE39] = 1, % ︹ PRESENTATION FORM FOR VERTICAL LEFT TORTOISE SHELL BRACKET
-    [0xFE3B] = 1, % ︻ PRESENTATION FORM FOR VERTICAL LEFT BLACK LENTICULAR BRACKET
-    [0xFE3D] = 1, % ︽ PRESENTATION FORM FOR VERTICAL LEFT DOUBLE ANGLE BRACKET
-    [0xFE3F] = 1, % ︿ PRESENTATION FORM FOR VERTICAL LEFT ANGLE BRACKET
-    [0xFE41] = 1, % ﹁ PRESENTATION FORM FOR VERTICAL LEFT CORNER BRACKET
-    [0xFE43] = 1, % ﹃ PRESENTATION FORM FOR VERTICAL LEFT WHITE CORNER BRACKET
-    [0xFE47] = 1, % ﹇ PRESENTATION FORM FOR VERTICAL LEFT SQUARE BRACKET
-    [0xFE59] = 1, % ﹙ SMALL LEFT PARENTHESIS
-    [0xFE5B] = 1, % ﹛ SMALL LEFT CURLY BRACKET
-    [0xFE5D] = 1, % ﹝ SMALL LEFT TORTOISE SHELL BRACKET
-    [0xFF08] = 1, % ( FULLWIDTH LEFT PARENTHESIS
-    [0xFF3B] = 1, % [ FULLWIDTH LEFT SQUARE BRACKET
-    [0xFF5B] = 1, % { FULLWIDTH LEFT CURLY BRACKET
-    [0xFF5F] = 1, % ⦅ FULLWIDTH LEFT WHITE PARENTHESIS
-    [0xFF62] = 1, % 「 HALFWIDTH LEFT CORNER BRACKET
-}
-local nobr_before = setmetatable({
-    [0x21] = 1, % ! EXCLAMATION MARK
-    [0x22] = 1, % " QUOTATION MARK
-    [0x27] = 1, % ' APOSTROPHE
-    [0x29] = 1, % ) RIGHT PARENTHESIS
-    [0x2C] = 1, % , COMMA
-    [0x2D] = 0, % - HYPHEN-MINUS
-    [0x2E] = 1, % . FULL STOP
-    [0x2F] = 0, % / SOLIDUS
-    [0x3A] = 0, % : COLON
-    [0x3B] = 1, % ; SEMICOLON
-    [0x3E] = 1, % > GREATER-THAN SIGN
-    [0x3F] = 1, % ? QUESTION MARK
-    [0x5C] = 0, % \ REVERSE SOLIDUS
-    [0x5D] = 1, % ] RIGHT SQUARE BRACKET
-    [0x7D] = 1, % } RIGHT CURLY BRACKET
-    [0x7E] = 0, % ~ TILDE
-    [0xB7] = 1, % · MIDDLE DOT
-    [0xBB] = 1, % » RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
-    [0x2013] = 0, % – EN DASH
-    [0x2014] = 0, % — EM DASH
-    [0x2015] = 1, % ― HORIZONTAL BAR
-    [0x2019] = 1, % ’ RIGHT SINGLE QUOTATION MARK
-    [0x201D] = 1, % ” RIGHT DOUBLE QUOTATION MARK
-    [0x2025] = 1, % ‥ TWO DOT LEADER
-    [0x2026] = 1, % … HORIZONTAL ELLIPSIS
-    [0x232A] = 1, % 〉 RIGHT-POINTING ANGLE BRACKET
-    [0x3001] = 1, % 、 IDEOGRAPHIC COMMA
-    [0x3002] = 1, % 。 IDEOGRAPHIC FULL STOP
-    [0x3005] = 1, % 々 IDEOGRAPHIC ITERATION MARK
-    [0x3009] = 1, % 〉 RIGHT ANGLE BRACKET
-    [0x300B] = 1, % 》 RIGHT DOUBLE ANGLE BRACKET
-    [0x300D] = 1, % 」 RIGHT CORNER BRACKET
-    [0x300F] = 1, % 』 RIGHT WHITE CORNER BRACKET
-    [0x3011] = 1, % 】 RIGHT BLACK LENTICULAR BRACKET
-    [0x3015] = 1, % 〕 RIGHT TORTOISE SHELL BRACKET
-    [0x3017] = 1, % 〗 RIGHT WHITE LENTICULAR BRACKET
-    [0x3019] = 1, % 〙 RIGHT WHITE TORTOISE SHELL BRACKET
-    [0x301B] = 1, % 〛 RIGHT WHITE SQUARE BRACKET
-    [0x301C] = 1, % 〜 WAVE DASH
-    [0x301E] = 1, % 〞 DOUBLE PRIME QUOTATION MARK
-    [0x301F] = 1, % 〟 LOW DOUBLE PRIME QUOTATION MARK
-    [0x3035] = 1, % 〵 VERTICAL KANA REPEAT MARK LOWER HALF
-    [0x303B] = 1, % 〻 VERTICAL IDEOGRAPHIC ITERATION MARK
-    [0x303C] = 1, % 〼 MASU MARK
-    [0x3041] = 3, % ぁ HIRAGANA LETTER SMALL A
-    [0x3043] = 3, % ぃ HIRAGANA LETTER SMALL I
-    [0x3045] = 3, % ぅ HIRAGANA LETTER SMALL U
-    [0x3047] = 3, % ぇ HIRAGANA LETTER SMALL E
-    [0x3049] = 3, % ぉ HIRAGANA LETTER SMALL O
-    [0x3063] = 3, % っ HIRAGANA LETTER SMALL TU
-    [0x3083] = 3, % ゃ HIRAGANA LETTER SMALL YA
-    [0x3085] = 3, % ゅ HIRAGANA LETTER SMALL YU
-    [0x3087] = 3, % ょ HIRAGANA LETTER SMALL YO
-    [0x308E] = 3, % ゎ HIRAGANA LETTER SMALL WA
-    [0x3095] = 3, % ゕ HIRAGANA LETTER SMALL KA
-    [0x3096] = 3, % ゖ HIRAGANA LETTER SMALL KE
-    [0x3099] = 1, %  COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
-    [0x309A] = 1, %  COMBINING KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
-    [0x309B] = 1, % ゛ KATAKANA-HIRAGANA VOICED SOUND MARK
-    [0x309C] = 1, % ゜ KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
-    [0x309D] = 1, % ゝ HIRAGANA ITERATION MARK
-    [0x309E] = 1, % ゞ HIRAGANA VOICED ITERATION MARK
-    [0x30A0] = 1, % ゠ KATAKANA-HIRAGANA DOUBLE HYPHEN
-    [0x30A1] = 3, % ァ KATAKANA LETTER SMALL A
-    [0x30A3] = 3, % ィ KATAKANA LETTER SMALL I
-    [0x30A5] = 3, % ゥ KATAKANA LETTER SMALL U
-    [0x30A7] = 3, % ェ KATAKANA LETTER SMALL E
-    [0x30A9] = 3, % ォ KATAKANA LETTER SMALL O
-    [0x30C3] = 3, % ッ KATAKANA LETTER SMALL TU
-    [0x30E3] = 3, % ャ KATAKANA LETTER SMALL YA
-    [0x30E5] = 3, % ュ KATAKANA LETTER SMALL YU
-    [0x30E7] = 3, % ョ KATAKANA LETTER SMALL YO
-    [0x30EE] = 3, % ヮ KATAKANA LETTER SMALL WA
-    [0x30F5] = 3, % ヵ KATAKANA LETTER SMALL KA
-    [0x30F6] = 3, % ヶ KATAKANA LETTER SMALL KE
-    [0x30FB] = 1, % ・ KATAKANA MIDDLE DOT
-    [0x30FC] = 1, % ー KATAKANA-HIRAGANA PROLONGED SOUND MARK
-    [0x30FD] = 1, % ヽ KATAKANA ITERATION MARK
-    [0x30FE] = 1, % ヾ KATAKANA VOICED ITERATION MARK
-    [0xFE30] = 1, % ︰ PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
-    [0xFE31] = 1, % ︱ PRESENTATION FORM FOR VERTICAL EM DASH
-    [0xFE32] = 1, % ︲ PRESENTATION FORM FOR VERTICAL EN DASH
-    [0xFE36] = 1, % ︶ PRESENTATION FORM FOR VERTICAL RIGHT PARENTHESIS
-    [0xFE38] = 1, % ︸ PRESENTATION FORM FOR VERTICAL RIGHT CURLY BRACKET
-    [0xFE3A] = 1, % ︺ PRESENTATION FORM FOR VERTICAL RIGHT TORTOISE SHELL BRACKET
-    [0xFE3C] = 1, % ︼ PRESENTATION FORM FOR VERTICAL RIGHT BLACK LENTICULAR BRACKET
-    [0xFE3E] = 1, % ︾ PRESENTATION FORM FOR VERTICAL RIGHT DOUBLE ANGLE BRACKET
-    [0xFE40] = 1, % ﹀ PRESENTATION FORM FOR VERTICAL RIGHT ANGLE BRACKET
-    [0xFE42] = 1, % ﹂ PRESENTATION FORM FOR VERTICAL RIGHT CORNER BRACKET
-    [0xFE44] = 1, % ﹄ PRESENTATION FORM FOR VERTICAL RIGHT WHITE CORNER BRACKET
-    [0xFE48] = 1, % ﹈ PRESENTATION FORM FOR VERTICAL RIGHT SQUARE BRACKET
-    [0xFE5A] = 1, % ﹚ SMALL RIGHT PARENTHESIS
-    [0xFE5C] = 1, % ﹜ SMALL RIGHT CURLY BRACKET
-    [0xFE5E] = 1, % ﹞ SMALL RIGHT TORTOISE SHELL BRACKET
-    [0xFF01] = 1, % ! FULLWIDTH EXCLAMATION MARK
-    [0xFF09] = 1, % ) FULLWIDTH RIGHT PARENTHESIS
-    [0xFF0C] = 1, % , FULLWIDTH COMMA
-    [0xFF0E] = 1, % . FULLWIDTH FULL STOP
-    [0xFF1A] = 1, % : FULLWIDTH COLON
-    [0xFF1B] = 1, % ; FULLWIDTH SEMICOLON
-    [0xFF1F] = 1, % ? FULLWIDTH QUESTION MARK
-    [0xFF3D] = 1, % ] FULLWIDTH RIGHT SQUARE BRACKET
-    [0xFF5D] = 1, % } FULLWIDTH RIGHT CURLY BRACKET
-    [0xFF60] = 1, % ⦆ FULLWIDTH RIGHT WHITE PARENTHESIS
-    [0xFF61] = 1, % 。 HALFWIDTH IDEOGRAPHIC FULL STOP
-    [0xFF63] = 1, % 」 HALFWIDTH RIGHT CORNER BRACKET
-    [0xFF64] = 1, % 、 HALFWIDTH IDEOGRAPHIC COMMA
-    [0xFF65] = 1, % ・ HALFWIDTH KATAKANA MIDDLE DOT
-    [0xFF9E] = 1, % ゙ HALFWIDTH KATAKANA VOICED SOUND MARK
-    [0xFF9F] = 1, % ゚ HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK
-}, { __index = function(_,c)
-        if c >= 0x1160  and c <= 0x11FF  then return 2 end
-        if c >= 0xD7B0  and c <= 0xD7FF  then return 2 end
-        if c >= 0x302A  and c <= 0x302F  then return 1 end
-        if c >= 0x31F0  and c <= 0x31FF  then return 3 end
-        if c >= 0xFF67  and c <= 0xFF70  then return 3 end
-        if c >= 0xFE00  and c <= 0xFE0F  then return 1 end
-        if c >= 0xFE10  and c <= 0xFE19 and not (c == 0xFE17) then return 1 end
-        if c >= 0xFE50  and c <= 0xFE58  then return 1 end
-        if c >= 0xE0100 and c <= 0xE01EF then return 1 end
-    end
-})
-local function is_cjk (c)
-    return  (c >= 0xAC00  and c <= 0xD7FF)
-    or      (c >= 0x1100  and c <= 0x11FF)
-    or      (c >= 0xA960  and c <= 0xA97F)
-    or      (c >= 0x2E80  and c <= 0x9FFF)
-    or      (c >= 0xF900  and c <= 0xFAFF)
-    or      (c >= 0xFE10  and c <= 0xFE1F)
-    or      (c >= 0xFE30  and c <= 0xFE6F)
-    or      (c >= 0xFF00  and c <= 0xFFEF)
-    or      (c >= 0x1F100 and c <= 0x1F2FF)
-    or      (c >= 0x20000 and c <= 0x2FA1F)
-    or      (nobr_after[c]  and c > 0x2014)
-    or      (nobr_before[c] and c > 0x2014)
-end
-local charclass = setmetatable({
-    [0x2018] = 1, [0x201C] = 1, [0x2329] = 1, [0x3008] = 1,
-    [0x300A] = 1, [0x300C] = 1, [0x300E] = 1, [0x3010] = 1,
-    [0x3014] = 1, [0x3016] = 1, [0x3018] = 1, [0x301A] = 1,
-    [0x301D] = 1, [0xFE17] = 1, [0xFE35] = 1, [0xFE37] = 1,
-    [0xFE39] = 1, [0xFE3B] = 1, [0xFE3D] = 1, [0xFE3F] = 1,
-    [0xFE41] = 1, [0xFE43] = 1, [0xFE47] = 1, [0xFF08] = 1,
-    [0xFF3B] = 1, [0xFF5B] = 1, [0xFF5F] = 1, [0xFF62] = 1,
-    [0x2019] = 2, [0x201D] = 2, [0x232A] = 2, [0x3001] = 2,
-    [0x3009] = 2, [0x300B] = 2, [0x300D] = 2, [0x300F] = 2,
-    [0x3011] = 2, [0x3015] = 2, [0x3017] = 2, [0x3019] = 2,
-    [0x301B] = 2, [0x301E] = 2, [0x301F] = 2, [0xFE10] = 2,
-    [0xFE11] = 2, [0xFE18] = 2, [0xFE36] = 2, [0xFE38] = 2,
-    [0xFE3A] = 2, [0xFE3C] = 2, [0xFE3E] = 2, [0xFE40] = 2,
-    [0xFE42] = 2, [0xFE44] = 2, [0xFE48] = 2, [0xFF09] = 2,
-    [0xFF0C] = 2, [0xFF3D] = 2, [0xFF5D] = 2, [0xFF60] = 2,
-    [0xFF63] = 2, [0xFF64] = 2, [0x00B7] = 3, [0x30FB] = 3,
-    [0xFF1A] = 3, [0xFF1B] = 3, [0xFF65] = 3, [0x3002] = 4,
-    [0xFE12] = 4, [0xFF0E] = 4, [0xFF61] = 4, [0x2015] = 5,
-    [0x2025] = 5, [0x2026] = 5, [0xFE19] = 5, [0xFE30] = 5,
-    [0xFE31] = 5, [0xFE15] = 6, [0xFE16] = 6, [0xFF01] = 6,
-    [0xFF1F] = 6,
-}, { __index = function() return 0 end })
-local intercharclass = { [0] =
-    { [0] = nil,    {1,1},  nil,    {.5,.5} },
-    { [0] = nil,    nil,    nil,    {.5,.5} },
-    { [0] = {1,1},  {1,1},  nil,    {.5,.5}, nil,    {1,1},  {1,1} },
-    { [0] = {.5,.5},{.5,.5},{.5,.5},{1,.5},  {.5,.5},{.5,.5},{.5,.5} },
-    { [0] = {1,0},  {1,0},  nil,    {1.5,.5},nil,    {1,0},  {1,0} },
-    { [0] = nil,    {1,1},  nil,    {.5,.5} },
-    { [0] = {1,1},  {1,1},  nil,    {.5,.5} },
-}
-local function get_new_penalty (p)
-    local penalty = node.new("penalty")
-    penalty.penalty = p
-    return penalty
-end
-local function get_new_glue (wd, st, sh, sto, sho)
-    local glue = node.new("glue")
-    glue.width   = wd or 0
-    glue.stretch = st or 0
-    glue.shrink  = sh or 0
-    glue.stretch_order = sto or 0
-    glue.shrink_order  = sho or 0
-    return glue
-end
-local function get_font_size (fid, space)
-    local f = fonts.hashes.identifiers[fid] or font.fonts[fid]
-    local size = f and f.parameters
-    if space then
-        size = size and size.space or 196608
-    else
-        size = size and size.quad  or 655360
-    end
-    return size/2
-end
-local function glyph_to_box (head, curr, class)
-    local g, h = curr
-    local size = get_font_size(g.font)
-    head, curr = node.remove(head, curr)
-    g.next, g.prev = nil, nil
-    local hss = get_new_glue(0, 65536, 65536, 2, 2)
-    if class == 1 then
-        h, hss.next, g.prev = hss, g, hss
-    elseif class == 2 or class == 4 then
-        h, g.next, hss.prev = g, hss, g
-    else
-        local hss2 = node.copy(hss)
-        h, hss.next, g.prev, g.next, hss2.prev = hss, g, hss, hss2, g
-    end
-    h = nodes.simple_font_handler(h)
-    local box = node.hpack(h, size, "exactly")
-    head, curr = node.insert_before(head, curr, box)
-    return head, curr
-end
-local function insert_cjk_penalty_glue (head, curr, f, var, cc, nc, nobr)
-    if nobr or cc == 1 or nc > 1 then
-        local penalty = get_new_penalty(10000)
-        head, curr = node.insert_after(head, curr, penalty)
-    end
-    local factor = get_font_size(f, var == 2)
-    local t = intercharclass[cc][nc]
-    local glue = get_new_glue(t[1]*factor, nil, t[2]*factor)
-    head, curr = node.insert_after(head, curr, glue)
-    return head, curr
-end
-local function insert_penalty_glue (head, curr, f, var, x)
-    if var == 1 then
-    else
-        local penalty = get_new_penalty(50)
-        head, curr = node.insert_after(head, curr, penalty)
-    end
-    local size, glue = get_font_size(f, x and var == 2)
-    if x then
-        glue = get_new_glue(size/2, size/4, size/8)
-    else
-        glue = get_new_glue(0, size/10, size/50)
-    end
-    head, curr = node.insert_after(head, curr, glue)
-    return head, curr
-end
-local function avoid_widow_char (head)
-    local curr = node.tail(head)
-    while curr do
-        if curr.id == glyph_id then
-            local c = curr.char or 0
-            if not nobr_before[c] or nobr_before[c] == 3 then
-                local var = node.has_attribute(curr, attr_korean)
-                if var and is_cjk(c) then
-                    curr = curr.prev
-                    if curr and curr.id == glue_id then
-                        curr = curr.prev
-                        if curr then
-                            local pv = var == 1 and 500 or 1000
-                            if curr.id == penalty_id then
-                                if curr.penalty < pv then curr.penalty = pv end
-                            else
-                                node.insert_after(head, curr, get_new_penalty(pv))
-                            end
-                        end
-                    end
-                end
-                break
-            end
-        end
-        curr = curr.prev
-    end
-end
-local function korean_break (head, lb)
-    local curr = head
-    while curr do
-        if curr.id == glyph_id then
-            local var = node.has_attribute(curr, attr_korean)
-            if var then
-                local c, f = curr.char or 0, curr.font or 0
-                local cc, cjkc = charclass[c], is_cjk(c)
-                if var > 0 and cc > 0 and cc < 5 then
-                    head, curr = glyph_to_box(head, curr, cc)
-                end
-                local next = curr.next
-                if next and next.id == glyph_id then
-                    local n = next.char or 0
-                    local nc = charclass[n]
-                    local nobr = nobr_before[n] or nobr_after[c]
-                    if var > 0 and intercharclass[cc][nc] then
-                        head, curr = insert_cjk_penalty_glue(head, curr, f, var, cc, nc, nobr)
-                    elseif not nobr then
-                        local cjkn = is_cjk(n)
-                        if cjkc or cjkn then
-                            if var > 0 and not (cjkc and cjkn) and not (nobr_before[c] == 0) then
-                                head, curr = insert_penalty_glue(head, curr, f, var, true)
-                            elseif lb then
-                                head, curr = insert_penalty_glue(head, curr, f, var)
-                            end
-                        end
-                    end
-                end
-            end
-        end
-        curr = curr.next
-    end
-    if lb then avoid_widow_char(head) end
-    return head
-end
-local josa_table = {
-    %           리을,   중성,   종성
-    [0xAC00] = {0xC774, 0xAC00, 0xC774}, % 가 = 이, 가, 이
-    [0xC740] = {0xC740, 0xB294, 0xC740}, % 은 = 은, 는, 은
-    [0xC744] = {0xC744, 0xB97C, 0xC744}, % 을 = 을, 를, 을
-    [0xC640] = {0xACFC, 0xC640, 0xACFC}, % 와 = 과, 와, 과
-    [0xC73C] = {nil,    nil,    0xC73C}, % 으(로) =   ,  , 으
-    [0xC774] = {0xC774, nil,    0xC774}, % 이(라) = 이,  , 이
-}
-local function josa_char_num (t, c)
-    c = c - math.floor(c/10)*10 + 0x30
-    return t[c] or 2
-end
-local josa_code = setmetatable({
-    [0x30] = 3, [0x31] = 1, [0x33] = 3, [0x36] = 3, [0x37] = 1,
-    [0x38] = 1, [0x4C] = 1, [0x4D] = 3, [0x4E] = 3, [0x6C] = 1,
-    [0x6D] = 3, [0x6E] = 3, [0xFB02] = 1, [0xFB04] = 1,
-},{ __index = function(t,c)
-        if c >= 0xAC00 and c <= 0xD7A3 then
-            c = c - 0xAC00
-            c = c - math.floor(c/28)*28 + 0x11A7
-        end
-        if c >= 0x11A8 and c <= 0x11FF then
-            if c == 0x11AF then return 1 end
-            return 3
-        end
-        if c >= 0xD7CB and c <= 0xD7FB then return 3 end
-        if c >= 0x2170 and c <= 0x217F then c = c - 0x10 end
-        if c >= 0x2160 and c <= 0x216F then
-            if c >= 0x216C then return 3 end
-            return josa_char_num(t, c - 0x215F)
-        end
-        if c >= 0x2460 and c <= 0x2473 then return josa_char_num(t, c - 0x245F) end
-        if c >= 0x2474 and c <= 0x2487 then return josa_char_num(t, c - 0x2473) end
-        if c >= 0x2488 and c <= 0x249B then return josa_char_num(t, c - 0x2487) end
-        if c >= 0x249C and c <= 0x24B5 then return t[c - 0x249C + 0x61] or 2 end
-        if c >= 0x24B6 and c <= 0x24CF then return t[c - 0x24B6 + 0x61] or 2 end
-        if c >= 0x24D0 and c <= 0x24E9 then return t[c - 0x24D0 + 0x61] or 2 end
-        if c >= 0x3131 and c <= 0x318E then
-            if c == 0x3139 then return 1 end
-            if c >= 0x314F and c <= 0x3163 or c >= 0x3187 then return 2 end
-            return 3
-        end
-        if c >= 0x3260 and c <= 0x327E then c = c - 0x60 end
-        if c >= 0x3200 and c <= 0x321E then
-            if c == 0x3203 then return 1 end
-            if c >= 0x320E then return 2 end
-            return 3
-        end
-        if c >= 0xFF10 and c <= 0xFF19 then return josa_char_num(t, c - 0xFF10) end
-        if c >= 0xFF21 and c <= 0xFF3A then return t[c - 0xFF21 + 0x61] or 2 end
-        if c >= 0xFF41 and c <= 0xFF5A then return t[c - 0xFF41 + 0x61] or 2 end
-        return 2
-    end })
-local function get_prev_char (p)
-    while p do
-        if p.id == glyph_id then
-            local pc = p.char or 0
-            if not nobr_after[pc] then
-                if not nobr_before[pc] or nobr_before[pc] >= 2 then
-                    return pc
-                end
-            end
-        elseif p.id == hbox_id or p.id == vbox_id then
-            local pc = get_prev_char(node.tail(p.head))
-            if pc then return pc end
-        end
-        p = p.prev
-    end
-end
-local function auto_josa (head)
-    local curr, tofree = head, {}
-    while curr do
-        if curr.id == glyph_id then
-            local josa = node.has_attribute(curr, attr_josa)
-            if josa then
-                local cc = curr.char or 0
-                if josa == 0 then
-                    josa = josa_code[get_prev_char(curr.prev) or 0x30]
-                end
-                if cc == 0xC774 then
-                    local n = curr.next
-                    if n and n.char and n.char >= 0xAC00 and n.char <= 0xD7A3 then
-                    else
-                        cc = 0xAC00
-                    end
-                end
-                local new = josa_table[cc]
-                if new then
-                    cc = new[josa]
-                    if cc then
-                        curr.char = cc
-                    else
-                        head = node.remove(head, curr)
-                        table.insert(tofree, curr)
-                    end
-                end
-                node.unset_attribute(curr, attr_josa)
-            end
-        end
-        curr = curr.next
-    end
-    for _,v in ipairs(tofree) do node.free(v) end
-    return head
-end
-local function reorder_tm (head)
-    local curr, tone = node.tail(head)
-    while curr do
-        if curr.id == glyph_id and node.has_attribute(curr, attr_korean) then
-            local c, wd = curr.char or 0, curr.width or 0
-            if (c == 0x302E or c == 0x302F) and wd > 0 then
-                tone = curr
-            elseif tone and not nobr_before[c] then
-                head = node.remove(head, tone)
-                tone.next, tone.prev = nil, nil
-                head, curr = node.insert_before(head, curr, tone)
-                tone = nil
-            end
-        end
-        curr = curr.prev
-    end
-    return head
-end
-local prepend_to_callback
-if luatexbase.callbacktypes then
-    prepend_to_callback = function(name, func, desc)
-        local t = { {func, desc} }
-        for _,v in ipairs(luatexbase.callback_descriptions(name)) do
-            table.insert(t, {luatexbase.remove_from_callback(name, v)})
-        end
-        for _,v in ipairs(t) do
-            luatexbase.add_to_callback(name, v[1], v[2])
-        end
-    end
-else
-    prepend_to_callback = function(name, func, desc)
-        luatexbase.add_to_callback(name, func, desc, 1)
-    end
-end
-prepend_to_callback ("hyphenate",
-    function(head)
-        local in_callback = luatexbase.in_callback or luatexbase.priority_in_callback
-        if in_callback("hyphenate", "polyglossia.disable_hyphenation") then
-            return false
-        end
-        local curr = head
-        while curr do
-            if curr.id == glyph_id and node.has_attribute(curr, attr_korean) and is_cjk(curr.char or 0) then
-                if curr.subtype == 1 then
-                    curr.subtype = 0
-                end
-            end
-            curr = curr.next
-        end
-        lang.hyphenate(head)
-    end,
-    "polyglossia.lang_korean")
-prepend_to_callback ("pre_linebreak_filter",
-    function(head)
-        head = auto_josa(head)
-        head = korean_break(head, true)
-        head = reorder_tm(head)
-        return head
-    end,
-    "polyglossia.lang_korean")
-prepend_to_callback ("hpack_filter",
-    function(head)
-        head = auto_josa(head)
-        head = korean_break(head)
-        head = reorder_tm(head)
-        return head
-    end,
-    "polyglossia.lang_korean")
-}
-
 % vim:ft=tex:tw=0:sw=4:ts=4:expandtab

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurdish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurdish.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurdish.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,384 @@
+% Created on September 1, 2019
+% Sina Ahmadi (https://sinaahmadi.github.io/)
+\ProvidesFile{gloss-kurdish.ldf}[polyglossia: module for Kurdish]
+
+\RequireBidi
+\RequirePackage{arabicnumbers}
+\RequirePackage{farsical}
+\RequirePackage{hijrical}
+
+\PolyglossiaSetup{kurdish}{
+  script=Arabic,
+  direction=RL,
+  scripttag=arab,
+  langtag=KUR,
+  hyphennames={nohyphenation},
+  fontsetup=true,
+  localnumeral=kurdishnumerals
+}
+
+\newif\if at kurdish@kurmanji
+\def\kurdish at variant{sorani}
+\define at choicekey*+{kurdish}{variant}[\val\nr]{sorani,kurmanji}[sorani]{%
+   \ifcase\nr\relax
+      % sorani:
+      \def\kurdish at variant{sorani}%
+      \@kurdish at kurmanjifalse%
+   \or
+      % kurmanji:
+      \def\kurdish at variant{kurmanji}%
+      \@kurdish at kurmanjitrue%
+   \fi
+   \kurdish at set@variety%
+   \xpg at info{Option: kurdish, variant=\val}%
+}{\xpg at warning{Unknown Kurdish variant `#1'}}
+
+\newif\if at kurdish@latin
+\newif\if at kurdish@arabic
+\define at choicekey*+{kurdish}{script}[\val\nr]{Arabic,Latin}{%
+   \ifcase\nr\relax
+      % Arabic:
+      \@kurdish at latinfalse%
+      \@kurdish at arabictrue%
+   \or
+      % Latin:
+      \@kurdish at latintrue%
+      \@kurdish at arabicfalse%
+   \fi
+   \kurdish at set@variety%
+   \xpg at info{Option: kurdish, script=\val}%
+}{\xpg at warning{Unknown Kurdish script `#1'}}
+
+
+\newif\if at western@numerals
+\newif\if at force@western at numerals
+\def\kurdish at script{arabic}
+\def\kurdish at pattern{nohyphenation}
+
+\def\kurdish at set@variety{%
+  \if at kurdish@latin% Latin explicitly set
+     \@western at numeralstrue%
+     \if at kurdish@kurmanji
+         \def\kurdish at pattern{kurmanji}%
+         \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurmanji}%
+     \else
+         \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurdish}%
+     \fi
+     \def\kurdish at script{latin}
+     \xpg at fontsetup@latin{kurdish}%
+  \else
+     \if at kurdish@arabic% Arabic explicitly set
+        \if at kurdish@kurmanji
+            \if at force@western at numerals\else\@western at numeralsfalse\fi%
+            \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurmanji}%
+            \def\kurdish at script{arabic}%
+        \else
+            \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurdish}%
+        \fi
+        \xpg at fontsetup@nonlatin{kurdish}%
+     \else% sorani=Arabic, kurmanji=Latin
+        \if at kurdish@kurmanji
+            \@western at numeralstrue%
+            \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurmanji}%
+            \xpg at fontsetup@latin{kurdish}%
+            \def\kurdish at script{latin}
+        \else
+            \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurdish}%
+            \xpg at fontsetup@nonlatin{kurdish}%
+        \fi
+     \fi
+  \fi
+}
+
+\def\tmp at western{western}
+\define at key{kurdish}{numerals}[eastern]{%
+  \def\@tmpa{#1}%
+  \ifx\@tmpa\tmp at western\@western at numeralstrue\@force at western@numeralstrue\else%
+    \@western at numeralsfalse%
+  \fi%
+}
+
+%this is needed for \abjad in arabicnumbers.sty
+\def\tmp at true{true}
+\define at key{kurdish}{abjadjimnotail}[true]{%
+  \def\@tmpa{#1}%
+  \ifx\@tmpa\tmp at true\abjad at jim@notailtrue%
+  \else
+    \abjad at jim@notailfalse
+  \fi%
+}
+
+% NOT YET USED
+\define at key{kurdish}{locale}[default]{%
+  \def\@kurdish at locale{#1}}
+
+
+%TODO add option for CALENDAR
+
+\setkeys{kurdish}{variant,locale}
+
+\def\kurdish at language{%
+   \polyglossia at setup@language at patterns{\kurdish at pattern}%
+}%
+
+\def\kurdishNativemonth#1{\ifcase#1%
+  \or رێبه‌ندان\or ره‌شه‌مێ\or خاكه‌لێوه‌\or گوڵان\or جۆزه‌ردان\or پووشپه‌ڕ\or خه‌رمانان\or گه‌لاوێژ\or ره‌زبه‌ر\or گه‌ڵارێزان\or سه‌رماوه‌ز\or به‌فرانبار\fi}
+\def\kurdishmonth#1{\ifcase#1%
+  \or کانونی دووەم\or شوبات\or ئازار\or نیسان\or ئایار\or حوزه‌یران\or ته‌ممووز\or ئاب\or ئه‌یلوول\or تشرینی یه‌كه‌م\or تشرینی دووهه‌م\or كانوونی یه‌كه‌م\fi}
+
+%\Hijritoday is now locale-aware and will format the date with this macro:
+\DefineFormatHijriDate{kurdish}{%
+  \@ensure at RTL{%
+    \kurdishnumber{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\kurdishnumber{\value{Hijriyear}}%
+  }%
+}
+
+\def\captionskurdish at sorani@arabic{%
+  \def\prefacename{\@ensure at RTL{پێشه‌كی}}%
+  \def\refname{\@ensure at RTL{سه‌رچاوه‌کان}}%
+  \def\abstractname{\@ensure at RTL{پوخته‌}}%
+  \def\bibname{\@ensure at RTL{کتێبنامه‌}}%
+  \def\chaptername{\@ensure at RTL{به‌ندی}}%
+  \def\appendixname{\@ensure at RTL{پاشکۆ}}%
+  \def\contentsname{\@ensure at RTL{نێوه‌ڕۆک}}%
+  \def\listfigurename{\@ensure at RTL{لیستی وێنه‌کان}}%
+  \def\listtablename{\@ensure at RTL{لیستی خشته‌کان}}%
+  \def\indexname{\@ensure at RTL{پێنوێن}}%
+  \def\figurename{\@ensure at RTL{وێنه‌}}%
+  \def\tablename{\@ensure at RTL{خشتە}}%
+  \def\partname{\@ensure at RTL{به‌شی}}%
+  \def\enclname{\@ensure at RTL{هاوپێچ}}%
+  \def\ccname{\@ensure at RTL{روونووس}}%
+  \def\headtoname{\@ensure at RTL{بۆ}}%
+  \def\pagename{\@ensure at RTL{لاپه‌ڕه‌}}%
+  \def\seename{\@ensure at RTL{چاو لێکه‌ن}}%
+  \def\alsoname{\@ensure at RTL{هه‌روه‌ها چاو لێکه‌ن}}%
+  \def\proofname{\@ensure at RTL{سەلماندن}}%
+  \def\glossaryname{\@ensure at RTL{فه‌رهه‌نگۆک}}%
+}
+
+\def\captionskurdish at sorani@latin{%
+  \def\prefacename{Pêşekî}%
+  \def\refname{Serçawekan}%
+  \def\abstractname{Puxte}%
+  \def\bibname{Kitêbname}%
+  \def\chaptername{Bendî}%
+  \def\appendixname{Paşko}%
+  \def\contentsname{Nêwerrok}%
+  \def\listfigurename{Lîstî Wênekan}%
+  \def\listtablename{Lîstî Xiştekan}%
+  \def\indexname{Pêrrist}%
+  \def\figurename{Wêney}%
+  \def\tablename{Xiştey}%
+  \def\partname{Beşî}%
+  \def\enclname{Hawpêç}%
+  \def\ccname{Rûnûs}%
+  \def\headtoname{Bo}%
+  \def\pagename{Laperre}%
+  \def\seename{Çaw lêken}%
+  \def\alsoname{Herweha çaw lêken}%
+  \def\proofname{Selmandin}%
+  \def\glossaryname{Ferhengok}%
+}
+
+\def\captionskurdish at kurmanji@latin{%
+  \def\prefacename{Peşgotin}%
+  \def\refname{Pirtuken bijartî}%
+  \def\abstractname{Kurtebîr}%
+  \def\bibname{Çavkanîya Pirtukan}%
+  \def\chaptername{Serê}%
+  \def\appendixname{Tebînîya}%
+  \def\contentsname{Navêrok}%
+  \def\listfigurename{Hejmara Dimena}%
+  \def\listtablename{Hejmara Kevalen}%
+  \def\indexname{Endeks}%
+  \def\figurename{Dimenê}%
+  \def\tablename{Kevala}%
+  \def\partname{Bêşa}%
+  \def\enclname{Dumahik}%
+  \def\ccname{Belavker}%
+  \def\headtoname{Ji bo}%
+  \def\pagename{Rûpelê}%
+  \def\seename{binêra}%
+  \def\alsoname{le vêya ji binêra}%
+  \def\proofname{Delîl}%
+  \def\glossaryname{Çavkanîya lêkolînê}%
+}
+
+\def\captionskurdish at kurmanji@arabic{%
+  \def\prefacename{\@ensure at RTL{پێشگۆتن}}%
+  \def\refname{\@ensure at RTL{پرتووکێن بژارتی}}%
+  \def\abstractname{\@ensure at RTL{کورتەبیر}}%
+  \def\bibname{\@ensure at RTL{چاڤکانییا پرتووکان}}%
+  \def\chaptername{\@ensure at RTL{سەرێ}}%
+  \def\appendixname{\@ensure at RTL{پاشکۆ}}%
+  \def\contentsname{\@ensure at RTL{ناڤێرۆک}}%
+  \def\listfigurename{\@ensure at RTL{هەژمارا دیمەنا}}%
+  \def\listtablename{\@ensure at RTL{هەژمارا کەڤالێن}}%
+  \def\indexname{\@ensure at RTL{پێرست}}%
+  \def\figurename{\@ensure at RTL{دیمەنێ}}%
+  \def\tablename{\@ensure at RTL{کەڤالا}}%
+  \def\partname{\@ensure at RTL{بەشا}}%
+  \def\enclname{\@ensure at RTL{دوماهک}}%
+  \def\ccname{\@ensure at RTL{بەلاڤکەر}}%
+  \def\headtoname{\@ensure at RTL{ژ بۆ}}%
+  \def\pagename{\@ensure at RTL{رووپەلێ}}%
+  \def\seename{\@ensure at RTL{بنێرا}}%
+  \def\alsoname{\@ensure at RTL{لە ڤێیا ژ بنێرا}}%
+  \def\proofname{\@ensure at RTL{دەلیل}}%
+  \def\glossaryname{\@ensure at RTL{چاڤکانییا لێکۆلینێ}}%
+}
+
+\def\captionskurdish{%
+  \csname captionskurdish@\kurdish at variant @\kurdish at script\endcsname%
+}
+
+\def\datekurdish at sorani@arabic{%
+   \def\today{\@ensure at RTL{\kurdishnumber\day{ی}\space\kurdishmonth{\month}{ی}\space\kurdishnumber\year}}%
+}
+
+\def\datekurdish at sorani@latin{%
+  \def\today{%
+     \number\day.~\ifcase\month\or
+      \januaryname\or \februaryname\or \marchname\or \aprilname\or
+      \mayname\or \junename\or \julyname\or \augustname\or
+      \septembername\or \octobername\or \novembername\or
+      \decembername\or \@ctrerr\fi~\number\year}%
+  \def\ontoday{%
+      \number\day’ê~\ifcase\month\or
+      \januaryname\or \februaryname\or \marchname\or \aprilname\or
+      \mayname\or \junename\or \julyname\or \augustname\or
+      \septembername\or \octobername\or \novembername\or
+      \decembername\or \@ctrerr\fi ê~\number\year}%
+  \def\januaryname{Kanûnî Yekem}%
+  \def\februaryname{Şubat}%
+  \def\marchname{Azar}%
+  \def\aprilname{Nîsan}%
+  \def\mayname{Ayar}%
+  \def\junename{Huzeyran}%
+  \def\julyname{Temmûz}%
+  \def\augustname{Ab}%
+  \def\septembername{Eylûl}%
+  \def\octobername{Tişrînî Yekem}%
+  \def\novembername{Tişrînî Dûhem}%
+  \def\decembername{Kanûnî Dûhem}%
+}
+
+\def\datekurdish at kurmanji@latin{%
+  \def\today{%
+     \number\day.~\ifcase\month\or
+      \januaryname\or \februaryname\or \marchname\or \aprilname\or
+      \mayname\or \junename\or \julyname\or \augustname\or
+      \septembername\or \octobername\or \novembername\or
+      \decembername\or \@ctrerr\fi~\number\year}%
+  \def\ontoday{%
+      \number\day’ê~\ifcase\month\or
+      \januaryname\or \februaryname\or \marchname\or \aprilname\or
+      \mayname\or \junename\or \julyname\or \augustname\or
+      \septembername\or \octobername\or \novembername\or
+      \decembername\or \@ctrerr\fi ê~\number\year}%
+  \def\januaryname{Çileya Paşîn}%
+  \def\februaryname{Sibat}%
+  \def\marchname{Adar}%
+  \def\aprilname{Nîsan}%
+  \def\mayname{Gulan}%
+  \def\junename{Hezîran}%
+  \def\julyname{Tîrmeh}%
+  \def\augustname{Tebax}%
+  \def\septembername{Îlon}%
+  \def\octobername{Çiriya Pêşîn}%
+  \def\novembername{Çiriya Paşîn}%
+  \def\decembername{Çileya Pêşîn}%
+}
+
+\def\datekurdish at kurmanji@arabic{%
+   \datekurdish at sorani@arabic% FIXME: correct?
+}
+
+% TODO: babel-kurmanji has these "alternative" month names
+% How to integrate them ("montnames=alternative" is not really good)?
+% It seems the month name question is all but straightforward:
+% https://en.wikipedia.org/wiki/Kurdish_calendar#Names
+%\def\datekurdish at kurmanji@alternate{%
+%  \datekurdish at kurmanji
+%  \def\januaryname{Rêbendan}%
+%  \def\februaryname{Reşemih}%
+%  \def\aprilname{Cotan}%           % Avrêl
+%  \def\junename{Pûşper}%
+%  \def\augustname{Gelavêj}%
+%  \def\septembername{Gelarezan}%   % Rezber
+%  \def\octobername{Kewçêr}%
+%  \def\novembername{Sermawez}%
+%  \def\decembername{Berfandar}%
+%}
+
+\def\datekurdish{%
+  \csname datekurdish@\kurdish at variant @\kurdish at script\endcsname%
+}
+
+\newcommand{\kurdishnumerals}[2]{\kurdishnumber{#2}}
+
+\def\kurdishnumber#1{%
+  \if at western@numerals
+    \number#1%
+  \else
+    \ifxetex
+      \ifnum\XeTeXcharglyph"06F0 > 0\relax
+        \farsidigits{\number#1}%
+      \else%
+         \arabicdigits{\number#1}%
+      \fi
+    \else\ifluatex
+      \expandafter\ifnum\directlua{polyglossia.check_char(0x6F0)} > 0\relax
+        \farsidigits{\number#1}%
+      \else%
+         \arabicdigits{\number#1}%
+      \fi
+    \fi\fi
+  \fi
+}
+
+%\def\kurdishnum#1{\expandafter\kurdishnumber\csname c@#1\endcsname}
+%\def\kurdishbracenum#1{(\expandafter\kurdishnumber\csname c@#1\endcsname)}
+%\def\kurdishornatebracenum#1{\char"FD3E\expandafter\kurdishnumber\csname c@#1\endcsname\char"FD3F}
+%\def\kurdishalph#1{\expandafter\@farsialph\csname c@#1\endcsname}
+
+\def\kurdish at numbers{%
+  \if at western@numerals%
+  \else%
+     \let\@alph\abjad%
+     \let\@Alph\abjad%
+  \fi%
+}
+
+\def\nokurdish at numbers{%
+  \let\@alph\@latinalph%
+  \let\@Alph\@latinAlph%
+}
+
+\def\kurdish at globalnumbers{%
+   \let\@arabic\kurdishnumber%
+   \renewcommand\thefootnote{\localnumeral*{footnote}}%
+   \renewcommand\theequation{\localnumeral*{equation}}%
+}
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
+\def\nokurdish at globalnumbers{
+   \let\@arabic\xpg at save@arabic%
+   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
+}
+
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
+\def\blockextras at kurdish{%
+   \def\MakeUppercase##1{##1}%
+}
+
+\def\noextras at kurdish{%
+   \let\MakeUppercase\xpg at save@MakeUppercase%
+}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurdish.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lao.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lao.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lao.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -8,9 +8,11 @@
 \PolyglossiaSetup{lao}{
   script=Lao,
   scripttag=lao,
+  langtag=LAO,
   hyphennames={lao},
   hyphenmins={1,1},
   fontsetup=true,
+  localnumeral=laonumerals
   %TODO localalph={xxx at alph,xxx at Alph}
   %TODO localdigits=laonumber
 }
@@ -76,6 +78,8 @@
   \fi
 }
 
+\newcommand{\laonumerals}[2]{\laonumber{#2}}
+
 \def\laonumber#1{%
   \if at lao@numerals
     \laodigits{\number#1}%
@@ -86,11 +90,10 @@
 \def\lao at globalnumbers{%
    \let\orig at arabic\@arabic%
    \let\@arabic\laonumber%
-   \renewcommand{\thefootnote}{\protect\laonumber{\c at footnote}}%
+   \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
 }
 \def\nolao at globalnumbers{%
    \let\@arabic\orig at arabic%
-   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
 }
 
 \endinput

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latex.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latex.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latex.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,33 @@
+\ProvidesFile{gloss-latex.ldf}[polyglossia: module for default language]
+
+\PolyglossiaSetup{latex}{
+  hyphennames={english},
+  hyphenmins={2,3},
+  langtag=ENG,
+  fontsetup=true,
+}
+
+\def\captionslatex{%
+   \def\prefacename{Preface}%
+   \def\refname{References}%
+   \def\abstractname{Abstract}%
+   \def\bibname{Bibliography}%
+   \def\chaptername{Chapter}%
+   \def\appendixname{Appendix}%
+   \def\contentsname{Contents}%
+   \def\listfigurename{List of Figures}%
+   \def\listtablename{List of Tables}%
+   \def\indexname{Index}%
+   \def\figurename{Figure}%
+   \def\tablename{Table}%
+   \def\partname{Part}%
+   \def\enclname{encl}%
+   \def\ccname{cc}%
+   \def\headtoname{To}%
+   \def\pagename{Page}%
+   \def\seename{see}%
+   \def\alsoname{see also}%
+   \def\proofname{Proof}%
+}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latex.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latin.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latin.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latin.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -21,6 +21,7 @@
 \PolyglossiaSetup{latin}{%
       hyphennames={latin},
       hyphenmins={2,2},
+      langtag=LAT,
       frenchspacing=true,
       fontsetup=true,
 }
@@ -51,7 +52,6 @@
   \let\latin at variant\l at latin
   \xpg at set@language at luatex@ii{latin}
   \medievaltrue \classictrue
-  \classicuclccodes
   \xpg at info{Option: Medieval Latin}%
 \else
   \ifx\@tempa\tmp at classic
@@ -64,7 +64,7 @@
          \let\latin at variant\l at classiclatin
       \fi
     \fi
-    \medievalfalse\classictrue\classicuclccodes
+    \medievalfalse\classictrue
     \xpg at info{Option: Classic Latin}%
   \else
    \ifx\@tempa\tmp at liturgical\unless\ifluatex
@@ -274,6 +274,7 @@
    \lccode\string"2019=\string"2019
    \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000
    \finalhyphendemerits=50000000
+   \ifclassic\classicuclccodes\fi
    \iflatin at babelshorthands\latin at shorthands\fi
    \iflatin at ecclesiastic\unless\ifluatex\ecclesiasticlatin at punctuation
    \let\@makefntext\latin at ecclesiastic@makefntext\fi
@@ -282,6 +283,7 @@
 
 \def\inlineextras at latin{%
    \lccode\string"2019=\string"2019
+   \ifclassic\classicuclccodes\fi
    \iflatin at babelshorthands\latin at shorthands\fi
    \iflatin at ecclesiastic
       \unless\ifluatex\ecclesiasticlatin at punctuation

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latvian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latvian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latvian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{latvian}{
   hyphennames={latvian},
   hyphenmins={2,2},
+  langtag=LVI,
   fontsetup=true,
 }
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lithuanian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lithuanian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lithuanian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -4,15 +4,17 @@
 \PolyglossiaSetup{lithuanian}{
   hyphennames={lithuanian},
   hyphenmins={2,2},
+  langtag=LTH,
+  indentfirst=true, % TODO Dokumentų rengimo taisyklių, patvirtintų Lietuvos vyriausiojo archyvaro 2011 m. liepos 4 d. įsakymu Nr. V-117, 29.1 punktą
   fontsetup=true
 }
 
 \def\captionslithuanian{%
+   \def\prefacename{Pratarmė}%
    \def\refname{Literatūra}%
    \def\abstractname{Santrauka}%
    \def\bibname{Literatūra}%
-   \def\prefacename{Pratarmė}%
-   \def\chaptername{Skyrius}%
+   \def\chaptername{Skyrius}% TODO letter case
    \def\appendixname{Priedas}%
    \def\contentsname{Turinys}%
    \def\listfigurename{Iliustracijų sąrašas}%
@@ -19,16 +21,16 @@
    \def\listtablename{Lentelių sąrašas}%
    \def\indexname{Rodyklė}%
    \def\figurename{pav.}%
-   \def\tablename{lentelė}%
+   \def\tablename{lentelė}% TODO any special reason for \protect in babel?
    \def\partname{Dalis}%
+   \def\enclname{Įdėta}%
+   \def\ccname{Kopijos}%
+   \def\headtoname{Kam}% TODO empty in babel?
    \def\pagename{puslapis}%
    \def\seename{žiūrėk}%
-   \def\alsoname{taip pat}%
-   \def\enclname{Įdėta}%
-   \def\ccname{Kopijos}%
-   \def\headtoname{Kam}%
+   \def\alsoname{taip pat}% TODO some other variants are considered in babel?
    \def\proofname{Įrodymas}%
-   \def\glossaryname{Terminų žodynas}%
+   \def\glossaryname{Terminų žodynas}% TODO some other variants are considered in babel?
 }
 
 \def\datelithuanian{%

Deleted: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-liturgicallatin.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-liturgicallatin.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-liturgicallatin.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,185 +0,0 @@
-%%
-%% This is file `gloss-liturgicallatin.ldf',
-%% generated with the docstrip utility.
-%%
-%% The original source files were:
-%%
-%% gloss-latin.dtx  (with options: `laliturgic')
-%%   ------------------------------------------------------------------
-%%   Latin module for polyglossia
-%%   Copyright (C) Claudio Beccari 2013-2016
-%%   Copyright (C) Élie Roux 2016
-%%   This work is distributed under the MIT License.
-%% 
-%%   See the postamble.
-%%   ------------------------------------------------------------------
-\ProvidesFile{gloss-liturgiclatin.ldf}
-        [2016/09/10 v.1.03 Latin support from polyglossia]
-%%
-
-
-\PolyglossiaSetup{liturgicallatin}{%
-      hyphennames={liturgicallatin},
-      hyphenmins={2,2},
-      frenchspacing=true,
-      fontsetup=true,
-}
-\def\liturgicallatincaptions{%
-   \def\prefacename{Præfatio}%
-   \def\refname{Conspectus librorum}%
-   \def\abstractname{Summarium}%
-   \def\bibname{Conspectus librorum}%
-   \def\chaptername{Caput}%
-   \def\appendixname{Additamentum}%
-   \def\contentsname{Index}%
-   \def\listfigurename{Conspectus descriptionum}%
-   \def\listtablename{Conspectus tabularum}%
-   \def\indexname{Index rerum notabilium}%
-   \def\figurename{Descriptio}%
-   \def\tablename{Tabula}%
-   \def\partname{Pars}%
-   \def\enclname{Additur}%
-   \def\ccname{Exemplar}%
-   \def\headtoname{\ignorespaces}%
-   \def\pagename{charta}%
-   \def\seename{cfr.}%
-   \def\alsoname{cfr.}%
-   \def\proofname{Demonstratio}%
-   \def\glossaryname{Glossarium}%
-   }
-
-\def\liturgicallatindate{%
-   \def\today{\uppercase\expandafter{\romannumeral\day}%
-      \space \ifcase\month%
-      \or Januarii\or Februarii\or Martii\or Aprilis\or Maji\or Junii\or%
-      Julii\or Augusti\or Septembris\or Octobris\or Novembris\or%
-      Decembris\fi%
-      \space \uppercase\expandafter{\romannumeral\year}}}
-
-\define at boolkey{liturgicallatin}[liturgicallatin@]{babelshorthands}[true]{}
-
-\ifsystem at babelshorthands
-  \setkeys{liturgicallatin}{babelshorthands=true}
-\else
-  \setkeys{liturgicallatin}{babelshorthands=false}
-\fi
-
-\ifcsundef{initiate at active@char}{%
-    \input{babelsh.def}%
-    \initiate at active@char{"}%
-    \initiate at active@char{'}%
-}{}
-
-\def\liturgicallatin at shorthands{%
-  \def\language at group{liturgicallatin}%
-  \bbl at activate{"}%
-  \declare at shorthand{liturgicallatin}{"}{\relax
-    \ifmmode
-      \def\xpglla at next{''}%
-    \else
-      \def\xpglla at nextdq{\futurelet\xpglla at temp\xpglla at cwm}%
-    \fi
-  \xpglla at nextdq}%
-  \bbl at activate{'}%
-  \declare at shorthand{liturgicallatin}{'}{\relax
-    \ifmmode
-      \def\xpglla at nextsq{'}%
-    \else
-      \def\xpglla at nextsq{\futurelet\temp at A\xpglla at putacute}%
-    \fi
-  \xpgla at nextsq}%
-}
-
-\def\xpglla at allowhyphens{\bbl at allowhyphens
-     \discretionary{-}{}{}\bbl at allowhyphens}
-
-\newcommand*{\xpglla at cwm}{\let\xpglla@@nextdq\relax
-  \ifcat\noexpand\xpglla at temp a%
-    \let\xpglla@@nextdq\xpglla at allowhyphens
-  \else
-    \ifx\xpglla at temp\ae
-        \let\xpglla@@nextdq\xpglla at allowhyphens
-    \else
-        \ifx\xpglla at temp\oe
-           \let\xpglla@@nextdq\xpglla at allowhyphens
-        \else
-           \if\noexpand\xpglla at temp\string|%
-              \def\xpglla@@nextdq{\xpglla at allowhyphens\@gobble}%
-           \fi
-        \fi
-    \fi
-  \fi
-  \xpglla@@nextdq}%
-
-\def\xpglla at putacute#1{\let\xpglla at nextsq\relax%
-\if a\xpglla at temp@A
-  æ\kern-0.175em^^^^0301\kern0.175em\xpglla at allowhyphens
-\else
-\if o\xpglla at temp@A
-  œ\kern-0.175em^^^^0301\kern0.175em\xpglla at allowhyphens
-\else
-  \if æ\xpglla at temp@A
-    æ^^^^0301%
-  \else
-    \if œ\xpglla at temp@A
-      œ^^^^0301%
-    \else
-      \string'%
-    \fi
-  \fi
-\fi
-\fi}%
-\def\noliturgicallatin at shorthands{%
-  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{"}}%
-  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{'}}%
-}
-
-\let\xpglla at savedvalues\empty
-\AtEndPreamble{%
-  \edef\xpglla at savedvalues{%
-    \clubpenalty=\the\clubpenalty\space
-    \@clubpenalty=\the\@clubpenalty\space
-    \widowpenalty=\the\widowpenalty\space
-    \finalhyphendemerits=\the\finalhyphendemerits}%
-}
-
-\def\noextras at liturgicallatin{%
-   \lccode\string"2019=\z@
-   \noliturgicallatin at shorthands
-   \xpglla at savedvalues
-}
-
-\def\blockextras at liturgicallatin{%
-   \lccode\string"2019=\string"2019
-   \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000
-   \finalhyphendemerits=50000000
-   \ifliturgicallatin at babelshorthands\liturgicallatin at shorthands\fi
-}
-
-\def\inlineextras at liturgicallatin{%
-   \lccode\string"2019=\string"2019
-   \ifliturgicallatin at babelshorthands\liturgicallatin at shorthands\fi
-}
-%%   Copyright (C) Claudio Beccari 2013-2016
-%%   Copyright (C) Élie Roux 2016
-%% 
-%%   Permission is hereby granted, free of charge, to any person obtaining
-%%   a copy of this software and associated documentation files
-%%   (the "Software"), to deal in the Software without restriction, including
-%%   without limitation the rights to use, copy, modify, merge, publish,
-%%   distribute, sublicense, and/or sell copies of the Software, and to permit
-%%   persons to whom the Software is furnished to do so, subject to the following
-%%   conditions:
-%% 
-%%   The above copyright notice and this permission notice shall be included in
-%%   all copies or substantial portions of the Software.
-%% 
-%%   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-%%   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-%%   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-%%   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-%%   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-%%   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-%%   IN THE SOFTWARE.
-%%
-%% End of file `gloss-liturgicallatin.ldf'.

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lsorbian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lsorbian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lsorbian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,45 +1,20 @@
 \ProvidesFile{gloss-lsorbian.ldf}[polyglossia: module for lower sorbian]
+
+% We only provide this gloss for babel compatibility. Since lsorbian is 
+% a sorbian variety, we use 'sorbian' with variant 'lower' now.
+
+\input{gloss-sorbian.ldf}
+
 \PolyglossiaSetup{lsorbian}{
+  language=Lower Sorbian,
+  babelname=lowersorbian,
   hyphennames={lsorbian,lowersorbian,Lsorbian},
+  langtag=LSB,
   hyphenmins={2,2},
   fontsetup=true,
 }
 
-\def\captionslsorbian{%
-   \def\refname{Referency}%
-   \def\abstractname{Abstrakt}%
-   \def\bibname{Literatura}%
-   \def\prefacename{Zawod}%
-   \def\chaptername{Kapitl}%
-   \def\appendixname{Dodawki}%
-   \def\contentsname{Wopśimjeśe}%
-   \def\listfigurename{Zapis wobrazow}%
-   \def\listtablename{Zapis tabulkow}%
-   \def\indexname{Indeks}%
-   \def\figurename{Wobraz}%
-   \def\tablename{Tabulka}%
-   %\def\thepart{}%
-   \def\partname{Źěl}%
-   \def\pagename{Strona}%
-   \def\seename{gl.}%
-   \def\alsoname{gl.~teke}%
-   \def\enclname{Pśiłoga}%
-   \def\ccname{CC}%
-   \def\headtoname{Komu}%
-   \def\proofname{Proof}%
-   \def\glossaryname{Glossary}%
-   }
-\def\datelsorbian{%
-    \def\today{\number\day.~\ifcase\month\or
-    januara\or februara\or měrca\or apryla\or maja\or
-    junija\or julija\or awgusta\or septembra\or oktobra\or
-    nowembra\or decembra\fi
-    \space \number\year}%
-    \def\oldtoday{\textlsorbian{\number\day.~\ifcase\month\or
-    wjelikego rožka\or małego rožka\or nalětnika\or
-    jatšownika\or rožownika\or smažnika\or pražnika\or
-    žnjeńca\or požnjeńca\or winowca\or nazymnika\or 
-    godownika\fi\space \number\year}}%
-    }
+\let\captionslsorbian\captionssorbian at lsorbian
+\let\datelsorbian\datesorbian at lsorbian
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-macedonian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-macedonian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-macedonian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -28,8 +28,6 @@
    \xpg at ill@value{#1}{macedonian at alph}\fi}%
 
 \def\macedonian at numbers{%
-   \let\latin at Alph\@Alph%
-   \let\latin at alph\@alph%
    \let\@Alph\macedonian at Alph%
    \let\@alph\macedonian at alph%
  }

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-magyar.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-magyar.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-magyar.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,70 +1,20 @@
 \ProvidesFile{gloss-magyar.ldf}[polyglossia: module for magyar]
+
+% We only provide this gloss for babel compatibility.
+
+\input{gloss-hungarian.ldf}
+
 \PolyglossiaSetup{magyar}{
   hyphennames={magyar,hungarian},
+  langtag=HUN,
   hyphenmins={2,2},
   fontsetup=true,
 }
 
-\frenchspacing
+\let\captionsmagyar\captionshungarian
+\let\datemagyar\datehungarian
+\let\ondatemagyar\ondatehungarian
+\let\blockextras at magyar\blockextras at hungarian
+\let\noextras at magyar\noextras at hungarian
 
-% change 'táblázat x.x' to 'x.x. táblázat'
-\newcommand{\@magyar at fnum@table}{\thetable.~\tablename}
-\let\fnum at table\@magyar at fnum@table
-
-% change 'ábra x.x' to 'x.x. ábra'
-\newcommand{\@magyar at fnum@figure}{\thefigure.~\figurename}
-\let\fnum at figure\@magyar at fnum@figure
-
-\def\captionsmagyar{%
-   \def\refname{Hivatkozások}%
-   \def\abstractname{Kivonat}%
-   \def\bibname{Irodalomjegyzék}%
-   \def\prefacename{Előszó}%
-   \def\chaptername{fejezet}%
-   \def\appendixname{Függelék}%
-   \def\contentsname{Tartalomjegyzék}%
-   \def\listfigurename{Ábrák jegyzéke}%
-   \def\listtablename{Táblázatok jegyzéke}%
-   \def\indexname{Tárgymutató}%
-   \def\figurename{ábra}%
-   \def\tablename{táblázat}%
-   %\def\thepart{}%
-   \def\partname{rész}%
-   \def\pagename{oldal}%
-   \def\seename{lásd}%
-   \def\alsoname{lásd még}%
-   \def\enclname{Melléklet}%
-   \def\ccname{Körlevél–címzettek}%
-   \def\headtoname{Címzett}%
-   \def\proofname{Bizonyítás}%
-   \def\glossaryname{Szójegyzék}%
-   }
-\def\datemagyar{%   
-   \def\today{%
-    \number\year.\nobreakspace\ifcase\month\or
-    január\or február\or március\or
-    április\or május\or június\or
-    július\or augusztus\or szeptember\or
-    október\or november\or december\fi
-    \space\number\day.}%
-   \def\ondatemagyar{%
-    \number\year.\nobreakspace\ifcase\month\or
-    január\or február\or március\or
-    április\or május\or június\or
-    július\or augusztus\or szeptember\or
-    október\or november\or december\fi
-      \space\ifcase\day\or
-      1-jén\or  2-án\or  3-án\or  4-én\or  5-én\or
-      6-án\or  7-én\or  8-án\or  9-én\or 10-én\or
-     11-én\or 12-én\or 13-án\or 14-én\or 15-én\or
-     16-án\or 17-én\or 18-án\or 19-én\or 20-án\or
-     21-én\or 22-én\or 23-án\or 24-én\or 25-én\or
-     26-án\or 27-én\or 28-án\or 29-én\or 30-án\or
-     31-én\fi}%
-   \let\ontoday\ondatemagyar}
-
-\def\noextras at magyar{%
-   \let\ontoday\@undefined
-}
-
 \endinput

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malay.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malay.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malay.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,171 @@
+\ProvidesFile{gloss-malay.ldf}[polyglossia: module for malay]
+
+\RequirePackage{hijrical}
+
+\PolyglossiaSetup{malay}{%
+  language=Malay,
+  langtag=MLY,
+  hyphennames={malay,melayu,bahasam,bahasai,indonesian,indon,bahasa},
+  hyphenmins={2,2},
+  fontsetup=true}
+
+\providebool{malay at melayu}
+\malay at melayufalse
+\def\malay at variant{malay}
+\define at choicekey*+{malay}{variant}[\val\nr]{indonesian,malaysian}[malaysian]{%
+   \ifcase\nr\relax
+      % indonesian:
+      \def\malay at variant{indonesian}%
+      \malay at melayufalse
+   \or
+      % malaysian:
+      \def\malay at variant{malay}%
+      \malay at melayutrue
+   \fi
+   \ifmalay at melayu
+      \SetLanguageKeys{malay}{language=Malay,langtag=MLY,babelname=bahasam}%
+      \xpg at fontsetup@latin{malay}%
+      % Check if \l at malay is defined. If not, try to set it to some variety
+      % (specific order as in the csv list below), or null language if everything fails
+      \xpg at ifdefined{malay}{}{%
+        \def\do##1{%
+            \xpg at ifdefined{##1}%
+              {\csletcs{l at malay}{l@##1}\listbreak}%
+              {}%
+        }%
+        \docsvlist{melayu,bahasam,bahasai,indonesian,indon,bahasa}
+        \xpg at ifdefined{malay}{}{%
+                 \xpg at warning{No hyphenation patterns for Malay (Malaysian) found\MessageBreak
+                              I will use the 'null' language instead}%
+                 \adddialect\l at malay0%
+        }%
+      }%
+   \else
+      \SetLanguageKeys{malay}{language=Indonesian,langtag=IND,babelname=bahasa}%
+      \xpg at fontsetup@latin{malay}%
+      % Check if \l at indonesian is defined. If not, try to set it to some variety
+      % (specific order as in the csv list below), or null language if everything fails
+      \xpg at ifdefined{indonesian}{}{%
+        \def\do##1{%
+           \xpg at ifdefined{##1}%
+              {\csletcs{l at indonesian}{l@##1}\listbreak}%
+              {}%
+        }%
+        \docsvlist{indon,bahasai,bahasam,malay,melayu,bahasa}
+        \xpg at ifdefined{indonesian}{}{%
+                 \xpg at warning{No hyphenation patterns for Malay (Indonesian) found\MessageBreak
+                              I will use the 'null' language instead}%
+                 \adddialect\l at indonesian0
+        }%
+      }%
+   \fi
+   \xpg at info{Option: malay, variant=\val}%
+}{\xpg at warning{Unknown malay variant `#1'}}
+
+
+\def\malay at language{%
+   \polyglossia at setup@language at patterns{\malay at variant}%
+}%
+
+
+\def\captionsmalay at indonesian{%
+   \def\refname{Pustaka}%
+   \def\abstractname{Ringkasan}%
+   \def\bibname{Bibliografi}%
+   \def\prefacename{Pendahuluan}%
+   \def\chaptername{Bab}%
+   \def\appendixname{Lampiran}%
+   \def\contentsname{Daftar Isi}%
+   \def\listfigurename{Daftar Gambar}%
+   \def\listtablename{Daftar Tabel}%
+   \def\indexname{Indeks}%
+   \def\figurename{Gambar}%
+   \def\tablename{Tabel}%
+   %\def\thepart{}%
+   \def\partname{Bagian}%
+   \def\pagename{Halaman}%
+   \def\seename{lihat}%
+   \def\alsoname{lihat juga}%
+   \def\enclname{Lampiran}%
+   \def\ccname{cc}%
+   \def\headtoname{Kepada}%
+   \def\proofname{Bukti}%
+   \def\glossaryname{Daftar Istilah}%
+}
+
+\def\captionsmalay at malay{%
+   \def\refname{Rujukan}%
+   \def\abstractname{Abstrak}%
+   \def\bibname{Bibliografi}%
+   \def\prefacename{Pendahuluan}%
+   \def\chaptername{Bab}%
+   \def\appendixname{Lampiran}%
+   \def\contentsname{Kandungan}%
+   \def\listfigurename{Senarai Rajah}%
+   \def\listtablename{Senarai Jadual}%
+   \def\indexname{Indeks}%
+   \def\figurename{Rajah}%
+   \def\tablename{Jadual}%
+   \def\thepart{}%
+   \def\partname{Bahagian}%
+   \def\pagename{Halaman}%
+   \def\seename{lihat}%
+   \def\alsoname{lihat juga}%
+   \def\enclname{Lampiran}%
+   \def\ccname{salinan kpd}%
+   \def\headtoname{Kepada}%
+   \def\proofname{Bukti}%
+   \def\glossaryname{Senarai Istilah}%
+}
+
+\def\captionsmalay{%
+  \csname captionsmalay@\malay at variant\endcsname%
+}
+
+\def\datemalay at indonesian{%
+   \def\today{\number\day~\ifcase\month\or
+    Januari\or Pebruari\or Maret\or April\or Mei\or Juni\or
+    Juli\or Agustus\or September\or Oktober\or Nopember\or Desember\fi
+    \space \number\year}}
+
+\def\datemalay at malay{%
+   \def\bahasam at day{%
+      \ifcase\day\or%
+        1hb\or 2hb\or 3hb\or 4hb\or 5hb\or%
+        6hb\or 7hb\or 8hb\or 9hb\or 10hb\or%
+        11hb\or 12hb\or 13hb\or 14hb\or 15hb\or%
+        16hb\or 17hb\or 18hb\or 19hb\or 20hb\or%
+        21hb\or 22hb\or 23hb\or 24hb\or 25hb\or%
+        26hb\or 27hb\or 28hb\or 29hb\or 30hb\or%
+        31hb\fi}%
+   \def\today{\bahasam at day~\ifcase\month\or
+    Januari\or Februari\or Mac\or April\or Mei\or Jun\or
+    Julai\or Ogos\or September\or Oktober\or November\or Disember\fi
+    \space \number\year}}
+
+\def\datemalay{%
+  \csname datemalay@\malay at variant\endcsname%
+}
+
+% Hijri calendar localizations
+\def\hijrimonthmalay at indonesian#1{%
+  \ifcase#1%
+  \or Muharram\or Safar\or Rabiul awal\or Rabiul akhir\or Jumadil awal\or Jumadil akhir\or Rajab%
+  \or Sya'ban\or Ramadhan\or Syawal\or Dzulkaidah\or Dzulhijjah\fi%
+}
+
+\def\hijrimonthmalay at malay#1{%
+  \ifcase#1%
+  \or Muharram\or Safar\or Rabiulawal\or Rabiulakhir\or Jamadilawal\or Jamadilakhir\or Rejab%
+  \or Syaaban\or Ramadan\or Syawal\or Zulkaedah\or Zulhijah\fi%
+}
+
+\def\hijrimonthmalay{%
+  \csname hijrimonthmalay@\malay at variant\endcsname%
+}
+
+%\Hijritoday is now locale-aware and will format the date with this macro:
+\DefineFormatHijriDate{malay}{%
+  \number\value{Hijriday}\space\hijrimonthmalay{\value{Hijrimonth}}\space\number\value{Hijriyear}}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malay.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-marathi.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-marathi.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-marathi.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -17,8 +17,8 @@
   hyphennames={marathi},
   hyphenmins={2,2},%CHECK
   fontsetup=true,
+  localnumeral=marathinumerals
   %TODO nouppercase=true,
-  %TODO localnumber=marathinumber
 }
 
 \def\tmp at western{Western}
@@ -31,6 +31,8 @@
     \marathi at devanagari@numeralsfalse
   \fi}
 
+\newcommand{\marathinumerals}[2]{\marathinumber{#2}}
+
 \def\marathinumber#1{%
   \ifmarathi at devanagari@numerals
     \devanagaridigits{\number#1}%
@@ -47,9 +49,9 @@
    \def\appendixname{परिशिष्ट}%
    \def\contentsname{अनुक्रमणिका}%
    \def\listfigurename{आकृत्यांची यादी}%
-   \def\listtablename{कॊष्टकांची यादी}%
+   \def\listtablename{कोष्टकांची यादी}%
    \def\indexname{सूची}%
-   \def\figurename{आक्रुती}%
+   \def\figurename{आकृती}%
    \def\tablename{कोष्टक}%
    %\def\thepart{}% TODO
    \def\partname{भाग}%
@@ -61,6 +63,7 @@
    \def\headtoname{प्रति}%
    \def\proofname{सिद्धता}%
    \def\glossaryname{स्पष्टीकरणांची यादी}%
+   \def\authorsand{आणि}%
 }
 \def\datemarathi{%
    \def\marathimonth{%

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mongolian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mongolian.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mongolian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,194 @@
+\ProvidesFile{gloss-mongolian.ldf}[polyglossia: module for mongolian]
+
+\RequirePackage{cyrillicnumbers}
+
+\PolyglossiaSetup{mongolian}{
+  script=Cyrillic,
+  scripttag=cyrl,
+  langtag=MNG,
+  hyphennames={mongolian},
+  hyphenmins={2,2},
+  frenchspacing=true,
+  fontsetup,
+  localnumeral=mongoliannumerals,
+  Localnumeral=Mongoliannumerals
+}
+
+% This file is derived from mongolian-babel. which
+% provides support for Mongolian (Khalkha variety)
+% with Cyrillic script
+% TODO: Implement script=mongolian and maybe other
+%       variants of Mongolian
+
+\newif\ifcyrillic at numerals
+\define at key{mongolian}{numerals}[arabic]{%
+   \ifstrequal{#1}{cyrillic}%
+      {\cyrillic at numeralstrue}%
+      {\cyrillic at numeralsfalse}%
+}
+
+\define at boolkey{mongolian}[mongolian@]{babelshorthands}[false]{}
+
+\setkeys{mongolian}{numerals}
+
+\ifsystem at babelshorthands
+  \setkeys{mongolian}{babelshorthands=true}
+\else
+  \setkeys{mongolian}{babelshorthands=false}
+\fi
+
+\ifcsundef{initiate at active@char}{%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
+}{}
+
+\def\mongolian at shorthands{%
+  \bbl at activate{"}%
+  \def\language at group{mongolian}%
+  \declare at shorthand{mongolian}{"`}{„}%
+  \declare at shorthand{mongolian}{"'}{“}%
+  \declare at shorthand{mongolian}{"<}{«}%
+  \declare at shorthand{mongolian}{">}{»}%
+  \declare at shorthand{mongolian}{""}{\hskip\z at skip}%
+  \declare at shorthand{mongolian}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
+  \declare at shorthand{mongolian}{"=}{\nobreak-\hskip\z at skip}%
+  \declare at shorthand{mongolian}{"|}{\textormath{\nobreak\discretionary{-}{}{\kern.03em}\allowhyphens}{}}%
+  \declare at shorthand{mongolian}{"-}{%
+     \def\mongolian at sh@tmp{%
+       \if\mongolian at sh@next-\expandafter\mongolian at sh@emdash%
+       \else\expandafter\mongolian at sh@hyphen\fi%
+     }%
+     \futurelet\mongolian at sh@next\mongolian at sh@tmp%
+  }%
+  \def\mongolian at sh@hyphen{%
+    \nobreak\-\bbl at allowhyphens}%
+  \def\mongolian at sh@emdash##1##2{\cdash-##1##2}%
+  \def\cdash##1##2##3{\def\tempx@{##3}%
+  \def\tempa@{-}\def\tempb@{~}\def\tempc@{*}%
+   \ifx\tempx@\tempa@\@Acdash\else
+    \ifx\tempx@\tempb@\@Bcdash\else
+     \ifx\tempx@\tempc@\@Ccdash\else
+      \errmessage{Wrong usage of cdash}\fi\fi\fi}%
+  \def\@Acdash{\ifdim\lastskip>\z@\unskip\nobreak\hskip.2em\fi
+    \cyrdash\hskip.2em\ignorespaces}%
+  \def\@Bcdash{\leavevmode\ifdim\lastskip>\z@\unskip\fi
+   \nobreak\cyrdash\penalty\exhyphenpenalty\hskip\z at skip\ignorespaces}%
+  \def\@Ccdash{\leavevmode
+   \nobreak\cyrdash\nobreak\hskip.35em\ignorespaces}%
+  \ifx\cyrdash\undefined
+    \def\cyrdash{\hbox to.8em{--\hss--}}%
+  \fi
+  \declare at shorthand{mongolian}{",}{\nobreak\hskip.2em\ignorespaces}%
+}
+
+\def\nomongolian at shorthands{%
+  \@ifundefined{initiate at active@char}{}{\bbl at deactivate{"}}%
+}
+
+% Taken from babel-mongolian
+\def\captionsmongolian{%
+   \def\prefacename{Өмнөх үг}%
+   \def\refname{Ашигласан ном}%
+   \def\abstractname{Удиртгал}%
+   \def\bibname{Номзүй}%
+   \def\chaptername{Бүлэг}%
+   \def\appendixname{Хавсралт}%
+   \ifcsundef{thechapter}%
+     {\def\contentsname{Агуулга}}%
+     {\def\contentsname{Гарчиг}}%
+   \def\listfigurename{Зургийн жагсаалт}%
+   \def\listtablename{Хүснэгтийн жагсаалт}%
+   \def\indexname{Товъёг}%
+   \def\authorname{Нэрийн хэлхээ}%
+   \def\figurename{Зураг}%
+   \def\tablename{Хүснэгт}%
+   \def\partname{Хэсэг}%
+   \def\enclname{Ишлэл}%
+   \def\ccname{э.с.}%
+   \def\headtoname{}%
+   \def\pagename{тал}%
+   \def\seename{талд үз}%
+   \def\alsoname{мөн талд үз}%
+   \def\proofname{Баталгаа}%
+}
+
+\def\datemongolian{%
+  \def\today{\number\year~оны \ifcase\month\or
+  1-р\or 2-р\or 3-р\or 4-р\or 5-р\or 6-р\or
+  7-р\or 8-р\or 9-р\or 10-р\or 11-р\or 12-р\fi
+  ~сарын \number\day}}
+
+\newcommand{\mongoliannumerals}[2]{\mongoliannumber{#2}}
+\newcommand{\Mongoliannumerals}[2]{\Mongoliannumber{#2}}
+
+\def\mongoliannumber#1{%
+  \ifcyrillic at numerals
+    \cyr at alph{#1}%
+  \else
+    \number#1%
+  \fi%
+}
+
+\def\Mongoliannumber#1{%
+  \ifcyrillic at numerals
+    \cyr at Alph{#1}%
+  \else
+    \number#1%
+  \fi%
+}
+
+\let\mongoliannumeral=\mongoliannumber
+\let\Mongoliannumeral=\Mongoliannumber
+
+\def\Asbuk#1{\expandafter\cyr at Alph\csname c@#1\endcsname}
+
+\def\asbuk#1{\expandafter\cyr at alph\csname c@#1\endcsname}
+
+% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
+% thus ends at 30. We now use proper cyrillic numbering.
+
+%\def\mongolian at 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 at ill@value{#1}{mongolian at Alph}\fi}
+
+%\def\mongolian at 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 at ill@value{#1}{mongolian at alph}\fi}
+
+\def\mongolian at numbers{%
+   \let\latin at alph\@alph
+   \let\latin at Alph\@Alph
+   \ifcyrillic at numerals%
+     \def\mongolian at alph##1{\expandafter\mongoliannumeral\expandafter{\the##1}}%
+     \def\mongolian at Alph##1{\expandafter\Mongoliannumeral\expandafter{\the##1}}%
+      \let\@alph\mongolian at alph%
+      \let\@Alph\mongolian at Alph%
+   \fi
+}
+
+\def\nomongolian at numbers{%
+   \let\@alph\latin at alph%
+   \let\@Alph\latin at Alph%
+}
+
+\def\noextras at mongolian{%
+   \ifcyrillic at numerals\nomongolian at numbers\fi%
+   \nomongolian at shorthands%
+}
+
+\def\blockextras at mongolian{%
+   \ifcyrillic at numerals\mongolian at numbers\fi%
+   \ifmongolian at babelshorthands\mongolian at shorthands\fi%
+}
+
+\def\inlineextras at mongolian{%
+   \ifmongolian at babelshorthands\mongolian at shorthands\fi%
+}
+
+\endinput
+


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mongolian.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nko.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nko.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nko.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,12 +2,16 @@
 \PolyglossiaSetup{nko}{%
   script=N'ko,
   scripttag=nko~,
+  langtag=NKO,
   fontsetup=true,
   hyphennames={nohyphenation},
-  direction=RL
+  direction=RL,
+  localnumeral=nkonumerals
 }
 \RequirePackage{nkonumbers}%
 
+\newcommand{\nkonumerals}[2]{\nkonumber{#2}}
+
 \def\captionsnko{%
   \def\prefacename{ߢߍߛߓߍ}%
   \def\refname{ߞߐߡߊߛߙߋ}%
@@ -36,30 +40,30 @@
 % ߂߀߁߃ ߞߏ߲ߞߏߜߍ ߕߟߋ߬ ߁߈ (RTL)
 % ( 18 February 2013 )
 % The word "ߕߟߋ߬" is mandatory between month name and day number.
+% Replace "ߕߟߋ߬" by "ߕߋ߬ߟߋ߫" if and only if day = 2 or day = 3 or day = 9 
+% or (day >= 20 and day <= 29).
 
+\newcommand*\nkodayprefix[1]{%
+  \ifnum\numexpr#1=2 ߕߋ߬ߟߋ߫\else%
+     \ifnum\numexpr#1=3 ߕߋ߬ߟߋ߫\else%
+        \ifnum\numexpr#1=9 ߕߋ߬ߟߋ߫\else%
+           \ifnum\numexpr#1>19\ifnum\numexpr#1<30 ߕߋ߬ߟߋ߫\else ߕߟߋ߬\fi\else ߕߟߋ߬\fi%
+        \fi%
+     \fi%
+  \fi%
+}
+
+\newcommand*\nkoday[1]{%
+  % If day = 1, put above "߁", NKO_COMBINING_SHORT_RISING_TONE
+  \ifnum\numexpr#1=1 ߁߭\else%
+    \nkonumber{#1}
+  \fi
+}
+
 \def\datenko{%
   \def\today{%
     \nkonumber{\year}\space
     \ifcase\month
-    \orߓߌ߲ߠߊߥߎߟߋ߲%
-    \orߞߏ߲ߞߏߜߍ%
-    \orߕߙߊߓߊ
-    \orߞߏ߲ߞߏߘߌ߬ߓߌ%
-    \orߘߓߊ߬ߕߊ%
-    \orߥߊ߬ߛߌߥߊ߬ߙߊ%
-    \orߞߊ߬ߙߌߝߐ߭%
-    \orߘߓߊ߬ߓߌߟߊ%
-    \orߕߎߟߊߝߌ߲%
-    \orߞߏ߲ߓߌߕߌ߮%
-    \orߣߍߣߍߓߊ%
-    \orߞߏ߬ߟߌ߲߬ߞߏߟߌ߲\fi
-    \spaceߕߟߋ߬
-    \space\nkonumber{\day}
-  }%
-
-  \def\today{%
-    \nkonumber{\year}\space
-    \ifcase\month
     \or ߓߌ߲ߠߊߥߎߟߋ߲%
     \or ߞߏ߲ߞߏߜߍ%
     \or ߕߙߊߓߊ%
@@ -72,8 +76,8 @@
     \or ߞߏ߲ߓߌߕߌ߮%
     \or ߣߍߣߍߓߊ%
     \or ߞߏ߬ߟߌ߲߬ߞߏߟߌ߲\fi
-    \space ߕߟߋ߬
-    \space\nkonumber{\day}
+    \space\nkodayprefix{\number\day}
+    \space\nkoday{\day}
   }%
 }%
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norsk.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norsk.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norsk.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,42 +1,20 @@
-\ProvidesFile{gloss-norsk.ldf}[polyglossia: module for norwegian]
+\ProvidesFile{gloss-norsk.ldf}[polyglossia: module for norwegian (bokmal)]
+
+% We only provide this gloss for babel compatibility. Since norsk is 
+% actually norwegian bokmal, we use 'norwegian' with variant 'bokmal' now.
+
+\input{gloss-norwegian.ldf}
+
 \PolyglossiaSetup{norsk}{
   hyphennames={norsk},
   hyphenmins={2,2},
+  langtag=NOR,
   frenchspacing=true,
   fontsetup=true,
 }
 
-\def\captionsnorsk{%
-   \def\refname{Referanser}%
-   \def\abstractname{Sammendrag}%
-   \def\bibname{Bibliografi}%
-   \def\prefacename{Forord}%
-   \def\chaptername{Kapittel}%
-   \def\appendixname{Tillegg}%
-   \def\contentsname{Innhold}%
-   \def\listfigurename{Figurer}%
-   \def\listtablename{Tabeller}%
-   \def\indexname{Register}%
-   \def\figurename{Figur}%
-   \def\tablename{Tabell}%
-   %\def\thepart{}% <<<
-   \def\partname{Del}%
-   \def\pagename{Side}%
-   \def\seename{Se}%
-   \def\alsoname{Se også}%
-   \def\enclname{Vedlegg}%
-   \def\ccname{Kopi sendt}%
-   \def\headtoname{Til}%
-   \def\proofname{Bevis}%
-   \def\glossaryname{Ordliste}%
-   }
+\let\captionsnorsk\captionsnorwegian at norsk
+\let\datenorsk\datenorwegian at norsk
 
-\def\datenorsk{%   
-   \def\today{\number\day.~\ifcase\month\or
-    januar\or februar\or mars\or april\or mai\or juni\or
-    juli\or august\or september\or oktober\or november\or desember
-    \fi\space\number\year}%
-    }
-
 \endinput
 

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norwegian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norwegian.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norwegian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,104 @@
+\ProvidesFile{gloss-norwegian.ldf}[polyglossia: module for norwegian]
+\PolyglossiaSetup{norwegian}{
+  hyphennames={nynorsk},
+  langtag=NYN,
+  hyphenmins={2,2},
+  frenchspacing=true,
+  fontsetup=false,
+}
+
+\def\norwegian at variant{nynorsk}
+\define at choicekey*+{norwegian}{variant}[\val\nr]{nynorsk,bokmal}[nynorsk]{%
+   \ifcase\nr\relax
+      % nynorsk:
+      \def\norwegian at variant{nynorsk}%
+      \SetLanguageKeys{norwegian}{langtag=NYN,babelname=nynorsk}%
+      \xpg at fontsetup@latin{norwegian}%
+   \or
+      % bokmal:
+      \def\norwegian at variant{norsk}%
+      \SetLanguageKeys{norwegian}{langtag=NOR,babelname=norsk}%
+      \xpg at fontsetup@latin{norwegian}%
+   \fi
+   \xpg at info{Option: norwegian, variant=\val}%
+}{\xpg at warning{Unknown norwegian variant `#1'}}
+
+
+\def\norwegian at language{%
+   \polyglossia at setup@language at patterns{\norwegian at variant}
+}%
+
+\def\captionsnorwegian at nynorsk{%
+   \def\refname{Referansar}%
+   \def\abstractname{Sammendrag}%
+   \def\bibname{Litteratur}%
+   \def\prefacename{Forord}%
+   \def\chaptername{Kapittel}%
+   \def\appendixname{Tillegg}%
+   \def\contentsname{Innhald}%
+   \def\listfigurename{Figurar}%
+   \def\listtablename{Tabellar}%
+   \def\indexname{Register}%
+   \def\figurename{Figur}%
+   \def\tablename{Tabell}%
+   %\def\thepart{}% <<<
+   \def\partname{Del}%
+   \def\pagename{Side}%
+   \def\seename{Sjå}%
+   \def\alsoname{Sjå òg}%
+   \def\enclname{Vedlegg}%
+   \def\ccname{Kopi til}%
+   \def\headtoname{Til}%
+   \def\proofname{Bevis}%
+   \def\glossaryname{Ordliste}%
+}
+
+\def\captionsnorwegian at norsk{%
+   \def\refname{Referanser}%
+   \def\abstractname{Sammendrag}%
+   \def\bibname{Bibliografi}%
+   \def\prefacename{Forord}%
+   \def\chaptername{Kapittel}%
+   \def\appendixname{Tillegg}%
+   \def\contentsname{Innhold}%
+   \def\listfigurename{Figurer}%
+   \def\listtablename{Tabeller}%
+   \def\indexname{Register}%
+   \def\figurename{Figur}%
+   \def\tablename{Tabell}%
+   %\def\thepart{}% <<<
+   \def\partname{Del}%
+   \def\pagename{Side}%
+   \def\seename{Se}%
+   \def\alsoname{Se også}%
+   \def\enclname{Vedlegg}%
+   \def\ccname{Kopi sendt}%
+   \def\headtoname{Til}%
+   \def\proofname{Bevis}%
+   \def\glossaryname{Ordliste}%
+}
+
+\def\captionsnorwegian{%
+  \csname captionsnorwegian@\norwegian at variant\endcsname%
+}
+
+\def\datenorwegian at nynorsk{%   
+   \def\today{\number\day.~\ifcase\month\or
+    januar\or februar\or mars\or april\or mai\or juni\or
+    juli\or august\or september\or oktober\or november\or desember
+    \fi\space\number\year}%
+}
+
+\def\datenorwegian at norsk{%   
+   \def\today{\number\day.~\ifcase\month\or
+    januar\or februar\or mars\or april\or mai\or juni\or
+    juli\or august\or september\or oktober\or november\or
+    desember\fi\space\number\year}%
+}
+
+\def\datenorwegian{%
+  \csname datenorwegian@\norwegian at variant\endcsname%
+}
+
+\endinput
+


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norwegian.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nynorsk.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nynorsk.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nynorsk.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,42 +1,20 @@
 \ProvidesFile{gloss-nynorsk.ldf}[polyglossia: module for norwegian (Nynorsk)]
+
+% We only provide this gloss for babel compatibility. Since nynorsk is 
+% a norwegian variety, we use 'norwegian' with variant 'nynorsk' now.
+
+\input{gloss-norwegian.ldf}
+
 \PolyglossiaSetup{nynorsk}{
   hyphennames={nynorsk},
+  langtag=NYN,
   hyphenmins={2,2},
   frenchspacing=true,
   fontsetup=true,
 }
 
-\def\captionsnynorsk{%
-   \def\refname{Referansar}%
-   \def\abstractname{Sammendrag}%
-   \def\bibname{Litteratur}%
-   \def\prefacename{Forord}%
-   \def\chaptername{Kapittel}%
-   \def\appendixname{Tillegg}%
-   \def\contentsname{Innhald}%
-   \def\listfigurename{Figurar}%
-   \def\listtablename{Tabellar}%
-   \def\indexname{Register}%
-   \def\figurename{Figur}%
-   \def\tablename{Tabell}%
-   %\def\thepart{}% <<<
-   \def\partname{Del}%
-   \def\pagename{Side}%
-   \def\seename{Sjå}%
-   \def\alsoname{Sjå òg}%
-   \def\enclname{Vedlegg}%
-   \def\ccname{Kopi til}%
-   \def\headtoname{Til}%
-   \def\proofname{Bevis}%
-   \def\glossaryname{Ordliste}%
-   }
+\let\captionsnorsk\captionsnorwegian at nynorsk
+\let\datenorsk\datenorwegian at nynorsk
 
-\def\datenynorsk{%   
-   \def\today{\number\day.~\ifcase\month\or
-    januar\or februar\or mars\or april\or mai\or juni\or
-    juli\or august\or september\or oktober\or november\or desember
-    \fi\space\number\year}%
-    }
-
 \endinput
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-occitan.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-occitan.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-occitan.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -19,6 +19,7 @@
      module for Occitan]
 \PolyglossiaSetup{occitan}{
   hyphennames={occitan},
+  langtag=OCI,
   hyphenmins={2,2},
   frenchspacing=true,
   indentfirst=true,
@@ -31,10 +32,13 @@
 \else
   \setkeys{occitan}{babelshorthands=false}
 \fi
+
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
+
 \def\occitan at shorthands{%
   \bbl at activate{"}%
   \def\language at group{occitan}%

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-persian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-persian.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-persian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,151 @@
+\ProvidesFile{gloss-persian.ldf}[polyglossia: module for persian]
+\ifluatex
+  \xpg at warning{Persian is not supported with LuaTeX.\MessageBreak
+I will proceed with the compilation, but\MessageBreak
+the output is not guaranteed to be correct\MessageBreak
+and may look very wrong.}
+\fi
+\RequireBidi
+\RequirePackage{arabicnumbers}
+\RequirePackage{farsical}
+\RequirePackage{hijrical}
+\PolyglossiaSetup{persian}{
+  babelname=farsi,
+  script=Arabic,
+  direction=RL,
+  scripttag=arab,
+  langtag=FAR,
+  hyphennames={nohyphenation},
+  fontsetup=true,
+  localnumeral=farsinumerals
+}
+
+\newif\if at western@numerals
+\def\tmp at western{western}
+\define at key{persian}{numerals}[eastern]{%
+  \def\@tmpa{#1}%
+  \ifx\@tmpa\tmp at western\@western at numeralstrue\else%
+    \@western at numeralsfalse%
+  \fi}
+
+%this is needed for \abjad in arabicnumbers.sty
+\def\tmp at true{true}
+\define at key{persian}{abjadjimnotail}[true]{%
+  \def\@tmpa{#1}%
+  \ifx\@tmpa\tmp at true\abjad at jim@notailtrue%
+  \else
+    \abjad at jim@notailfalse
+  \fi}
+
+% NOT YET USED
+\define at key{persian}{locale}[default]{%
+  \def\@persian at locale{#1}}
+
+%TODO add option for CALENDAR
+
+\setkeys{persian}{locale,numerals}
+
+\def\farsigregmonth#1{\ifcase#1%
+  \or ژانویه\or فوریه\or مارس\or آوریل\or مه\or ژوئن\or ژوئیه\or اوت\or سپتامبر\or اکتبر\or نوامبر\or دسامبر\fi}
+\def\farsimonth#1{\ifcase#1%
+  \or کانون ثانی\or شباط\or اذار%%or ادار
+    \or نیسان\or ایار\or حزیران\or تموز\or آب\or ایلول\or تشرین اول\or تشرین ثانی\or کانون اول\fi}
+
+%\Hijritoday is now locale-aware and will format the date with this macro:
+\DefineFormatHijriDate{persian}{\@ensure at RTL{%
+\farsinumber{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\farsinumber{\value{Hijriyear}}}}
+
+\def\captionspersian{%
+\def\prefacename{\@ensure at RTL{پیشگفتار}}%
+\def\refname{\@ensure at RTL{مراجع}}%
+\def\abstractname{\@ensure at RTL{چکیده}}%
+\def\bibname{\@ensure at RTL{کتاب‌نامه}}%
+\def\chaptername{\@ensure at RTL{فصل}}%
+\def\appendixname{\@ensure at RTL{پیوست}}%
+\def\contentsname{\@ensure at RTL{فهرست مطالب}}%
+\def\listfigurename{\@ensure at RTL{لیست تصاویر}}%
+\def\listtablename{\@ensure at RTL{لیست جداول}}%
+\def\indexname{\@ensure at RTL{نمایه}}%
+\def\figurename{\@ensure at RTL{شكل}}%
+\def\tablename{\@ensure at RTL{جدول}}%
+\def\partname{\@ensure at RTL{بخش}}%
+\def\enclname{\@ensure at RTL{پیوست}}%
+\def\ccname{\@ensure at RTL{رونوشت}}%
+\def\headtoname{\@ensure at RTL{به}}%
+\def\pagename{\@ensure at RTL{صفحة}}%
+\def\seename{\@ensure at RTL{ببینید}}%
+\def\alsoname{\@ensure at RTL{نیز ببینید}}%
+\def\proofname{\@ensure at RTL{برهان}}%
+\def\glossaryname{\@ensure at RTL{دانش‌نامه}}%
+}
+\def\datepersian{%
+   \def\today{\@ensure at RTL{\farsinumber\day\space\farsigregmonth{\month}\space\farsinumber\year}}%
+}
+
+\newcommand{\farsinumerals}[2]{\farsinumber{#2}}
+
+\newif\ifpersiandigits
+
+\def\farsinumber#1{%
+  \if at western@numerals
+    \number#1%
+  \else
+    \ifxetex
+      \ifnum\XeTeXcharglyph"06F0 > 0\relax
+        \persiandigitstrue
+      \fi
+    \else\ifluatex
+      \expandafter\ifnum\directlua{polyglossia.check_char(0x6F0)} > 0\relax
+        \persiandigitstrue
+      \fi
+    \fi\fi
+    \ifpersiandigits
+      \farsidigits{\number#1}%
+      %%{\protect\addfontfeature{Mapping=farsidigits}\number#1}%
+    \else%
+      \arabicdigits{\number#1}%
+      %%{\protect\addfontfeature{Mapping=arabicdigits}\number#1}%
+    \fi
+  \fi
+}
+
+%\def\farsinum#1{\expandafter\farsinumber\csname c@#1\endcsname}
+%\def\farsibracenum#1{(\expandafter\farsinumber\csname c@#1\endcsname)}
+%\def\farsiornatebracenum#1{\char"FD3E\expandafter\farsinumber\csname c@#1\endcsname\char"FD3F}
+%\def\farsialph#1{\expandafter\@farsialph\csname c@#1\endcsname}
+
+\def\persian at numbers{%
+   \let\@alph\abjad%
+   \let\@Alph\abjad%
+}
+
+\def\nopersian at numbers{%
+  \let\@alph\@latinalph%
+  \let\@Alph\@latinAlph%
+}
+
+\def\persian at globalnumbers{%
+   \let\@arabic\farsinumber%
+   \renewcommand\thefootnote{\localnumeral*{footnote}}%
+   \renewcommand\theequation{\localnumeral*{equation}}%
+}
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
+\def\nopersian at globalnumbers{
+   \let\@arabic\xpg at save@arabic%
+}
+
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
+\def\blockextras at persian{%
+   \def\MakeUppercase##1{##1}%
+}
+
+\def\noextras at persian{%
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase
+}
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-persian.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-piedmontese.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-piedmontese.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-piedmontese.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -4,6 +4,7 @@
 \PolyglossiaSetup{piedmontese}{
   hyphennames={piedmontese},
   hyphenmins={2,2},
+  langtag=PMS,
   frenchspacing=true,
   fontsetup=true,
 }
@@ -18,8 +19,9 @@
 \fi
 
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\piedmontese at shorthands{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-polish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-polish.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-polish.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{polish}{
   hyphennames={polish},
   hyphenmins={2,2},
+  langtag=PLK,
   frenchspacing=true,
   fontsetup=true,
 }

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuges.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuges.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuges.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,40 +1,25 @@
-\ProvidesFile{gloss-portuges.ldf}[polyglossia: module for portuguese]
+\ProvidesFile{gloss-portuges.ldf}[polyglossia: module for portuguese (DEPRECATED!)]
+
+% We only provide this gloss for backwards compatibility. The name
+% 'portuges' was selected in accordance with babel (which probably
+% introduced it in 8.3 filename times). Since polyglossia uses full
+% English language names, we use 'portuguese' now.
+
+% FIXME: Once we support babel aliases (#112) this gloss can go.
+
+\xpg at warning{The language name 'portuges' is deprectated.\MessageBreak
+             Please use 'portuguese' instead.}
+
+\input{gloss-portuguese.ldf}
+
 \PolyglossiaSetup{portuges}{
   hyphennames={portuges,portuguese},
   hyphenmins={2,3},
+  langtag=PTG,
   fontsetup=true,
 }
 
-\def\captionsportuges{%
-  \def\refname{Referências}%
-  \def\abstractname{Resumo}%
-  \def\bibname{Bibliografia}%
-  \def\prefacename{Prefácio}%
-  \def\chaptername{Capítulo}%
-  \def\appendixname{Apêndice}%
-  \def\contentsname{Conteúdo}%
-  \def\listfigurename{Lista de Figuras}%
-  \def\listtablename{Lista de Tabelas}%
-  \def\indexname{Índice}%
-  \def\figurename{Figura}%
-  \def\tablename{Tabela}%
-  %\def\thepart{}%
-  \def\partname{Parte}%
-  \def\pagename{Página}%
-  \def\seename{ver}%
-  \def\alsoname{ver também}%
-  \def\enclname{Anexo}%
-  \def\ccname{Com cópia a}%
-  \def\headtoname{Para}%
-  \def\proofname{Demonstração}%
-  \def\glossaryname{Glossário}%
-  }
-
-\def\dateportuges{%   
-  \def\today{\number\day\space de\space\ifcase\month\or
-    Janeiro\or Fevereiro\or Março\or Abril\or Maio\or Junho\or
-    Julho\or Agosto\or Setembro\or Outubro\or Novembro\or Dezembro\fi
-    \space de\space\number\year}%
-  }
+\let\captionsportuges\captionsportuguese at portuges
+\let\dateportuges\dateportuguese at portuges
      
 \endinput

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuguese.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuguese.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuguese.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,103 @@
+\ProvidesFile{gloss-portuguese.ldf}[polyglossia: module for portuguese]
+\PolyglossiaSetup{portuguese}{
+  babelname=portuges,
+  hyphennames={portuges,portuguese},
+  hyphenmins={2,3},
+  langtag=PTG,
+  fontsetup=true,
+}
+
+\def\portuguese at variant{portuges}
+\define at choicekey*+{portuguese}{variant}[\val\nr]{portuguese,brazilian}[portuguese]{%
+   \ifcase\nr\relax
+      % portuguese:
+      \def\portuguese at variant{portuges}%
+   \or
+      % brazilian:
+      \def\portuguese at variant{brazil}%
+      \SetLanguageKeys{portuguese}{babelname=brazil}%
+      \xpg at ifdefined{brazil}{}%
+	    {\xpg at warning{No hyphenation patterns were loaded for "Portuguese (Brazil)"\MessageBreak
+	      I will use the standard patterns for Portuguese instead}%
+	    \adddialect\l at brazil\l at portuges\relax}%
+   \fi
+   \xpg at info{Option: portuguese, variant=\val}%
+}{\xpg at warning{Unknown portuguese variant `#1'}}
+
+
+\def\portuguese at language{%
+   \polyglossia at setup@language at patterns{\portuguese at variant}
+}%
+
+\def\captionsportuguese at portuges{%
+  \def\refname{Referências}%
+  \def\abstractname{Resumo}%
+  \def\bibname{Bibliografia}%
+  \def\prefacename{Prefácio}%
+  \def\chaptername{Capítulo}%
+  \def\appendixname{Apêndice}%
+  \def\contentsname{Conteúdo}%
+  \def\listfigurename{Lista de Figuras}%
+  \def\listtablename{Lista de Tabelas}%
+  \def\indexname{Índice}%
+  \def\figurename{Figura}%
+  \def\tablename{Tabela}%
+  \def\partname{Parte}%
+  \def\pagename{Página}%
+  \def\seename{ver}%
+  \def\alsoname{ver também}%
+  \def\enclname{Anexo}%
+  \def\ccname{Com cópia a}%
+  \def\headtoname{Para}%
+  \def\proofname{Demonstração}%
+  \def\glossaryname{Glossário}%
+}
+
+\def\captionsportuguese at brazil{%
+   \def\refname{Referências}%
+   \def\abstractname{Resumo}%
+   \def\bibname{Referências Bibliográficas}%
+   \def\prefacename{Prefácio}%
+   \def\chaptername{Capítulo}%
+   \def\appendixname{Apêndice}%
+   \def\contentsname{Sumário}%
+   \def\listfigurename{Lista de Figuras}%
+   \def\listtablename{Lista de Tabelas}%
+   \def\indexname{Índice Remissivo}%
+   \def\figurename{Figura}%
+   \def\tablename{Tabela}%
+   \def\partname{Parte}%
+   \def\pagename{Página}%
+   \def\seename{veja}%
+   \def\alsoname{veja também}%
+   \def\enclname{Anexo}%
+   \def\ccname{Cópia para}%
+   \def\headtoname{Para}%
+   \def\proofname{Demonstração}%
+   \def\glossaryname{Glossário}%
+}
+
+\def\captionsportuguese{%
+  \csname captionsportuguese@\portuguese at variant\endcsname%
+}
+
+\def\dateportuguese at portuges{%   
+  \def\today{\number\day\space de\space\ifcase\month\or
+    Janeiro\or Fevereiro\or Março\or Abril\or Maio\or Junho\or
+    Julho\or Agosto\or Setembro\or Outubro\or Novembro\or Dezembro\fi
+    \space de\space\number\year}%
+}
+
+
+\def\dateportuguese at brazil{%   
+   \def\today{\number\day\space de\space\ifcase\month\or
+      janeiro\or fevereiro\or março\or abril\or maio\or junho\or
+      julho\or agosto\or setembro\or outubro\or novembro\or dezembro%
+      \fi\space de\space\number\year}%
+}
+
+\def\dateportuguese{%
+  \csname dateportuguese@\portuguese at variant\endcsname%
+}
+     
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuguese.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romanian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romanian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romanian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -3,6 +3,7 @@
 \PolyglossiaSetup{romanian}{
   hyphennames={romanian},
   hyphenmins={2,2},
+  langtag=ROM,
   fontsetup=true,
 }
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romansh.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romansh.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romansh.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -3,6 +3,7 @@
 \PolyglossiaSetup{romansh}{%
   hyphennames={romansh},
   hyphenmins={2,2},
+  langtag=RMS,
   indentfirst=true,
   fontsetup=true,
 }

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-russian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-russian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-russian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,4 +1,7 @@
 \ProvidesFile{gloss-russian.ldf}[polyglossia: module for russian]
+
+\RequirePackage{cyrillicnumbers}
+
 \PolyglossiaSetup{russian}{
   script=Cyrillic,
   scripttag=cyrl,
@@ -6,22 +9,30 @@
   hyphennames={russian},
   hyphenmins={2,2},
   frenchspacing=true,
-  fontsetup
-  %TODO localalph={russian at alph,russian at Alph}
+  fontsetup,
+  localnumeral=russiannumerals,
+  Localnumeral=Russiannumerals
 }
 
+\newif\if at russian@modern
 \define at key{russian}{spelling}[modern]{%
   \ifstrequal{#1}{old}%
-    {\def\captionsrussian{\captionsrussian at old}%
-     \def\daterussian{\daterussian at old}}%
-    {\def\captionsrussian{\captionsrussian at modern}%
-     \def\daterussian{\daterussian at modern}}%
+    {\@russian at modernfalse}%
+    {\@russian at moderntrue}%
 }
 
+\def\captionsrussian{%
+   \if at russian@modern\captionsrussian at modern\else\captionsrussian at old\fi%
+}%
+
+\def\daterussian{%
+   \if at russian@modern\daterussian at modern\else\daterussian at old\fi%
+}%
+
 \newif\ifcyrillic at numerals
-\define at key{russian}{numerals}[latin]{%
+\define at key{russian}{numerals}[arabic]{%
    \ifstrequal{#1}{cyrillic}%
-      {\cyrillic at numeralstrue}
+      {\cyrillic at numeralstrue}%
       {\cyrillic at numeralsfalse}%
 }
 
@@ -38,6 +49,7 @@
 \ifcsundef{initiate at active@char}{%
   \input{babelsh.def}%
   \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\russian at shorthands{%
@@ -53,8 +65,8 @@
   \declare at shorthand{russian}{"|}{\textormath{\nobreak\discretionary{-}{}{\kern.03em}\allowhyphens}{}}%
   \declare at shorthand{russian}{"-}{%
     \def\russian at sh@tmp{%
-      \if\russian at sh@next-\expandafter\russian at sh@emdash
-      \else\expandafter\russian at sh@hyphen\fi
+      \if\russian at sh@next-\expandafter\russian at sh@emdash%
+      \else\expandafter\russian at sh@hyphen\fi%
     }%
     \futurelet\russian at sh@next\russian at sh@tmp}%
   \def\russian at sh@hyphen{%
@@ -73,7 +85,7 @@
   \def\@Ccdash{\leavevmode
    \nobreak\cyrdash\nobreak\hskip.35em\ignorespaces}%
   \ifx\cyrdash\undefined
-    \def\cyrdash{\hbox to.8em{--\hss--}}
+    \def\cyrdash{\hbox to.8em{--\hss--}}%
   \fi
   \declare at shorthand{russian}{",}{\nobreak\hskip.2em\ignorespaces}%
 }
@@ -123,7 +135,8 @@
       октября\or
       ноября\or
       декабря\fi%
-      \space \number\year\space г.}}
+      \space \number\year\space г.}%
+}
      
 \def\captionsrussian at old{%
    \def\prefacename{Предисловіе}%
@@ -149,7 +162,8 @@
    \def\seename{см.}%
    \def\alsoname{см.~также}%
    \def\proofname{Доказательство}%
-}  
+}
+
 \def\daterussian at old{%
       \def\today{\number\day%
       \space\ifcase\month\or%
@@ -165,7 +179,8 @@
       октября\or
       ноября\or
       декабря\fi%
-      \space \number\year\space г.}}
+      \space \number\year\space г.}%
+}
 
 % The following is based on some ideas from ruscor.sty
 \def\russian at capsformat{%
@@ -172,11 +187,16 @@
    \ifdef{\KOMAScript}{%
       \ifdef{\chapterformat}{%
         \renewcommand{\chapterformat}{\prechapter\thechapter\postchapter}}{}%
-      \renewcommand{\sectionformat}{\presection\thesection\postsection}%
-      \renewcommand{\subsectionformat}{\presubsection\thesubsection\postsubsection}%
-      \renewcommand{\subsubsectionformat}{\presubsubsection\thesubsubsection\postsubsubsection}%
-      \renewcommand{\paragraphformat}{\preparagraph\theparagraph\postparagraph}%
-      \renewcommand{\subparagraphformat}{\presubparagraph\thesubparagraph\postsubparagraph}%
+      \ifdef{\sectionformat}{%
+        \renewcommand{\sectionformat}{\presection\thesection\postsection}}{}%
+      \ifdef{\subsectionformat}{%
+        \renewcommand{\subsectionformat}{\presubsection\thesubsection\postsubsection}}{}%
+      \ifdef{\subsubsectionformat}{%
+        \renewcommand{\subsubsectionformat}{\presubsubsection\thesubsubsection\postsubsubsection}}{}%
+      \ifdef{\paragraphformat}{%
+        \renewcommand{\paragraphformat}{\preparagraph\theparagraph\postparagraph}}{}%
+      \ifdef{\subparagraphformat}{%
+        \renewcommand{\subparagraphformat}{\presubparagraph\thesubparagraph\postsubparagraph}}{}%
    }{%
       \def\@seccntformat##1{\csname pre##1\endcsname%
          \csname the##1\endcsname%
@@ -194,27 +214,58 @@
    \def\presubsection{}%
    \def\presubsubsection{}%
    \def\preparagraph{}%
-   \def\presubparagraph{}}
+   \def\presubparagraph{}%
+}
 
-\def\Asbuk#1{\expandafter\russian at Alph\csname c@#1\endcsname}
-\def\russian at 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 at ill@value{#1}{russian at Alph}\fi}
-\def\asbuk#1{\expandafter\russian at alph\csname c@#1\endcsname}
-\def\russian at 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 at ill@value{#1}{russian at alph}\fi}
+\newcommand{\russiannumerals}[2]{\russiannumber{#2}}
+\newcommand{\Russiannumerals}[2]{\Russiannumber{#2}}
 
+\def\russiannumber#1{%
+  \ifcyrillic at numerals
+    \cyr at alph{#1}%
+  \else
+    \number#1%
+  \fi%
+}
+
+\def\Russiannumber#1{%
+  \ifcyrillic at numerals
+    \cyr at Alph{#1}%
+  \else
+    \number#1%
+  \fi%
+}
+
+\let\russiannumeral=\russiannumber
+\let\Russiannumeral=\Russiannumber
+
+\def\Asbuk#1{\expandafter\cyr at Alph\csname c@#1\endcsname}
+
+\def\asbuk#1{\expandafter\cyr at alph\csname c@#1\endcsname}
+
+% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
+% thus ends at 30. We now use proper cyrillic numbering.
+
+%\def\russian at 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 at ill@value{#1}{russian at Alph}\fi}
+
+%\def\russian at 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 at ill@value{#1}{russian at alph}\fi}
+
 \def\russian at numbers{%
-   \let\latin at alph\@alph%
-   \let\latin at Alph\@Alph%
-   \ifcyrillic at numerals
-     \let\@alph\russian at alph%
-     \let\@Alph\russian at Alph%
+   \let\latin at alph\@alph
+   \let\latin at Alph\@Alph
+   \ifcyrillic at numerals%
+     \def\russian at alph##1{\expandafter\russiannumeral\expandafter{\the##1}}%
+     \def\russian at Alph##1{\expandafter\Russiannumeral\expandafter{\the##1}}%
+      \let\@alph\russian at alph%
+      \let\@Alph\russian at Alph%
    \fi
 }
 
@@ -227,22 +278,27 @@
    \ifdef{\KOMAScript}{%
       \ifdef{\chapterformat}{%
         \renewcommand{\chapterformat}{\thechapter\autodot\enskip}}{}%
-      \renewcommand{\sectionformat}{\thesection\autodot\enskip}%
-      \renewcommand{\subsectionformat}{\thesubsection\autodot\enskip}%
-      \renewcommand{\subsubsectionformat}{\thesubsubsection\autodot\enskip}%
-      \renewcommand{\paragraphformat}{\theparagraph\autodot\enskip}%
-      \renewcommand{\subparagraphformat}{\thesubparagraph\autodot\enskip}%
+      \ifdef{\sectionformat}{%
+        \renewcommand{\sectionformat}{\thesection\autodot\enskip}}{}%
+      \ifdef{\subsectionformat}{%
+        \renewcommand{\subsectionformat}{\thesubsection\autodot\enskip}}{}%
+      \ifdef{\subsubsectionformat}{%
+        \renewcommand{\subsubsectionformat}{\thesubsubsection\autodot\enskip}}{}%
+      \ifdef{\paragraphformat}{%
+        \renewcommand{\paragraphformat}{\theparagraph\autodot\enskip}}{}%
+      \ifdef{\subparagraphformat}{%
+        \renewcommand{\subparagraphformat}{\thesubparagraph\autodot\enskip}}{}%
    }{%
       \def\@seccntformat##1{\csname the##1\endcsname\quad}% = LaTeX kernel
    }%
-   \ifcyrillic at numerals\norussian at numbers\fi
+   \ifcyrillic at numerals\norussian at numbers\fi%
    \norussian at shorthands%
 }
 
 \def\blockextras at russian{%
    \russian at capsformat%
-   \ifcyrillic at numerals\russian at numbers\fi
-   \ifrussian at babelshorthands\russian at shorthands\fi
+   \ifcyrillic at numerals\russian at numbers\fi%
+   \ifrussian at babelshorthands\russian at shorthands\fi%
 }
 
 \def\inlineextras at russian{%

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sami.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sami.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sami.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,84 @@
+\ProvidesFile{gloss-sami.ldf}[polyglossia: module for sami]
+
+\PolyglossiaSetup{sami}{
+  babelname=samin,
+  hyphennames={samin},
+  hyphenmins={2,2},
+  language={Northern Sami},
+  langtag=NSM,
+  fontsetup=true,
+}
+
+% TODO: Add other Sami varieties
+\def\sami at variant{northern}
+%\define at choicekey*+{sami}{variant}[\val\nr]{northern}[nothern]{%
+%   \ifcase\nr\relax
+%      % northern:
+%      \def\sami at variant{samin}%
+%      \SetLanguageKeys{sami}{language=Northern Sami,langtag=NSM}%
+%      \xpg at fontsetup@latin{sami}%
+%   \or
+%      % other:
+%      \def\sami at variant{}%
+%      \SetLanguageKeys{sami}{language= Sami,langtag=}%
+%      \xpg at fontsetup@latin{sami}%
+%   \fi
+%   \xpg at info{Option: sami, variant=\val}%
+%}{\xpg at warning{Unknown sami variant `#1'}}
+
+
+%\def\sami at language{%
+%   \polyglossia at setup@language at patterns{\sami at variant}
+%}%
+
+\def\captionssami at northern{%
+   \def\refname{Čujuhusat}%
+   \def\abstractname{Čoahkkáigeassu}%
+   \def\bibname{Girjjálašvuohta}%
+   \def\prefacename{Ovdasátni}%
+   \def\chaptername{Kapihttal}%
+   \def\appendixname{Čuovus}%
+   \def\contentsname{Sisdoallu}%
+   \def\listfigurename{Govvosat}%
+   \def\listtablename{Tabeallat}%
+   \def\indexname{Registtar}%
+   \def\figurename{Govus}%
+   \def\tablename{Tabealla}%
+   \def\thepart{}%
+   \def\partname{Oassi}%
+   \def\pagename{Siidu}%
+   \def\seename{geahča}%
+   \def\alsoname{geahča maiddái}%
+   \def\enclname{Mielddus}%
+   \def\ccname{Kopia sáddejuvvon}%
+   \def\headtoname{Vuostáiváldi}%
+   \def\proofname{Duođaštus}%
+   \def\glossaryname{Sátnelistu}%
+}
+
+\def\captionssami{%
+  \csname captionssami@\sami at variant\endcsname%
+}
+
+\def\datesami at northern{%
+  \def\today{\ifcase\month\or
+    ođđajagemánu\or
+    guovvamánu\or
+    njukčamánu\or
+    cuoŋománu\or
+    miessemánu\or
+    geassemánu\or
+    suoidnemánu\or
+    borgemánu\or
+    čakčamánu\or
+    golggotmánu\or
+    skábmamánu\or
+    juovlamánu\fi
+    \space\number\day.~b.\space\number\year}%
+}
+
+\def\datesami{%
+  \csname datesami@\sami at variant\endcsname%
+}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sami.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-samin.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-samin.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-samin.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,50 +1,19 @@
 \ProvidesFile{gloss-samin.ldf}[polyglossia: module for samin]
 
+% We only provide this gloss for babel compatibility. Since samin is 
+% a sami variety, we use 'sami' with variant 'northern' now.
+
+\input{gloss-sami.ldf}
+
 \PolyglossiaSetup{samin}{
   hyphennames={samin},
   hyphenmins={2,2},
+  language={Northern Sami},
+  langtag=NSM,
   fontsetup=true,
 }
 
-\def\captionssamin{%
-   \def\refname{Čujuhusat}%
-   \def\abstractname{Čoahkkáigeassu}%
-   \def\bibname{Girjjálašvuohta}%
-   \def\prefacename{Ovdasátni}%
-   \def\chaptername{Kapihttal}%
-   \def\appendixname{Čuovus}%
-   \def\contentsname{Sisdoallu}%
-   \def\listfigurename{Govvosat}%
-   \def\listtablename{Tabeallat}%
-   \def\indexname{Registtar}%
-   \def\figurename{Govus}%
-   \def\tablename{Tabealla}%
-   \def\thepart{}%
-   \def\partname{Oassi}%
-   \def\pagename{Siidu}%
-   \def\seename{geahča}%
-   \def\alsoname{geahča maiddái}%
-   \def\enclname{Mielddus}%
-   \def\ccname{Kopia sáddejuvvon}%
-   \def\headtoname{Vuostáiváldi}%
-   \def\proofname{Duođaštus}%
-   \def\glossaryname{Sátnelistu}%
-   }
-\def\datesamin{%
-  \def\today{\ifcase\month\or
-    ođđajagemánu\or
-    guovvamánu\or
-    njukčamánu\or
-    cuoŋománu\or
-    miessemánu\or
-    geassemánu\or
-    suoidnemánu\or
-    borgemánu\or
-    čakčamánu\or
-    golggotmánu\or
-    skábmamánu\or
-    juovlamánu\fi
-    \space\number\day.~b.\space\number\year}%
-  }
+\let\captionssamin\captionssami at nothern
+\let\datesamin\datesami at nothern
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sanskrit.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sanskrit.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sanskrit.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,4 +1,11 @@
 \ProvidesFile{gloss-sanskrit.ldf}[polyglossia: module for sanskrit]
+\ifluatex
+  \xpg at warning{Sanskrit is not supported with LuaTeX.\MessageBreak
+I will proceed with the compilation, but\MessageBreak
+the output is not guaranteed to be correct\MessageBreak
+and may look very wrong.}
+\fi
+
 \RequirePackage{devanagaridigits}
 
 \PolyglossiaSetup{sanskrit}{
@@ -7,11 +14,10 @@
   hyphenmins={1,3},
   frenchspacing=true,
   fontsetup=false, % will be done below
-  %TODO localnumber=sanskritnumber
+  localnumeral=sanskritnumerals
 }
 
 \define at key{sanskrit}{Script}[Devanagari]{%
-  \setkeys[xpg at setup]{sanskrit}{script=#1}%
   \ifcsdef{fontsetup at sanskrit@#1}%
     {\csname fontsetup at sanskrit@#1\endcsname}%
     {\xpg at error{`#1' is not a valid script for Sanskrit}%
@@ -19,65 +25,82 @@
 }
 
 \def\fontsetup at sanskrit@Devanagari{%
-  \def\xpg at scripttag@sanskrit{deva}%
+  \SetLanguageKeys{sanskrit}{scripttag=deva,script=Devanagari}
   \xpg at fontsetup@nonlatin{sanskrit}}
 \def\fontsetup at sanskrit@Gujarati{%
-  \def\xpg at scripttag@sanskrit{gujr}%
+  \SetLanguageKeys{sanskrit}{scripttag=gujr,script=Gujarati}
   \xpg at fontsetup@nonlatin{sanskrit}}
 \def\fontsetup at sanskrit@Malayalam{%
-  \def\xpg at scripttag@sanskrit{mlym}%
+  \SetLanguageKeys{sanskrit}{scripttag=mlym,script=Malayalam}
   \xpg at fontsetup@nonlatin{sanskrit}}
 \def\fontsetup at sanskrit@Bengali{%
-  \def\xpg at scripttag@sanskrit{beng}%
+  \SetLanguageKeys{sanskrit}{scripttag=beng,script=Bengali}
   \xpg at fontsetup@nonlatin{sanskrit}}
 \def\fontsetup at sanskrit@Kannada{%
-  \def\xpg at scripttag@sanskrit{knda}%
+  \SetLanguageKeys{sanskrit}{scripttag=knda,script=Kannada}
   \xpg at fontsetup@nonlatin{sanskrit}}
 \def\fontsetup at sanskrit@Telugu{%
-  \def\xpg at scripttag@sanskrit{telu}%
+  \SetLanguageKeys{sanskrit}{scripttag=telu,script=Telugu}
   \xpg at fontsetup@nonlatin{sanskrit}}
-%% DW
 \def\fontsetup at sanskrit@Latin{%
-    \def\xpg at scripttag@sanskrit{latn}%
-    \xpg at fontsetup@latin{sanskrit}}
-%% DW
+  \SetLanguageKeys{sanskrit}{scripttag=latn,script=Latin}
+  \xpg at fontsetup@latin{sanskrit}}
 
 \setkeys{sanskrit}{Script} %sets the default for Devanagari
 
-%% TODO option for numerals (Devanagari or Western)
-%\def\tmp at western{Western}
-%\newif\ifsanskrit at devanagari@numerals
-%\sanskrit at devanagari@numeralstrue
-%
-%\define at key{sanskrit}{numerals}[Devanagari]{%
-%  \def\@tmpa{#1}%
-%  \ifx\@tmpa\tmp at western
-%    \sanskrit at devanagari@numeralsfalse
-%  \fi}
+\def\tmp at western{Western}
+\newif\ifsanskrit at devanagari@numerals
+\sanskrit at devanagari@numeralstrue
 
-\newXeTeXintercharclass\sanskrit at punctthin % ! ? ; : danda double_danda
+\define at key{sanskrit}{numerals}[Devanagari]{%
+  \def\@tmpa{#1}%
+  \ifx\@tmpa\tmp at western
+    \sanskrit at devanagari@numeralsfalse
+  \fi%
+}
 
+\newcommand{\sanskritnumerals}[2]{\sanskritnumber{#2}}
+
+\def\sanskritnumber#1{%
+  \ifsanskrit at devanagari@numerals
+    \devanagaridigits{\number#1}%
+  \else
+    \number#1%
+  \fi%
+}
+
+% FIXME: Support LuaTeX
+\ifxetex
+  \newXeTeXintercharclass\sanskrit at punctthin % ! ? ; : danda double_danda
+\fi
+
 \def\sanskrit at punctthinspace{{\unskip\thinspace}}
 
 \def\sanskrit at punctuation{%
-  \XeTeXinterchartokenstate=1%
-  \XeTeXcharclass `\! \sanskrit at punctthin
-  \XeTeXcharclass `\? \sanskrit at punctthin
-  \XeTeXcharclass `\; \sanskrit at punctthin
-  \XeTeXcharclass `\: \sanskrit at punctthin
-  \XeTeXcharclass `\। \sanskrit at punctthin
-  \XeTeXcharclass `\॥ \sanskrit at punctthin
-  \XeTeXinterchartoks \z@ \sanskrit at punctthin = \sanskrit at punctthinspace
+  % FIXME: Support LuaTeX
+  \ifxetex
+    \XeTeXinterchartokenstate=1%
+    \XeTeXcharclass `\! \sanskrit at punctthin
+    \XeTeXcharclass `\? \sanskrit at punctthin
+    \XeTeXcharclass `\; \sanskrit at punctthin
+    \XeTeXcharclass `\: \sanskrit at punctthin
+    \XeTeXcharclass `\। \sanskrit at punctthin
+    \XeTeXcharclass `\॥ \sanskrit at punctthin
+    \XeTeXinterchartoks \z@ \sanskrit at punctthin = \sanskrit at punctthinspace
+  \fi
 }
 
 \def\nosanskrit at punctuation{%
-  \XeTeXcharclass `\! \z@
-  \XeTeXcharclass `\? \z@
-  \XeTeXcharclass `\; \z@
-  \XeTeXcharclass `\: \z@
-  \XeTeXcharclass `\। \z@
-  \XeTeXcharclass `\॥ \z@
-  \XeTeXinterchartokenstate=0%
+  % FIXME: Support LuaTeX
+  \ifxetex
+    \XeTeXcharclass `\! \z@
+    \XeTeXcharclass `\? \z@
+    \XeTeXcharclass `\; \z@
+    \XeTeXcharclass `\: \z@
+    \XeTeXcharclass `\। \z@
+    \XeTeXcharclass `\॥ \z@
+    \XeTeXinterchartokenstate=0%
+  \fi
 }
 
 \def\noextras at sanskrit{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-scottish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-scottish.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-scottish.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,44 +1,18 @@
 \ProvidesFile{gloss-scottish.ldf}[polyglossia: module for scottish]
 
+% We only provide this gloss for babel compatibility. Since scottish is 
+% a gaelic variety, we use 'gaelic' with variant 'scottish' now.
+
+\input{gloss-gaelic.ldf}
+
 \PolyglossiaSetup{scottish}{
   hyphennames={scottish},
   hyphenmins={2,2},
+  langtag=GAE,
   fontsetup=true,
 }
 
-\def\captionsscottish{%
-   \def\refname{Iomraidh}%
-   \def\abstractname{Brìgh}%
-   \def\bibname{Leabhraichean}%
-   \def\prefacename{Preface}%    <-- needs translation
-   \def\chaptername{Caibideil}%
-   \def\appendixname{Ath-sgr`ıobhadh}%
-   \def\contentsname{Clàr-obrach}%
-   \def\listfigurename{Liosta Dhealbh}%
-   \def\listtablename{Liosta Chlàr}%
-   \def\indexname{Clàr-innse}%
-   \def\figurename{Dealbh}%
-   \def\tablename{Clàr}%
-   %\def\thepart{}%
-   \def\partname{Cuid}%
-   \def\pagename{t.d.}%
-   \def\seename{see}%    <-- needs translation
-   \def\alsoname{see also}%    <-- needs translation
-   \def\enclname{a-staigh}%
-   \def\ccname{lethbhreac gu}%
-   \def\headtoname{gu}%
-   \def\proofname{Proof}%    <-- needs translation 
-   \def\glossaryname{Glossary}%    <-- needs translation
-   }
+\let\captionsscottish\captionsgaelic at scottish
+\let\datescottish\dategaelic at scottish
 
-\def\datescottish{%
-   \def\today{%
-    \number\day\space \ifcase\month\or
-    am Faoilteach\or an Gearran\or am Màrt\or an Giblean\or
-    an Cèitean\or an t-Òg mhios\or an t-Iuchar\or
-    Lùnasdal\or an Sultuine\or an Dàmhar\or
-    an t-Samhainn\or an Dubhlachd\fi
-    \space \number\year}%
-    }
-
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-serbian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-serbian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-serbian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -4,29 +4,33 @@
 %% same thing for all languages that have a "script" key !
 %% BETTER APPROACH: see gloss-sanskrit!
 
+\RequirePackage{cyrillicnumbers}
+
 \PolyglossiaSetup{serbian}{
   langtag=SRB,
   hyphennames={serbian},
   hyphenmins={2,2},
   indentfirst=true,
-  fontsetup=false
+  fontsetup=false,
+  localnumeral=serbiannumerals,
+  Localnumeral=Serbiannumerals
   %TODO localalph
 }
 
 \newif\if at serbian@cyr
 
-\define at key{serbian}{Script}[Cyrillic]{% TODO FIXDOC: keyname is CHANGED: script -> Script !!!
+\define at key{serbian}{Script}[Cyrillic]{%
   \ifstrequal{#1}{Cyrillic}%
     {\@serbian at cyrtrue
-     \setkeys[xpg at setup]{serbian}{script=Cyrillic}%
-     \def\xpg at scripttag@serbian{cyrl}%
+     \SetLanguageKeys{serbian}{scripttag=cyrl,script=Cyrillic,babelname=serbianc}
      \xpg at fontsetup@nonlatin{serbian}%
     }%
     {\ifstrequal{#1}{Latin}%
       {\@serbian at cyrfalse
-      \xpg at fontsetup@latin{serbian}%
-      %TODO \def\serbian at language{\language=\l at serbianlat}%
-      % or should we use Croatian patterns as a fallback for the time being???
+       \SetLanguageKeys{serbian}{scripttag=latn,script=Latin}
+       \xpg at fontsetup@latin{serbian}%
+       %TODO \def\serbian at language{\language=\l at serbianlat}%
+       % or should we use Croatian patterns as a fallback for the time being???
       }%
       {\xpg at error{Unknown script `#1' for Serbian language\MessageBreak
       Valid values are "Cyrillic" and "Latin"}}%
@@ -34,15 +38,24 @@
 }
 \define at key{serbian}{script}[Cyrillic]{\setkeys{serbian}{Script=#1}}
 
-\setkeys{serbian}{Script}
+\newif\ifserbian at numerals
+\define at key{serbian}{numerals}[arabic]{%
+   \ifstrequal{#1}{latin}{\serbian at numeralsfalse}{%
+       \ifstrequal{#1}{cyrillic}%
+          {\serbian at numeralstrue}
+          {\serbian at numeralsfalse}%
+   }%
+}
 
+\setkeys{serbian}{Script,numerals}
+
 \def\captionsserbian{%
    \if at serbian@cyr\captionsserbian at cyr\else\captionsserbian at lat\fi
-   }
+}
 
 \def\dateserbian{%
    \if at serbian@cyr\dateserbian at cyr\else\dateserbian at lat\fi
-   }
+}
 
 \def\captionsserbian at lat{%
    \def\refname{Bibliografija}%
@@ -71,13 +84,14 @@
    \def\headtoname{Prima}%
    \def\proofname{Dokaz}%
    \def\glossaryname{Rečnik nepoznatih reči}%
-   }
+}
+
 \def\dateserbian at lat{%
    \def\today{\number\day .~\ifcase\month\or
     januar\or februar\or mart\or april\or maj\or
     jun\or jul\or avgust\or septembar\or oktobar\or novembar\or
     decembar\fi \space \number\year.}%
-    }
+}
 
 \def\captionsserbian at cyr{%
    \def\refname{Библиографија}%
@@ -105,15 +119,84 @@
    \def\headtoname{Прима}%
    \def\proofname{Доказ}%
    \def\glossaryname{Речник непознатих речи}%
-   }
+}
+
 \def\dateserbian at cyr{%
    \def\today{\number\day .~\ifcase\month\or
     јануар\or фебруар\or март\or април\or мај\or
     јун\or јул\or август\or септембар\or октобар\or новембар\or
     децембар\fi \space \number\year.}%
-    }
+}
 
+
+\newcommand{\serbiannumerals}[2]{\serbiannumber{#2}}
+\newcommand{\Serbiannumerals}[2]{\Serbiannumber{#2}}
+
+\def\serbiannumber#1{%
+  \ifserbian at numerals
+    \cyr at alph{#1}%
+  \else
+    \number#1%
+  \fi
+}
+
+\def\Serbiannumber#1{%
+  \ifserbian at numerals
+    \cyr at Alph{#1}%
+  \else
+    \number#1%
+  \fi
+}
+
+\let\serbiannumeral=\serbiannumber
+\let\Serbiannumeral=\Serbiannumber
+
+\def\serbian at numbers{%
+   \let\latin at alph\@alph
+   \let\latin at Alph\@Alph
+   \ifserbian at numerals
+     \def\serbian at alph##1{\expandafter\serbiannumeral\expandafter{\the##1}}%
+     \def\serbian at Alph##1{\expandafter\Serbiannumeral\expandafter{\the##1}}%
+      \let\@alph\serbian at alph%
+      \let\@Alph\serbian at Alph%
+   \fi
+}
+
+\def\noserbian at numbers{%
+   \let\@alph\latin at alph
+   \let\@Alph\latin at Alph
+}
+
+\def\blockextras at serbian{%
+   \ifserbian at numerals\serbian at numbers\fi
+}
+ 
+\def\noextras at serbian{%
+   \ifserbian at numerals\noserbian at numbers\fi
+}
+
+\def\Asbuk#1{\expandafter\cyr at Alph\csname c@#1\endcsname}
+
+\def\asbuk#1{\expandafter\cyr at alph\csname c@#1\endcsname}
+
+% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
+% thus ends at 30. We now use proper cyrillic numbering.
+
+%\def\cyr at 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 Ч\or Џ\or Ш\else\xpg at ill@value{#1}{cyr at Alph}\fi}
+
+%\def\cyr at 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 ч\or џ\or ш\else\xpg at ill@value{#1}{cyr at alph}\fi}
+
+ 
 \endinput
+
 % TODO ? stuff from babel
 
 \def\sh{\mathop{\operator at font sh}\nolimits} % same as \sinh
@@ -132,4 +215,3 @@
 \def\Expect{\mathop{\mathsf E\hskip0pt}\nolimits}
 \def\Variance{\mathop{\mathsf D\hskip0pt}\nolimits}
 
-

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovak.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovak.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovak.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -3,6 +3,7 @@
 \PolyglossiaSetup{slovak}{
   hyphennames={slovak},
   hyphenmins={2,2},
+  langtag=SKY,
   fontsetup=true,
 }
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovenian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovenian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovenian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,7 +2,9 @@
 
 \PolyglossiaSetup{slovenian}{
   hyphennames={slovenian,slovene},
+  babelname=slovene,
   hyphenmins={2,2},
+  langtag=SLV,
   fontsetup=true,
 }
 
@@ -60,10 +62,10 @@
 \def\Abeceda#1{\expandafter\slovenian at Alph\csname c@#1\endcsname}
 
 \def\setlocalalph{%
-  \def\extras at slovenian{\let\savealph\alph\let\saveAlph\Alph\let\alph\abeceda\let\Alph\Abeceda}
+  \def\extras at slovenian{\let\alph\abeceda\let\Alph\Abeceda}
   \def\blockextras at slovenian{\extras at slovenian}
   \def\inlineextras at slovenian{\extras at slovenian}
-  \def\noextras at slovenian{\let\alph\savealph\let\Alph\saveAlph}
+  \def\noextras at slovenian{\let\alph\latinalph\let\Alph\latinAlph}
 }
 
 \endinput

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sorbian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sorbian.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sorbian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,166 @@
+\ProvidesFile{gloss-sorbian.ldf}[polyglossia: module for sorbian]
+
+\PolyglossiaSetup{sorbian}{
+  language=Upper Sorbian,
+  babelname=uppersorbian,
+  hyphennames={usorbian,uppersorbian},
+  langtag=USB,
+  hyphenmins={2,2},
+  fontsetup=true,
+}
+
+\def\sorbian at variant{usorbian}
+\define at choicekey*+{sorbian}{variant}[\val\nr]{upper,lower}[upper]{%
+   \ifcase\nr\relax
+      % upper:
+      \def\sorbian at variant{usorbian}%
+      \SetLanguageKeys{sorbian}{language=Upper Sorbian,langtag=USB,babelname=uppersorbian}%
+      \xpg at fontsetup@latin{sorbian}%
+      % Check if \l at usorbian is defined. If not, try to set it to some variety
+      % (specific order as in the csv list below), or null language if everything fails
+      \xpg at ifdefined{usorbian}{}{%
+        \def\do##1{%
+            \xpg at ifdefined{##1}%
+              {\csletcs{l at usorbian}{l@##1}\listbreak}%
+              {}%
+        }%
+        \docsvlist{uppersorbian}
+        \xpg at ifdefined{usorbian}{}{%
+                 \xpg at warning{No hyphenation patterns for Upper Sorbian found\MessageBreak
+                              I will use the 'null' language instead}%
+                 \adddialect\l at usorbian0%
+        }
+      }%
+   \or
+      % lower:
+      \def\sorbian at variant{lsorbian}%
+      \SetLanguageKeys{sorbian}{language=Lower Sorbian,langtag=LSB,babelname=lowersorbian}%
+      \xpg at fontsetup@latin{sorbian}%
+      % Check if \l at lsorbian is defined. If not, try to set it to some variety
+      % (specific order as in the csv list below), or null language if everything fails
+      \xpg at ifdefined{lsorbian}{}{%
+        \def\do##1{%
+           \xpg at ifdefined{##1}%
+              {\csletcs{l at lsorbian}{l@##1}\listbreak}%
+              {}%
+        }%
+        \docsvlist{lowersorbian,Lsorbian,usorbian,uppersorbian}
+        \xpg at ifdefined{lsorbian}{}{%
+                 \xpg at warning{No hyphenation patterns for Lower Sorbian found\MessageBreak
+                              I will use the 'null' language instead}%
+                 \adddialect\l at lsorbian0%
+        }
+     }%
+   \fi
+   \xpg at info{Option: sorbian, variant=\val}%
+}{\xpg at warning{Unknown sorbian variant `#1'}}
+
+
+\define at boolkey{sorbian}[sorbian@]{olddate}[true]{}
+
+\setkeys{sorbian}{variant}
+
+
+\def\sorbian at language{%
+   \polyglossia at setup@language at patterns{\sorbian at variant}%
+}%
+
+
+\def\captionssorbian at lsorbian{%
+   \def\refname{Referency}%
+   \def\abstractname{Abstrakt}%
+   \def\bibname{Literatura}%
+   \def\prefacename{Zawod}%
+   \def\chaptername{Kapitl}%
+   \def\appendixname{Dodawki}%
+   \def\contentsname{Wopśimjeśe}%
+   \def\listfigurename{Zapis wobrazow}%
+   \def\listtablename{Zapis tabulkow}%
+   \def\indexname{Indeks}%
+   \def\figurename{Wobraz}%
+   \def\tablename{Tabulka}%
+   %\def\thepart{}%
+   \def\partname{Źěl}%
+   \def\pagename{Strona}%
+   \def\seename{gl.}%
+   \def\alsoname{gl.~teke}%
+   \def\enclname{Pśiłoga}%
+   \def\ccname{CC}%
+   \def\headtoname{Komu}%
+   \def\proofname{Proof}%
+   \def\glossaryname{Glossary}%
+}
+
+\def\captionssorbian at usorbian{%
+   \def\refname{Referency}%
+   \def\abstractname{Abstrakt}%
+   \def\bibname{Literatura}%
+   \def\prefacename{Zawod}%
+   \def\chaptername{Kapitl}%
+   \def\appendixname{Dodawki}%
+   \def\contentsname{Wobsah}%
+   \def\listfigurename{Zapis wobrazow}%
+   \def\listtablename{Zapis tabulkow}%
+   \def\indexname{Indeks}%
+   \def\figurename{Wobraz}%
+   \def\tablename{Tabulka}%
+   %\def\thepart{}%
+   \def\partname{Dźěl}%
+   \def\pagename{Strona}%
+   \def\seename{hl.}%
+   \def\alsoname{hl.~tež}%
+   \def\enclname{Přłoha}%
+   \def\ccname{CC}%
+   \def\headtoname{Komu}%
+   \def\proofname{Proof}% <-- needs translation
+   \def\glossaryname{Glossary}% <-- needs translation
+}%
+
+\def\captionssorbian{%
+  \csname captionssorbian@\sorbian at variant\endcsname%
+}
+
+\def\datesorbian at lsorbian{%
+    \def\oldtoday{%
+      \number\day.~\ifcase\month\or
+      wjelikego rožka\or małego rožka\or nalětnika\or
+      jatšownika\or rožownika\or smažnika\or pražnika\or
+      žnjeńca\or požnjeńca\or winowca\or nazymnika\or 
+      godownika\fi\space \number\year}%
+    \def\today{%
+      \ifsorbian at olddate
+        \oldtoday%
+      \else
+        \number\day.~\ifcase\month\or
+        januara\or februara\or měrca\or apryla\or maja\or
+        junija\or julija\or awgusta\or septembra\or oktobra\or
+        nowembra\or decembra\fi
+        \space \number\year%
+      \fi
+   }%
+}
+
+\def\datesorbian at usorbian{%
+  \def\oldtoday{\number\day.~\ifcase\month\or
+    wulkeho róžka\or małeho róžka\or nalětnika\or
+    jutrownika\or róžownika\or  smažnika\or pražnika\or
+    žnjenca\or požnjenca\or winowca\or nazymnika\or
+    hodownika\fi \space \number\year}%
+  \def\today{%
+    \ifsorbian at olddate
+      \oldtoday%
+    \else
+      \number\day.~\ifcase\month\or
+      januara\or februara\or měrca\or apryla\or meje\or junija\or
+      julija\or awgusta\or septembra\or oktobra\or
+      nowembra\or decembra\fi
+      \space \number\year%
+    \fi
+  }%
+}
+
+\def\datesorbian{%
+  \csname datesorbian@\sorbian at variant\endcsname%
+}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sorbian.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanish.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanish.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -2,6 +2,7 @@
 \PolyglossiaSetup{spanish}{
   hyphennames={spanish},
   hyphenmins={2,2},
+  langtag=ESP,
   frenchspacing=true,
   indentfirst=true,
   fontsetup=true,

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swedish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swedish.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swedish.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -3,6 +3,7 @@
 \PolyglossiaSetup{swedish}{
   hyphennames={swedish},
   hyphenmins={2,2},
+  langtag=SVE,
   frenchspacing=true,
   fontsetup=true,
 }

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-syriac.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-syriac.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-syriac.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -11,9 +11,11 @@
 \PolyglossiaSetup{syriac}{
   script=Syriac,
   scripttag=syrc,
+  langtag=SYR,
   direction=RL,
   hyphennames={syriac,nohyphenation},
   fontsetup=true,
+  localnumeral=syriacnumerals
   %TODO localalph
 }
 
@@ -115,18 +117,31 @@
 
 \def\@syriacnumber#1{%
    \if at eastern@numerals
-     \ifnum\XeTeXcharglyph"0661 > 0%
-     %%% we test for the presence of one of ١٢٣٤٥٦٧٨٩٠ in the Syriac font, 
-     %%% else we try \arabicfont if defined (and give a warning), 
-     %%% else we fall back to the Western numerals.
-       %%\protect\addfontfeature{Mapping=arabicdigits}\number#1}%
-       \protect\arabicdigits{\number#1}%
-     \else%
-       \ifcsdef{arabicfont}%
-         {\protect\arabicdigits{\number#1}%
-          \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: I am using \string\arabicfont instead}}%
-         {\number#1%%% <---changed from \RL{\protect\reset at font\protect\number#1}%
-          \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: since \string\arabicfont is not defined, we'll use Western numerals instead}}%
+      %%% we test for the presence of one of ١٢٣٤٥٦٧٨٩٠ in the Syriac font, 
+      %%% else we try \arabicfont if defined (and give a warning), 
+      %%% else we fall back to the Western numerals.
+      \ifxetex
+         \ifnum\XeTeXcharglyph"0661 > 0%
+           %%\protect\addfontfeature{Mapping=arabicdigits}\number#1}%
+           \protect\arabicdigits{\number#1}%
+         \else%
+           \ifcsdef{arabicfont}%
+	     {\protect\arabicdigits{\number#1}%
+	      \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: I am using \string\arabicfont instead}}%
+	     {\number#1%%% <---changed from \RL{\protect\reset at font\protect\number#1}%
+	      \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: since \string\arabicfont is not defined, we'll use Western numerals instead}}%
+         \fi
+     \else% LuaTeX
+         \expandafter\ifnum\directlua{polyglossia.check_char(0x661)} > 0\relax
+           %%\protect\addfontfeature{Mapping=arabicdigits}\number#1}%
+           \protect\arabicdigits{\number#1}%
+         \else%
+           \ifcsdef{arabicfont}%
+	     {\protect\arabicdigits{\number#1}%
+	      \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: I am using \string\arabicfont instead}}%
+	     {\number#1%%% <---changed from \RL{\protect\reset at font\protect\number#1}%
+	      \xpg at warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs: since \string\arabicfont is not defined, we'll use Western numerals instead}}%
+         \fi
      \fi
    \else
      %%\RL{\protect\reset at font\number#1}%
@@ -134,31 +149,39 @@
    \fi}
 
 \def\syriac at numbers{%
-   \let\@latinalph\@alph%
-   \let\@latinAlph\@Alph%
    \let\@alph\abjadsyriac%
    \let\@Alph\abjadsyriac%
 }
+
 \def\nosyriac at numbers{%
-  \let\@alph\@latinalph%
-  \let\@Alph\@latinAlph%
-  }
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
+}
+
+\newcommand{\syriacnumerals}[2]{\syriacnumber{#2}}
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
 \def\syriac at globalnumbers{%
-  \let\orig at arabic\@arabic%
   \let\@arabic\syriacnumber%
-  \renewcommand\thefootnote{\protect\syriacnumber{\c at footnote}}%
+  \renewcommand\thefootnote{\localnumeral*{footnote}}%
 }
+
 \def\nosyriac at globalnumbers{%
-  \let\@arabic\orig at arabic%
-  \renewcommand\thefootnote{\protect\number{\c at footnote}}%
-  }
+  \let\@arabic\xpg at save@arabic%
+}
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at syriac{%
-   \let\@@MakeUppercase\MakeUppercase%
    \def\MakeUppercase##1{##1}%
-   }
+}
+
 \def\noextras at syriac{%
-   \let\MakeUppercase\@@MakeUppercase%
-   }
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase%
+}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-thai.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-thai.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-thai.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -17,8 +17,10 @@
 \PolyglossiaSetup{thai}{
   script=Thai,
   scripttag=thai,
+  langtag=THA,
   hyphennames={nohyphenation},
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=thainumerals
   %TODO localalph={xxx at alph,xxx at Alph}
   %TODO localdigits=thainumber
 }
@@ -84,6 +86,8 @@
   \fi
 }
 
+\newcommand{\thainumerals}[2]{\thainumber{#2}}
+
 \def\thainumber#1{%
   \if at thai@numerals
     \thaidigits{\number#1}%
@@ -106,8 +110,6 @@
      ศ\or ษ\or ส\or ห\or ฬ\or อ\or ฮ\else\xpg at ill@value{#1}{@thaialph}\fi}
      
 \def\thai at numbers{%
-   \let\@latinalph\@alph%
-   \let\@latinAlph\@Alph%
    \if at thai@numerals
      \let\@alph\@thaialph%
      \let\@Alph\@thaiAlph%
@@ -114,18 +116,17 @@
    \fi
 }
 \def\nothai at numbers{%
-  \let\@alph\@latinalph%
-  \let\@Alph\@latinAlph%
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
 }
 
 \def\thai at globalnumbers{%
    \let\orig at arabic\@arabic%
    \let\@arabic\thainumber%
-   \renewcommand{\thefootnote}{\protect\thainumber{\c at footnote}}%
+   \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
 }
 \def\nothai at globalnumbers{%
    \let\@arabic\orig at arabic%
-   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
 }
 
 \def\blockextras at thai{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-tibetan.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-tibetan.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-tibetan.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -8,10 +8,11 @@
 \PolyglossiaSetup{tibetan}{
   script=Tibetan,
   scripttag=tibt,
+  langtag=TIB,
   hyphennames={nohyphenation},
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=tibetannumerals
   %TODO localalph={xxx at alph,xxx at Alph}
-  %TODO localdigits=tibetannumber
 }
 
 \newif\if at tibetan@numerals
@@ -126,10 +127,10 @@
   \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 ས\or ཧ\or ཨ
  \else\xpg at ill@value{#1}{@tibetanalph}\fi}
-     
+
+\newcommand{\tibetanumerals}[2]{\tibetannumber{#2}}
+
 \def\tibetan at numbers{%
-   \let\@latinalph\@alph%
-   \let\@latinAlph\@Alph%
    \if at tibetan@numerals
      \let\@alph\@tibetanalph%
      \let\@Alph\@tibetanAlph%
@@ -136,19 +137,18 @@
    \fi
 }
 \def\notibetan at numbers{%
-  \let\@alph\@latinalph%
-  \let\@Alph\@latinAlph%
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
 }
 
 \def\tibetan at globalnumbers{%
    \let\xpg at orig@arabic\@arabic%
    \let\@arabic\tibetannumber%
-   \renewcommand{\thefootnote}{\protect\tibetannumber{\c at footnote}}%
+   \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
 }
 
 \def\notibetan at globalnumbers{%
    \let\@arabic\xpg at orig@arabic%
-   \renewcommand\thefootnote{\protect\number{\c at footnote}}%
 }
 
 \def\noextras at tibetan{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ukrainian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ukrainian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ukrainian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -31,8 +31,9 @@
 \fi
 
 \ifcsundef{initiate at active@char}{%
-\input{babelsh.def}%
-\initiate at active@char{"}%
+  \input{babelsh.def}%
+  \initiate at active@char{"}%
+  \shorthandoff{"}%
 }{}
 
 \def\ukrainian at shorthands{%
@@ -151,8 +152,6 @@
    ц\or ч\or ш\or щ\or ю\or я\else\xpg at ill@value{#1}{ukrainian at alph}\fi}
 
 \def\ukrainian at numbers{%
-   \let\latin at Alph\@Alph%
-   \let\latin at alph\@alph%
    \let\@Alph\ukrainian at Alph%
    \let\@alph\ukrainian at alph%
 }

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-urdu.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-urdu.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-urdu.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -16,9 +16,9 @@
   scripttag=arab,
   langtag=URD,
   hyphennames={urdu,nohyphenation},
-  fontsetup=true
+  fontsetup=true,
+  localnumeral=urdunumerals
   %TODO localalph={abjad,abjad}
-  %TODO localnumber=urdunumber
 }
 
 \newif\if at western@numerals
@@ -108,37 +108,41 @@
   \fi}
 
 \def\urdu at numbers{%
-  \let\@latinalph\@alph%
-  \let\@latinAlph\@Alph%
   \let\@alph\abjad%
   \let\@Alph\abjad%
-  }
+}
 
 \def\nourdu at numbers{%
-  \let\@alph\@latinalph%
-  \let\@Alph\@latinAlph%
-  }
+  \let\@alph\latin at alph%
+  \let\@Alph\latin at Alph%
+}
 
+\newcommand{\urdunumerals}[2]{\urdunumber{#2}}
+
+% Store original definition
+\let\xpg at save@arabic\@arabic
+
 \def\urdu at globalnumbers{%
-  \let\orig at arabic\@arabic%
   \let\@arabic\urdunumber%
   % For some reason \thefootnote needs to be set separately:
-  \renewcommand\thefootnote{\protect\urdunumber{\c at footnote}}%
-  }
+  \renewcommand\thefootnote{\localnumeral*{footnote}}%
+}
 
 \def\nourdu at globalnumbers{
-  \let\@arabic\orig at arabic%
-  \renewcommand\thefootnote{\protect\number{\c at footnote}}%
-  }
+  \let\@arabic\xpg at save@arabic%
+}
 
+% Save original \MakeUppercase definition
+\let\xpg at save@MakeUppercase\MakeUppercase
+
 \def\blockextras at urdu{%
-  \let\@@MakeUppercase\MakeUppercase%
   \def\MakeUppercase##1{##1}%
-  }
+}
 
 \def\noextras at urdu{%
-  \let\MakeUppercase\@@MakeUppercase%
-  }
+   % restore original \MakeUppercase definition
+   \let\MakeUppercase\xpg at save@MakeUppercase%
+}
 
 \endinput
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-usorbian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-usorbian.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-usorbian.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,48 +1,20 @@
 \ProvidesFile{gloss-usorbian.ldf}[polyglossia: module for upper sorbian]
 
+% We only provide this gloss for babel compatibility. Since usorbian is 
+% a sorbian variety, we use 'sorbian' with variant 'upper' now.
+
+\input{gloss-sorbian.ldf}
+
 \PolyglossiaSetup{usorbian}{
+  language=Upper Sorbian,
+  babelname=uppersorbian,
   hyphennames={usorbian,uppersorbian},
   hyphenmins={2,2},
+  langtag=USB,
   fontsetup=true,
 }
 
-\def\captionsusorbian{%
-   \def\refname{Referency}%
-   \def\abstractname{Abstrakt}%
-   \def\bibname{Literatura}%
-   \def\prefacename{Zawod}%
-   \def\chaptername{Kapitl}%
-   \def\appendixname{Dodawki}%
-   \def\contentsname{Wobsah}%
-   \def\listfigurename{Zapis wobrazow}%
-   \def\listtablename{Zapis tabulkow}%
-   \def\indexname{Indeks}%
-   \def\figurename{Wobraz}%
-   \def\tablename{Tabulka}%
-   %\def\thepart{}%
-   \def\partname{Dźěl}%
-   \def\pagename{Strona}%
-   \def\seename{hl.}%
-   \def\alsoname{hl.~tež}%
-   \def\enclname{Přłoha}%
-   \def\ccname{CC}%
-   \def\headtoname{Komu}%
-   \def\proofname{Proof}% <-- needs translation
-   \def\glossaryname{Glossary}% <-- needs translation
-   }%
+\let\captionsusorbian\captionssorbian at usorbian
+\let\dateusorbian\datesorbian at usorbian
 
-\def\dateusorbian{%   
-  \def\today{\number\day.~\ifcase\month\or
-    januara\or februara\or měrca\or apryla\or meje\or junija\or
-    julija\or awgusta\or septembra\or oktobra\or
-    nowembra\or decembra\fi
-    \space \number\year}%
-  %TODO implement option olddate:
-    \def\oldtoday{\number\day.~\ifcase\month\or
-    wulkeho róžka\or małeho róžka\or nalětnika\or
-    jutrownika\or róžownika\or  smažnika\or pražnika\or
-    žnjenca\or požnjenca\or winowca\or nazymnika\or
-    hodownika\fi \space \number\year}%
-  }
-
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-welsh.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-welsh.ldf	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-welsh.ldf	2019-10-28 20:58:49 UTC (rev 52555)
@@ -3,6 +3,7 @@
 \PolyglossiaSetup{welsh}{
   hyphennames={welsh},
   hyphenmins={2,3},
+  langtag=WEL,
   fontsetup=true,
 }
 
@@ -66,10 +67,11 @@
     Mai\or Mehefin\or Gorffennaf\or Awst\or
     Medi\or Hydref\or Tachwedd\or Rhagfyr\fi%
     \space\number\year}%
-
   \def\formaltoday{%
-    \expandafter\welsh at article\welsh at ordinal@long\day\space o\space\ifcase\month\or Ionawr\or Chwefror\or Fawrth\or Ebrill\or Fai\or Fehefin\or Orffenaf\or Awst\or Fedi\or Hydref\or Dachwedd\or Ragfyr\fi
+    \expandafter\welsh at article\welsh at ordinal@long\day\space o\space\ifcase\month\or
+    Ionawr\or Chwefror\or Fawrth\or Ebrill\or Fai\or Fehefin\or Orffenaf\or Awst\or
+    Fedi\or Hydref\or Dachwedd\or Ragfyr\fi%
     \space\number\year}%
-  }
+}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/hebrewcal.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/hebrewcal.sty	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/hebrewcal.sty	2019-10-28 20:58:49 UTC (rev 52555)
@@ -5,12 +5,16 @@
 \ifluatex\RequirePackage{luabidi}\else\RequirePackage{bidi}\fi
 
 \newif\if at xpg@hebrewcal at marcheshvan
+\@xpg at hebrewcal@marcheshvanfalse
+
 \DeclareOption{marcheshvan}{\@xpg at hebrewcal@marcheshvantrue}
-\ifx\if at xpg@hebrew at marcheshvan\undefined
-  \newif\if at xpg@hebrew at marcheshvan
-  \@xpg at hebrew@marcheshvanfalse
-\fi
 
+\@ifundefined{if at xpg@hebrew at marcheshvan}{}{%
+  \if at xpg@hebrew at marcheshvan
+     \@xpg at hebrewcal@marcheshvantrue
+  \fi
+}
+
 %% TODO rewrite this on the basis of Reingold & Dershowitz 
 %%      on the model of hijrical (using calc)
 
@@ -66,7 +70,7 @@
         \ifcase#1%
            % nothing for 0
            \or תשרי%
-           \or\if at xpg@hebrewcal at marcheshvan מרחשון\else\if at xpg@hebrew at marcheshvan מרחשון\else חשון\fi\fi%
+           \or\if at xpg@hebrewcal at marcheshvan מרחשון\else חשון\fi%
            \or כסלו%
            \or טבת%
            \or שבט%
@@ -91,8 +95,7 @@
         \ifcase #1%
             % nothing for 0
             \or Tishrei%
-            % \or\if at xpg@hebrewcal at marcheshvan Marcheshvan\else\if at xpg@hebrew at marcheshvan Marcheshvan\else Heshvan\fi\fi%
-            \or\if at xpg@hebrewcal at marcheshvan Marcheshvan\else\if at xpg@hebrew at marcheshvan Marcheshvan\else Heshvan\fi\fi%
+            \or\if at xpg@hebrewcal at marcheshvan Marcheshvan\else Heshvan\fi%
             \or Kislev%
             \or Tebeth%
             \or Shebat%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-frpt.lua
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-frpt.lua	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-frpt.lua	2019-10-28 20:58:49 UTC (rev 52555)
@@ -14,15 +14,15 @@
 
 local insert_node_before = node.insert_before
 local insert_node_after  = node.insert_after
-local remove_node        = nodes.remove
+local remove_node        = node.remove
 local has_attribute      = node.has_attribute
 local node_copy          = node.copy
 local new_node           = node.new
 
+local math_code          = nodecodes.math
 local end_of_math        = node.end_of_math
 if not end_of_math then -- luatex < .76
   local traverse_nodes = node.traverse_id
-  local math_code      = nodecodes.math
   local end_of_math = function (n)
     for n in traverse_nodes(math_code, n.next) do
       return n
@@ -160,10 +160,10 @@
                         if somespace then
                             local somepenalty = somepenalty(prevprev,10000)
                             if somepenalty then
-                                head = remove_node(head,prev,true)
-                                head = remove_node(head,prevprev,true)
+                                head = remove_node(head,prev)
+                                head = remove_node(head,prevprev)
                             else
-                                head = remove_node(head,prev,true)
+                                head = remove_node(head,prev)
                             end
                         end
                         insert_node_before(head,start,get_penalty_node())
@@ -177,13 +177,13 @@
                         if somepenalty then
                             local somespace = somespace(nextnext,true)
                             if somespace then
-                                head = remove_node(head,next,true)
-                                head = remove_node(head,nextnext,true)
+                                head = remove_node(head,next)
+                                head = remove_node(head,nextnext)
                             end
                         else
                             local somespace = somespace(next,true)
                             if somespace then
-                                head = remove_node(head,next,true)
+                                head = remove_node(head,next)
                             end
                         end
                         insert_node_after(head,start,get_kern_node(map[2]*quad))

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-korean.lua
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-korean.lua	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-korean.lua	2019-10-28 20:58:49 UTC (rev 52555)
@@ -0,0 +1,603 @@
+--
+-- polyglossia-korean.lua
+--
+
+local glyph_id = node.id"glyph"
+local hbox_id  = node.id"hlist"
+local vbox_id  = node.id"vlist"
+local glue_id  = node.id"glue"
+local penalty_id = node.id"penalty"
+local disc_id  = node.id"disc"
+
+--
+-- attr_korean: variant = plain (0), classic (1), modern (2)
+--
+local attr_korean = luatexbase.attributes["xpg at attr@korean"]
+local attr_josa   = luatexbase.attributes["xpg at attr@autojosa"]
+
+--
+-- characters after which linebreak is not allowed
+--
+local nobr_after = {
+    [0x28] = 1, -- ( LEFT PARENTHESIS
+    [0x3C] = 1, -- < LESS-THAN SIGN
+    [0x5B] = 1, -- [ LEFT SQUARE BRACKET
+    [0x60] = 1, -- ` GRAVE ACCENT
+    [0x7B] = 1, -- { LEFT CURLY BRACKET
+    [0xAB] = 1, -- « LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
+    [0x2018] = 1, -- ‘ LEFT SINGLE QUOTATION MARK
+    [0x201C] = 1, -- “ LEFT DOUBLE QUOTATION MARK
+    [0x2329] = 1, -- 〈 LEFT-POINTING ANGLE BRACKET
+    [0x3008] = 1, -- 〈 LEFT ANGLE BRACKET
+    [0x300A] = 1, -- 《 LEFT DOUBLE ANGLE BRACKET
+    [0x300C] = 1, -- 「 LEFT CORNER BRACKET
+    [0x300E] = 1, -- 『 LEFT WHITE CORNER BRACKET
+    [0x3010] = 1, -- 【 LEFT BLACK LENTICULAR BRACKET
+    [0x3014] = 1, -- 〔 LEFT TORTOISE SHELL BRACKET
+    [0x3016] = 1, -- 〖 LEFT WHITE LENTICULAR BRACKET
+    [0x3018] = 1, -- 〘 LEFT WHITE TORTOISE SHELL BRACKET
+    [0x301A] = 1, -- 〚 LEFT WHITE SQUARE BRACKET
+    [0x301D] = 1, -- 〝 REVERSED DOUBLE PRIME QUOTATION MARK
+    [0xFE17] = 1, -- ︗ PRESENTATION FORM FOR VERTICAL LEFT WHITE LENTICULAR BRACKET
+    [0xFE35] = 1, -- ︵ PRESENTATION FORM FOR VERTICAL LEFT PARENTHESIS
+    [0xFE37] = 1, -- ︷ PRESENTATION FORM FOR VERTICAL LEFT CURLY BRACKET
+    [0xFE39] = 1, -- ︹ PRESENTATION FORM FOR VERTICAL LEFT TORTOISE SHELL BRACKET
+    [0xFE3B] = 1, -- ︻ PRESENTATION FORM FOR VERTICAL LEFT BLACK LENTICULAR BRACKET
+    [0xFE3D] = 1, -- ︽ PRESENTATION FORM FOR VERTICAL LEFT DOUBLE ANGLE BRACKET
+    [0xFE3F] = 1, -- ︿ PRESENTATION FORM FOR VERTICAL LEFT ANGLE BRACKET
+    [0xFE41] = 1, -- ﹁ PRESENTATION FORM FOR VERTICAL LEFT CORNER BRACKET
+    [0xFE43] = 1, -- ﹃ PRESENTATION FORM FOR VERTICAL LEFT WHITE CORNER BRACKET
+    [0xFE47] = 1, -- ﹇ PRESENTATION FORM FOR VERTICAL LEFT SQUARE BRACKET
+    [0xFE59] = 1, -- ﹙ SMALL LEFT PARENTHESIS
+    [0xFE5B] = 1, -- ﹛ SMALL LEFT CURLY BRACKET
+    [0xFE5D] = 1, -- ﹝ SMALL LEFT TORTOISE SHELL BRACKET
+    [0xFF08] = 1, -- ( FULLWIDTH LEFT PARENTHESIS
+    [0xFF3B] = 1, -- [ FULLWIDTH LEFT SQUARE BRACKET
+    [0xFF5B] = 1, -- { FULLWIDTH LEFT CURLY BRACKET
+    [0xFF5F] = 1, -- ⦅ FULLWIDTH LEFT WHITE PARENTHESIS
+    [0xFF62] = 1, -- 「 HALFWIDTH LEFT CORNER BRACKET
+}
+
+--
+-- characters before which linebreak is not allowed
+--   (currently, not much differences among the followings)
+--   1: normal chars
+--   2: hangul jamo vowels and trailing consonants
+--   3: kana small letters
+--   0: dashes (supress visible spacing)
+--
+local nobr_before = setmetatable({
+    [0x21] = 1, -- ! EXCLAMATION MARK
+    [0x22] = 1, -- " QUOTATION MARK
+    [0x27] = 1, -- ' APOSTROPHE
+    [0x29] = 1, -- ) RIGHT PARENTHESIS
+    [0x2C] = 1, -- , COMMA
+    [0x2D] = 0, -- - HYPHEN-MINUS
+    [0x2E] = 1, -- . FULL STOP
+    [0x2F] = 0, -- / SOLIDUS
+    [0x3A] = 0, -- : COLON
+    [0x3B] = 1, -- ; SEMICOLON
+    [0x3E] = 1, -- > GREATER-THAN SIGN
+    [0x3F] = 1, -- ? QUESTION MARK
+    [0x5C] = 0, -- \ REVERSE SOLIDUS
+    [0x5D] = 1, -- ] RIGHT SQUARE BRACKET
+    [0x7D] = 1, -- } RIGHT CURLY BRACKET
+    [0x7E] = 0, -- ~ TILDE
+    [0xB7] = 1, -- · MIDDLE DOT
+    [0xBB] = 1, -- » RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
+    [0x2013] = 0, -- – EN DASH
+    [0x2014] = 0, -- — EM DASH
+    [0x2015] = 1, -- ― HORIZONTAL BAR
+    [0x2019] = 1, -- ’ RIGHT SINGLE QUOTATION MARK
+    [0x201D] = 1, -- ” RIGHT DOUBLE QUOTATION MARK
+    [0x2025] = 1, -- ‥ TWO DOT LEADER
+    [0x2026] = 1, -- … HORIZONTAL ELLIPSIS
+    [0x232A] = 1, -- 〉 RIGHT-POINTING ANGLE BRACKET
+    [0x3001] = 1, -- 、 IDEOGRAPHIC COMMA
+    [0x3002] = 1, -- 。 IDEOGRAPHIC FULL STOP
+    [0x3005] = 1, -- 々 IDEOGRAPHIC ITERATION MARK
+    [0x3009] = 1, -- 〉 RIGHT ANGLE BRACKET
+    [0x300B] = 1, -- 》 RIGHT DOUBLE ANGLE BRACKET
+    [0x300D] = 1, -- 」 RIGHT CORNER BRACKET
+    [0x300F] = 1, -- 』 RIGHT WHITE CORNER BRACKET
+    [0x3011] = 1, -- 】 RIGHT BLACK LENTICULAR BRACKET
+    [0x3015] = 1, -- 〕 RIGHT TORTOISE SHELL BRACKET
+    [0x3017] = 1, -- 〗 RIGHT WHITE LENTICULAR BRACKET
+    [0x3019] = 1, -- 〙 RIGHT WHITE TORTOISE SHELL BRACKET
+    [0x301B] = 1, -- 〛 RIGHT WHITE SQUARE BRACKET
+    [0x301C] = 1, -- 〜 WAVE DASH
+    [0x301E] = 1, -- 〞 DOUBLE PRIME QUOTATION MARK
+    [0x301F] = 1, -- 〟 LOW DOUBLE PRIME QUOTATION MARK
+    [0x3035] = 1, -- 〵 VERTICAL KANA REPEAT MARK LOWER HALF
+    [0x303B] = 1, -- 〻 VERTICAL IDEOGRAPHIC ITERATION MARK
+    [0x303C] = 1, -- 〼 MASU MARK
+    [0x3041] = 3, -- ぁ HIRAGANA LETTER SMALL A
+    [0x3043] = 3, -- ぃ HIRAGANA LETTER SMALL I
+    [0x3045] = 3, -- ぅ HIRAGANA LETTER SMALL U
+    [0x3047] = 3, -- ぇ HIRAGANA LETTER SMALL E
+    [0x3049] = 3, -- ぉ HIRAGANA LETTER SMALL O
+    [0x3063] = 3, -- っ HIRAGANA LETTER SMALL TU
+    [0x3083] = 3, -- ゃ HIRAGANA LETTER SMALL YA
+    [0x3085] = 3, -- ゅ HIRAGANA LETTER SMALL YU
+    [0x3087] = 3, -- ょ HIRAGANA LETTER SMALL YO
+    [0x308E] = 3, -- ゎ HIRAGANA LETTER SMALL WA
+    [0x3095] = 3, -- ゕ HIRAGANA LETTER SMALL KA
+    [0x3096] = 3, -- ゖ HIRAGANA LETTER SMALL KE
+    [0x3099] = 1, --  COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
+    [0x309A] = 1, --  COMBINING KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
+    [0x309B] = 1, -- ゛ KATAKANA-HIRAGANA VOICED SOUND MARK
+    [0x309C] = 1, -- ゜ KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
+    [0x309D] = 1, -- ゝ HIRAGANA ITERATION MARK
+    [0x309E] = 1, -- ゞ HIRAGANA VOICED ITERATION MARK
+    [0x30A0] = 1, -- ゠ KATAKANA-HIRAGANA DOUBLE HYPHEN
+    [0x30A1] = 3, -- ァ KATAKANA LETTER SMALL A
+    [0x30A3] = 3, -- ィ KATAKANA LETTER SMALL I
+    [0x30A5] = 3, -- ゥ KATAKANA LETTER SMALL U
+    [0x30A7] = 3, -- ェ KATAKANA LETTER SMALL E
+    [0x30A9] = 3, -- ォ KATAKANA LETTER SMALL O
+    [0x30C3] = 3, -- ッ KATAKANA LETTER SMALL TU
+    [0x30E3] = 3, -- ャ KATAKANA LETTER SMALL YA
+    [0x30E5] = 3, -- ュ KATAKANA LETTER SMALL YU
+    [0x30E7] = 3, -- ョ KATAKANA LETTER SMALL YO
+    [0x30EE] = 3, -- ヮ KATAKANA LETTER SMALL WA
+    [0x30F5] = 3, -- ヵ KATAKANA LETTER SMALL KA
+    [0x30F6] = 3, -- ヶ KATAKANA LETTER SMALL KE
+    [0x30FB] = 1, -- ・ KATAKANA MIDDLE DOT
+    [0x30FC] = 1, -- ー KATAKANA-HIRAGANA PROLONGED SOUND MARK
+    [0x30FD] = 1, -- ヽ KATAKANA ITERATION MARK
+    [0x30FE] = 1, -- ヾ KATAKANA VOICED ITERATION MARK
+    [0xFE30] = 1, -- ︰ PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
+    [0xFE31] = 1, -- ︱ PRESENTATION FORM FOR VERTICAL EM DASH
+    [0xFE32] = 1, -- ︲ PRESENTATION FORM FOR VERTICAL EN DASH
+    [0xFE36] = 1, -- ︶ PRESENTATION FORM FOR VERTICAL RIGHT PARENTHESIS
+    [0xFE38] = 1, -- ︸ PRESENTATION FORM FOR VERTICAL RIGHT CURLY BRACKET
+    [0xFE3A] = 1, -- ︺ PRESENTATION FORM FOR VERTICAL RIGHT TORTOISE SHELL BRACKET
+    [0xFE3C] = 1, -- ︼ PRESENTATION FORM FOR VERTICAL RIGHT BLACK LENTICULAR BRACKET
+    [0xFE3E] = 1, -- ︾ PRESENTATION FORM FOR VERTICAL RIGHT DOUBLE ANGLE BRACKET
+    [0xFE40] = 1, -- ﹀ PRESENTATION FORM FOR VERTICAL RIGHT ANGLE BRACKET
+    [0xFE42] = 1, -- ﹂ PRESENTATION FORM FOR VERTICAL RIGHT CORNER BRACKET
+    [0xFE44] = 1, -- ﹄ PRESENTATION FORM FOR VERTICAL RIGHT WHITE CORNER BRACKET
+    [0xFE48] = 1, -- ﹈ PRESENTATION FORM FOR VERTICAL RIGHT SQUARE BRACKET
+    [0xFE5A] = 1, -- ﹚ SMALL RIGHT PARENTHESIS
+    [0xFE5C] = 1, -- ﹜ SMALL RIGHT CURLY BRACKET
+    [0xFE5E] = 1, -- ﹞ SMALL RIGHT TORTOISE SHELL BRACKET
+    [0xFF01] = 1, -- ! FULLWIDTH EXCLAMATION MARK
+    [0xFF09] = 1, -- ) FULLWIDTH RIGHT PARENTHESIS
+    [0xFF0C] = 1, -- , FULLWIDTH COMMA
+    [0xFF0E] = 1, -- . FULLWIDTH FULL STOP
+    [0xFF1A] = 1, -- : FULLWIDTH COLON
+    [0xFF1B] = 1, -- ; FULLWIDTH SEMICOLON
+    [0xFF1F] = 1, -- ? FULLWIDTH QUESTION MARK
+    [0xFF3D] = 1, -- ] FULLWIDTH RIGHT SQUARE BRACKET
+    [0xFF5D] = 1, -- } FULLWIDTH RIGHT CURLY BRACKET
+    [0xFF60] = 1, -- ⦆ FULLWIDTH RIGHT WHITE PARENTHESIS
+    [0xFF61] = 1, -- 。 HALFWIDTH IDEOGRAPHIC FULL STOP
+    [0xFF63] = 1, -- 」 HALFWIDTH RIGHT CORNER BRACKET
+    [0xFF64] = 1, -- 、 HALFWIDTH IDEOGRAPHIC COMMA
+    [0xFF65] = 1, -- ・ HALFWIDTH KATAKANA MIDDLE DOT
+    [0xFF9E] = 1, -- ゙ HALFWIDTH KATAKANA VOICED SOUND MARK
+    [0xFF9F] = 1, -- ゚ HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK
+}, { __index = function(_,c)
+        if c >= 0x1160  and c <= 0x11FF  then return 2 end
+        if c >= 0xD7B0  and c <= 0xD7FF  then return 2 end
+        if c >= 0x302A  and c <= 0x302F  then return 1 end
+        if c >= 0x31F0  and c <= 0x31FF  then return 3 end
+        if c >= 0xFF67  and c <= 0xFF70  then return 3 end
+        if c >= 0xFE00  and c <= 0xFE0F  then return 1 end
+        if c >= 0xFE10  and c <= 0xFE19 and not (c == 0xFE17) then return 1 end
+        if c >= 0xFE50  and c <= 0xFE58  then return 1 end
+        if c >= 0xE0100 and c <= 0xE01EF then return 1 end
+    end
+})
+
+--
+-- whether 'c' is a cjk character
+--
+local function is_cjk (c)
+    return c >= 0xAC00  and c <= 0xD7FF
+    or     c >= 0x1100  and c <= 0x11FF
+    or     c >= 0xA960  and c <= 0xA97F
+    or     c >= 0x2E80  and c <= 0x9FFF
+    or     c >= 0xF900  and c <= 0xFAFF
+    or     c >= 0xFE10  and c <= 0xFE1F
+    or     c >= 0xFE30  and c <= 0xFE6F
+    or     c >= 0xFF00  and c <= 0xFFEF
+    or     c >= 0x1F100 and c <= 0x1F2FF
+    or     c >= 0x20000 and c <= 0x2FA1F
+    or     nobr_after[c]  and c > 0x2014
+    or     nobr_before[c] and c > 0x2014
+end
+
+--
+-- classify cjk characters
+--   1: openings
+--   2: closings
+--   3: centered chars
+--   4: full stops
+--   5: ellipses
+--   6: exclamation and question marks
+--   0: all others
+--
+local charclass = setmetatable({
+    [0x2018] = 1, [0x201C] = 1, [0x2329] = 1, [0x3008] = 1,
+    [0x300A] = 1, [0x300C] = 1, [0x300E] = 1, [0x3010] = 1,
+    [0x3014] = 1, [0x3016] = 1, [0x3018] = 1, [0x301A] = 1,
+    [0x301D] = 1, [0xFE17] = 1, [0xFE35] = 1, [0xFE37] = 1,
+    [0xFE39] = 1, [0xFE3B] = 1, [0xFE3D] = 1, [0xFE3F] = 1,
+    [0xFE41] = 1, [0xFE43] = 1, [0xFE47] = 1, [0xFF08] = 1,
+    [0xFF3B] = 1, [0xFF5B] = 1, [0xFF5F] = 1, [0xFF62] = 1,
+    [0x2019] = 2, [0x201D] = 2, [0x232A] = 2, [0x3001] = 2,
+    [0x3009] = 2, [0x300B] = 2, [0x300D] = 2, [0x300F] = 2,
+    [0x3011] = 2, [0x3015] = 2, [0x3017] = 2, [0x3019] = 2,
+    [0x301B] = 2, [0x301E] = 2, [0x301F] = 2, [0xFE10] = 2,
+    [0xFE11] = 2, [0xFE18] = 2, [0xFE36] = 2, [0xFE38] = 2,
+    [0xFE3A] = 2, [0xFE3C] = 2, [0xFE3E] = 2, [0xFE40] = 2,
+    [0xFE42] = 2, [0xFE44] = 2, [0xFE48] = 2, [0xFF09] = 2,
+    [0xFF0C] = 2, [0xFF3D] = 2, [0xFF5D] = 2, [0xFF60] = 2,
+    [0xFF63] = 2, [0xFF64] = 2, [0x00B7] = 3, [0x30FB] = 3,
+    [0xFF1A] = 3, [0xFF1B] = 3, [0xFF65] = 3, [0x3002] = 4,
+    [0xFE12] = 4, [0xFF0E] = 4, [0xFF61] = 4, [0x2015] = 5,
+    [0x2025] = 5, [0x2026] = 5, [0xFE19] = 5, [0xFE30] = 5,
+    [0xFE31] = 5, [0xFE15] = 6, [0xFE16] = 6, [0xFF01] = 6,
+    [0xFF1F] = 6,
+}, { __index = function() return 0 end })
+
+--
+-- table for spacing between char classes
+--   1 stands for 0.5*fontsize when variant=classic
+--
+local intercharclass = { [0] =
+    { [0] = nil,    {1,1},  nil,    {.5,.5} },
+    { [0] = nil,    nil,    nil,    {.5,.5} },
+    { [0] = {1,1},  {1,1},  nil,    {.5,.5}, nil,    {1,1},  {1,1} },
+    { [0] = {.5,.5},{.5,.5},{.5,.5},{1,.5},  {.5,.5},{.5,.5},{.5,.5} },
+    { [0] = {1,0},  {1,0},  nil,    {1.5,.5},nil,    {1,0},  {1,0} },
+    { [0] = nil,    {1,1},  nil,    {.5,.5} },
+    { [0] = {1,1},  {1,1},  nil,    {.5,.5} },
+}
+
+--
+-- get a new penalty node
+--
+local function get_new_penalty (p)
+    local penalty = node.new("penalty")
+    penalty.penalty = p
+    return penalty
+end
+
+--
+-- get a new glue node
+--
+local function get_new_glue (...)
+    local glue = node.new("glue")
+    node.setglue(glue, ...)
+    return glue
+end
+
+--
+-- return 0.5*fontsize of given fontid
+--   space: true if variant=modern; then 0.5*interword_space
+--
+local function get_font_size (fid, space)
+    local size = font.getparameters(fid)
+    if space then
+        size = size and size.space or 196608
+    else
+        size = size and size.quad  or 655360
+    end
+    return size/2
+end
+
+--
+-- charclass 1 thru 4 will be packed in \hbox to 0.5em{\hss? curr \hss?}
+--   when variant=classic/modern
+--
+local function glyph_to_box (head, curr, class)
+    local g, h = curr
+    local size = get_font_size(g.font)
+    head, curr = node.remove(head, curr)
+    g.next, g.prev = nil, nil
+    local hss = get_new_glue(0, 65536, 65536, 2, 2)
+    if class == 1 then
+        h, hss.next, g.prev = hss, g, hss
+    elseif class == 2 or class == 4 then
+        h, g.next, hss.prev = g, hss, g
+    else
+        local hss2 = node.copy(hss)
+        h, hss.next, g.prev, g.next, hss2.prev = hss, g, hss, hss2, g
+    end
+    h = nodes.simple_font_handler(h)
+    local box = node.hpack(h, size, "exactly")
+    if curr then
+        head, curr = node.insert_before(head, curr, box)
+    else
+        head, curr = node.insert_after(head, node.tail(head), box)
+    end
+    return head, curr
+end
+
+--
+-- insert spacing defined as charclass[a][b] between a and b
+--   f:    fontid
+--   var:  variant = plain, classic, modern
+--   cc:   charclass of current char
+--   nc:   charclass of next char
+--   nobr: linebreak is not allowed
+--
+local function insert_cjk_penalty_glue (head, curr, f, var, cc, nc, nobr)
+    if nobr or cc == 1 or nc > 1 then
+        local penalty = get_new_penalty(10000)
+        head, curr = node.insert_after(head, curr, penalty)
+    end
+    local factor = get_font_size(f, var == 2)
+    local t = intercharclass[cc][nc]
+    local glue = get_new_glue(t[1]*factor, nil, t[2]*factor)
+    head, curr = node.insert_after(head, curr, glue)
+    return head, curr
+end
+
+--
+-- insert inter-character spacing in other normal cases
+--   f:   fontid
+--   var: variant = plain, classic, modern
+--   x:   true between cjk and non-cjk (a little more spacing)
+--
+local function insert_penalty_glue (head, curr, f, var, x)
+    if var ~= 1 then
+        local penalty = get_new_penalty(50)
+        head, curr = node.insert_after(head, curr, penalty)
+    end
+    local size, glue = get_font_size(f, x and var == 2)
+    if x then
+        glue = get_new_glue(size/2, size/4, size/8)
+    else
+        glue = get_new_glue(0, size/10, size/50)
+    end
+    head, curr = node.insert_after(head, curr, glue)
+    return head, curr
+end
+
+--
+-- main process for linebreak and inter-character spacing
+--   lb: true if pre_linebreak_filter
+--
+local function korean_break (head, lb)
+    local curr = head
+    while curr do
+        if curr.id == glyph_id then
+            local var = node.has_attribute(curr, attr_korean)
+            if var then
+                local c, f = curr.char or 0, curr.font or 0
+                local cc, cjkc = charclass[c], is_cjk(c)
+
+                -- compress cjk punctuations when charclass is 1 thru 4
+                if var > 0 and cc > 0 and cc < 5 then
+                    head, curr = glyph_to_box(head, curr, cc)
+                end
+
+                local next = curr.next
+                if next and next.id == glyph_id then
+                    local n = next.char or 0
+                    local nc = charclass[n]
+                    local nobr = nobr_before[n] or nobr_after[c]
+
+                    -- insert spacing as of intercharclass
+                    if var > 0 and intercharclass[cc][nc] then
+                        head, curr = insert_cjk_penalty_glue(head, curr, f, var, cc, nc, nobr)
+
+                    -- or insert spacing when linebreak is allowed
+                    elseif not nobr then
+                        local cjkn = is_cjk(n)
+
+                        -- if curr or next is cjk char
+                        if cjkc or cjkn then
+
+                            -- if between cjk and non-cjk
+                            if var > 0 and not (cjkc and cjkn) and nobr_before[c] ~= 0 then
+                                head, curr = insert_penalty_glue(head, curr, f, var, true)
+
+                            -- or under pre_linebreak_filter
+                            elseif lb then
+                                head, curr = insert_penalty_glue(head, curr, f, var)
+                            end
+                        end
+                    end
+                end
+            end
+        end
+        curr = curr.next
+    end
+    return head
+end
+
+--
+-- process for reordering hangul tone marks (U+302E, U+302F)
+--   some hangul fonts (eg. Noto CJK) are so designed that hangul tone marks
+--   should be moved to the first position of a syllable.
+--   Currently, this functionality is not provided by luaotfload.
+--
+local function reorder_tm (head)
+    local curr, tone = node.slide(head)
+    while curr do
+        if curr.id == glyph_id and node.has_attribute(curr, attr_korean) then
+            local c, wd = curr.char or 0, curr.width or 0
+            if (c == 0x302E or c == 0x302F) and wd > 0 then
+                tone = curr
+            elseif tone and not nobr_before[c] then
+                head = node.remove(head, tone)
+                tone.next, tone.prev = nil, nil
+                head, curr = node.insert_before(head, curr, tone)
+                tone = nil
+            end
+        end
+        curr = curr.prev
+    end
+    return head
+end
+
+--
+-- automatic josa selection
+--
+local josa_table = {
+    --          consonant ㄹ, vowel,  other consonants
+    [0xAC00] = {0xC774,       0xAC00, 0xC774}, -- 가 => 이, 가, 이
+    [0xC740] = {0xC740,       0xB294, 0xC740}, -- 은 => 은, 는, 은
+    [0xC744] = {0xC744,       0xB97C, 0xC744}, -- 을 => 을, 를, 을
+    [0xC640] = {0xACFC,       0xC640, 0xACFC}, -- 와 => 과, 와, 과
+    [0xC73C] = {nil,          nil,    0xC73C}, -- 으(로) =>   ,  , 으
+    [0xC774] = {0xC774,       nil,    0xC774}, -- 이(라) => 이,  , 이
+}
+
+--
+-- helper function for number-like characters
+--
+local function josa_char_num (t, c)
+    c = c % 10 + 0x30
+    return t[c] or 2
+end
+
+--
+-- decide josa selection
+--
+local josa_code = setmetatable({
+    [0x30] = 3, [0x31] = 1, [0x33] = 3, [0x36] = 3, [0x37] = 1,
+    [0x38] = 1, [0x4C] = 1, [0x4D] = 3, [0x4E] = 3, [0x6C] = 1,
+    [0x6D] = 3, [0x6E] = 3, [0xFB02] = 1, [0xFB04] = 1,
+},{ __index = function(t,c)
+        if c >= 0xAC00 and c <= 0xD7A3 then
+            c = (c - 0xAC00) % 28 + 0x11A7
+        end
+        if c >= 0x11A8 and c <= 0x11FF then
+            if c == 0x11AF then return 1 end
+            return 3
+        end
+        if c >= 0xD7CB and c <= 0xD7FB then return 3 end
+        if c >= 0x2170 and c <= 0x217F then c = c - 0x10 end
+        if c >= 0x2160 and c <= 0x216F then
+            if c >= 0x216C then return 3 end
+            return josa_char_num(t, c - 0x215F)
+        end
+        if c >= 0x2460 and c <= 0x2473 then return josa_char_num(t, c - 0x245F) end
+        if c >= 0x2474 and c <= 0x2487 then return josa_char_num(t, c - 0x2473) end
+        if c >= 0x2488 and c <= 0x249B then return josa_char_num(t, c - 0x2487) end
+        if c >= 0x249C and c <= 0x24B5 then return t[c - 0x249C + 0x61] or 2 end
+        if c >= 0x24B6 and c <= 0x24CF then return t[c - 0x24B6 + 0x61] or 2 end
+        if c >= 0x24D0 and c <= 0x24E9 then return t[c - 0x24D0 + 0x61] or 2 end
+        if c >= 0x3131 and c <= 0x318E then
+            if c == 0x3139 then return 1 end
+            if c >= 0x314F and c <= 0x3163 or c >= 0x3187 then return 2 end
+            return 3
+        end
+        if c >= 0x3260 and c <= 0x327E then c = c - 0x60 end
+        if c >= 0x3200 and c <= 0x321E then
+            if c == 0x3203 then return 1 end
+            if c >= 0x320E then return 2 end
+            return 3
+        end
+        if c >= 0xFF10 and c <= 0xFF19 then return josa_char_num(t, c - 0xFF10) end
+        if c >= 0xFF21 and c <= 0xFF3A then return t[c - 0xFF21 + 0x61] or 2 end
+        if c >= 0xFF41 and c <= 0xFF5A then return t[c - 0xFF41 + 0x61] or 2 end
+        return 2
+    end
+})
+
+--
+-- obtain char that comes just before the josa
+--
+local function get_prev_char (p)
+    while p do
+        if p.id == glyph_id then
+            local pc = p.char or 0
+            if not nobr_after[pc] then
+                if not nobr_before[pc] or nobr_before[pc] >= 2 then
+                    return pc
+                end
+            end
+        elseif p.id == hbox_id or p.id == vbox_id then
+            local pc = get_prev_char(node.slide(p.head))
+            if pc then return pc end
+        end
+        p = p.prev
+    end
+end
+
+--
+-- main process of josa selection
+--
+local function auto_josa (head)
+    local curr, tofree = head, {}
+    while curr do
+        if curr.id == glyph_id then
+            local josa = node.has_attribute(curr, attr_josa)
+            if josa then
+                local cc = curr.char or 0
+                if josa == 0 then
+                    josa = josa_code[get_prev_char(curr.prev) or 0x30]
+                end
+                if cc == 0xC774 then
+                    local n = curr.next
+                    if n and n.char and n.char >= 0xAC00 and n.char <= 0xD7A3 then
+                    else
+                        cc = 0xAC00
+                    end
+                end
+                local new = josa_table[cc]
+                if new then
+                    cc = new[josa]
+                    if cc then
+                        curr.char = cc
+                    else
+                        head = node.remove(head, curr)
+                        table.insert(tofree, curr)
+                    end
+                end
+                node.unset_attribute(curr, attr_josa)
+            end
+        end
+        curr = curr.next
+    end
+    for _,v in ipairs(tofree) do node.free(v) end
+    return head
+end
+
+--
+-- now register to luatex callbacks
+--   As char value of glyphs can be changed by opentype GSUB process,
+--   we have to occupy the first position among callback functions.
+--
+local prepend_to_callback
+if luatexbase.base_add_to_callback then
+    prepend_to_callback = function(name, func, desc)
+        luatexbase.add_to_callback(name, func, desc, 1)
+    end
+else
+    prepend_to_callback = function(name, func, desc)
+        local t = { {func, desc} }
+        for _,v in ipairs(luatexbase.callback_descriptions(name)) do
+            table.insert(t, {luatexbase.remove_from_callback(name, v)})
+        end
+        for _,v in ipairs(t) do
+            luatexbase.add_to_callback(name, v[1], v[2])
+        end
+    end
+end
+
+prepend_to_callback ("pre_linebreak_filter",
+    function(head)
+        head = auto_josa(head)
+        head = korean_break(head, true)
+        head = reorder_tm(head)
+        return head
+    end,
+    "polyglossia.lang_korean")
+
+prepend_to_callback ("hpack_filter",
+    function(head)
+        head = auto_josa(head)
+        head = korean_break(head)
+        head = reorder_tm(head)
+        return head
+    end,
+    "polyglossia.lang_korean")
+
+-- vim:ft=lua:tw=0:sw=4:ts=4:expandtab


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-korean.lua
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.lua
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.lua	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.lua	2019-10-28 20:58:49 UTC (rev 52555)
@@ -26,12 +26,11 @@
 polyglossia = polyglossia or {}
 local polyglossia = polyglossia
 
-local current_language
-local last_language
-local default_language
+-- predefined l at nohyphenation or dummy new language
+local nohyphid = luatexbase.registernumber'l at nohyphenation' or lang.id(lang.new())
+-- key `nohyphenation` is for .sty file when possibly undefined l at nohyphenation
+local newloader_loaded_languages = { nohyphenation = nohyphid }
 
-polyglossia.newloader_loaded_languages = { }
-polyglossia.newloader_max_langid = 0
 local newloader_available_languages = dofile(kpse.find_file('language.dat.lua'))
 -- Suggestion by Dohyun Kim on #129
 local t = { }
@@ -51,8 +50,7 @@
 
 local function select_language(lang, id)
   loadlang(lang, id)
-  current_language = lang
-  last_language = lang
+  polyglossia.current_language = lang
 end
 
 local function set_default_language(lang, id)
@@ -59,18 +57,6 @@
   polyglossia.default_language = lang
 end
 
-local function falsefun()
-  return false
-end
-
-local function disable_hyphenation()
-  luatexbase.add_to_callback("hyphenate", falsefun, "polyglossia.disable_hyphenation")
-end
-
-local function enable_hyphenation()
-  luatexbase.remove_from_callback("hyphenate", "polyglossia.disable_hyphenation")
-end
-
 local check_char
 
 if luaotfload and luaotfload.aux and luaotfload.aux.font_has_glyph then
@@ -106,9 +92,12 @@
     require('polyglossia-tibt')
 end
 
+-- LaTeX's language register is \count19
+local lang_register = 19
+
 -- New hyphenation pattern loader: use language.dat.lua directly and the language identifiers
 local function newloader(langentry)
-    loaded_language = polyglossia.newloader_loaded_languages[langentry]
+    local loaded_language = newloader_loaded_languages[langentry]
     if loaded_language then
         log_info('Language ' .. langentry .. ' already loaded; id is ' .. lang.id(loaded_language))
         -- texio.write_nl('term and log', 'Language ' .. langentry .. ' already loaded with patterns ' .. tostring(loaded_language) .. '; id is ' .. lang.id(loaded_language))
@@ -115,7 +104,7 @@
         -- texio.write_nl('term and log', 'Language ' .. langentry .. ' already loaded with patterns ' .. loaded_language['patterns'] .. '; id is ' .. lang.id(loaded_language))
         return lang.id(loaded_language)
     else
-        langdata = newloader_available_languages[langentry]
+        local langdata = newloader_available_languages[langentry]
         if langdata and langdata['special'] == 'language0' then return 0 end
 
         if langdata then
@@ -123,35 +112,59 @@
             for k, v in pairs(langdata) do
 				s = s .. "\n" .. k .. "\t" .. tostring(v)
             end
-            polyglossia.newloader_max_langid = polyglossia.newloader_max_langid + 1
-            -- langobject = lang.new(newloader_max_langid)
-            lang.new(); lang.new(); lang.new()
-            langobject = lang.new()
+
+            --
+            -- LaTeX's \newlanguage increases language register (count19),
+            -- whereas LuaTeX's lang.new() increases its own language id.
+            -- So when a user has declared, say, \newlanguage\lang at xyz, then
+            -- these two numbers do not match each other. If we do not consider
+            -- this possible situation, our newloader() function will
+            -- unfortunately overwrite the language \lang at xyz.
+            --
+            -- Threfore here we will compare LaTeX's \newlanguage number with
+            -- LuaTeX's lang.new() id and select the bigger one for our new
+            -- language object. Also we will update LaTeX's language register
+            -- by this new id, so that another possible \newlanguage should not
+            -- overwrite our language object.
+            --
+            -- get next \newlanguage allocation number
+            local langcnt = tex.count[lang_register] + 1
+            -- get new lang object
+            local langobject = lang.new()
+            local langid = lang.id(langobject)
+            -- get bigger one between \newlanguage and new lang obj id
+            local maxlangid = math.max(langcnt, langid)
+            -- set language register for possible \newlanguage
+            tex.setcount('global', lang_register, maxlangid)
+            -- get new lang object if needeed
+            if langid ~= maxlangid then
+              langobject = lang.new(maxlangid)
+            end
 			s = s .. "\npatterns: " .. langdata.patterns
 			log_info(s)
             if langdata.patterns and langdata.patterns ~= '' then
-                pattfilepath = kpse.find_file(langdata.patterns)
+                local pattfilepath = kpse.find_file(langdata.patterns)
                 if pattfilepath then
-                    pattfile = io.open(pattfilepath)
+                    local pattfile = io.open(pattfilepath)
                     lang.patterns(langobject, pattfile:read('*all'))
                     pattfile:close()
                 end
             end
             if langdata.hyphenation and langdata.hyphenation ~= '' then
-                hyphfilepath = kpse.find_file(langdata.hyphenation)
+                local hyphfilepath = kpse.find_file(langdata.hyphenation)
                 if hyphfilepath then
-                    hyphfile = io.open(hyphfilepath)
+                    local hyphfile = io.open(hyphfilepath)
                     lang.hyphenation(langobject, hyphfile:read('*all'))
                     hyphfile:close()
                 end
             end
-            polyglossia.newloader_loaded_languages[langentry] = langobject
+            newloader_loaded_languages[langentry] = langobject
 
             log_info('Language ' .. langentry .. ' was not yet loaded; created with id ' .. lang.id(langobject))
             return lang.id(langobject)
         else
             log_warning('Language ' .. langentry .. ' not found in language.dat.lua')
-            return 255
+            return nohyphid
         end
     end
 end
@@ -159,11 +172,11 @@
 polyglossia.loadlang = loadlang
 polyglossia.select_language = select_language
 polyglossia.set_default_language = set_default_language
-polyglossia.current_language = current_language -- doesn't seem to be working well :-(
-polyglossia.default_language = default_language
 polyglossia.check_char = check_char
 polyglossia.load_frpt = load_frpt
 polyglossia.load_tibt_eol = load_tibt_eol
-polyglossia.disable_hyphenation = disable_hyphenation
-polyglossia.enable_hyphenation = enable_hyphenation
 polyglossia.newloader = newloader
+polyglossia.newloader_loaded_languages = newloader_loaded_languages
+-- global variables:
+-- polyglossia.default_language
+-- polyglossia.current_language

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,5 +1,5 @@
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{polyglossia}[2019/04/04 v1.44
+\ProvidesPackage{polyglossia}[2019/10/27 v1.45
   Alternative to Babel for XeLaTeX and LuaLaTeX]
 \RequirePackage{etoolbox}
 \RequirePackage{makecmds}
@@ -12,6 +12,17 @@
 \RequirePackage{ifluatex}
 % For symmetry with ifluatex
 \RequirePackage{ifxetex}
+\RequirePackage{expl3}
+\RequirePackage{l3keys2e}
+\RequirePackage{xparse}
+\RequirePackage{filehook}
+
+% correct a bug in tracklang
+\AtBeginOfPackageFile*{tracklang}{
+  \@ifpackagelater{tracklang}{2019/08/30}{}{\global\def\AddTrackedLangage{\AddTrackedLanguage}}
+}
+
+
 % fontspec now uses LaTeX3 packages such as expl3, so we need this:
 \ExplSyntaxOn
 
@@ -18,7 +29,7 @@
 %% This is for compatibility with Babel-aware package:
 \cslet{ver at babel.sty}{\@empty} % this "fakes" babel
 \def\languageshorthands#1{\relax} %this is for scrlttr2 class
-\AtEndPreamble{\let\bbl at set@language\xpg at set@language} %for biblatex
+\AtEndPreamble{\let\bbl at set@language\xpg at set@language at aux} %for biblatex
 \AtEndPreamble{\let\bbl at main@language\xpg at main@language} %for biblatex
 
 \ifluatex
@@ -32,9 +43,40 @@
   {\let\xpg at boundaryclass=\e at alloc@intercharclass at top}
 
 % Useful for getting list of loaded languages and variants. Like babel's bbl at loaded
-\let\xpg at loaded\@empty
-\let\xpg at vloaded\@empty
+\let\xpg at loaded\@empty% list of loaded languages (polyglossia name)
+\let\xpg at vloaded\@empty% list of loaded variants
+\let\xpg at bloaded\@empty% list of loaded languages (babel name)
 
+% counter in latin
+\def\latinalph#1{\expandafter\latin at alph\csname c@#1\endcsname}
+\def\latinAlph#1{\expandafter\latin at Alph\csname c@#1\endcsname}
+
+% select language hook
+\cs_new_nopar:Nn \polyglossia at AtBeginDocument@selectlanguage: {}
+% \disablehyphenation hook
+\cs_new_nopar:Nn \polyglossia at AtBeginDocument@hyphenation: {}
+
+% hook to be executed at begin of document
+\cs_new_nopar:Nn \polyglossia at AtBeginDocument: {
+  % save various command
+  \let\latin at alph\@alph   % TODO rename when we have the C locale
+  \let\latin at Alph\@Alph   % TODO rename when we have the C locale
+  % push to C language gloss
+  \let\polyglossia at Clang@@arabic\@arabic
+  \let\polyglossia at Clang@arabic\arabic
+  
+  \xpg at initial@setup
+  % apply \familydefault changes
+  \xpg at set@familydefault
+  % now we have the C locale definition: select the language
+  \polyglossia at AtBeginDocument@selectlanguage:
+  % If hyphenation disabling has been requested in preamble, do it now
+  \polyglossia at AtBeginDocument@hyphenation:
+}
+\AtBeginDocument{
+  \polyglossia at AtBeginDocument:
+}
+
 %% custom message macros
 \providecommand*{\xpg at error}[1]{%
    \PackageError{polyglossia}{#1}{}%
@@ -64,6 +106,24 @@
 \def\xpg at ill@value#1#2{%
   \xpg at warning{Illegal~ value~ (#1)~ for~ #2}}
 
+% error out if lang is not loaded
+\cs_new_nopar:Nn \polyglossia at error@iflangnotloaded:n
+{
+  \cs_if_exist:cF{#1 at loaded}
+  {
+    \xpg at error{language~ #1~ is~ not~ loaded.~ Please~ load~ it~ before~ using~ it.}
+  }
+}
+
+
+% error do not use directly the gloss file
+\msg_new:nnn { polyglossia } { directloadgloss }
+{
+  You~ should~ not~ load~ directly~ the~ gloss~ file~ using~ `\string\usepackage'.
+  You~ must~ use~ `\string\setotherlanguage\{#1\}' or  `\string\setmainlanguage\{#1\}'.
+}
+\msg_redirect_name:nnn { polyglossia } { directloadgloss } { critical }
+
 %% use macro if defined, else warn that it is not
 \def\csuse at warn#1{%
    \ifcsundef{#1}{\xpg at warning{ \expandafter\string\csname #1\endcsname\space is~ not~ defined}}%
@@ -75,86 +135,79 @@
 
 %% Used by the language definitions files for right-to-left languages
 \def\RequireBidi{%
-  \AtBeginDocument{%
-    \ifxetex
-      \RequirePackage{bidi}
-    \else\ifluatex
-      \RequirePackage{luabidi}
-    \else
-      \xpg at warning{You’re running a TeX engine that is not LuaTeX or XeTeX.\MessageBreak
-  That is almost guaranteed to cause problems.}
-    \fi\fi}}
+  \str_case_e:nnF{\c_sys_engine_str}{
+    {luatex}{\ifx\@onlypreamble\@notprerr\else\RequirePackage{luabidi}\fi}
+    {xetex}{\ifx\@onlypreamble\@notprerr\else\RequirePackage{bidi}\fi}
+  }
+  {
+    \xpg at warning{You’re running a TeX engine that is not LuaTeX or XeTeX.\MessageBreak
+      That is almost guaranteed to cause problems.}
+  }
+}
 
+% (lua)bidi commands to change directionality for paragraphs
+% and inline text.
+% overwritten with correct package
+\cs_new_nopar:Nn{\polyglossia at setpardirection:n}{%
+  \str_case_e:nnTF{#1}{%
+       {LR}{\relax}%
+       {RL}{\xpg at error{right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}}%
+     }%
+     {}%
+     {\xpg at error{Unknown~ language~ direction~ #1 ~(base~ wrapper)}}%
+}
+\cs_new_nopar:Nn{\polyglossia at settextdirection:n}{%
+  \str_case_e:nnTF{#1}{%
+       {LR}{\relax}%
+       {RL}{\xpg at error{right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}}%
+     }%
+     {}%
+     {\xpg at error{Unknown~ language~ direction~ #1 ~(base~ wrapper)}}%
+}
+\AtEndOfPackageFile*{bidi}{%
+  \ExplSyntaxOn%
+  \cs_gset_nopar:Nn{\polyglossia at setpardirection:n}{%
+    \str_case_e:nnTF{#1}{%
+        {LR}{\setLR}%
+        {RL}{\setRL}%
+      }%
+      {}%
+      {\xpg at error{Unknown~ language~ direction~ #1 ~(bidi~ wrapper)}}%
+  }%
+  \cs_gset_nopar:Nn{\polyglossia at settextdirection:n}{%
+    \str_case_e:nnTF{#1}{%
+        {LR}{\LRE}%
+        {RL}{\RLE}%
+      }%
+      {}%
+      {\xpg at error{Unknown~ language~ direction~ #1 ~(bidi~ wrapper)}}%
+  }%
+  \ExplSyntaxOff%
+}
+\AtEndOfPackageFile*{luabidi}{%
+  \ExplSyntaxOn%
+  \cs_gset_nopar:Nn{\polyglossia at setpardirection:n}{%
+    \str_case_e:nnTF{#1}{%
+        {LR}{\setLR}%
+        {RL}{\setRL}%
+      }
+      {}%
+      {\xpg at error{Unknown~ language~ direction~ #1 ~(luabidi~ wrapper)}}%
+  }%
+  \cs_gset_nopar:Nn{\polyglossia at settextdirection:n}{%
+    \str_case_e:nnTF{#1}{%
+        {LR}{\LRE}%
+        {RL}{\RLE}%
+      }
+      {}%
+      {\xpg at error{Unknown~ language~ direction~ #1 ~(luabidi~ wrapper)}}%
+  }%
+  \ExplSyntaxOff%
+}
+
 %% compatibility with babel
 \let\addto\gappto% gappto is defined in etoolbox
 
-%% == Utility macros ==
-%%   They are needed because \MakeUppercase and \MakeLowercase are protected,
-%%   but we need to change case while defining csnames when setting up fonts for
-%%   non-Latin scripts. For instance with "Script=Arabic" we need to lowercase
-%%   "Arabic" to create \arabicfont.
-\def\xpg at uppercasefirst#1{\expandafter\xpg@@uppercasefirst #1}
-\def\xpg@@uppercasefirst#1{%
-       \if a#1A\else
-       \if b#1B\else
-       \if c#1C\else
-       \if d#1D\else
-       \if e#1E\else
-       \if f#1F\else
-       \if g#1G\else
-       \if h#1H\else
-       \if i#1I\else
-       \if j#1J\else
-       \if k#1K\else
-       \if l#1L\else
-       \if m#1M\else
-       \if n#1N\else
-       \if o#1O\else
-       \if p#1P\else
-       \if q#1Q\else
-       \if r#1R\else
-       \if s#1S\else
-       \if t#1T\else
-       \if u#1U\else
-       \if v#1V\else
-       \if w#1W\else
-       \if x#1X\else
-       \if y#1Y\else
-       \if z#1Z\else
-       \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
-}
-
-\def\xpg at lowercasefirst#1{\expandafter\xpg@@lowercasefirst #1}
-\def\xpg@@lowercasefirst#1{%
-       \if A#1a\else
-       \if B#1b\else
-       \if C#1c\else
-       \if D#1d\else
-       \if E#1e\else
-       \if F#1f\else
-       \if G#1g\else
-       \if H#1h\else
-       \if I#1i\else
-       \if J#1j\else
-       \if K#1k\else
-       \if L#1l\else
-       \if M#1m\else
-       \if N#1n\else
-       \if O#1o\else
-       \if P#1p\else
-       \if Q#1q\else
-       \if R#1r\else
-       \if S#1s\else
-       \if T#1t\else
-       \if U#1u\else
-       \if V#1v\else
-       \if W#1w\else
-       \if X#1x\else
-       \if Y#1y\else
-       \if Z#1z\else
-       \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
-}
-
 %% NEW EXPERIMENTAL SETUP INTERFACE FOR GLOSS FILES
 %% options currently available:
 %% language : the name of the language (as understood by fontspec)
@@ -161,7 +214,6 @@
 %% hyphennames : the different hyphenation patterns to try (comma separated list)
 %%%   TODO: if pattern is prefixed by !, then it should be loaded as a fallback, with \xpg at nopatterns@fallback - i.e. with a warning: e.g. sanskrit for hindi, or catalan for asturian. – Also for languages with variants!  (English and German, etc.)
 %% script : the name of the script (as understood by fontspec) – default is Latin
-%% direction : the direction of the script: LR or RL
 %% scripttag : the OpenType tag for the script
 %% langtag : the OpenType tag for the language
 %% hyphenmins : the hyphenmins for this language (comma-sep list of two integers)
@@ -170,113 +222,505 @@
 %% fontsetup : boolean
 %% TODO: nouppercase : boolean (for scripts like Arabic, Devanagari, etc which have no concept of uppercase/lowercase)
 %% TODO: localalph = {<alph_csname>,<Alph_csname>}
-%% TODO: localnumber = <csname>
+%% TODO: localnumeral = <csname>
 %%       or even better localdigits = {0123456789} for fully automatic setup
-
 \newif\if at xpg@language at really@defined@
 \newcommand*\PolyglossiaSetup[2]{%
+  \polyglossia at keys_define_lang:n{#1}%
+  \keys_set:nn { polyglossia / #1 } { #2 }%
+  \prop_log:N{\polyglossia at langsetup}
+  \polyglossia_setup_hyphen:n {#1}
   %define booleans etoolbox style and set defaults
   %% TODO ? \providetoggle{#1 at setup@done}%
-  \providetoggle{#1 at RL}%
-  \providetoggle{#1 at latin}\toggletrue{#1 at latin}%
-  \providetoggle{#1 at scriptlangequal}% whether lang and script names are same: e.g. Hebrew, Arabic
-  \providebool{#1 at fontsetup}%
-  \providebool{#1 at indentfirst}%
-  \providebool{#1 at frenchspacing}%
   % we initialize these so that we can use \gappto below
   \csgdef{init at extras@#1}{}%
   \csgdef{init at noextras@#1}{}% we don't use this yet: remove?
-  \csgdef{xpg at langname@#1}{\xpg at uppercasefirst{#1}}%
-  %needed for docsvlist with hyphennames key:
-  \def\do##1{%
-    \xpg at check@ifdefined{#1}
-    \if at xpg@language at really@defined@\else
-      \ifstrequal{#1}{##1}{}%
-      {\xpg at ifdefined{##1}%
-        {\expandafter\ifx\csname l@##1\endcsname\l at nohyphenation\else\csletcs{l@#1}{l@##1}\xpg at set@language at luatex@iv{##1}\fi}%
-        {\csdef{l@##1}{l at nohyphenation}}%
-      }%
-    \fi
-  }%
-  %define all keys:
-  \xpg at define@keys{#1}%
-  \setkeys[xpg at setup]{#1}{#2}%
   % here we do the fontsetup:
-  \ifbool{#1 at fontsetup}%
-    {\xpg at fontsetup@auto{#1}}%
-    {\xpg at info{Skipping~ automatic~ font~ setup~ for~ language~ #1}}%
+  \polyglossia at lang@autosetupfont:n{#1}
   %% TODO? \toggletrue{#1 at setup@done}%
   % reinit \do
   \def\do##1{\setotherlanguage{##1}}%
 }
 
-\def\xpg at first#1,#2{#1}
-\def\xpg at second#1,#2{#2}
+% Adjust language key setting after initial setup
+% This is needed, e.g., for languages with varying script
+\DeclareDocumentCommand \SetLanguageKeys { m m }
+{
+  \clist_map_inline:nn { #1 } { \keys_set:nn { polyglossia / ##1 } { #2 } }
+}
 
-\def\xpg at define@keys#1{%
-  \define at key[xpg at setup]{#1}{script}{%
-    \ifstrequal{##1}{Latin}%
-      {\toggletrue{#1 at latin}}%
-      {\togglefalse{#1 at latin}}%
-    \csgdef{xpg at scriptname@#1}{##1}%
-    \csgdef{xpg at scriptname@#1 at lc}{\xpg at lowercasefirst{##1}}}%
-  \define at key[xpg at setup]{#1}{scripttag}{%
-    \csgdef{xpg at scripttag@#1}{##1}}%
-  \define at key[xpg at setup]{#1}{language}{%
-    \csgdef{xpg at langname@#1}{##1}}%
-  \define at key[xpg at setup]{#1}{langtag}{%
-    \csgdef{xpg at langtag@#1}{##1}}%
-  \define at key[xpg at setup]{#1}{hyphennames}[{#1}]{%
-    \docsvlist{##1}%
-    % if l@#1 does not yet exist,
-    % we assign it to nohyphenation
-    % we do this here in case the hyphennames key was omitted
+
+% setup hyphennames from a str list of hyphen
+\cs_new:Nn \polyglossia_setup_hyphen:n {
+  \exp_args:Nne \clist_set:Nn{\l_tmpa_clist}{\prop_item:Nn \polyglossia at langsetup {#1 / hyphennames}}
+  \providebool{havehyphen}
+  \boolfalse{havehyphen}
+  % for each hyphen in the set until we find one that works
+  \clist_map_inline:Nn \l_tmpa_clist {
+    \ifbool{havehyphen}{}{%
+       % check if language hyphenname is defined
+       \polyglossia at check@ifdefined:NF{#1}{%
+          % if not, first consider nohyphenation
+          \str_if_eq:nnTF{##1}{nohyphenation}
+            {%
+               \cs_gset_eq:cc{l@#1}{l@##1}
+               \global\booltrue{havehyphen}
+            }{%
+               % then test if hyphenation is defined
+               \xpg at ifdefined{##1}{
+                  % test if language hyphenation is nohyphenation
+                  \cs_if_eq:cNF{l@#1}{\l at nohyphenation}{\global\booltrue{havehyphen}}{%
+                      % if false define language to hyphenation if it is not equal...
+                      \str_if_eq:nnF{#1}{##1}{\cs_gset_eq:cc{l@#1}{l@##1}}
+                      % ...and load
+                      \xpg at set@hyphenation at patterns{##1}
+                      \global\booltrue{havehyphen}
+                  }%
+               }{}%
+           }%
+       }%
+    }%
+  }%
+  % if l@#1 does not yet exist,
+  % we assign it to nohyphenation
+  % we do this here in case and if the hyphennames key was omitted
+  \ifbool{havehyphen}{}{%
     \xpg at ifdefined{#1}{}%
-      {\xpg at nopatterns{\csname xpg at langname@#1\endcsname}%
-       \expandafter\adddialect\csname l@#1\endcsname\l at nohyphenation\relax}%
-    \csdef{#1 at language}{%
-      \ifbool{xpg at hyphenation@disabled}{%
-        \xdef\xpg at lastlanguage{\the\csname l@#1\endcsname}%
-      }{%
-        \ifluatex%
-          \xpg at set@language at luatex@iv{#1}%
-        \fi%
-        \language=\csname l@#1\endcsname%
-      }%
+    {
+      \xpg at nopatterns{#1}
+      \expandafter\adddialect\csname l@#1\endcsname\l at nohyphenation\relax
     }%
   }%
-  \define at choicekey+[xpg at setup]{#1}{direction}[\val\nr]{LR,RL}[LR]%
-    {\ifcase\nr\relax
-        \togglefalse{#1 at RL}%
-      \or
-        \toggletrue{#1 at RL}%
-        \ifcsundef{RTL}{\ifluatex\RequirePackage{luabidi}\else\RequirePackage{bidi}\fi}{}% FIXME Use \RequireBidi and remove calls in individual gloss files.
-    \fi}%
-    {\xpg at warning{#1: Invalid value \val\space for key "direction"}}%
-  \define at key[xpg at setup]{#1}{hyphenmins}[{2,3}]%
-    {\begingroup\edef\x{\endgroup
-       \noexpand\setlocalhyphenmins{#1}{\xpg at first##1}{\xpg at second##1}}\x}
-  \define at boolkey[xpg at setup]{#1}[#1@]{frenchspacing}[true]{%
-    \ifbool{#1 at frenchspacing}%
-      {\csgappto{init at extras@#1}{\frenchspacing}}%
-      {\csgappto{init at extras@#1}{\nonfrenchspacing}}}%
-  \define at boolkey[xpg at setup]{#1}[#1@]{indentfirst}[true]{%
-    \ifbool{#1 at indentfirst}%
-      {\csgappto{init at extras@#1}{\french at indent}}%
-      {\csgappto{init at extras@#1}{\nofrench at indent}}}%
-%  \define at choicekey*+[xpg at setup]{#1}{fontsetup}[\val\nr]{none,custom,auto}[none]%
-%    %{\csgdef{#1 at fontsetup}{\val}}%
-%    {\xpg at fontsetup{\val}{#1}}%
-%    {\xpg at warning{Invalid value \val\space for key "fontsetup" in module "#1"}}%
-  \define at boolkey[xpg at setup]{#1}[#1@]{fontsetup}[true]{}%
-  %TODO assign csnames corr. to localized alph and Alph
-  %  \define at key[xpg at setup]{#1}{localalph}[{#1 at alph,#1 at Alph}]{%
-  %  \cslet{xpg at localalph@#1}{\expandafter\csname\xpg at first##1\endcsname}%
-  %  \cslet{xpg at localAlph@#1}{\expandafter\csname\xpg at second##1\endcsname}%
-  %}%
-  %TODO same thing with localdigits
+  \csdef{#1 at language}{%
+    \polyglossia at setup@language at patterns{#1}%
+  }%
+  % setup hypenmins
+  \exp_args:NNe \clist_set:Nn \l_tmpa_clist
+    { \prop_item:Nn \polyglossia at langsetup {#1 / hyphenmins} }
+  \cs_if_eq:cNF {l@#1} \l at nohyphenation
+    {
+      \use:x
+        {
+          \exp_not:N \setlocalhyphenmins {#1}
+            { \clist_item:Nn \l_tmpa_clist {1} }
+            { \clist_item:Nn \l_tmpa_clist {2} }
+        }
+    }
 }
 
+\newcommand*\polyglossia at setup@language at patterns[1]{%
+  \ifbool{xpg at hyphenation@disabled}{%
+    \xdef\xpg at lastlanguage{\the\csname l@#1\endcsname}%
+  }{%
+    % first, test if \l@#1 exists
+    % without that, \csname l@#1\endcsname will be defined as \relax
+    \cs_if_exist:cTF {l@#1}
+      {
+        \cs_if_eq:cNTF {l@#1} \l at nohyphenation
+          {
+            \language=\l at nohyphenation
+          }
+          {
+            \xpg at set@hyphenation at patterns{#1}
+          }
+      }
+      {
+        \xpg at set@hyphenation at patterns{#1}
+      }
+  }
+}
+
+\prop_new:N \polyglossia at langsetup
+
+\cs_new_protected:Npn \polyglossia at keys_define_lang:n #1 {
+  \keys_define:nn {polyglossia}{
+    % the script font
+    #1 / script
+       .code:n = {
+          \prop_gput:Nnn{\polyglossia at langsetup}{#1/script}{##1}
+          \prop_gput:Nnx{\polyglossia at langsetup}{#1/lcscript}
+               {\tl_if_empty:nF{##1}{\str_lower_case:n##1}}
+    },
+    #1 / script
+       .value_required:n = true,
+    #1 / script
+       .initial:n = latin,
+    % the opentype script tag
+    #1 / scripttag
+       .code:n = {\prop_gput:Nnn{\polyglossia at langsetup}{#1/scripttag}{##1}},
+    #1 / scripttag
+       .default:n = {},
+    #1 / scripttag
+      .initial:n = {},
+    % the language full name
+    #1 / language
+       .code:n = {\prop_gput:Nnn{\polyglossia at langsetup}{#1/language}{##1}},
+    #1 / language
+       .value_required:n = true,
+    #1 / language
+        .initial:x = {\str_upper_case:n#1},
+    % the language tag
+    #1 / langtag
+       .code:n = {\prop_gput:Nnn{\polyglossia at langsetup}{#1/langtag}{##1}},
+    #1 / langtag
+       .value_required:n = true,
+    #1 / langtag
+       .initial:n = {},
+    % hyphennames
+    #1 / hyphennames
+    .code:n = {
+      \clist_set:Nn{\l_tmpa_clist}{##1}
+      \prop_gput:Nnx{\polyglossia at langsetup}{#1/hyphennames}{\clist_use:Nn \l_tmpa_clist {,}}
+    },
+    #1 / hyphennames
+       .value_required:n = true,
+    #1 / hyphennames
+      .initial:x = {\c_empty_clist},
+    % direction
+    #1 / direction
+    .  code:n = {
+           \str_case_e:nnTF{##1}{
+             {LR}{}
+             {RL}{\RequireBidi}
+           }
+           {\prop_gput:Nnn{\polyglossia at langsetup}{#1/direction}{##1}}
+           {\xpg at error{Unknown~ direction~ "##1"~ for~ language~ "#1"}}
+       },
+    #1 / direction
+      .value_required:n = true,
+    #1 / direction
+      .initial:n = {LR},
+    % minimal left and right hyphenation minima using
+    #1 / hyphenmins
+    .code:n = {
+      % check syntax
+      \int_compare:nNnF { \clist_count:n {##1} } = {2}
+        {\xpg at error{hypenmins~should~be~a~list~of~two~entries,~got~"##1"}}
+      % set prop
+      \prop_gput:Nnn \polyglossia at langsetup {#1/hyphenmins} {##1}
+    },
+    #1 / hyphenmins
+      .value_required:n = true,
+    #1 / hyphenmins
+     .initial:n = {2,3},
+    % frenchspacing
+    #1 / frenchspacing
+    .code:n = {
+        \str_case_e:nnTF{##1}{
+            {true}{}
+            {false}{}
+          }
+          {}
+          {\xpg at error{frenchspacing~should~be~true~or~false. Is~ "##1"~ for~ language~ "#1"}}
+        \prop_gput:Nnn{\polyglossia at langsetup}{#1/frenchspacing}{##1}
+    },
+    #1 / frenchspacing
+      .default:n = true,
+    #1 / frenchspacing
+      .initial:n = false,
+    % indent first line
+    #1 / indentfirst
+    .code:n = {
+      \str_case_e:nnTF{##1}{
+            {true}{}
+            {false}{}
+          }
+          {}
+          {\xpg at error{indentfirst~should~be~true~or~false. Is~ "##1"~ for~ language "#1"}}
+      \prop_gput:Nnn{\polyglossia at langsetup}{#1/indentfirst}{##1}
+    },
+    #1 / indentfirst
+      .default:n = true,
+    #1 / indentfirst
+      .initial:n = false,
+    % fontsetup
+    #1 / fontsetup
+      .code:n = {
+         \str_case_e:nnTF{##1}{
+            {true}{}
+            {false}{}
+          }
+          {}
+          {\xpg at error{fontsetup~should~be~true~or~false. Is "##1"~ for~ language~ "#1"}}
+       \prop_gput:Nnn{\polyglossia at langsetup}{#1/fontsetup}{##1}
+       },
+    #1 / fontsetup
+      .default:n = true,
+    #1 / fontsetup
+      .initial:n = false,
+    % environment name
+    #1 / envname
+       .code:n = {
+           \prop_gput:Nnn{\polyglossia at langsetup}{#1/envname}{##1}
+       },
+    #1/ envname.value_required:n = true,
+    #1/ envname.initial:n = {#1},
+    % babel name
+    #1 / babelname
+       .code:n = {
+           \prop_gput:Nnn{\polyglossia at langsetup}{#1/babelname}{##1}
+       },
+    #1/ babelname.value_required:n = true,
+    #1/ babelname.initial:n = {#1},
+    % default numerals
+    #1 / localnumeral
+         . code:n =  {
+            \prop_gput:Nnn{\polyglossia at langsetup}{#1/localnumeral}{##1}
+            \prop_gput:Nnn{\polyglossia at langsetup}{#1/Localnumeral}{##1}
+         },
+    #1 / localnumeral.value_required:n = true,
+    #1 / localnumeral.initial:n = {polyglossia at C@localnumeral},
+    % uppercased
+    #1 / Localnumeral
+         . code:n =  {
+            \prop_gput:Nnn{\polyglossia at langsetup}{#1/Localnumeral}{##1}
+         },
+    #1 / Localnumeral.value_required:n = true,
+    #1 / Localnumeral.initial:n = {polyglossia at C@localnumeral}
+  }
+}
+
+% TODO move to C module
+\newcommand*{\polyglossia at C@localnumeral}[2]{
+   \polyglossia at Clang@@arabic{#2}
+}
+
+% print using main language
+% #2 is the numeral to print
+% #3 is the mainlanguage (should be expanded)
+% #4 is the current language (should be expanded)
+% #1 is the option list (should be expanded)
+% #5 is the name of the field to use
+\cs_new:Nn \polyglossia_localnumeral_mainlang:nnnnn {
+  \foreignlanguage{#3}{\use:c {\prop_item:Nn \polyglossia at langsetup  {#3/#5}} {#1} {#2}}
+}
+
+
+% print using local language
+% #2 is the numeral to print
+% #3 is the mainlanguage (should be expanded)
+% #4 is the current language (should be expanded)
+% #1 is the option list (should be expanded)
+% #5 is the name of the field to use
+\cs_new:Nn \polyglossia_localnumeral_locallang:nnnnn {
+  \use:c {\prop_item:Nn \polyglossia at langsetup  {#4/#5}} {#1} {#2}
+}
+
+% this function try to resolve some simple parameter about lang
+% call #2 then branching if found
+% call parameter #3 if not found
+% (use curing)
+\cs_new:Npn \polyglossia_localnumeral_callshortcutorlong:nF #1#2 {
+  \str_case:nnF{#1}{
+    {lang=local}{\polyglossia_localnumeral_locallang:nnnnn}
+  }
+  {#2}
+}
+
+\cs_new:Npn \polyglossia_iii_map_csv_field_split_kv_iii_localnumeral:w  #1 = #2 \q_stop {
+  \str_case:nnF{#2}{
+    {local}  {\clist_map_break:n{\use_i:nn \polyglossia_localnumeral_locallang:nnnnn }}
+    {default}{\clist_map_break:n{\use_i:nn \polyglossia_localnumeral_locallang:nnnnn }}
+    {*}      {\clist_map_break:n{\use_i:nn\polyglossia_localnumeral_mainlang:nnnnn   }}
+    {main}   {\clist_map_break:n{\use_i:nn\polyglossia_localnumeral_mainlang:nnnnn   }}
+  }{
+    \clist_map_break:n{ \use_i_ii:nnn \polyglossia_localnumeral_langlang:nnnnnn {{#2}} }
+  }
+}
+
+
+% call the language
+% #3 is the numeral to print
+% #4 is the mainlanguage (should be expanded)
+% #5 is the current language (should be expanded)
+% #2 is the option list (should be expanded)
+% #6 is the name of the field to use
+% #1 is the language used
+\cs_new:Nn \polyglossia_localnumeral_langlang:nnnnnn {
+   \foreignlanguage{#1}{\use:c {\prop_item:Nn \polyglossia at langsetup  {#1/#6}} {#2} {#3}}
+}
+
+
+% check if empty value
+\cs_new:Npn \polyglossia_iii_map_csv_field_split_kv_ii_localnumeral:w  #1 #2 = #3 \q_stop {
+  \quark_if_no_value:NTF {#3}
+  {
+    \clist_map_break:n{\use_i:nn \polyglossia_localnumeral_locallang:nnnnn}
+  }
+  {
+    \polyglossia_iii_map_csv_field_split_kv_iii_localnumeral:w #1 \q_stop
+  }
+}
+
+\cs_new:Npn \polyglossia_iii_map_csv_field_split_kv_i_localnumeral:nw #1 #2 = #3 \q_stop {
+  % parse only lang tag
+  \tl_trim_spaces_apply:nN {#2} \str_if_eq:nnT {lang}
+  {
+    % if empty value
+    \quark_if_nil:nTF{#3}
+    {
+      \clist_map_break:n{\use_i:nn \polyglossia_localnumeral_locallang:nnnn}
+    }
+    {
+      % here we know what we have an equal sign
+      \polyglossia_iii_map_csv_field_split_kv_ii_localnumeral:w {#1} #1 \q_no_value \q_stop
+    }
+  }
+}
+
+% map function 
+\cs_new:Nn \polyglossia_iii_map_csv_localnumeral:n {
+  % fast case is do nothing is empty 
+  \tl_if_empty:nF{#1}
+  {
+    \polyglossia_iii_map_csv_field_split_kv_i_localnumeral:nw {#1} #1 = \q_nil \q_stop
+  }
+}
+
+
+% treat option is empty and option is lang=local
+% #2 number
+% #3 mainlanguage
+% #4 locallanguage
+% #5 field to call
+% #1 option
+% strip space to option
+\cs_new:Nn \polyglossia_iii_localnumeral:nnnnn {
+  \tl_if_blank:nTF{#1}
+  {
+    \polyglossia_localnumeral_mainlang:nnnnn
+  }
+  {
+    \str_if_eq:nnTF{#1}{lang=local}
+    {
+      \polyglossia_localnumeral_locallang:nnnnn
+    }
+    {
+      % use postscript like trick push to stack {#1} {#2} {#3} {#4}
+      \polyglossia_localnumeral_callshortcutorlong:nF {#1}
+      {
+        % same trick here if found we emit  \use_i:nn
+        % thus discarding the default choice that is not lang specified thus local
+        \clist_map_function:nN {#1} {\polyglossia_iii_map_csv_localnumeral:n}
+        \polyglossia_localnumeral_locallang:nnnnn
+      }
+    }
+    {#1} {#2} {#3} {#4} {#5}
+  }
+}
+
+
+% internal helper useful for oeee and onnn
+% #1 number
+% #2 mainlanguage
+% #3 locallanguage
+% #4 option
+% #5 field to call
+% strip space to option
+\cs_new:Nn \polyglossia_ii_localnumeral:nnnnn {
+  \tl_trim_spaces_apply:nN {#4} \polyglossia_iii_localnumeral:nnnnn {#1}{#2}{#3}{#5}
+}
+\cs_generate_variant:Nn \polyglossia_ii_localnumeral:nnnnn {
+  eeenn, eeeon, eeeen
+}
+
+% convert the counter to value
+% #1 counter
+% #2 mainlanguage
+% #3 locallanguage
+% #4 option
+\cs_new:Nn \polyglossia_i_localnumeral:nnnnn
+{
+  \polyglossia_ii_localnumeral:eeeen {\int_value:w #1} {#2} {#3} {#4} {#5}
+}
+
+% print number usage \localnumeral[option]{numeral}
+% or \localnumeral*[option]{counter}
+% \Localnumeral[]{numeral} use main language
+% \localnumeral{numeral} use local language
+\NewExpandableDocumentCommand{\localnumeral}{som}
+{
+  \IfBooleanTF{#1}%
+    {% starred: take counter
+      \exp_args:Nc \polyglossia_i_localnumeral:nnnnn {c@#3}
+         {\mainlanguagename} {\languagename} {\IfNoValueTF {#2}{lang=local}{#2}} {localnumeral}
+    }{% unstarred: take number
+      \polyglossia_ii_localnumeral:eeeen {\int_eval:n{#3}}
+         {\mainlanguagename} {\languagename} {\IfNoValueTF {#2}{lang=local}{#2}} {localnumeral}
+    }
+}
+
+% print number usage \Localnumeral[option]{numeral}
+% or \Localnumeral*[option]{counter}
+% \Localnumeral[]{numeral} use main language
+% \localnumeral{numeral} use local language
+\NewExpandableDocumentCommand{\Localnumeral}{som}
+{
+  \IfBooleanTF{#1}%
+    {% starred: take counter
+      \exp_args:Nc \polyglossia_i_localnumeral:nnnnn {c@#3}
+         {\mainlanguagename} {\languagename} {\IfNoValueTF {#2}{lang=local}{#2}} {Localnumeral}
+    }{% unstarred: take number
+      \polyglossia_ii_localnumeral:eeeon {\int_eval:n{#3}}
+         {\mainlanguagename} {\languagename} {\IfNoValueTF {#2}{lang=local}{#2}} {Localnumeral}
+    }
+}
+
+\cs_new_nopar:Nn{\polyglossia at lang@frenchspacing:n}{
+  \prop_get:NnNTF \polyglossia at langsetup {#1/frenchspacing} \l_tmpa_tl
+      {
+        \str_case_e:nnF{\l_tmpa_tl}{
+          {true}{\frenchspacing}
+          {false}{\nonfrenchspacing}
+        }
+        {\xpg at error{frenchspacing~should~be~true~or~false. Is~"\l_tmpa_ttl"~ for~ language~ "#1"}}
+      }
+      {
+        \xpg at error{Could~ not~ retrieve~ key~ frenchspacing~ for~ language~ "#1"}
+        \prop_show:N{\polyglossia at langsetup}
+      }
+}
+
+\cs_new_nopar:Nn{\polyglossia at lang@indentfirst:n}{
+  \prop_get:NnNTF \polyglossia at langsetup {#1/indentfirst} \l_tmpa_tl
+      {
+        \str_case_e:nnF{\l_tmpa_tl}{
+          {true}{\french at indent}
+          {false}{\nofrench at indent}
+        }
+        {\xpg at error{indentfirst~should~be~true~or~false. Is~"\l_tmpa_ttl"~ for~ language~ "#1"}}
+      }
+      {
+        \xpg at error{Could~ not~ retrieve~ key~ indentfirst~ for~ language~ "#1"}
+        \prop_show:N{\polyglossia at langsetup}
+      }
+}
+
+
+\cs_new:Nn{\polyglossia at lang@setpardirection:n}{
+  \prop_get:NnNTF \polyglossia at langsetup {#1/direction} \l_tmpa_tl
+      {
+        \polyglossia at setpardirection:n{\l_tmpa_tl}
+      }
+      {
+        \xpg at error{Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
+        \prop_show:N{\polyglossia at langsetup}
+      }
+}
+
+
+\cs_new:Nn{\polyglossia at lang@settextdirection:nn}{
+  \prop_get:NnNTF \polyglossia at langsetup {#1/direction} \l_tmpa_tl
+      {
+        \polyglossia at settextdirection:n{\l_tmpa_tl}{#2}
+      }
+      {
+        \xpg at error{Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
+        \prop_show:N{\polyglossia at langsetup}
+      }
+}
+
+\AtEndDocument{\prop_log:N{\polyglossia at langsetup}}
 \def\xpg at lastlanguage{0}%
 
 \providebool{xpg at hyphenation@disabled}%
@@ -283,14 +727,24 @@
 \boolfalse{xpg at hyphenation@disabled}
 
 \def\xpg at disablehyphenation{%
+  \ifx\@onlypreamble\@notprerr%
+     \xpg@@disablehyphenation%
+  \else%
+     % if this is used in the preamble, we have to postpone
+     % the execution until the main language has been set (#125).
+     \cs_gset_nopar:Nn \polyglossia at AtBeginDocument@hyphenation: {
+        \xpg@@disablehyphenation%
+     }%
+  \fi%
+}
+
+\def\xpg@@disablehyphenation{%
   \ifbool{xpg at hyphenation@disabled}{}{%
     \booltrue{xpg at hyphenation@disabled}%
     \xdef\xpg at lastlanguage{\the\language}%
-    \xpg at set@language at luatex@iv{nohyphenation}
+    % We do not call \xpg at set@hyphenation at patterns here to avoid a warning message.
+    % "nohyphenation" is not listed in language.dat.lua.
     \language=\l at nohyphenation%
-    \ifluatex %
-      \directlua{polyglossia.disable_hyphenation()}%
-    \fi %
   }%
 }
 
@@ -298,9 +752,6 @@
   \ifbool{xpg at hyphenation@disabled}{%
     \boolfalse{xpg at hyphenation@disabled}%
     \language=\csname xpg at lastlanguage\endcsname%
-    \ifluatex %
-      \directlua{polyglossia.enable_hyphenation()}%
-    \fi %
   }{}%
 }
 
@@ -311,151 +762,163 @@
 %\def\xpg at fontsetup@none#1{\csgdef{#1 at font}{\ifcsdef{#1font}{\csname #1font\endcsname}{}}} %<-- simplistic
 %\def\xpg at fontsetup@custom#1{\csuse{#1 at font}}
 
-\def\xpg at fontsetup@auto#1{\iftoggle{#1 at latin}%
-  {\xpg at fontsetup@latin{#1}}%
-  {\xpg at fontsetup@nonlatin{#1}}%
+\cs_new:Nn \polyglossia at lang@autosetupfont:n {
+  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia at langsetup}{#1/fontsetup}}{true}
+  {
+    \str_if_eq:eeTF{\prop_item:Nn{\polyglossia at langsetup}{#1/lcscript}}{latin}%
+         {\xpg at fontsetup@latin{#1}}
+         {\xpg at fontsetup@nonlatin{#1}}
+  }
+  {
+    \xpg at info{Skipping~ automatic~ font~ setup~ for~ language~ #1}
+  }
 }
 
-\def\xpg at addfontfeature@lang#1#2{% #1 is langtag, #2 is langname
-  % Turkish is a special case: tag can be TRK or TUR
-  \edef\tmp at Turkish{Turkish}%
-  \edef\tmp@@langname{#2}%
-  %  \ifstrequal{#2}{Turkish}%
-  \ifx\tmp@@langname\tmp at Turkish
-    \fontspec_if_language:nTF {TRK}%
-      {\addfontfeature{Language=Turkish}}%
-      {\fontspec_if_language:nTF {TUR}%
-        {\addfontfeature{Language=Turkish}}%
-        {}}%
-    % else not Turkish
-  \else
-     \edef\tmp@@langparam{Language=#2}%
-     \expandafter\expandafter\expandafter\fontspec_if_language:nTF \expandafter{#1}%
-      {\expandafter\expandafter\expandafter\addfontfeature\expandafter{\tmp@@langparam}}%
-      {}%
-  \fi
+
+% add fontfeature Language=#2 to langtag #1
+% do nothing if #1 or #2 is empty
+\cs_new:Nn \polyglossia at addfontfeature@language:nn {
+  \bool_if:nTF{\tl_if_empty_p:n{#1} || \tl_if_empty_p:n{#2}}
+  {
+    % maybe an error ?
+    \xpg at warning{Asking~ to~ add~ empty~ feature~to~ latin~ font~
+      (Language="#2"~ to~ langtag~ "#1")}
+  }
+  {
+    \str_if_eq:nnTF{#2}{Turkish}{
+      \fontspec_if_language:nTF {TRK}%
+      {
+        \addfontfeature{Language=Turkish}
+      }
+      {
+        \fontspec_if_language:nTF {TUR}%
+        {
+          \addfontfeature{Language=Turkish}
+        }{}
+      }
+    }{
+      \fontspec_if_language:nTF{#1}
+      {
+        \addfontfeature{Language=#2}
+      }
+      {}
+    }
+  }
 }
+\cs_generate_variant:Nn  \polyglossia at addfontfeature@language:nn { on , no, oo , Vn, nV, VV , xn, nx, xx}
 
-\def\xpg at addfontfeature@script#1#2{% #1 is scripttag, #2 is scriptname
-  \edef\tmp@@scriptparam{Script=#2}%
-  \expandafter\expandafter\expandafter\fontspec_if_script:nTF \expandafter{#1}%
-    {\expandafter\expandafter\expandafter\addfontfeature\expandafter{\tmp@@scriptparam}}%
-    {\xpg at error{The~ current~ roman~ font~ does~ not~ contain~ the~ \expandafter\noexpand#2 ~ script!\MessageBreak
-    Please~ define~ \expandafter\string\csname \xpg at lowercasefirst{#2}font\endcsname\space with~ \string\newfontfamily}}%
+% add fontfeature Script=#2 to scripttag #1
+% do nothing if #1 or #2 is empty
+\cs_new:Nn \polyglossia at addfontfeature@script:nn {
+  \bool_if:nTF{\tl_if_empty_p:n{#1} || \tl_if_empty_p:n{#2}}
+  {
+    % maybe an error ?
+    \xpg at warning{Asking~ to~ add~ empty~ feature~to~ latin~ font
+                 (Script="#2"~ to~ scripttag~ "#1")}
+  }
+  {
+    \fontspec_if_script:nTF{#1}
+       {\addfontfeature{Script=#2}}
+       {\xpg at error{
+          The~ current~ latin ~ font~ \l_fontspec_family_tl\space does~ not~ contain~ the~"#2"~ script!\MessageBreak
+          Please~ define~\csname\tl_if_empty:nF{#2}{\str_lower_case:n#2}font\endcsname~
+          with~ \string\newfontfamily\space command
+          }
+        }
+  }
 }
+\cs_generate_variant:Nn  \polyglossia at addfontfeature@script:nn { on , no, oo , Vn, nV, VV , xn, nx, xx}
 
 \def\xpg at fontsetup@latin#1{%
   \begingroup
   \csgdef{#1 at font@rm}{%
-    \ifcsdef{#1font}{\csname #1font\endcsname}%
-      {\edef\tmp at langtag{\csuse{xpg at langtag@#1}}%
-       \edef\tmp at langname{\csuse{xpg at langname@#1}}%
-       \rmfamilylatin%
-        \ifcsvoid{xpg at langtag@#1}{}{%
-          \ifcsvoid{xpg at langname@#1}{}{%
-           \xpg at addfontfeature@lang{\tmp at langtag}{\tmp at langname}}%
-      }}}%
+    \cs_if_exist_use:cF{#1font}{
+      \rmfamilylatin
+      \polyglossia at addfontfeature@language:xx{\prop_item:Nn{\polyglossia at langsetup}{#1/langtag}}
+                                              {\prop_item:Nn{\polyglossia at langsetup}{#1/language}}
+    }
+  }
   \csgdef{#1 at font@sf}{%
-    \ifcsdef{#1fontsf}{\csname #1fontsf\endcsname}%
-      {\edef\tmp at langtag{\csuse{xpg at langtag@#1}}%
-       \edef\tmp at langname{\csuse{xpg at langname@#1}}%
-       \sffamilylatin%
-      \ifcsvoid{xpg at langtag@#1}{}{%
-        \ifcsvoid{xpg at langname@#1}{}{%
-           \xpg at addfontfeature@lang{\tmp at langtag}{\tmp at langname}}%
-      }}}%
+    \cs_if_exist_use:cF{#1fontsf}{
+      \sffamilylatin
+      \polyglossia at addfontfeature@language:xx{\prop_item:Nn{\polyglossia at langsetup}{#1/langtag}}
+                                              {\prop_item:Nn{\polyglossia at langsetup}{#1/language}}
+    }%
+  }%
   \csgdef{#1 at font@tt}{%
-    \ifcsdef{#1fonttt}{\csname #1fonttt\endcsname}%
-      {\edef\tmp at langtag{\csuse{xpg at langtag@#1}}%
-       \edef\tmp at langname{\csuse{xpg at langname@#1}}%
-       \ttfamilylatin%
-      \ifcsvoid{xpg at langtag@#1}{}{%
-        \ifcsvoid{xpg at langname@#1}{}{%
-           \xpg at addfontfeature@lang{\tmp at langtag}{\tmp at langname}}%
-      }}}%
+    \cs_if_exist_use:cF{#1fonttt}{
+      \ttfamilylatin
+      \polyglossia at addfontfeature@language:xx{\prop_item:Nn{\polyglossia at langsetup}{#1/langtag}}
+                                              {\prop_item:Nn{\polyglossia at langsetup}{#1/language}}
+    }%
+  }%
   \endgroup
 }
 
 \def\xpg at fontsetup@nonlatin#1{%
   \begingroup
-  \edef\tmp at langname@lc{#1}% eg ukrainian
-  \edef\tmp at scriptname@lc{\csuse{xpg at scriptname@#1 at lc}}% eg cyrillic
-  \ifx\tmp at scriptname@lc\tmp at langname@lc
-    \toggletrue{#1 at scriptlangequal}%
-  \else
-    \togglefalse{#1 at scriptlangequal}%
-  \fi
   \csgdef{#1 at font@rm}{%
-    \ifcsdef{#1font}%
-      {\@nameuse{#1font}}%
-      {\edef\tmp at scripttag{\csuse{xpg at scripttag@#1}}% eg cyrl
-       \edef\tmp at scriptname{\csuse{xpg at scriptname@#1}}% eg Cyrillic
-       \edef\tmp at langtag{\csuse{xpg at langtag@#1}}% eg UKR
-       \edef\tmp at langname{\csuse{xpg at langname@#1}}% eg Ukrainian
+    \cs_if_exist_use:cF{#1font}
+      {
        \providetoggle{#1 at use@script at font}%
-       \iftoggle{#1 at scriptlangequal}%
+       \str_if_eq:nnTF{\prop_item:Nn{\polyglossia at langsetup}{#1/script}}{\prop_item:Nn{\polyglossia at langsetup}{#1/language}}
         {\rmfamilylatin}%
-        {\expandafter\ifcsname\csuse{xpg at scriptname@#1 at lc} font\endcsname% eg \cyrillicfont
-           \toggletrue{#1 at use@script at font}%
-           \expandafter\csname\csuse{xpg at scriptname@#1 at lc} font\endcsname
-         \else
-           \rmfamilylatin
-         \fi}
+        {\cs_if_exist_use:cTF{\prop_item:Nn{\polyglossia at langsetup}{#1/lcscript} font}
+          {
+             \toggletrue{#1 at use@script at font}%
+           }
+           {
+             \rmfamilylatin
+           }
+       }
        \iftoggle{#1 at use@script at font}{}{%
-         \ifcsvoid{xpg at scripttag@#1}{}{%
-           \ifcsvoid{xpg at scriptname@#1}{}{%
-             \xpg at addfontfeature@script{\tmp at scripttag}{\tmp at scriptname}}}}%
-       \ifcsvoid{xpg at langtag@#1}{}{%
-         \ifcsvoid{xpg at langname@#1}{}{%
-         \xpg at addfontfeature@lang{\tmp at langtag}{\tmp at langname}}}%
+           \polyglossia at addfontfeature@script:xx{\prop_item:Nn{\polyglossia at langsetup}{#1/scripttag}}
+                                                 {\prop_item:Nn{\polyglossia at langsetup}{#1/script}}
+       }%
+       \polyglossia at addfontfeature@language:xx{\prop_item:Nn{\polyglossia at langsetup}{#1/langtag}}
+                                              {\prop_item:Nn{\polyglossia at langsetup}{#1/language}}
       }}%
   \csgdef{#1 at font@sf}{%
-    \ifcsdef{#1fontsf}%
-      {\@nameuse{#1fontsf}}%
-      {\edef\tmp at scripttag{\csuse{xpg at scripttag@#1}}% eg cyrl
-       \edef\tmp at scriptname{\csuse{xpg at scriptname@#1}}% eg Cyrillic
-       \edef\tmp at langtag{\csuse{xpg at langtag@#1}}% eg UKR
-       \edef\tmp at langname{\csuse{xpg at langname@#1}}% eg Ukrainian
+    \cs_if_exist_use:cF{#1fontsf}%
+      {
        \providetoggle{#1 at use@script at fontsf}%
-       \iftoggle{#1 at scriptlangequal}%
+       \str_if_eq:nnTF{\prop_item:Nn{\polyglossia at langsetup}{#1/script}}{\prop_item:Nn{\polyglossia at langsetup}{#1/language}}
         {\sffamilylatin}%
-        {\expandafter\ifcsname\csuse{xpg at scriptname@#1 at lc} fontsf\endcsname% eg \cyrillicfontsf
-           \toggletrue{#1 at use@script at fontsf}%
-           \expandafter\csname\csuse{xpg at scriptname@#1 at lc} fontsf\endcsname
-         \else
-           \sffamilylatin
-         \fi}
+        {\cs_if_exist_use:cTF{\prop_item:Nn{\polyglossia at langsetup}{#1/lcscript} fontsf}
+          {
+             \toggletrue{#1 at use@script at fontsf}%
+           }
+           {
+             \sffamilylatin
+           }
+       }
        \iftoggle{#1 at use@script at fontsf}{}{%
-         \ifcsvoid{xpg at scripttag@#1}{}{%
-           \ifcsvoid{xpg at scriptname@#1}{}{%
-             \xpg at addfontfeature@script{\tmp at scripttag}{\tmp at scriptname}}}}%
-       \ifcsvoid{xpg at langtag@#1}{}{%
-         \ifcsvoid{xpg at langname@#1}{}{%
-         \xpg at addfontfeature@lang{\tmp at langtag}{\tmp at langname}}}%
+           \polyglossia at addfontfeature@script:xx{\prop_item:Nn{\polyglossia at langsetup}{#1/scripttag}}
+                                                 {\prop_item:Nn{\polyglossia at langsetup}{#1/script}}
+       }%
+       \polyglossia at addfontfeature@language:xx{\prop_item:Nn{\polyglossia at langsetup}{#1/langtag}}
+                                              {\prop_item:Nn{\polyglossia at langsetup}{#1/language}}
       }}%
   \csgdef{#1 at font@tt}{%
-    \ifcsdef{#1fonttt}%
-      {\@nameuse{#1fonttt}}%
-      {\edef\tmp at scripttag{\csuse{xpg at scripttag@#1}}% eg cyrl
-       \edef\tmp at scriptname{\csuse{xpg at scriptname@#1}}% eg Cyrillic
-       \edef\tmp at langtag{\csuse{xpg at langtag@#1}}% eg UKR
-       \edef\tmp at langname{\csuse{xpg at langname@#1}}% eg Ukrainian
+    \cs_if_exist_use:cF{#1fonttt}%
+      {
        \providetoggle{#1 at use@script at fonttt}%
-       \iftoggle{#1 at scriptlangequal}%
-        {\ttfamilylatin}%
-        {\expandafter\ifcsname\csuse{xpg at scriptname@#1 at lc} fonttt\endcsname% eg \cyrillicfonttt
-           \toggletrue{#1 at use@script at fonttt}%
-           \expandafter\csname\csuse{xpg at scriptname@#1 at lc} fonttt\endcsname
-         \else
-           \ttfamilylatin
-         \fi}
+       \str_if_eq:nnTF{\prop_item:Nn{\polyglossia at langsetup}{#1/script}}{\prop_item:Nn{\polyglossia at langsetup}{#1/language}}
+       {\ttfamilylatin}%
+       {\cs_if_exist_use:cTF{\prop_item:Nn{\polyglossia at langsetup}{#1/lcscript} fonttt}
+           {
+             \toggletrue{#1 at use@script at fonttt}%
+           }
+           {
+             \ttfamilylatin
+           }
+       }
        \iftoggle{#1 at use@script at fonttt}{}{%
-         \ifcsvoid{xpg at scripttag@#1}{}{%
-           \ifcsvoid{xpg at scriptname@#1}{}{%
-             \xpg at addfontfeature@script{\tmp at scripttag}{\tmp at scriptname}}}}%
-       \ifcsvoid{xpg at langtag@#1}{}{%
-         \ifcsvoid{xpg at langname@#1}{}{%
-         \xpg at addfontfeature@lang{\tmp at langtag}{\tmp at langname}}}%
+           \polyglossia at addfontfeature@script:xx{\prop_item:Nn{\polyglossia at langsetup}{#1/scripttag}}
+                                                 {\prop_item:Nn{\polyglossia at langsetup}{#1/script}}
+       }%
+       \polyglossia at addfontfeature@language:xx{\prop_item:Nn{\polyglossia at langsetup}{#1/langtag}}
+                                              {\prop_item:Nn{\polyglossia at langsetup}{#1/language}}
       }}%
   \endgroup
 }
@@ -464,8 +927,8 @@
 
 %% ensure localization of \markright and \markboth commands
 %%% THIS IS NOW DISABLED BY DEFAULT
-\define at boolkey{polyglossia}[xpg@]{localmarks}[false]{%
-   \ifbool{xpg at localmarks}{%
+\newcommand{\local at marks}[1]{}
+\def\enable at local@marks{
       \xpg at info{Option:~ localmarks}%
       \def\local at marks##1{%
          \def\markboth####1####2{%
@@ -492,12 +955,9 @@
             \def\@markright####1####2####3{\@temptokena{\protect\@@ensure at maindir{####1}}%
                \unrestored at protected@xdef\@themark{{\the\@temptokena}%
                {\protect\@@ensure at maindir{####3}}}}}%
-    }{% else
-      \def\local at marks##1{}%
-    }%
 }
-\setkeys{polyglossia}{localmarks=false}
 
+
 % Easy way out – Arthur, 2012-08-01
 \ifcsdef{newXeTeXintercharclass}{%
 % to reset the intercharclass of a character to "normal"
@@ -504,9 +964,15 @@
 \newXeTeXintercharclass\xpg at normalclass %TODO
 }{}
 
+\ifxetex
 %% when no patterns are available, we use \l at nohyphenation, assigned to 255
 %%  (suggestion by Enrico Gregorio)
-\@ifundefined{l at nohyphenation}{\chardef\l at nohyphenation=255 }{}
+  \@ifundefined{l at nohyphenation}{\chardef\l at nohyphenation=255 }{}
+\else\ifluatex
+  \@ifundefined{l at nohyphenation}{\chardef\l at nohyphenation=\directlua{
+    tex.sprint(polyglossia.newloader_loaded_languages.nohyphenation)}\relax
+  }{}
+\fi\fi
 
 %we call this macro when a gloss file is not found for a given language
 \def\xpg at nogloss#1{%
@@ -525,74 +991,133 @@
   \makeatletter
   \input{#1}\catcode`\@=\xpg at atcatcode}
 
+% try to load a language file
+\cs_new:Nn \polyglossia_load_lang_definition:nn {
+  \file_if_exist:nTF{gloss-#2.ldf}
+  {
+    \xpg at input{gloss-#2.ldf}
+    \setkeys{#2}{#1}
+  }
+  {
+    \xpg at nogloss{#2}
+  }
+}
+
+
+% define environment and command
+\cs_new:Nn \polyglossia at define@language at cmd:n {
+  \exp_args:Ne
+  \newenvironment {\prop_item:Nn{\polyglossia at langsetup}{#1/envname}} [1] []
+  {
+    \begin{otherlanguage}[##1]{#1}
+  }%
+  {
+    \end{otherlanguage}
+  }%
+  \exp_args:Nc \newcommand {text#1} [2][]
+  {%
+    \xpg at textlanguage[##1]{#1}{##2}%
+  }%
+}
+
 \newcommand{\setdefaultlanguage}[2][]{%
-  \edef\xpg at loaded{#2\ifx\xpg at loaded\@empty\else,\xpg at loaded\fi}%
-   \IfFileExists{gloss-#2.ldf}%
-   {\ifcsundef{#2 at loaded}%
-     {\xpg at input{gloss-#2.ldf}%
-     \xpg at info{Default~ language~ is~ #2}%
-     \def\languagename{#2}%
-     \ifluatex %
-       \directlua{polyglossia.set_default_language('\luatexluaescapestring{\string#2}')}%
-     \fi %
-      % This is needed because \arabic is a built-in LaTeX command:
-      % so now we have \begin{Arabic}... instead of \begin{arabic}...
-      \ifstrequal{#2}{arabic}%
-      {\newenvironment{Arabic}[1][]{\begin{otherlanguage}[####1]{arabic}}%
-        {\end{otherlanguage}}}%
-      {\newenvironment{#2}[1][]{\begin{otherlanguage}[####1]{#2}}%
-        {\end{otherlanguage}}}%
-      \expandafter\newcommand\csname text#2\endcsname[2][]{%
-        \ifcsdef{RTL}%
-          {\iftoggle{#2 at RL}%
-            {\@ensure at RTL{\foreignlanguage[####1]{#2}{####2}}}%
-            {\@ensure at LTR{\foreignlanguage[####1]{#2}{####2}}}%
-          }% else bidi not loaded
-          {\iftoggle{#2 at RL}%
-            {\xpg at error{Language~ #2~ is~ right-to-left,~ but~ bidi~ package~ was~ not~ loaded!}}%
-            {\foreignlanguage[####1]{#2}{####2}}%
-          }%
-      }%
-      \csletcs{local#2}{text#2}%
-      \csgdef{#2 at loaded}{}%
-      \gdef\xpg at main@language{#2}%
-      }%
-      {\xpg at warning{gloss-#2.ldf~ is~ already~ loaded!}}%:
-      %% The following settings are for the default language and script:
-      \iftoggle{#2 at RL}{\@RTLmaintrue}{}% this tells bidi.sty that the document is RTL
-      \AtBeginDocument{%
-      \selectlanguage[#1]{#2}%
-      \selectbackgroundlanguage{#2}}%
-   }%
-   %ELSE
-   {\xpg at nogloss{#2}}%
+  \ifcsundef{#2 at loaded}%
+  {
+    % latex is an internal language, so do not record
+    \ifstrequal{#2}{latex}{}{%
+      \global\edef\xpg at loaded{#2\ifx\xpg at loaded\@empty\else,\xpg at loaded\fi}%
+      \global\edef\xpg at bloaded{\prop_item:Nn{\polyglossia at langsetup}{#2/babelname}%
+          \ifx\xpg at bloaded\@empty\else,\xpg at bloaded\fi}%
+    }%
+    \polyglossia_load_lang_definition:nn{#1}{#2}
+    % define environment and command (except for internal latex language)
+    \ifstrequal{#2}{latex}{}{%
+      \polyglossia at define@language at cmd:n{#2}
+    }%
+    \csgdef{#2 at loaded}{}%
+  }
+  {
+    \relax
+  }
+  \gdef\xpg at main@language{#2}%
+  \tl_if_blank:nTF {#1}{\gdef\mainlanguagevariant{}}{%
+     % If the optional argument sets a value for the key “variant”,
+     % store it in \xpg at main@langvariant
+     \clist_map_inline:nn { #1 } {%
+         \xpg at parsevariantkeyvalue##1=@xpg at main@langvariant\relax
+     }%
+  }%
+  % Store babelname of main language (for external packages such as biblatex)
+  \xdef\mainbabelname{\prop_item:Nn{\polyglossia at langsetup}{#2/babelname}}%
+  %% The following settings are for the default language and script
+  % this tells bidi.sty or luabidi.sty that the document is RTL
+  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia at langsetup}{#2/direction}}{RL}{%
+    \str_case_e:nnF{\c_sys_engine_str}{%
+      {luatex}{\setRTLmain}
+      {xetex}{\@RTLmaintrue\setnonlatin}
+    }{}%
+  }{}%
+  \cs_gset_nopar:Nn \polyglossia at AtBeginDocument@selectlanguage: {
+    \selectbackgroundlanguage{#2}
+    \selectlanguage[#1]{#2}%
+  }
+  \xpg at info{Default~ language~ is~ #2}%
+  \polyglossia at set@language at name[#1]{#2}%
+  \def\mainlanguagename{#2}
+  % Store babelname of current language (for external packages such as biblatex)
+  \xdef\babelname{\prop_item:Nn{\polyglossia at langsetup}{#2/babelname}}%
+  \ifluatex %
+  \directlua{polyglossia.set_default_language('\luatexluaescapestring{\string#2}')}%
+  \fi %
 }
 
 \let\setmainlanguage=\setdefaultlanguage
 
+\def\mainbabelname{}%
+\def\mainlanguagevariant{}%
+% Store main language variant for external packages
+\define at key{xpg at main@langvariant}{variant}{%
+  \gdef\mainlanguagevariant{#1}%
+}
+
+\def\babelname{}%
+\def\languagevariant{}%
+% Store current language variant for external packages
+\define at key{xpg at set@langvariant}{variant}{%
+  \def\languagevariant{#1}%
+}
+
+\newcommand*\polyglossia at set@language at name[2][]{
+  \def\languagename{#2}%
+  \tl_if_blank:nTF {#1}{%
+     \ifcsundef{#2 at gvar}{\def\languagevariant{}}{\def\languagevariant{\csuse{#2 at gvar}}}
+   }{%
+     % If the argument sets a value for the key “variant”,
+     % store it in \xpg at set@langvariant
+     \clist_map_inline:nn { #1 } {%
+         \xpg at parsevariantkeyvalue##1=@xpg at set@langvariant\relax
+     }%
+  }%
+}
+
+
 \newcommand{\resetdefaultlanguage}[2][]{%
-    \ifcsundef{#2 at loaded}{%
-     \xpg at error{gloss-#2.ldf~ is~ not~ loaded!}}%
-    {\csuse{no\xpg at main@language @globalnumbers}% disable globalnumbers of previously defined default language
-    \csuse{noextras@\xpg at main@language}%
-    \csuse{init at noextras@\xpg at main@language}%
-    \def\languagename{#2}%
-    \iftoggle{#2 at RL}{\@rlmaintrue\@rl at footnotetrue}{}%
-    \selectlanguage[#1]{#2}%
-    \selectbackgroundlanguage{#2}}}
+  \polyglossia at error@iflangnotloaded:n{#2}
+  % disable globalnumbers of previously defined default language
+  \csuse{no\xpg at main@language @globalnumbers}
+  \csuse{noextras@\xpg at main@language}%
+  % This is a hook for external packages which want to access variants
+  % via babelname (such as biblatex)
+  \cs_if_exist_use:c{noextras at bbl@\mainbabelname}%
+  \csuse{init at noextras@\xpg at main@language}%
+  \polyglossia at set@language at name[#1]{#2}%
+  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia at langsetup}{#2/direction}}{RL}{\@rlmaintrue\@rl at footnotetrue}{}%
+  \selectlanguage[#1]{#2}%
+  \selectbackgroundlanguage{#2}%
+  % Store babelname of current language (for external packages such as biblatex)
+  \xdef\babelname{\prop_item:Nn{\polyglossia at langsetup}{#2/babelname}}%
+}
 
-\expandafter\ifx\familydefault\sfdefault
-  \def\familytype{sf}
-\else\expandafter\ifx\familydefault\ttdefault
-  \def\familytype{tt}
-\else
-  \def\familytype{rm}
-\fi\fi
-% This robustifies the redefinitions of \<xx>family (suggestion by Enrico Gregorio)
-% e.g. to prevent expansion of the \familytype redefinition in auxiliary files
-\csgappto{rmfamily~}{\def\familytype{rm}}
-\csgappto{sffamily~}{\def\familytype{sf}}
-\csgappto{ttfamily~}{\def\familytype{tt}}
 % This saves the normalfont for the latin script since we may change normalfont in other scripts
 \let\normalfontlatin=\normalfont%
 \let\rmfamilylatin=\rmfamily%
@@ -599,11 +1124,36 @@
 \let\sffamilylatin=\sffamily%
 \let\ttfamilylatin=\ttfamily%
 
+\def\xpg at set@familydefault{%
+  % We need the \edef route here in order
+  % to detect both \renewcommand and \let
+  % changes.
+  \edef\tempa{\familydefault}%
+  \edef\tempb{\sfdefault}%
+  \ifcsequal{tempa}{tempb}%
+     {\def\familytype{sf}}
+     {\edef\tempb{\ttdefault}%
+      \ifcsequal{tempa}{tempb}%
+         {\def\familytype{tt}}
+         {\def\familytype{rm}}}
+  % This robustifies the redefinitions of \<xx>family (suggestion by Enrico Gregorio)
+  % e.g. to prevent expansion of the \familytype redefinition in auxiliary files
+  \csgappto{rmfamily~}{\def\familytype{rm}}
+  \csgappto{sffamily~}{\def\familytype{sf}}
+  \csgappto{ttfamily~}{\def\familytype{tt}}
+  % This (re-)saves the normalfont for the latin script since we may
+  % change normalfont in other scripts
+  \let\normalfontlatin=\normalfont%
+  \let\rmfamilylatin=\rmfamily%
+  \let\sffamilylatin=\sffamily%
+  \let\ttfamilylatin=\ttfamily%
+}
+
 \def\resetfontlatin{%
    \let\rmfamily=\rmfamilylatin%
    \let\sffamily=\sffamilylatin%
    \let\ttfamily=\ttfamilylatin%
-   \let\normalfont=\normalfontlatin}
+   \global\let\normalfont=\normalfontlatin}
 
 \def\selectfontfamilylatin{%
   \def\tmp at tt{tt}\def\tmp at sf{sf}%
@@ -625,7 +1175,9 @@
   \letcs{\rmfamily}{#1 at font@rm}%
   \letcs{\sffamily}{#1 at font@sf}%
   \letcs{\ttfamily}{#1 at font@tt}%
-  \gdef\normalfont{\protect\xpg at select@fontfamily{#1}}%
+  \gdef\normalfont{\protect\xpg at select@fontfamily{#1}%
+                     \fontseries{\seriesdefault}\selectfont%
+                     \fontshape{\shapedefault}\selectfont}%
   \gdef\reset at font{\protect\normalfont}%
 }
 
@@ -634,47 +1186,37 @@
                         \@afterindenttrue}
 \def\nofrench at indent{\let\@afterindentfalse\@@fterindentfalse
                           \@afterindentfalse}
-
 \newcommand{\selectbackgroundlanguage}[1]{%
-    \iftoggle{#1 at latin}{}{\xpg at set@normalfont{#1}}%
-    \csuse{#1 at globalnumbers}%
-    }
+  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia at langsetup}{#1/lcscript}}{latin}{}{\xpg at set@normalfont{#1}}%
+  \csuse{#1 at globalnumbers}%
+}
 
 \newcommand{\setotherlanguage}[2][]{%
-  \edef\xpg at loaded{#2\ifx\xpg at loaded\@empty\else,\xpg at loaded\fi}%
-   \IfFileExists{gloss-#2.ldf}%
-   {\ifcsundef{#2 at loaded}%
-     {\xpg at input{gloss-#2.ldf}%
-      \setkeys{#2}{#1}%
-      \edef\@tmpa{arabic}%
-      \edef\@tmpb{#2}%
-      \ifx\@tmpb\@tmpa%
-      \newenvironment{Arabic}[1][]{\begin{otherlanguage}[####1]{arabic}}%
-         {\end{otherlanguage}}%
-      \else
-      \newenvironment{#2}[1][]{\begin{otherlanguage}[####1]{#2}}%
-         {\end{otherlanguage}}%
-      \fi
-      \expandafter\newcommand\csname text#2\endcsname[2][]{%
-        \ifcsdef{RTL}%
-          {\iftoggle{#2 at RL}%
-            {\@ensure at RTL{\foreignlanguage[####1]{#2}{####2}}}%
-            {\@ensure at LTR{\foreignlanguage[####1]{#2}{####2}}}%
-          }% else bidi not loaded
-          {\iftoggle{#2 at RL}%
-            {\xpg at error{Language~ #2~ is~ right-to-left,~ but~ bidi~ package~ was~ not~ loaded!}}%
-            {\foreignlanguage[####1]{#2}{####2}}%
-          }%
-        }%
-     \csletcs{local#2}{text#2}%
-     \csgdef{#2 at loaded}{}%
-     }%
-     {\xpg at warning{gloss-#2.ldf~ is~ already~ loaded!}}%
-   }%
-   %ELSE
-   {\xpg at nogloss{#2}}%
+  \ifcsundef{#2 at loaded}
+  {
+    \global\edef\xpg at loaded{#2\ifx\xpg at loaded\@empty\else,\xpg at loaded\fi}%
+    \polyglossia_load_lang_definition:nn{#1}{#2}
+    % define environment and command
+    \polyglossia at define@language at cmd:n{#2}
+    \csgdef{#2 at loaded}{}%
+    % If a variant is set, store it.
+    \gdef\otherlanguagevariant{}
+    \tl_if_blank:nTF {#1}{}{%
+      % If the optional argument sets a value for the key “variant”,
+      % store it in \xpg at main@langvariant
+      \clist_map_inline:nn { #1 } {%
+         \xpg at parsevariantkeyvalue##1=@xpg at other@langvariant\relax
+      }%
+    }%
+    \csgdef{#2 at gvar}{\otherlanguagevariant}%
+  }{}
 }
 
+% Store main language variant for external packages
+\define at key{xpg at other@langvariant}{variant}{%
+  \gdef\otherlanguagevariant{#1}%
+}
+
 \newcommand\setotherlanguages[1]{%
   \def\do##1{\setotherlanguage{##1}}%
    \docsvlist{#1}}%
@@ -688,145 +1230,332 @@
   \lefthyphenmin=\tw@
   \righthyphenmin=\thr@@}
 
-\def\noextrascurrent#1{\csuse{noextras@#1}}
+\def\xpg at initial@setup{%
+  \common at language%
+}
 
-\def\xpg at initial@setup{\ifcsundef{languagename}{}%
-   {\noextrascurrent{\languagename}}%
-   \common at language}
+\providecommand{\foreignlanguage}{}
 
-\AtBeginDocument{\xpg at initial@setup}
+% wrapper for foreignlanguage and otherlanguage*
+\newcommand*\polyglossia at setforeignlanguage[2][]{
+  \select@@language[#1]{#2}
+  % Store babelname of current language (for external packages such as biblatex)
+  \xdef\babelname{\prop_item:Nn{\polyglossia at langsetup}{#2/babelname}}%
+}
 
-\providecommand{\foreignlanguage}{}
+% joint code of \foreignlanguage, otherlanguage*
+% and \text<lang>
+\newcommand{\xpg at otherlanguage}[2][]
+{%
+  \polyglossia at error@iflangnotloaded:n{#2}
+  \setkeys{#2}{#1}%
+  \polyglossia at setforeignlanguage[#1]{#2}
+  % buggy restoration heure
+  \csuse{inlineextras@#2}%
+  % This is a hook for external packages which want to access variants
+  % via babelname (such as biblatex)
+  \cs_if_exist_use:c{inlineextras at bbl@\babelname}%
+}
 
-\renewcommand{\foreignlanguage}[3][]{%
-   \ifcsundef{#2 at loaded}%
-     {\xpg at nogloss{#2}}%
-     {{\select@@language{#2}%
-      \setkeys{#2}{#1}%
-      \use at localhyphenmins{#2}%
-      \ifbool{#2 at frenchspacing}{\frenchspacing}{\nonfrenchspacing}%
-      \csuse{inlineextras@#2}%
-      #3}%
-     }%
+\renewcommand{\foreignlanguage}[3][]
+{%
+  \polyglossia at error@iflangnotloaded:n{#2}
+   \bgroup
+   \xpg at otherlanguage[#1]{#2}%
+   \polyglossia at lang@settextdirection:nn{#2}{#3}%
+   \egroup
 }
 
 % otherlanguage* is the environment equivalent of \foreignlanguage
 \expandafter\providecommand\csname otherlanguage*\endcsname{}
-\renewenvironment{otherlanguage*}[2][]{%
-   \ifcsundef{#2 at loaded}%
-     {\xpg at nogloss{#2}}%
-     {\select@@language{#2}%
-      \setkeys{#2}{#1}%
-      \use at localhyphenmins{#2}%
-      \ifbool{#2 at frenchspacing}{\frenchspacing}{\nonfrenchspacing}%
-      \csuse{inlineextras@#2}\csuse{date#2}%
-     }%
-}{}
 
+\renewenvironment{otherlanguage*}[2][]
+{%
+  \xpg at otherlanguage[#1]{#2}%
+  \polyglossia at lang@settextdirection:nn{#2}\bgroup%
+}
+{\egroup}
+
+% use by \text<lang>. Equivalent to \foreignlanguage,
+% except that dates are localized.
+\newcommand*\xpg at textlanguage[3][]{%
+  \polyglossia at error@iflangnotloaded:n{#2}
+   \bgroup
+   \xpg at otherlanguage[#1]{#2}%
+   \csuse{date#2}%
+   % This is a hook for external packages which want to access variants
+   % via babelname (such as biblatex)
+   \cs_if_exist_use:c{date at bbl@\babelname}%
+   \polyglossia at lang@settextdirection:nn{#2}{#3}%
+   \egroup
+  % Reset the language's/script's font families
+  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia at langsetup}{#2/lcscript}}{latin}{}{\resetfontlatin}%
+}
+
+
+% Define language-specific hyphenation exceptions
+\newcommand\pghyphenation[3][]{
+  \bgroup
+  \polyglossia at error@iflangnotloaded:n{#2}
+  \setkeys{#2}{#1}%
+  \select@@language[#1]{#2}%
+  \hyphenation{#3}%
+  \egroup
+}
+
+
 %Hook that other package authors can use
 %(for instance biblatex):
 \newcommand*{\xpg at hook@setlanguage}{}
 
-\providecommand{\selectlanguage}{}
-\renewcommand{\selectlanguage}[2][]{%
-   \ifcsundef{#2 at loaded}%
-     {\xpg at nogloss{#2}}%
-     {\def\xpg at pop@language{%
-         \xpg at set@language{\languagename}%
-         \xpg at hook@setlanguage%
-         \let\emp at langname\@undefined}%
-      \aftergroup\xpg at pop@language%
-      % If the optional argument sets a value for the key “variant”, copy it to xpg at langvariant
-      \def\do##1{%
-          \def\xpg at parsekeyvalue####1=####2\relax{%
-              \def\@tmpa{####1}
-              \def\@tmpb{variant}
-              \ifx\@tmpa\@tmpb\setkeys{xpg at langvariant}{##1}\fi
-          }%
-          \xpg at parsekeyvalue##1=\relax
-      }%
-      \docsvlist{#1}
-      \setkeys{#2}{#1}%
-      \xpg at set@language{#2}%
+\def\xpg at pop@language at i#1#2{%
+  \xpg at set@language at aux[#1]{#2}%
+  \xpg at hook@setlanguage
+  \let\emp at langname\@undefined}
+
+\DeclareDocumentCommand \selectlanguage {s O{} m}
+{%
+  \polyglossia at error@iflangnotloaded:n{#3}
+  \IfBooleanF {#1}
+    {
+      \tl_set:Nx \xpg at pop@language { \exp_not:N \xpg at pop@language at i {#2} {#3} }
+      \group_insert_after:N \xpg at pop@language
+    }
+  \tl_if_blank:nTF {#2}{}{%
+     % If the optional argument sets a value for the key “variant”, copy it to xpg at langvariant
+    \clist_map_inline:nn { #2 } {%
+         \xpg at parsevariantkeyvalue##1=@xpg at langvariant\relax
      }%
+     \setkeys{#3}{#2}%
+   }%
+   % The starred variant does not write to the aux
+   \IfBooleanTF#1{%
+     \xpg at set@language at nonaux[#2]{#3}%
+   }{%
+     \xpg at set@language at aux[#2]{#3}%
+   }%
+   \ifluatex%
+     \directlua{polyglossia.select_language('\luatexluaescapestring{\string#3}',
+                     \the\csname l@#3\endcsname)}%
+   \fi%
+  \def\xpg at tmp@babelname{\prop_item:Nn{\polyglossia at langsetup}{#3/babelname}}
+  % Store babelname in \xpg at bloaded csv list
+  \ifcsundef{\csname xpg at tmp@babelname\endcsname @bbl at loaded}
+  {
+    \global\edef\xpg at bloaded{\xpg at tmp@babelname%
+          \ifx\xpg at bloaded\@empty\else,\xpg at bloaded\fi}%
+    \csgdef{\csname xpg at tmp@babelname\endcsname @bbl at loaded}{}%
+  }{}
 }
 
-% Save any variant in csv list of variants
+% Helper to get and register "variant" keyval
+\def\xpg at parsevariantkeyvalue#1=#2@#3\relax{%
+   \def\@tmpa{#1}
+   \def\@tmpb{variant}
+   \ifx\@tmpa\@tmpb\setkeys{#3}{#1=#2}\fi
+}%
+
+
+% Append any variant to csv list of variants
 \define at key{xpg at langvariant}{variant}{%
-  \edef\xpg at vloaded{#1\ifx\xpg at vloaded\@empty\else,\xpg at vloaded\fi}}
+  \edef\xpg at vloaded{#1\ifx\xpg at vloaded\@empty\else,\xpg at vloaded\fi}%
+}
 
-\newcommand{\xpg at set@language}[1]{%
-   \select at language{#1}%
+\prg_set_conditional:Npnn \polyglossia at check@if at lang@loaded:N #1 { p , T , F , TF }{
+  \cs_if_exist:cTF{#1}{
+     \prg_return_true:
+  }{
+    \prg_return_false:
+  }
+}
+
+% Test if language is loaded
+\newcommand*\iflanguageloaded[3]{%
+  \polyglossia at check@if at lang@loaded:NTF{#1 at loaded}{#2}{#3}%
+}
+
+% Same for babellanguage is loaded
+\newcommand*\ifbabellanguageloaded[3]{%
+  \polyglossia at check@if at lang@loaded:NTF{#1 at bbl@loaded}{#2}{#3}%
+}
+
+\newcommand*{\xpg at set@language at nonaux}[2][]{%
+   \@select at language[#1]{#2}%
+}
+
+
+\newcommand*{\xpg at set@language at aux}[2][]{%
+   % Store babelname of current language (for external packages such as biblatex)
+   \xdef\babelname{\prop_item:Nn{\polyglossia at langsetup}{#2/babelname}}%
+   \@select at language[#1]{#2}%
+    % Write to the aux
    \if at filesw%
-      \protected at write\@auxout{}{\protect\select at language{#1}}%
-      \addtocontents{toc}{\protect\select at language{#1}}%
-      \addtocontents{lof}{\protect\select at language{#1}}%
-      \addtocontents{lot}{\protect\select at language{#1}}%
+      \ifx#1\\\\%
+          \protected at write\@auxout{}{\protect\selectlanguage*{#2}}%
+          \addtocontents{toc}{\protect\selectlanguage*{#2}}%
+          \addtocontents{lof}{\protect\selectlanguage*{#2}}%
+          \addtocontents{lot}{\protect\selectlanguage*{#2}}%
+       \else
+          \protected at write\@auxout{}{\protect\selectlanguage*[#1]{#2}}%
+          \addtocontents{toc}{\protect\selectlanguage*[#1]{#2}}%
+          \addtocontents{lof}{\protect\selectlanguage*[#1]{#2}}%
+          \addtocontents{lot}{\protect\selectlanguage*[#1]{#2}}%
+       \fi
    \fi
 }
 
-\def\xpg at set@language at luatex@iii#1#2{%
-    % here we use lu at texhyphen@loaded@\the\language, the same as in babel
-    \ifcsdef{bbl at hyphendata@#2}{}{%
-        \global\@namedef{bbl at hyphendata@\the\language}{}%
-        \directlua{polyglossia.select_language('\luatexluaescapestring{\string#1}', \the\csname l@#1\endcsname)}%
-    }
+% Open a group in the aux file. This is to keep
+% nested language options local (see #320)
+\newcommand*{\xpg at set@group at aux}{%
+   \if at filesw%
+      \protected at write\@auxout{}{\bgroup}%
+      \addtocontents{toc}{\bgroup}%
+      \addtocontents{lof}{\bgroup}%
+      \addtocontents{lot}{\bgroup}%
+    \fi
 }
 
-\newcommand\xpg at check@ifdefined[1]{%
-    \expandafter\ifx\csname l@#1\endcsname\relax\@xpg at language@really at defined@false\else
-        \ifx\csname l@#1\endcsname\l at nohyphenation\@xpg at language@really at defined@false\else
-            \@xpg at language@really at defined@true
-        \fi
+% Close the group in the aux file
+\newcommand*{\xpg at unset@group at aux}{%
+   \if at filesw%
+      \protected at write\@auxout{}{\egroup}%
+      \addtocontents{toc}{\egroup}%
+      \addtocontents{lof}{\egroup}%
+      \addtocontents{lot}{\egroup}%
     \fi
 }
 
+\prg_set_conditional:Npnn \polyglossia at check@ifdefined:N #1 { p , T , F , TF }{
+  \cs_if_exist:cTF {l@#1}
+    {
+      \cs_if_eq:cNTF {l@#1} \l at nohyphenation
+        {
+          \prg_return_false:
+        }
+        {
+          % it's possible that sometimes \csname l@#1\endcsname becomes \relax
+          \cs_if_eq:cNTF {l@#1} \relax
+            { \prg_return_false: }
+            { \prg_return_true: }
+        }
+    }
+    {
+      \prg_return_false:
+    }
+}
+
+\def\polyglossia at luatex@load at lang#1{%
+  % if \l@#1 is not properly defined, call lua function newloader(#1),
+  % and assign the returned number to \l@#1
+  \polyglossia at check@ifdefined:NF {#1}
+    {
+      \expandafter\chardef\csname l@#1\endcsname=
+        \directlua{ tex.sprint(polyglossia.newloader'#1') }\relax
+    }
+}
+
+% This check is also used by biblatex, so don't
+% rename silently.
 \newcommand\xpg at ifdefined[3]{%
+    % With luatex, we first need to define \l@#1.
     \ifluatex
-        \xpg at set@language at luatex@iv{#1}%
+      \polyglossia at luatex@load at lang{#1}%
     \fi
-    \xpg at check@ifdefined{#1}
-    \if at xpg@language at really@defined@#2\else#3\fi
+    \polyglossia at check@ifdefined:NTF{#1}{#2}{#3}%
 }%
 
-\newcommand\xpg at set@language at luatex@iv[1]{%
-    \ifluatex
-        \xpg at check@ifdefined{#1}%
-        \if at xpg@language at really@defined@\else
-            \expandafter\chardef\csname l@#1\endcsname=\directlua{tex.sprint(polyglossia.newloader('#1'))}%
-        \fi
-        \language\directlua{tex.sprint(polyglossia.newloader('#1'))}%
+% Set \bbl at hyphendata@\the\language, which is (lua)babel's
+% hyphenation pattern hook
+% FIXME Clarifiy why/when this is needed.
+\newcommand*\xpg at set@bbl at hyphendata[1]{%
+    \ifluatex%
+        \ifcsdef{bbl at hyphendata@#1}{}{%
+            \global\@namedef{bbl at hyphendata@\the\language}{}%
+        }%
+    \fi% 
+}
+
+% Set hyphenation patterns for a given language. This does the right
+% thing both for XeTeX and LuaTeX
+\newcommand*\xpg at set@hyphenation at patterns[1]{%
+  \ifluatex
+    \polyglossia at luatex@load at lang{#1}%
+    \language=\csname l@#1\endcsname
+  \else
+    \ifxetex
+      \language=\csname l@#1\endcsname
+    \else
+      \xpg at warning{You’re~running~a~TeX~engine~that~is~not~LuaTeX~or~XeTeX.\MessageBreak
+        That~is~almost~guaranteed~to~cause~problems.}%
     \fi
+  \fi
 }
 
+% FIXME: Remove after gloss-latin (last user) has been rewritten)
 \newcommand\xpg at set@language at luatex@ii[1]{%
-   \ifluatex %
-     \xpg at set@language at luatex@iii{#1}{\expandafter\the\csname l@#1\endcsname}
-   \fi % 
+     \xpg at set@bbl at hyphendata{\expandafter\the\csname l@#1\endcsname}
 }
 
-\def\select at language#1{%
-   \ifluatex %
-      \xpg at set@language at luatex@iii{#1}{\the\language}
-   \fi %
+
+\newcommand*\@select at language[2][]{
+   % hook for compatibility with biblatex
+   \select at language{#2}
+   \xpg at set@bbl at hyphendata{\the\language}
    \xpg at initial@setup%
-   \select@@language{#1}%
-   \ifcsundef{setRL}{}%
-   {\iftoggle{#1 at RL}{\setRL}{\setLR}}%
-   \csuse{captions#1}%
-   \local at marks{#1}%
-   \csuse{init at extras@#1}%
-   \csuse{blockextras@#1}%
+   \select@@language[#1]{#2}%
+   \polyglossia at lang@setpardirection:n{#2}%
+   \csuse{captions#2}%
+   \csuse{date#2}%
+   % These are hooks for external packages which want to access variants
+   % via babelname (such as biblatex)
+   \cs_if_exist_use:c{captions at bbl@\babelname}%
+   \cs_if_exist_use:c{date at bbl@\babelname}%
+   \local at marks{#2}%
+   \csuse{init at extras@#2}%
+   \polyglossia at lang@indentfirst:n{#2}
+   \csuse{blockextras@#2}%
+   % This is a hook for external packages which want to access variants
+   % via babelname (such as biblatex)
+   \cs_if_exist_use:c{blockextras at bbl@\babelname}%
+ }
+
+% hook for compatibility with biblatex
+\def\select at language#1{}
+
+\def\noextrascurrent#1{%
+   \csuse{noextras@#1}%
+   % This is a hook for external packages which want to access variants
+   % via babelname (such as biblatex)
+   \cs_if_exist_use:c{noextras at bbl@\babelname}
 }
 
 % Common code for `\select at language' and `\foreignlanguage'.
-\newcommand{\select@@language}[1]{%
-  \edef\languagename{#1}%
-  \xpg at select@fontfamily{#1}%
-  \csuse at warn{#1 at language}%
-  \csuse{date#1}%
-  \csuse{#1 at numbers}%
-  \use at localhyphenmins{#1}%
+\newcommand{\select@@language}[2][]{%
+  % disable the extras and number settings of the previous language
+  \ifcsundef{languagename}{}{%
+     \noextrascurrent{\languagename}%
+     \csuse{no\languagename @numbers}%
+     \ifxetex
+        \str_if_eq:eeTF{\prop_item:Nn{\polyglossia at langsetup}{\languagename/direction}}{RL}%
+            {%
+               \str_if_eq:eeTF{\prop_item:Nn{\polyglossia at langsetup}{#2/direction}}{RL}%
+                  {}% RTL -> RTL
+                  {\setlatin}% RTL -> LTR
+            }{%
+               \str_if_eq:eeTF{\prop_item:Nn{\polyglossia at langsetup}{#2/direction}}{RL}%
+                  {\setnonlatin}% LTR -> RTL
+                  {}% LTR -> LTR
+           }%
+     \fi
+  }%
+  \polyglossia at set@language at name[#1]{#2}%
+  % Set the language's/script's font families
+  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia at langsetup}{#2/lcscript}}{latin}{\resetfontlatin}{\xpg at set@normalfont{#2}}%
+  \xpg at select@fontfamily{#2}%
+  \csuse at warn{#2 at language}%
+  \csuse{#2 at numbers}%
+  \use at localhyphenmins{#2}%
+  \polyglossia at lang@frenchspacing:n{#2}
 }
 
 
@@ -835,8 +1564,11 @@
 \provideenvironment{otherlanguage}{}{}
 
 \renewenvironment{otherlanguage}[2][]
-   {\selectlanguage[#1]{#2}}
-   {}
+{
+  \xpg at set@group at aux%
+  \selectlanguage[#1]{#2}
+}
+{\xpg at unset@group at aux}
 
 \newcommand{\setlocalhyphenmins}[3]{%
    \xpg at ifdefined{#1}{%
@@ -853,20 +1585,71 @@
    \ifcsundef{#1hyphenmins}{}%
    {\expandafter\expandafter\expandafter\set at hyphenmins\csname #1hyphenmins\endcsname\relax}}
 
-\define at boolkey{polyglossia}[system@]{babelshorthands}[false]{}
+\AtEndPreamble{%
+   \@ifpackageloaded{bidi}{%
+      \providecommand*{\aemph}[1]{$\overline{\hboxR{#1}}$}%
+   }{}%
+   \@ifpackageloaded{luabidi}{%
+      \providecommand*{\aemph}[1]{$\overline{\hbox{\RL{#1}}}$}%
+   }{}%
+}
 
-\AtEndPreamble{\@ifpackageloaded{bidi}{\providecommand*{\aemph}[1]{$\overline{\hboxR{#1}}$}}{}}% TODO Make that work for luabidi too.
 
-%% Package Options %%
-\DeclareOption{nolocalmarks}{\setkeys{polyglossia}{localmarks=false}}
-\DeclareOption{localmarks}{\setkeys{polyglossia}{localmarks=true}}
-\DeclareOption{babelshorthands}{\setkeys{polyglossia}{babelshorthands=true}}
-\DeclareOption{quiet}{%
+% keys for main package
+\keys_define:nn { polyglossia } {
+  verbose
+     .bool_set:N = \l_polyglossia_verbose_bool,
+  verbose
+     .default:n = true,
+  % compatibility
+  quiet
+     .meta:n =  { verbose = false },
+
+  localmarks
+     .bool_set:N = \l_polyglossia_localmarks_bool,
+  localmarks
+     .default:n = false,
+  % compatibility
+  nolocalmarks
+     .meta:n = { localmarks = false },
+   
+  babelshorthands
+     .bool_set:N = \l_polyglossia_babelshorthands_bool,
+  babelshorthands
+     .default:n = true,
+}
+
+\keys_set:nn { polyglossia } {
+  localmarks = false,
+  verbose = true,
+  babelshorthands = false,
+}
+
+% load by default latex
+\setmainlanguage{latex}
+% then process key in order to overwrite
+\ProcessKeysOptions{polyglossia}
+
+\bool_if:nTF \l_polyglossia_verbose_bool {} {
    \gdef\@latex at info#1{\relax}% no latex info
    \gdef\@font at info#1{\relax}% no latex font info
    \gdef\@font at warning#1{\relax}% no latex font warnings
    \gdef\zf at PackageInfo#1{\relax}% no fontspec info
-   \gdef\xpg at info#1{\relax}}% no polyglossia info
+   \gdef\xpg at info#1{\relax}% no polyglossia info
+}
+
+\bool_if:nTF \l_polyglossia_localmarks_bool {} {
+  \enable at local@marks{}
+}{}
+
+% compatibility
+\newif\ifsystem at babelshorthands
+\bool_if:nTF \l_polyglossia_babelshorthands_bool {
+  \system at babelshorthandstrue
+}{
+  \system at babelshorthandsfalse
+}
+
 %
 % FIXME these should also be loaded \AtEndOfPackage !!!
 \def\xpg at option#1#2{%
@@ -873,5 +1656,5 @@
   \ifcsundef{xpg at main@language}{\setdefaultlanguage}{\setotherlanguage}%
     [#1]{#2}}
 \ExplSyntaxOff
-\ProcessOptions*
+
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/xgreek-fixes.def
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/xgreek-fixes.def	2019-10-28 20:57:44 UTC (rev 52554)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/xgreek-fixes.def	2019-10-28 20:58:49 UTC (rev 52555)
@@ -1,4 +1,17 @@
 % the following fixes are taken verbatim from xgreek.sty:
+% \message{Package `xgreek' version 3.0.1 by Apostolos Syropoulos}
+\global\lccode"0370="0371 \global\uccode"0370="0370
+\global\lccode"0371="0371 \global\uccode"0371="0370
+\global\lccode"0372="0373 \global\uccode"0372="0372
+\global\lccode"0373="0373 \global\uccode"0373="0372
+\global\lccode"0376="0377 \global\uccode"0376="0376
+\global\lccode"0377="0377 \global\uccode"0377="0376
+\global\lccode"03FD="037B \global\uccode"03FD="03FD
+\global\lccode"037B="037B \global\uccode"037B="03FD
+\global\lccode"03FE="037C \global\uccode"03FE="03FE
+\global\lccode"037C="037C \global\uccode"037C="03FE
+\global\lccode"03FF="037D \global\uccode"03FF="03FF
+\global\lccode"037D="037D \global\uccode"037D="03FF
 \global\lccode"0386="03AC \global\uccode"0386="0391
 \global\lccode"0388="03AD \global\uccode"0388="0395
 \global\lccode"0389="03AC \global\uccode"0389="0397
@@ -81,8 +94,8 @@
 \global\lccode"03DD="03DD \global\uccode"03DD="03DC
 \global\lccode"03DE="03DF \global\uccode"03DE="03DE
 \global\lccode"03DF="03DF \global\uccode"03DF="03DE
-\global\lccode"03E0="03E1 \global\uccode"03E0="039A
-\global\lccode"03E0="03E1 \global\uccode"03E1="03A1
+\global\lccode"03E0="03E1 \global\uccode"03E0="03E0
+\global\lccode"03E1="03E1 \global\uccode"03E1="03E0
 \global\lccode"03F0="03BA \global\uccode"03F0="039A
 \global\lccode"03F1="03C1 \global\uccode"03F1="03A1
 \global\lccode"03F2="03F2 \global\uccode"03F2="03F9
@@ -287,7 +300,7 @@
 \global\lccode"1FE2="1FE2 \global\uccode"1FE2="03AB
 \global\lccode"1FE3="1FE3 \global\uccode"1FE3="03AB
 \global\lccode"1FE4="1FE4 \global\uccode"1FE4="03A1
-\global\lccode"1FE5="1FE5 \global\uccode"1FE5="1FEC
+\global\lccode"1FE5="1FE5 \global\uccode"1FE5="03A1
 \global\lccode"1FE6="1FE6 \global\uccode"1FE6="03A5
 \global\lccode"1FE7="1FE7 \global\uccode"1FE7="03AB
 \global\lccode"1FE8="1FE0 \global\uccode"1FE8="1FE8



More information about the tex-live-commits mailing list