texlive[71813] Master/texmf-dist: polyglossia (15jul24)

commits+karl at tug.org commits+karl at tug.org
Mon Jul 15 23:38:31 CEST 2024


Revision: 71813
          https://tug.org/svn/texlive?view=revision&revision=71813
Author:   karl
Date:     2024-07-15 23:38:31 +0200 (Mon, 15 Jul 2024)
Log Message:
-----------
polyglossia (15jul24)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/polyglossia/README.md
    trunk/Master/texmf-dist/doc/latex/polyglossia/example-arabic.pdf
    trunk/Master/texmf-dist/doc/latex/polyglossia/example-arabic.tex
    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/examples.tex
    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/arabicnumbers.sty
    trunk/Master/texmf-dist/tex/latex/polyglossia/cal-util.def
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-aeb.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-af.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-afb.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-afrikaans.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-albanian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-am.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-american.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-amharic.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-apd.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-IQ.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-JO.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-LB.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-MR.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-PS.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-SY.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-YE.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar.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-arq.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ary.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arz.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ast.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-asturian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-australian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-austrian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ayl.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasa.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-be-tarask.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-be.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-belarusian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bengali.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bg.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bn.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bo.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bosnian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-br.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-british.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bs.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bulgarian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ca.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-canadian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-canadien.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-catalan.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-chinese.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb-Arab.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb-Latn.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cop.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-coptic.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-croatian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cy.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cz.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-czech.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-da.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-danish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT-1901.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT-1996.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH-1901.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH-1996.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE-1901.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE-1996.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT-1901.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT-1996.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH-1901.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH-1996.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE-1901.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE-1996.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-divehi.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dsb.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dutch.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dv.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el-monoton.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el-polyton.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-AU.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-CA.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-GB.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-NZ.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-US.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-english.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-eo.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es-ES.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es-MX.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es.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-et.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-eu.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fa.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-farsi.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fi.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-finnish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CA-u-sd-canb.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CA.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CH.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-FR.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr.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-friulian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fur.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ga.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gaelic.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-galician.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gd.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-georgian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-german.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-germanb.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gl.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-grc.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-greek.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-he.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hebrew.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hi.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hindi.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hr.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hsb.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hu.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hungarian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hy.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ia.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-icelandic.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-id.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-is.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-it.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-italian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ja.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-japanese.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ka.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-km.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr-Arab.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr-Latn.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kn.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ko.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-korean.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku-Arab.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku-Latn.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurdish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurmanji.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-classic.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-ecclesia.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-medieval.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lao.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latex.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-lo.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lowersorbian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lsorbian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lt.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lv.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-malay.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malayalam.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-marathi.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mk.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ml.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mn.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mongolian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mr.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-naustrian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nb.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-newzealand.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ngerman.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-norwegian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nswissgerman.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-odia.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-or.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-pa.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-persian.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-polutonikogreek.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuges.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuguese.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-punjabi.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-sami.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-serbianc.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovak.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovene.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovenian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sorbian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanishmx.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swedish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swissgerman.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-syriac.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-tamil.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-telugu.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-turkish.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-turkmen.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ug.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ukrainian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-uppersorbian.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-uyghur.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-vietnamese.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-welsh.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-zh-CN.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-zh-TW.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/hebrewcal.sty
    trunk/Master/texmf-dist/tex/latex/polyglossia/hijrical.sty
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-french.lua
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-latin.lua
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-punct.lua
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-sanskrit.lua
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-tibt.lua
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.lua
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/latex/polyglossia/example-uyghur.tex
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-acadian.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-classiclatin.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ecclesiasticlatin.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-medievallatin.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-cjk-spacing.lua

Removed Paths:
-------------
    trunk/Master/texmf-dist/doc/latex/polyglossia/example-chinese.pdf
    trunk/Master/texmf-dist/doc/latex/polyglossia/example-japanese.pdf
    trunk/Master/texmf-dist/doc/latex/polyglossia/example-odia.pdf
    trunk/Master/texmf-dist/doc/latex/polyglossia/test-welsh.pdf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-acadien.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinclassic.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinecclesiastic.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinmedieval.ldf
    trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-korean.lua

Modified: trunk/Master/texmf-dist/doc/latex/polyglossia/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/polyglossia/README.md	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/doc/latex/polyglossia/README.md	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-# THE POLYGLOSSIA PACKAGE v2.1
+# THE POLYGLOSSIA PACKAGE v2.2
 ## Multilingual typesetting with XeLaTeX and LuaLaTeX
 
 This package provides an alternative to Babel for users of XeLaTeX and LuaLaTeX.

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

Modified: trunk/Master/texmf-dist/doc/latex/polyglossia/example-arabic.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/polyglossia/example-arabic.tex	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/doc/latex/polyglossia/example-arabic.tex	2024-07-15 21:38:31 UTC (rev 71813)
@@ -4,7 +4,12 @@
 \usepackage{xltxtra,url,amsmath}
 \setmainfont{Linux Libertine O}
 \defaultfontfeatures{Scale=MatchLowercase}
-\newfontfamily\arabicfont[Script=Arabic]{Amiri}
+\newfontfamily\arabicfont[Script=Arabic]{Amiri}[%
+ UprightFont = *-Regular,
+  BoldFont = *-Bold,
+  Extension = .ttf,
+  ItalicFont = *-Italic,
+  BoldItalicFont = *-BoldItalic]
 \newfontfamily\arabicfonttt[Script=Arabic,Scale=.75]{DejaVu Sans Mono}
 \newfontfamily\farsifont[Script=Arabic,Scale=1.1,WordSpace=2]{IranNastaliq}
 \let\XeTeX\undefined

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

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

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

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

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

Added: trunk/Master/texmf-dist/doc/latex/polyglossia/example-uyghur.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/polyglossia/example-uyghur.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/polyglossia/example-uyghur.tex	2024-07-15 21:38:31 UTC (rev 71813)
@@ -0,0 +1,128 @@
+% !TeX TS-program = xelatex
+\documentclass[a4paper]{book}
+\usepackage{polyglossia}
+\usepackage{graphicx}
+\usepackage{url,amsmath}
+
+\setmainlanguage{uyghur}
+\newfontfamily\arabicfont[Script=Arabic,Scale=1]{UKIJ Tuz}
+\let\arabicfonttt\ttfamily
+
+\setotherlanguage[variant=british]{english}
+
+\title{لاتېكىس قوللانمىسى}
+\author{neouyghur}
+\date{\today}
+
+\begin{document}
+
+\maketitle
+
+\tableofcontents
+
+\listoffigures
+
+\listoftables
+
+\pagenumbering{arabic}
+
+\chapter{ئۇيغۇرلار}
+
+\section{ئۇيغۇرلار ۋە ئۇلارنىڭ تۇرمۇش مەدەنىيىتى}
+
+ئۇيغۇرلار شىنجاڭ ئۇيغۇر ئاپتونوم رايونىنىڭ ھەقىقىي ئىگىلىرى ۋە مىراسخورلىرى بولۇپ، بۇ رايوندا توپلىشىپ ياشايدىغان غوللۇق، يەرلىك مىللەت ۋە ئاپتونومىيە ھوقۇقى يۈرگۈزگۈچى مىللەت. ئۇيغۇرلار پارچە ھالەتتە، جۇڭگونىڭ بىر قاتار چوڭ شەھەرلىرىدە خىزمەت ۋە تىجارەت قىلىدۇ. ئۇيغۇرلار شىنجاڭ ئۇيغۇر ئاپتونوم رايونىدىن باشقا، يەنە جۇڭگو، قازاقىستان، قىرغىزىستان، ئۆزبېكىستان، تاجىكىستان، تۈركمەنىستان (ئاساسلىقى بايرام ئەلى رايونى)، پاكىستان، ئەرەبىستان، تۈركىيە، ئاۋسترالىيە، گېرمانىيە، نورۋىگىيە، گوللاندىيە، شىۋىتسىيە، فىنلاندىيە، بېلگىيە، روسيە، ئامېرىكا قاتارلىق دۆلەتلەردە كۆرۈنەرلىك نوپۇستا، مۇئەييەن جامائەت تۈركۈمى شەكلىدە ياشايدۇ.
+
+\begin{english}
+The \textbf{Uyghurs}\footnote{%
+	From \url{https://en.wikipedia.org/wiki/Uyghurs}}  have traditionally inhabited a series of oases scattered across the Taklamakan Desert within the Tarim Basin. These oases have historically existed as independent states or were controlled by many civilizations including China, the Mongols, the Tibetans and various Turkic polities. The Uyghurs gradually started to become Islamized in the 10th century and most Uyghurs identified as Muslims by the 16th century. Islam has since played an important role in Uyghur culture and identity. 
+\end{english}
+
+\section{نىكاھ}
+ئۇيغۇرلاردا نىكاھ مۇناسىۋىتى بىلەن چاي ئىچكۈزۈش، توي ئالدىدىكى مەسلىھەت چايلىرى، نىكاھ ئوقۇپ قىز-يىگىتنىڭ رازىلىقىنى ئېلىش، توي مۇراسىمى، يىگىت-قىزلار ئولتۇرۇشى، قۇدىلار چىللاقلىرى ئىزچىل ساقلىنىپ كەلدى. ئۇيغۇرلاردا دەپنە مۇراسىمى ھەرقايسى دىنىي مەدەنىيەتلەر تەسىرىدە ھەرخىل بولسىمۇ، ئەمما مېيىتنى پاكىزە يۇيۇپ كېپەنلەش، ھازىدارلار ئاق رومال سېلىپ، ئاق بەلۋاغ باغلاپ يىغا-زارە قىلىش، مېيىتنىڭ نامىزىنى چۈشۈرۈش، جىنازىنى ئالمىشىپ تالىشىپ كۈتۈرۈپ قەبرىستانلىققا ئېلىپ بېرىش، لەھەتتە مېيىتنىڭ يۈزىنى قىبلە (غەرب) تەرەپكە قىلىپ ياتقۇزۇش، ئىچ گۆرنىڭ ئاغزىنى كېسەك بىلەن ئېتىپ، تاش گۆرنى توپا بىلەن كۆمۈش، قەبرە بېشىدا مېيىتنىڭ ئىجابىي تەرىپىگە گۇۋاھلىق بېرىش، قەبرە تېشى-گۈمبەز ئورنىتىش، مېيىتنىڭ يەتتە، قىرىق، يىل نەزىرلىرىنى ئۆتكۈزۈش ئادەتلىرى بىردەك ئىزچىل بۇلۇپ كەلدى. ئۇيغۇرلار ۋە ئۇلارنىڭ ئەجدادلىرى مېيىت سۆڭىكىنى كاھىش (ساپال) ساندۇققا سېلىپ يەرلىككە قۇيۇش، مېيىتنى تاش گۆرگە كۆمۈش، مېيىتنى ئاستىغا ياغاچ شادا قويۇلغان گۆرگە ياتقۇزۇپ، ئۈستىگە قىزىل تۇپراق ۋە قۇم تۆكۈپ كۆمۈش، شام گۆرگە قويۇش قاتارلىق دەپنە قىلىش ئۇسۇللىرىنىمۇ قوللاندى. 
+
+\section{ھېيت-ئايەم}
+
+
+\begin{figure}
+	\begin{center}
+\includegraphics[scale=1]{example-image-a}
+\caption{ئا رەسىم.}
+	\end{center}
+\end{figure}
+
+\begin{table}
+\begin{center}
+	\begin{tabular}{||c c c c||} 
+		\hline
+		Col1 & Col2 & Col2 & Col3 \\ [0.5ex] 
+		\hline\hline
+		1 & 6 & 87837 & 787 \\ 
+		\hline
+		2 & 7 & 78 & 5415 \\
+		\hline
+		3 & 545 & 778 & 7507 \\
+		\hline
+		4 & 545 & 18744 & 7560 \\
+		\hline
+		5 & 88 & 788 & 6344 \\ [1ex] 
+		\hline
+	\end{tabular}
+	\caption{بىر سىناق جەدۋەل}
+\end{center}
+\end{table}
+
+\begin{equation}
+	x^2 + y^2 = z^2
+	\label{test}
+\end{equation}
+
+
+\chapter{مەڭگۈ تاش يادىكارلىقلىرى}
+
+\section{تەس مەڭگۈ تېشى}
+بۇ مەڭگۈ تاش يادىكارلىقى 1976- يىلى موڭغۇلىيەدىكى تەس دەرياسىنىڭ سول قىرغىدىكى نوغۇن تولغوي ئىگىزلىكىنىڭ يېنىدىن تېپىلغانلىقى ئۈچۈن، «تەس مەڭگۈ تېشى» دەپ ئاتالغان. «تەس مەڭگۈ تېشى» ئورخۇن ئۇيغۇر خانلىقى دەۋرىگە مەنسۇپ يادىكارلىقلارنىڭ ئىچىدە بۇزغۇنچىلىققا ئۇچرىشى ئېغىرراق. ئەڭ مۇھىم بولغان يازما يادىكارلىق. ئۇنىڭدا بۆگۈ قاغان (759- 780- يىللار) ئەجدادى (دادىسى) بولغان ئەل ئەتمىش بىلگە قاغان (مويۇنچۇر، 747- 759- يىللار9 دەۋرىگىچە بولغان ئۇيغۇر قاغانلىرىنىڭ تارىخى، جۈملىدىن بىرىنچى ۋە ئىككىنچى ئۇيغۇر خانلىقىنىڭ تەقدىرى. كۆل بىلگە قاغان ۋە ئەل ئەتمىش بىلگە قاغان باشچىلىقىدىكى ئۈچىنچى ئۇيغۇر خانلىقىنىڭ بەرپا بولۇشى قاتارلىق مەسىلىلەر ھەققىدە مەلۇمات بېرىلگەن. بۇ ھەقتىكى بىر قىسىم مەزمۇنلار كونا- يېڭى تاڭنامىلەردە ئۇچرىمايدۇ. شۇڭا تەس مەڭگۈ تېشىدىكى مەلۇماتلار زور سېلىشتۇرما قىممەتكە ئىگە. تەتقىقاتلارغا قارىغاندا، «تەس مەڭگۈ تېشى» نىڭ ئاپتورى مويۇنچۇر قاغاننىڭ يېقىن تۇققىنى تۈپەك ئالىپ شۇل دېگەن كىشى بولۇپ، مەڭگۈ تاشنى قاغان يېڭىدىن تەختكە چىققان ۋاقىتتا توغرىسى 761- 762- يىللىرى ئورنىتىلغان، دېيىشكە بولىدۇ.
+
+
+\begin{table}
+	\begin{center}
+		\begin{tabular}{||c c c c||} 
+			\hline
+			Col1 & Col2 & Col2 & Col3 \\ [0.5ex] 
+			\hline\hline
+			1 & 6 & 87837 & 787 \\ 
+			\hline
+			2 & 7 & 78 & 5415 \\
+			\hline
+			3 & 545 & 778 & 7507 \\
+			\hline
+			4 & 545 & 18744 & 7560 \\
+			\hline
+			5 & 88 & 788 & 6344 \\ [1ex] 
+			\hline
+		\end{tabular}
+		\caption{يەنە بىر سىناق جەدۋەل}
+	\end{center}
+\end{table}
+
+\section{تېرخىن مەڭگۈ تېشى}
+
+\begin{figure}
+	\begin{center}
+	\includegraphics[scale=0.5]{example-image-b}
+	\caption{ب رەسىم.}
+	\end{center}
+\end{figure}
+
+\begin{thebibliography}{9}
+	\bibitem{latexcompanion} 
+	Michel Goossens, Frank Mittelbach, and Alexander Samarin. 
+	\textit{The \LaTeX\ Companion}. 
+	Addison-Wesley, Reading, Massachusetts, 1993.
+	
+	\bibitem{einstein} 
+	ئو. تۇرسۇن. 
+	\textit{لاتېكىست قوللانمىسى}. (ئۇيغۇرچە) 
+	[\textit{بىر ژورنال}]. , 322(10):891–921, 1905.
+\end{thebibliography}
+
+\end{document}


Property changes on: trunk/Master/texmf-dist/doc/latex/polyglossia/example-uyghur.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/doc/latex/polyglossia/examples.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/polyglossia/examples.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/polyglossia/examples.tex	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/doc/latex/polyglossia/examples.tex	2024-07-15 21:38:31 UTC (rev 71813)
@@ -16,7 +16,12 @@
 \setmainfont{Linux Libertine O}
 \defaultfontfeatures{Scale=MatchLowercase}
 \setmonofont{Inconsolata}
-\newfontfamily\arabicfont[Script=Arabic]{Amiri}
+\newfontfamily\arabicfont[Script=Arabic]{Amiri}[%
+ UprightFont = *-Regular,
+  BoldFont = *-Bold,
+  Extension = .ttf,
+  ItalicFont = *-Italic,
+  BoldItalicFont = *-BoldItalic]
 \newfontfamily\syriacfont[Script=Syriac]{Serto Jerusalem}
 \newfontfamily\hebrewfont[Script=Hebrew]{Ezra SIL}
 \newfontfamily\sanskritfont[Script=Devanagari]{Sanskrit 2003}

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	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/doc/latex/polyglossia/polyglossia.tex	2024-07-15 21:38:31 UTC (rev 71813)
@@ -23,8 +23,10 @@
     ]{hyperref}
 \usepackage{array}
 \usepackage{metalogo}
-\let\XeTeX\undefined
-\let\XeLaTeX\undefined
+\ifxetex
+  \let\XeTeX\undefined
+  \let\XeLaTeX\undefined
+\fi
 \usepackage[babelshorthands]{polyglossia}
 \usepackage{farsical}
 %
@@ -124,15 +126,23 @@
 \usepackage[osf]{libertine}
 % Monospace: Package dejavu-otf
 \setmonofont[Scale=MatchLowercase]{DejaVuSansMono}
-% Libertine includes Hebrew, but we load it separately since
-% osf is not supported with this script and we want to avoid the
-% respective warnings
-\newfontfamily\hebrewfont[Script=Hebrew]{Linux Libertine O}
+% Package culmus
+\newfontfamily\hebrewfont[Script=Hebrew]{DavidCLM}[
+  UprightFont = *-Medium,
+  BoldFont = *-Bold,
+  Extension = .otf,
+  ItalicFont = *-MediumItalic,
+  BoldItalicFont = *-BoldItalic]
 % Package dejavu-otf
 \newfontfamily\armenianfont[Script=Armenian,Scale=MatchLowercase]{DejaVuSans}
 \newfontfamily\georgianfont[Scale=MatchLowercase]{DejaVuSerif}
 % Package amiri
-\newfontfamily\arabicfont[Script=Arabic]{Amiri-Regular}
+\newfontfamily\arabicfont[Script=Arabic]{Amiri}[%
+ UprightFont = *-Regular,
+  BoldFont = *-Bold,
+  Extension = .ttf,
+  ItalicFont = *-Italic,
+  BoldItalicFont = *-BoldItalic]
 % No Syriac otf/ttf font seems available on CTAN
 % This one, from the Syriac Institute, is included on Linux
 % in the x11-fonts set and can be downloaded from
@@ -457,7 +467,7 @@
 	dv               & divehi      &                                                    \tabularnewline
 	el               & greek       &                                                    \tabularnewline
 	el-monoton       & greek       & variant=monotonic  [\emph{default}]                \tabularnewline
-	el-polyton       & greek       & varant=polytonic                                   \tabularnewline
+	el-polyton       & greek       & variant=polytonic                                   \tabularnewline
 	en               & english     &                                                    \tabularnewline
 	en-AU            & english     & variant=australian                                 \tabularnewline
 	en-CA            & english     & variant=canadian                                   \tabularnewline
@@ -771,13 +781,25 @@
 
 \section{Font setup}
 
-With polyglossia it is possible to associate a specific font with any script or language
+With \pkg{polyglossia} it is possible to associate a specific font with any script or language
 that occurs in the document. That font should always be defined as
-\cmd{\⟨script⟩font}\ or \cmd{\⟨language⟩font}.
+\cmd{\⟨script⟩font}\ or \cmd{\⟨language⟩font}. Note that ¦⟨language⟩¦ points to the \pkg{polyglossia}
+language name, ¦⟨script⟩¦ might point either to an OpenType script name as defined by \pkg{fontspec}
+(\eg ¦Latin¦) \new{2.2}or a BCP-47 script tag (\eg ¦Latn¦), though the script is fully lower-cased
+in the \cmd{\⟨script⟩font}\ command.
+
 For instance, if the default font defined by \cmd\setmainfont\
 does not support Greek, then one can define the font used to display Greek with:\\
-\centerline{ \cmd\newfontfamily\cmd{\greekfont[Script=Greek,\meta{…}]\marg{font}}. }
-Note that polyglossia will use the font defined as is, so assure to do all necessary settings
+\centerline{\cmd\newfontfamily\cmd{\greekfont[Script=Greek,\meta{…}]\marg{font}}}
+%
+If you want to setup a blackletter font specifically for the German blackletter script variant,
+you might do so by:\\
+\centerline{\cmd\newfontfamily\cmd{\latffont[\meta{…}]\marg{font}}}
+%
+Setting up a font specifically for traditional Chinese is possible via:\\
+\centerline{\cmd\newfontfamily\cmd{\hantfont[Script=CJK,\meta{…}]\marg{font}}}
+%
+Note that \pkg{polyglossia} will use the font defined as is, so assure to do all necessary settings
 (please refer to the \pkg{fontspec} documentation for details).
 For instance, if \cmd\arabicfont\ is explicitly defined, then the option ¦Script=Arabic¦ should
 be included in that definition.
@@ -787,10 +809,12 @@
 \cmd{\⟨script⟩fontsf} or \cmd{\⟨language⟩fontsf} and \cmd{\⟨script⟩fonttt} or \cmd{\⟨language⟩fonttt}, respectively.
 
 Whenever a new language is activated, \pkg{polyglossia} will first check whether
-a font has been defined for that language or – for languages in non-Latin scripts –
-for the script it uses. If it is not defined, it will use the currently active font
-and – in the case of OpenType fonts – will attempt to turn on the appropriate
-OpenType tags for the script and language used, in case these are available in
+a font has been defined for that language. If this is not the case, it will check whether a font associated
+with the BCP-47 script tag of the current language is defined. If this also isn't the case, \pkg{polyglossia}
+will finally check (but this only for languages in non-Latin scripts) whether there is a font associated
+with the OpenType script tag. If none of these fonts is defined, \pkg{polyglossia} will use the currently
+active font as defined by ¦\setmainfont¦, ¦\setsansfont¦ or ¦\setmonofont¦ and – in the case of OpenType fonts –
+will attempt to turn on the appropriate OpenType tags for the script and language used, in case these are available in
 the font, by means of \pkg{fontspec}’s \cmd\addfontfeature. If the current font
 does not appear to support the script of that language, an error message is
 displayed.
@@ -1585,7 +1609,7 @@
 			\end{table}
 	\item \xpgchoicekey[1.46]{hyphenation}{\xpgvalue{classic}, \xpgvalue{modern}, or \xpgvalue{liturgical}}
 			There are three different sets of hyphenation patterns for Latin. Separate
-			documention for them is available on the
+			documentation for them is available on the
 			Internet.\footnote{Refer to \url{https://github.com/gregorio-project/hyphen-la/blob/master/doc/README.md\#hyphenation-styles}}
 			Each of the four variants mentioned above has its default set of hyphenation
 			patterns as indicated by table \ref{tab:latin-hyphenation}. Use the
@@ -1657,7 +1681,7 @@
 				\item[¦'AE¦] for Ǽ (AE ligature with acute), also available for \'Œ
 			\end{shorthands}
 	\item \xpgboolkeyfalse[1.46]{prosodicshorthands}
-			Enable shorthands for prosodic marks (macrons and breves) very similiar to
+			Enable shorthands for prosodic marks (macrons and breves) very similar to
 			those provided by \pkg{babel-latin} using the ¦withprosodicmarks¦
 			modifier.
 			Note that the active ¦=¦ character used for macrons will cause problems with
@@ -2563,7 +2587,7 @@
 \subsection{Islamic calendar (hijrical.sty)}\label{sec:hijrical}
 This package computes dates in the lunar Islamic (Hijra) calendar.\footnote{ %
 	It makes use of the arithmetical algorithm in chapter 6 of
-	Reingold \& Gershowitz, \textit{Calendrical calculation: the Millenium edition}
+	Reingold \& Gershowitz, \textit{Calendrical calculation: the Millennium edition}
 	(Cambridge University Press, 2001).\label{reingold}}
 It provides two macros for the end-user.
 The command
@@ -2698,6 +2722,31 @@
 
 \bgroup\footnotesize
 
+\subsection*{2.2 (2024/07/15)}
+
+\subsubsection*{Bug fixes}
+\begin{itemize}
+	\item Fix \texttt{lang} environment (\TXI{633}).
+	\item Fix first number of Maghrib abjad numbering for Algeria, Morocco and
+	      Tunisia (\TXI{640}).
+	\item Fix some captions strings in Bulgarian, Chinese, Esperanto, Estonian, Hindi,
+	      Latvian, and Slovak (\TXP{651})
+	\item Improve performance with multilingual documents that have a TOC (\TXI{641}).
+\end{itemize}
+
+\subsubsection*{New Features}
+\begin{itemize}
+	\item Add possibility to associate a font to a language/variant with reference to
+	      a BCP-47 script tag (\TXI{636}). 
+\end{itemize}
+
+\subsubsection*{Internal work}
+\begin{itemize}
+	\item The major rewrite of the package code has been finished. More code has been cleaned up,
+	and \pkg{polyglossia} employs modern concepts (\pkg{latex3} and modern \LaTeXe).
+	All key-val handling uses \pkg{l3keys} now rather than \pkg{xkeyval}.
+\end{itemize}
+
 \subsection*{2.1 (2024/03/07)}
 
 \subsubsection*{Bug fixes}
@@ -3756,7 +3805,7 @@
 \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: \TA{Johannes
+whose splendid work has made my task almost trivial in comparison: \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 Kryukov} (\pkg{antomega}),
 \TA{Will Robertson} (\pkg{fontspec}), \TA{Apostolos Syropoulos} (\pkg{xgreek}), \TA{Youssef Jabri}
@@ -3783,7 +3832,7 @@
 since we took over.
 In alphabetical order: \TA{Ignas Anikevicius}, \TA{Sina Ahmadi}, \TA{Matthew Bertucci}, \TA{Wouter Bolsterlee}, \TA{Christian Buhtz},
 \TA{Ashok Das}, \TA{Oleg Domanov}, user \TA{fakhriaunur}, \TA{Philipp Gesang}, \TA{Kevin Godby},
-\TA{Enrico Gregorio}, \TA{Khaled Hosny}, \TA{Najib Idrissi}, user \TA{julroy67}, \TA{Dohyun Kim}, \TA{Phil Kime},
+\TA{Enrico Gregorio}, \TA{Khaled Hosny}, \TA{Stephen Huan}, \TA{Najib Idrissi}, user \TA{julroy67}, \TA{Dohyun Kim}, \TA{Phil Kime},
 \TA{Mike Kroutikov}, \TA{Ivan Kokan}, \TA{Caleb Maclennan}, \TA{Gyula Magyarkuti}, \TA{José Mancera}, \TA{Miquel Ortega},
 \TA{Yevgen Pogribnyi}, \TA{Will Robertson}, \TA{Maïeul Rouquette}, \TA{Elie Roux}, \TA{Hugo Roy},  \TA{Guy Rutenberg},
 \TA{Marcin Serwin}, \TA{Arvinder Singh}, \TA{Avisek Jena}, \TA{Philipp Stephani}, \TA{Niranjan Tambe}, \TA{Takuji Tanaka},

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

Modified: trunk/Master/texmf-dist/source/latex/polyglossia/polyglossia.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/polyglossia/polyglossia.dtx	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/source/latex/polyglossia/polyglossia.dtx	2024-07-15 21:38:31 UTC (rev 71813)
@@ -8,7 +8,7 @@
 \iffalse
 %</internal>
 %<*README>
-# THE POLYGLOSSIA PACKAGE v2.1
+# THE POLYGLOSSIA PACKAGE v2.2
 ## Multilingual typesetting with XeLaTeX and LuaLaTeX
 
 This package provides an alternative to Babel for users of XeLaTeX and LuaLaTeX.
@@ -65,7 +65,8 @@
   ____________________________
 
   The polyglossia package         
-  (C) 2008–2010 François Charette    
+  (C) 2008–2010 François Charette
+  (C) 2023-2024 Udi Fogiel
   (C) 2011–2024 Arthur Reutenauer
   (C) 2013 Elie Roux
   (C) 2019 Bastien Roucariès
@@ -76,19 +77,29 @@
 \endpreamble
 \postamble
 
- Copyright (C) 2024 by Arthur Reutenauer <arthur 'dot' reutenauer 'at' normalesup 'dot' org> 
+ Copyright (C) 2024 by The Polyglossia Team http://github.com/reutenauer/polyglossia/ 
 
- This work may be distributed and/or modified under the
- conditions of the LaTeX Project Public License, either version 1.3
- of this license of (at your option) any later version.
- The latest version of this license is in
-   http://www.latex-project.org/lppl.txt
- and version 1.3 or later is part of all distributions of LaTeX
- version 2005/12/01 or later.
+ Except where otherwise noted, Polyglossia is placed under the terms of the
+ MIT licence (https://opensource.org/licenses/MIT).
+ 
+ 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:
 
- This work has the LPPL maintenance status `maintained'.
+ 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.
 
- The Current Maintainer of this work is Arthur Reutenauer.
+ Please report issues to http://github.com/reutenauer/polyglossia/issues
 
 
 \endpostamble
@@ -98,8 +109,8 @@
 \generate{\file{farsical.sty}{\from{polyglossia.dtx}{farsical.sty}}}
 \generate{\file{hebrewcal.sty}{\from{polyglossia.dtx}{hebrewcal.sty}}}
 \generate{\file{hijrical.sty}{\from{polyglossia.dtx}{hijrical.sty}}}
+\generate{\file{polyglossia-cjk-spacing.lua}{\from{polyglossia.dtx}{polyglossia-cjk-spacing.lua}}}
 \generate{\file{polyglossia-french.lua}{\from{polyglossia.dtx}{polyglossia-french.lua}}}
-\generate{\file{polyglossia-korean.lua}{\from{polyglossia.dtx}{polyglossia-korean.lua}}}
 \generate{\file{polyglossia-latin.lua}{\from{polyglossia.dtx}{polyglossia-latin.lua}}}
 \generate{\file{polyglossia-punct.lua}{\from{polyglossia.dtx}{polyglossia-punct.lua}}}
 \generate{\file{polyglossia-sanskrit.lua}{\from{polyglossia.dtx}{polyglossia-sanskrit.lua}}}
@@ -109,7 +120,7 @@
 \generate{\file{babelsh.def}{\from{polyglossia.dtx}{babelsh.def}}}
 \generate{\file{cal-util.def}{\from{polyglossia.dtx}{cal-util.def}}}
 \generate{\file{xgreek-fixes.def}{\from{polyglossia.dtx}{xgreek-fixes.def}}}
-\generate{\file{gloss-acadien.ldf}{\from{polyglossia.dtx}{gloss-acadien.ldf}}}
+\generate{\file{gloss-acadian.ldf}{\from{polyglossia.dtx}{gloss-acadian.ldf}}}
 \generate{\file{gloss-aeb.ldf}{\from{polyglossia.dtx}{gloss-aeb.ldf}}}
 \generate{\file{gloss-af.ldf}{\from{polyglossia.dtx}{gloss-af.ldf}}}
 \generate{\file{gloss-afb.ldf}{\from{polyglossia.dtx}{gloss-afb.ldf}}}
@@ -163,6 +174,7 @@
 \generate{\file{gloss-ckb-Arab.ldf}{\from{polyglossia.dtx}{gloss-ckb-Arab.ldf}}}
 \generate{\file{gloss-ckb-Latn.ldf}{\from{polyglossia.dtx}{gloss-ckb-Latn.ldf}}}
 \generate{\file{gloss-ckb.ldf}{\from{polyglossia.dtx}{gloss-ckb.ldf}}}
+\generate{\file{gloss-classiclatin.ldf}{\from{polyglossia.dtx}{gloss-classiclatin.ldf}}}
 \generate{\file{gloss-cop.ldf}{\from{polyglossia.dtx}{gloss-cop.ldf}}}
 \generate{\file{gloss-coptic.ldf}{\from{polyglossia.dtx}{gloss-coptic.ldf}}}
 \generate{\file{gloss-croatian.ldf}{\from{polyglossia.dtx}{gloss-croatian.ldf}}}
@@ -195,6 +207,7 @@
 \generate{\file{gloss-dsb.ldf}{\from{polyglossia.dtx}{gloss-dsb.ldf}}}
 \generate{\file{gloss-dutch.ldf}{\from{polyglossia.dtx}{gloss-dutch.ldf}}}
 \generate{\file{gloss-dv.ldf}{\from{polyglossia.dtx}{gloss-dv.ldf}}}
+\generate{\file{gloss-ecclesiasticlatin.ldf}{\from{polyglossia.dtx}{gloss-ecclesiasticlatin.ldf}}}
 \generate{\file{gloss-el-monoton.ldf}{\from{polyglossia.dtx}{gloss-el-monoton.ldf}}}
 \generate{\file{gloss-el-polyton.ldf}{\from{polyglossia.dtx}{gloss-el-polyton.ldf}}}
 \generate{\file{gloss-el.ldf}{\from{polyglossia.dtx}{gloss-el.ldf}}}
@@ -277,9 +290,6 @@
 \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-latinclassic.ldf}{\from{polyglossia.dtx}{gloss-latinclassic.ldf}}}
-\generate{\file{gloss-latinecclesiastic.ldf}{\from{polyglossia.dtx}{gloss-latinecclesiastic.ldf}}}
-\generate{\file{gloss-latinmedieval.ldf}{\from{polyglossia.dtx}{gloss-latinmedieval.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-lo.ldf}{\from{polyglossia.dtx}{gloss-lo.ldf}}}
@@ -292,6 +302,7 @@
 \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-medievallatin.ldf}{\from{polyglossia.dtx}{gloss-medievallatin.ldf}}}
 \generate{\file{gloss-mk.ldf}{\from{polyglossia.dtx}{gloss-mk.ldf}}}
 \generate{\file{gloss-ml.ldf}{\from{polyglossia.dtx}{gloss-ml.ldf}}}
 \generate{\file{gloss-mn.ldf}{\from{polyglossia.dtx}{gloss-mn.ldf}}}
@@ -351,16 +362,9 @@
 \generate{\file{gloss-welsh.ldf}{\from{polyglossia.dtx}{gloss-welsh.ldf}}}
 \generate{\file{gloss-zh-CN.ldf}{\from{polyglossia.dtx}{gloss-zh-CN.ldf}}}
 \generate{\file{gloss-zh-TW.ldf}{\from{polyglossia.dtx}{gloss-zh-TW.ldf}}}
-\generate{\file{arabicdigits.map}{\from{polyglossia.dtx}{arabicdigits.map}}}
-\generate{\file{bengalidigits.map}{\from{polyglossia.dtx}{bengalidigits.map}}}
-\generate{\file{devanagaridigits.map}{\from{polyglossia.dtx}{devanagaridigits.map}}}
-\generate{\file{farsidigits.map}{\from{polyglossia.dtx}{farsidigits.map}}}
-\generate{\file{gurmukhidigits.map}{\from{polyglossia.dtx}{gurmukhidigits.map}}}
-\generate{\file{odiadigits.map}{\from{polyglossia.dtx}{odiadigits.map}}}
-\generate{\file{thaidigits.map}{\from{polyglossia.dtx}{thaidigits.map}}}
 \def\MetaPrefix{-- }
+\generate{\file{polyglossia-cjk-spacing.lua}{\from{polyglossia.dtx}{polyglossia-cjk-spacing.lua}}}
 \generate{\file{polyglossia-french.lua}{\from{polyglossia.dtx}{polyglossia-french.lua}}}
-\generate{\file{polyglossia-korean.lua}{\from{polyglossia.dtx}{polyglossia-korean.lua}}}
 \generate{\file{polyglossia-latin.lua}{\from{polyglossia.dtx}{polyglossia-latin.lua}}}
 \generate{\file{polyglossia-punct.lua}{\from{polyglossia.dtx}{polyglossia-punct.lua}}}
 \generate{\file{polyglossia-sanskrit.lua}{\from{polyglossia.dtx}{polyglossia-sanskrit.lua}}}
@@ -405,8 +409,10 @@
     ]{hyperref}
 \usepackage{array}
 \usepackage{metalogo}
-\let\XeTeX\undefined
-\let\XeLaTeX\undefined
+\ifxetex
+  \let\XeTeX\undefined
+  \let\XeLaTeX\undefined
+\fi
 \usepackage[babelshorthands]{polyglossia}
 \usepackage{farsical}
 %
@@ -506,15 +512,23 @@
 \usepackage[osf]{libertine}
 % Monospace: Package dejavu-otf
 \setmonofont[Scale=MatchLowercase]{DejaVuSansMono}
-% Libertine includes Hebrew, but we load it separately since
-% osf is not supported with this script and we want to avoid the
-% respective warnings
-\newfontfamily\hebrewfont[Script=Hebrew]{Linux Libertine O}
+% Package culmus
+\newfontfamily\hebrewfont[Script=Hebrew]{DavidCLM}[
+  UprightFont = *-Medium,
+  BoldFont = *-Bold,
+  Extension = .otf,
+  ItalicFont = *-MediumItalic,
+  BoldItalicFont = *-BoldItalic]
 % Package dejavu-otf
 \newfontfamily\armenianfont[Script=Armenian,Scale=MatchLowercase]{DejaVuSans}
 \newfontfamily\georgianfont[Scale=MatchLowercase]{DejaVuSerif}
 % Package amiri
-\newfontfamily\arabicfont[Script=Arabic]{Amiri-Regular}
+\newfontfamily\arabicfont[Script=Arabic]{Amiri}[%
+ UprightFont = *-Regular,
+  BoldFont = *-Bold,
+  Extension = .ttf,
+  ItalicFont = *-Italic,
+  BoldItalicFont = *-BoldItalic]
 % No Syriac otf/ttf font seems available on CTAN
 % This one, from the Syriac Institute, is included on Linux
 % in the x11-fonts set and can be downloaded from
@@ -850,7 +864,7 @@
 % 	dv               & divehi      &                                                    \tabularnewline
 % 	el               & greek       &                                                    \tabularnewline
 % 	el-monoton       & greek       & variant=monotonic  [\emph{default}]                \tabularnewline
-% 	el-polyton       & greek       & varant=polytonic                                   \tabularnewline
+% 	el-polyton       & greek       & variant=polytonic                                   \tabularnewline
 % 	en               & english     &                                                    \tabularnewline
 % 	en-AU            & english     & variant=australian                                 \tabularnewline
 % 	en-CA            & english     & variant=canadian                                   \tabularnewline
@@ -1164,13 +1178,25 @@
 % 
 % \section{Font setup}
 % 
-% With polyglossia it is possible to associate a specific font with any script or language
+% With \pkg{polyglossia} it is possible to associate a specific font with any script or language
 % that occurs in the document. That font should always be defined as
-% \cmd{\⟨script⟩font}\ or \cmd{\⟨language⟩font}.
+% \cmd{\⟨script⟩font}\ or \cmd{\⟨language⟩font}. Note that ¦⟨language⟩¦ points to the \pkg{polyglossia}
+% language name, ¦⟨script⟩¦ might point either to an OpenType script name as defined by \pkg{fontspec}
+% (\eg ¦Latin¦) \new{2.2}or a BCP-47 script tag (\eg ¦Latn¦), though the script is fully lower-cased
+% in the \cmd{\⟨script⟩font}\ command.
+% 
 % For instance, if the default font defined by \cmd\setmainfont\
 % does not support Greek, then one can define the font used to display Greek with:\\
-% \centerline{ \cmd\newfontfamily\cmd{\greekfont[Script=Greek,\meta{…}]\marg{font}}. }
-% Note that polyglossia will use the font defined as is, so assure to do all necessary settings
+% \centerline{\cmd\newfontfamily\cmd{\greekfont[Script=Greek,\meta{…}]\marg{font}}}
+% ^^A
+% If you want to setup a blackletter font specifically for the German blackletter script variant,
+% you might do so by:\\
+% \centerline{\cmd\newfontfamily\cmd{\latffont[\meta{…}]\marg{font}}}
+% ^^A
+% Setting up a font specifically for traditional Chinese is possible via:\\
+% \centerline{\cmd\newfontfamily\cmd{\hantfont[Script=CJK,\meta{…}]\marg{font}}}
+% ^^A
+% Note that \pkg{polyglossia} will use the font defined as is, so assure to do all necessary settings
 % (please refer to the \pkg{fontspec} documentation for details).
 % For instance, if \cmd\arabicfont\ is explicitly defined, then the option ¦Script=Arabic¦ should
 % be included in that definition.
@@ -1180,10 +1206,12 @@
 % \cmd{\⟨script⟩fontsf} or \cmd{\⟨language⟩fontsf} and \cmd{\⟨script⟩fonttt} or \cmd{\⟨language⟩fonttt}, respectively.
 % 
 % Whenever a new language is activated, \pkg{polyglossia} will first check whether
-% a font has been defined for that language or – for languages in non-Latin scripts –
-% for the script it uses. If it is not defined, it will use the currently active font
-% and – in the case of OpenType fonts – will attempt to turn on the appropriate
-% OpenType tags for the script and language used, in case these are available in
+% a font has been defined for that language. If this is not the case, it will check whether a font associated
+% with the BCP-47 script tag of the current language is defined. If this also isn't the case, \pkg{polyglossia}
+% will finally check (but this only for languages in non-Latin scripts) whether there is a font associated
+% with the OpenType script tag. If none of these fonts is defined, \pkg{polyglossia} will use the currently
+% active font as defined by ¦\setmainfont¦, ¦\setsansfont¦ or ¦\setmonofont¦ and – in the case of OpenType fonts –
+% will attempt to turn on the appropriate OpenType tags for the script and language used, in case these are available in
 % the font, by means of \pkg{fontspec}’s \cmd\addfontfeature. If the current font
 % does not appear to support the script of that language, an error message is
 % displayed.
@@ -1978,7 +2006,7 @@
 % 			\end{table}
 % 	\item \xpgchoicekey[1.46]{hyphenation}{\xpgvalue{classic}, \xpgvalue{modern}, or \xpgvalue{liturgical}}
 % 			There are three different sets of hyphenation patterns for Latin. Separate
-% 			documention for them is available on the
+% 			documentation for them is available on the
 % 			Internet.\footnote{Refer to \url{https://github.com/gregorio-project/hyphen-la/blob/master/doc/README.md\#hyphenation-styles}}
 % 			Each of the four variants mentioned above has its default set of hyphenation
 % 			patterns as indicated by table \ref{tab:latin-hyphenation}. Use the
@@ -2050,7 +2078,7 @@
 % 				\item[¦'AE¦] for Ǽ (AE ligature with acute), also available for \'Œ
 % 			\end{shorthands}
 % 	\item \xpgboolkeyfalse[1.46]{prosodicshorthands}
-% 			Enable shorthands for prosodic marks (macrons and breves) very similiar to
+% 			Enable shorthands for prosodic marks (macrons and breves) very similar to
 % 			those provided by \pkg{babel-latin} using the ¦withprosodicmarks¦
 % 			modifier.
 % 			Note that the active ¦=¦ character used for macrons will cause problems with
@@ -2956,7 +2984,7 @@
 % \subsection{Islamic calendar (hijrical.sty)}\label{sec:hijrical}
 % This package computes dates in the lunar Islamic (Hijra) calendar.\footnote{ %
 % 	It makes use of the arithmetical algorithm in chapter 6 of
-% 	Reingold \& Gershowitz, \textit{Calendrical calculation: the Millenium edition}
+% 	Reingold \& Gershowitz, \textit{Calendrical calculation: the Millennium edition}
 % 	(Cambridge University Press, 2001).\label{reingold}}
 % It provides two macros for the end-user.
 % The command
@@ -3091,6 +3119,31 @@
 % 
 % \bgroup\footnotesize
 % 
+% \subsection*{2.2 (2024/07/15)}
+% 
+% \subsubsection*{Bug fixes}
+% \begin{itemize}
+% 	\item Fix \texttt{lang} environment (\TXI{633}).
+% 	\item Fix first number of Maghrib abjad numbering for Algeria, Morocco and
+% 	      Tunisia (\TXI{640}).
+% 	\item Fix some captions strings in Bulgarian, Chinese, Esperanto, Estonian, Hindi,
+% 	      Latvian, and Slovak (\TXP{651})
+% 	\item Improve performance with multilingual documents that have a TOC (\TXI{641}).
+% \end{itemize}
+% 
+% \subsubsection*{New Features}
+% \begin{itemize}
+% 	\item Add possibility to associate a font to a language/variant with reference to
+% 	      a BCP-47 script tag (\TXI{636}). 
+% \end{itemize}
+% 
+% \subsubsection*{Internal work}
+% \begin{itemize}
+% 	\item The major rewrite of the package code has been finished. More code has been cleaned up,
+% 	and \pkg{polyglossia} employs modern concepts (\pkg{latex3} and modern \LaTeXe).
+% 	All key-val handling uses \pkg{l3keys} now rather than \pkg{xkeyval}.
+% \end{itemize}
+% 
 % \subsection*{2.1 (2024/03/07)}
 % 
 % \subsubsection*{Bug fixes}
@@ -4149,7 +4202,7 @@
 % \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: \TA{Johannes
+% whose splendid work has made my task almost trivial in comparison: \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 Kryukov} (\pkg{antomega}),
 % \TA{Will Robertson} (\pkg{fontspec}), \TA{Apostolos Syropoulos} (\pkg{xgreek}), \TA{Youssef Jabri}
@@ -4176,7 +4229,7 @@
 % since we took over.
 % In alphabetical order: \TA{Ignas Anikevicius}, \TA{Sina Ahmadi}, \TA{Matthew Bertucci}, \TA{Wouter Bolsterlee}, \TA{Christian Buhtz},
 % \TA{Ashok Das}, \TA{Oleg Domanov}, user \TA{fakhriaunur}, \TA{Philipp Gesang}, \TA{Kevin Godby},
-% \TA{Enrico Gregorio}, \TA{Khaled Hosny}, \TA{Najib Idrissi}, user \TA{julroy67}, \TA{Dohyun Kim}, \TA{Phil Kime},
+% \TA{Enrico Gregorio}, \TA{Khaled Hosny}, \TA{Stephen Huan}, \TA{Najib Idrissi}, user \TA{julroy67}, \TA{Dohyun Kim}, \TA{Phil Kime},
 % \TA{Mike Kroutikov}, \TA{Ivan Kokan}, \TA{Caleb Maclennan}, \TA{Gyula Magyarkuti}, \TA{José Mancera}, \TA{Miquel Ortega},
 % \TA{Yevgen Pogribnyi}, \TA{Will Robertson}, \TA{Maïeul Rouquette}, \TA{Elie Roux}, \TA{Hugo Roy},  \TA{Guy Rutenberg},
 % \TA{Marcin Serwin}, \TA{Arvinder Singh}, \TA{Avisek Jena}, \TA{Philipp Stephani}, \TA{Niranjan Tambe}, \TA{Takuji Tanaka},
@@ -4208,11 +4261,12 @@
 %    \begin{macrocode}
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesExplPackage
-  {polyglossia} {2024/03/07} {v2.1}
+  {polyglossia} {2024/07/15} {v2.2}
   {Modern multilingual typesetting with XeLaTeX and LuaLaTeX}
 
+% TODO Handle remaining uses in the gloss files (\patchcmd)
+%      and remove package call afterwards
 \RequirePackage{etoolbox}
-\RequirePackage{xkeyval}[2008/08/13]
 % Will raise error if used with anything else than XeTeX or LuaTeX
 \RequirePackage{fontspec}[2010/06/08]% v2.0
 \RequirePackage{iftex}
@@ -4219,13 +4273,6 @@
 
 \prg_generate_conditional_variant:Nnn \clist_if_in:Nn {Ne} {TF, T, F} % check if needed
 
-% correct a bug in tracklang
-\AddToHook{package/tracklang/after}{%
-  \IfPackageAtLeastTF{tracklang}{2019/08/30}
-      {}
-      {\cs_gset_eq:NN \AddTrackedLangage \AddTrackedLanguage}
-}
-
 %% The following is for compatibility with Babel-aware package:
 % \languageshorthands is provided by babelsh.def, which is
 % only loaded by some glosses, but some classes presuppose
@@ -4232,9 +4279,10 @@
 % it is there generally. So let's provide a stub:
 \ProvideDocumentCommand \languageshorthands { m } {}
 % These have to be provided at the end of the preamble
-\AddToHook{begindocument/before}{
-  \cs_gset_eq:NN \bbl at set@language \xpg at set@language at aux  % for biblatex
-  \cs_gset_eq:NN \bbl at main@language \xpg at main@language    % for biblatex
+\hook_gput_code:nnn {begindocument/before} {.}
+{
+  \cs_gset_eq:NN \bbl at set@language \xpg_set_language_aux:nn  % for biblatex
+  \cs_gset_eq:NN \bbl at main@language \xpg_main_language_tl    % for biblatex
   \ProvideDocumentCommand \texorpdfstring { m m } { #1 }  % dummy command if hyperref is not loaded
 }
 
@@ -4243,16 +4291,15 @@
 %% \l at nohyphenation is defined in polyglossia.lua
 \sys_if_engine_luatex:TF
   {
-	\RequirePackage{luatexbase} % already included by fontspec, but needed here
-	\RequireLuaModule{polyglossia}
+	\lua_load_module:n{polyglossia}
   }{
 	\cs_if_free:cT { l at nohyphenation } 
 	   { \chardef\l at nohyphenation=255 }
   }
 
-% Which version of XeTeX do we use? What is the boudary class? 4095 or 255
+% Which version of XeTeX do we use? What is the boundary class? 4095 or 255
 \cs_if_exist:cTF { e at alloc@intercharclass at top }
-  { \let\xpg at boundaryclass=\e at alloc@intercharclass at top }
+  { \cs_gset_eq:NN \xpg at boundaryclass \e at alloc@intercharclass at top }
   { \chardef\xpg at boundaryclass=\@cclv }
 
 % Useful for getting list of loaded languages and variants. Like babel's bbl at loaded
@@ -4288,18 +4335,18 @@
 \cs_new_nopar:Nn \__xpg_at_begin_document:
 {
   % 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
+  \cs_gset_eq:cc{latin at alph}{@alph}% TODO rename when we have the C locale
+  \cs_gset_eq:cc{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
+  \cs_gset_eq:cc{xpg_Clang_arabic}{@arabic}
   
   \xpg_initial_setup:
   % apply \familydefault changes
-  \xpg at set@familydefault
+  \xpg_set_familydefault:
 }
 
-\AddToHook{begindocument}{
+\hook_gput_code:nnn {begindocument} {.}
+{
   \__xpg_at_begin_document:
 }
 
@@ -4307,7 +4354,8 @@
 % loaded after \set[main|other]language
 % Track whether the main language has been set
 \bool_new:N \g_xpg_main_lang_set_bool
-\AddToHook{begindocument/end}{
+\hook_gput_code:nnn {begindocument/end} {.}
+{
   % now we have the C locale definition: select the language
   \__xpg_at_begin_document_selectlanguage:
   \bool_gset_true:N \g_xpg_main_lang_set_bool
@@ -4315,99 +4363,177 @@
   \__xpg_at_begin_document_hyphenation:
 }
 
-%% custom message macros
-\providecommand*{\xpg at error}[1]{
-   \PackageError{polyglossia}{#1}{}
+%
+% MESSAGES
+%
+
+% message templates
+\msg_new:nnn { polyglossia } { general } { #1 }
+
+\msg_new:nnn { polyglossia } { languagenotloaded }
+{
+  The~ language~ #1~ is~ not~ loaded.~ You~ must~ load~ it~ in~ order~ to~ use~ it.
 }
+\msg_redirect_name:nnn { polyglossia } { languagenotloaded } { critical }
 
-\providecommand*{\xpg at warning}[1]{
-   \PackageWarning{polyglossia}{#1}
+\msg_new:nnn { polyglossia } { languagenolongerloaded }
+{
+  The~ language~ #1~ is~ no~ longer~ loaded.~ Please~ rerun~ LaTeX.
 }
+\msg_redirect_name:nnn { polyglossia } { languagenolongerloaded } { warning }
 
-\providecommand*{\xpg at info}[1]{
-   \PackageInfo{polyglossia}
-   {#1\@gobble}
-} %% the \@gobble is to prevent displaying the line nr
+\msg_new:nnn { polyglossia } { unknownlocalnumeral }
+{
+  Unknown~ key~ "#1"~ in~ \string\localnumeral.
+}
 
-%TODO change all instances of \xpg at nopatterns in gloss-*.ldf files
-\providecommand*{\xpg at nopatterns@fallback}[2][nohyphenation]{
-   \xpg at warning{No~ hyphenation~ patterns~ were~ loaded~ for~ `#2'\MessageBreak
-         I~ will~ use~ \string\language=\string\l@ #1\space instead}
-   \expandafter\adddialect\csname l@#2\expandafter\endcsname\csname l@#1\endcsname\relax}
+\msg_new:nnn { polyglossia } { localnumeralemptyvalue }
+{
+  Keys~ of~ \string\localnumeral~ must~ have~ a~ value.
+}
 
-\providecommand*{\xpg at nopatterns}[1]{
-   \xpg at warning{No~ hyphenation~ patterns~ were~ loaded~ for~ `#1'\MessageBreak
-         I~ will~ use~ \string\language=\string\l at nohyphenation\space instead}
-   %%TODO? \expandafter\adddialect\csname l@#1\endcsname\l at nohyphenation\relax
-   }
+\msg_new:nnn { polyglossia } { illvalue }
+{
+  Illegal~ value~ (#1)~ for~ #2!
+}
 
-\def\xpg at ill@value#1#2{
-  \xpg at warning{Illegal~ value~ (#1)~ for~ #2}}
+\msg_new:nnn { polyglossia } { illarg }
+{
+  Invalid~ argument~ (#1)~ for~ #2!
+}
 
-% error out if lang is not loaded
-\cs_new_nopar:Nn \xpg_error_if_lang_not_loaded:n
+\msg_new:nnn { polyglossia } { nopatterns }
 {
-  \seq_if_in:NeF \__xpg_langs_loaded {#1}
-  {
-    \xpg at error{language~ #1~ is~ not~ loaded.~ Please~ load~ it~ before~ using~ it.}
-  }
+  No~ hyphenation~ patterns~ were~ loaded~ for~ `#2' \iow_newline:
+  I~ will~ use~ \string\language=\string\l@ #1\space instead.
 }
 
-\msg_new:nnn { polyglossia } { languagenotloaded }
+\msg_new:nnn { polyglossia } { undefcmd }
 {
-  The~ language~ #1~ is~ not~ loaded.~ You~ should~ load~ it.
+  \tl_to_str:N {#1} ~ is~ not~ defined!
 }
-\msg_redirect_name:nnn { polyglossia } { languagenotloaded } { critical }
 
-\msg_new:nnn { polyglossia } { languagenolongerloaded }
+%% custom message macros
+\cs_new_nopar:Nn \xpg_error_msg:n
 {
-  The~ language~ #1~ is~ no~ longer~ loaded.~ Please~ rerun~ LaTeX.
+   \exp_args:Nnne \msg_error:nnn { polyglossia } { general } { #1 }
 }
-\msg_redirect_name:nnn { polyglossia } { languagenolongerloaded } { warning }
 
-\msg_new:nnn { polyglossia } { unknownlocalnumeral }
+\cs_new_nopar:Nn \xpg_warning_msg:n
 {
-  Unknown~ key~ "#1"~ in~ \string\localnumeral.
+   \exp_args:Nnne \msg_warning:nnn { polyglossia } { general } { #1 }
 }
 
-\msg_new:nnn { polyglossia } { localnumeralemptyvalue }
+\cs_new_nopar:Nn \xpg_info_msg:n
 {
-  Keys~ of~ \string\localnumeral~ must~ have~ value.
+   \exp_args:Nnne \msg_info:nnn { polyglossia } { general } { #1 }
 }
 
+\cs_new_nopar:Nn \xpg_no_patterns_msg:n
+{
+   \msg_warning:nnnn { polyglossia } { nopatterns } { nohyphenation } { #1 }
+}
 
+\cs_new_nopar:Nn \xpg_ill_value_msg:nn
+{
+  \msg_warning:nnnn { polyglossia } { illvalue } { #1 } { #2 }
+}
+
+\cs_new_nopar:Nn \xpg_ill_arg_msg:nn
+{
+  \msg_error:nnnn { polyglossia } { illarg } { #1 } { #2 }
+}
+
+% error out if lang is not loaded
+\cs_new_nopar:Nn \xpg_error_if_lang_not_loaded:n
+{
+  \seq_if_in:NeF \__xpg_langs_loaded {#1}
+  {
+    \msg_error:nnn { polyglossia } { languagenotloaded } { #1 }
+  }
+}
+
 %% use macro if defined, else warn that it is not
 \cs_new_nopar:Nn \__xpg_use_or_warn:N
 {
   \cs_if_exist_use:NF {#1}
   {
-    \xpg at warning {  \tl_to_str:N {#1} ~ is~ not~ defined }
+    \msg_error:nnn { polyglossia } { undefcmd } { #1 }
   }
 }
 \cs_generate_variant:Nn \__xpg_use_or_warn:N {c}
 
+% gloss message interface
+\cs_set_eq:cc { xpg at error }      { xpg_error_msg:n }
+\cs_set_eq:cc { xpg at warning }    { xpg_warning_msg:n }
+\cs_set_eq:cc { xpg at info }       { xpg_info_msg:n }
+\cs_set_eq:cc { xpg at ill@value }  { xpg_ill_value_msg:nn }
 
+
+\NewDocumentCommand \XPGNoPatternsFallback { O{ nohyphenation } m }
+{
+   \msg_warning:nnnn { polyglossia } { nopatterns } { #1 } { #2 }
+   \exp_args:Ncc \adddialect {l@#2} {l@#1}
+}
+
+\NewDocumentCommand \CheckHyphenationPatterns { m }
+{
+   \xpg_if_language_defined:nF {#1}
+    {
+      \XPGNoPatternsFallback{#1}
+    }
+}
+
+%
+% END MESSAGES
+
+
 %% ensure directionality if bidi is loaded, else ignore
-\def\@@ensure at dir#1{\ifcsundef{@ensure at dir}{#1}{\@ensure at dir{#1}}}
-\def\@@ensure at maindir#1{\ifcsundef{@ensure at maindir}{#1}{\@ensure at maindir{#1}}}
+%%% FIXME still used?
+\cs_new_nopar:Npn \@@ensure at dir #1
+{
+  \cs_if_exist_use:c{@ensure at dir}{#1}
+}
 
-%% Used by the language definitions files for right-to-left languages
-\NewDocumentCommand \RequireBidi {}
+\cs_new_nopar:Npn \@@ensure at maindir #1
 {
-    \sys_if_engine_luatex:TF
-      {\ifx\@onlypreamble\@notprerr\else\RequirePackage{luabidi}\fi}
-      {\ifx\@onlypreamble\@notprerr\else\RequirePackage{bidi}\fi}
+  \cs_if_exist_use:c{@ensure at maindir}{#1}
 }
 
-% if #1 is LR run #2 else #3
+% if we are in the document preamble run T else F
+\prg_set_conditional:Nnn \xpg_if_in_preamble: {T, F, TF}
+{
+  \cs_if_eq:NNTF { \@onlypreamble } { \@notprerr }
+  {
+    \prg_return_false:
+  }
+  {
+    \prg_return_true:
+  }
+}
+
+%% Used by the language definitions files for right-to-left languages
+\DeclareDocumentCommand \RequireBidi {}
+  {
+    \xpg_if_in_preamble:T
+      {
+        \sys_if_engine_luatex:TF
+          { \RequirePackage{luabidi} }
+          { \RequirePackage{bidi} }
+      }
+    \DeclareDocumentCommand \RequireBidi {} {}
+  }
+
+% if #1 is LR run T else F
 \prg_set_conditional:Nnn \__xpg_if_LR_str:n {p, T, F, TF}
 {
-  \str_case_e:nnF{#1}{
+  \str_case_e:nnF{#1}
+  {
     {LR}{\prg_return_true:}
     {RL}{\prg_return_false:}
   }
   {
-    \xpg at error{Unknown~ direction~#1}
+    \xpg_error_msg:n {Unknown~ direction~#1}
     \prg_return_false:
   }
 }
@@ -4420,7 +4546,7 @@
 {
   \__xpg_if_LR_str:nF {#1}
   {
-    \xpg at error{right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}
+    \xpg_error_msg:n {right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}
   }
 }
 \cs_new_nopar:Nn \__xpg_set_text_direction:n
@@ -4427,10 +4553,11 @@
 {
   \__xpg_if_LR_str:nF {#1}
   {
-    \xpg at error{right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}
+    \xpg_error_msg:n {right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}
   }
 }
-\AddToHook{package/bidi/after}{
+\hook_gput_code:nnn {package/bidi/after} {.}
+{
   \cs_gset_nopar:Nn \__xpg_set_par_direction:n
   {
     \__xpg_if_LR_str:nTF{#1}
@@ -4452,7 +4579,8 @@
     }
   }
 }
-\AddToHook{package/luabidi/after}{
+\hook_gput_code:nnn {package/luabidi/after} {.}
+{
   \cs_gset_nopar:Nn \__xpg_set_par_direction:n
   {
     \__xpg_if_LR_str:nTF{#1}
@@ -4481,13 +4609,21 @@
   { \cs_new_nopar:Nn \__xpg_setRTLmain: { \@RTLmaintrue\setnonlatin } }
 
 %% compatibility with babel
-\let\addto\gappto % gappto is defined in etoolbox
+\cs_set:Npn \addto #1 #2
+{
+  \cs_if_exist:NF { #1 }
+     { \cs_new:Npn { #1 } {} }
+  \tl_gput_right:Nn { #1 } { #2 }
+}
 
-%% NEW EXPERIMENTAL SETUP INTERFACE FOR GLOSS FILES
+%% SETUP INTERFACE FOR GLOSS FILES
 %% options currently available:
 %% language : the name of the language (as understood by fontspec)
 %% 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.)
+%%%   TODO: if pattern is prefixed by !, then it should be loaded as a fallback,
+%%%%        with \CheckHyphenationPatterns - 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
 %% scripttag : the OpenType tag for the script
 %% langtag : the OpenType tag for the language
@@ -4495,19 +4631,20 @@
 %% frenchspacing : boolean
 %% indentfirst : boolean
 %% fontsetup : boolean
-%% TODO: nouppercase : boolean (for scripts like Arabic, Devanagari, etc which have no concept of uppercase/lowercase)
+%% TODO: nouppercase : boolean (for scripts like Arabic, Devanagari, etc which have
+%%       no concept of uppercase/lowercase)
 %% TODO: localalph = {<alph_csname>,<Alph_csname>}
 %% TODO: localnumeral = <csname>
 %%       or even better localdigits = {0123456789} for fully automatic setup
-\newcommand*\PolyglossiaSetup[2]{
+\NewDocumentCommand \PolyglossiaSetup { m m }
+{
   \__xpg_keys_define_lang:n{#1}
   \keys_set:nn { polyglossia / #1 } { #2 }
   \__xpg_setup_hyphen:n {#1}
   %define booleans etoolbox style and set defaults
   %% TODO ? \providetoggle{#1 at setup@done}%
-  % 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?
+  % we initialize this so that we can append below
+  \cs_gset:cpn {init at extras@#1} {}
   % here we do the fontsetup:
   \__xpg_auto_setupfont:n { #1 }
   %% TODO? \toggletrue{#1 at setup@done}
@@ -4526,35 +4663,41 @@
   \clist_map_inline:nn { #1 } { \keys_set:nn { polyglossia / ##1 } { #2 } }
 }
 
-
+\bool_new:N \l__xpg_have_hyphen_bool
 % setup hyphennames from a str list of hyphen
 \cs_new:Nn \__xpg_setup_hyphen:n
 {
-  \clist_set:Ne{\l_tmpa_clist}{\prop_item:Nn \g_xpg_langsetup_prop {#1 / hyphennames}}
-  \providebool{havehyphen}
-  \boolfalse{havehyphen}
+  \clist_set:Ne{\l_tmpa_clist}{\prop_item:Nn \l_xpg_langsetup_prop {#1 / hyphennames}}
+  \bool_set_false:N \l__xpg_have_hyphen_bool
   % for each hyphen in the set until we find one that works
-  \clist_map_inline:Nn \l_tmpa_clist {
-    \ifbool{havehyphen}{}{
+  \clist_map_inline:Nn \l_tmpa_clist
+  {
+    \bool_if:NF \l__xpg_have_hyphen_bool
+    {
        % check if language hyphenname is defined
-      \__xpg_check_if_exist_l@:nF{#1}{
+      \__xpg_pattern_check_if_exists:nF{#1}
+      {
           % if not, first consider nohyphenation
           \str_if_eq:nnTF{##1}{nohyphenation}
             {
                \cs_gset_eq:cc{l@#1}{l@##1}
-               \global\booltrue{havehyphen}
-            }{
+               \bool_gset_true:N \l__xpg_have_hyphen_bool
+            }
+            {
                % then test if hyphenation is defined
-               \xpg at ifdefined{##1}{
+               \xpg_if_language_defined:nT {##1}
+               {
                   % test if language hyphenation is nohyphenation
-                  \cs_if_eq:cNF{l@#1}{\l at nohyphenation}{\global\booltrue{havehyphen}}{%
+                  \cs_if_eq:cNTF{l@#1}{\l at nohyphenation}
+                    { \bool_gset_true:N \l__xpg_have_hyphen_bool }
+                    {
                       % 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}
-                  }
-                }{}
+                      \xpg_set_hyphenation_patterns:n {##1}
+                      \bool_gset_true:N \l__xpg_have_hyphen_bool
+                    }
+               }
            }
        }
     }
@@ -4562,19 +4705,17 @@
   % 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{#1}
-      \expandafter\adddialect\csname l@#1\endcsname\l at nohyphenation\relax
-    }
+  \bool_if:NF \l__xpg_have_hyphen_bool
+  {
+    \CheckHyphenationPatterns{#1}
   }
-  \csdef{#1 at language}{
-    \polyglossia at setup@language at patterns{#1}
+  \cs_gset:cpn {#1 at language}
+  {
+    \SetupPolyglossiaLangPatterns{#1}
   }
   % setup hyphenmins
   \clist_set:Ne \l_tmpa_clist
-    { \prop_item:Nn \g_xpg_langsetup_prop {#1 / hyphenmins} }
+    { \prop_item:Nn \l_xpg_langsetup_prop {#1 / hyphenmins} }
   \cs_if_eq:cNF {l@#1} \l at nohyphenation
     {
       \use:x
@@ -4586,7 +4727,8 @@
     }
 }
 
-\newcommand*\polyglossia at setup@language at patterns[1]{
+\NewDocumentCommand \SetupPolyglossiaLangPatterns { m }
+{
   \bool_if:NTF \g__xpg_hyphenation_disabled_bool
   {
     \tl_gset:Ne \g__xpg_lastlanguage_tl {\the\csname l@#1\endcsname}
@@ -4600,32 +4742,29 @@
             \language=\l at nohyphenation
           }
           {
-            \xpg at set@hyphenation at patterns{#1}
+            \xpg_set_hyphenation_patterns:n {#1}
           }
       }
       {
         % Since this function is sometimes called from the gloss files
         % directly, we need to check whether the requested hyphenname exists.
-        \xpg at ifdefined{#1}{}
-        {
-          \xpg at nopatterns{#1}
-          \expandafter\adddialect\csname l@#1\endcsname\l at nohyphenation\relax%
-        }
-        \xpg at set@hyphenation at patterns{#1}
+        \CheckHyphenationPatterns{#1}
+        \xpg_set_hyphenation_patterns:n {#1}
       }
   }
 }
 
-\prop_new:N \g_xpg_langsetup_prop
+\prop_new_linked:N \l_xpg_langsetup_prop
 
 \cs_new_protected:Npn \__xpg_keys_define_lang:n #1
 {
-  \keys_define:nn {polyglossia}{
+  \keys_define:nn {polyglossia}
+  {
     % the script font
     #1 / script
        .code:n = {
-          \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/script}{##1}
-          \prop_gput:Nne{\g_xpg_langsetup_prop}{#1/lcscript}
+          \prop_put:Nnn \l_xpg_langsetup_prop {#1/script}{##1}
+          \prop_put:Nne \l_xpg_langsetup_prop {#1/lcscript}
                {\tl_if_empty:nF{##1}{\str_lowercase:n{##1}}}
     },
     #1 / script
@@ -4634,7 +4773,7 @@
        .initial:n = latin,
     % the opentype script tag
     #1 / scripttag
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/scripttag}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/scripttag}{##1}},
     #1 / scripttag
        .default:n = {},
     #1 / scripttag
@@ -4641,7 +4780,7 @@
       .initial:n = {},
     % the language full name
     #1 / language
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/language}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/language}{##1}},
     #1 / language
        .value_required:n = true,
     #1 / language
@@ -4648,7 +4787,7 @@
         .initial:x = {\str_uppercase:n#1},
     % the language tag
     #1 / langtag
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/langtag}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/langtag}{##1}},
     #1 / langtag
        .value_required:n = true,
     #1 / langtag
@@ -4655,7 +4794,7 @@
        .initial:n = {},
     % the BCP-47 tag
     #1 / bcp47
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47}{##1}},
     #1 / bcp47
        .value_required:n = true,
     #1 / bcp47
@@ -4662,7 +4801,7 @@
        .initial:n = {},
     % the BCP-47 language tag
     #1 / bcp47-language
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-language}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-language}{##1}},
     #1 / bcp47-language
        .value_required:n = true,
     #1 / bcp47-language
@@ -4669,7 +4808,7 @@
        .initial:n = {},
     % the BCP-47 region tag
     #1 / bcp47-region
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-region}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-region}{##1}},
     #1 / bcp47-region
        .value_required:n = false,
     #1 / bcp47-region
@@ -4676,14 +4815,19 @@
        .initial:n = {},
     % the BCP-47 script tag
     #1 / bcp47-script
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-script}{##1}},
+       .code:n =
+         {
+           \prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-script}{##1}
+           \prop_put:Nne \l_xpg_langsetup_prop {#1/lc-bcp47-script}
+               {\tl_if_empty:nF{##1}{\str_lowercase:n{##1}}}
+         },
     #1 / bcp47-script
        .value_required:n = true,
     #1 / bcp47-script
-       .initial:n = {},
+       .initial:n = {Latn},
     % the BCP-47 variant tag
     #1 / bcp47-variant
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-variant}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-variant}{##1}},
     #1 / bcp47-variant
        .value_required:n = false,
     #1 / bcp47-variant
@@ -4690,7 +4834,7 @@
        .initial:n = {},
     % the BCP-47 extension-t tag
     #1 / bcp47-extension-t
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-extension-t}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-extension-t}{##1}},
     #1 / bcp47-extension-t
        .value_required:n = false,
     #1 / bcp47-extension-t
@@ -4697,7 +4841,7 @@
        .initial:n = {},
     % the BCP-47 extension-u tag
     #1 / bcp47-extension-u
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-extension-u}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-extension-u}{##1}},
     #1 / bcp47-extension-u
        .value_required:n = false,
     #1 / bcp47-extension-u
@@ -4704,7 +4848,7 @@
        .initial:n = {},
     % the BCP-47 extension-x tag
     #1 / bcp47-extension-x
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-extension-x}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-extension-x}{##1}},
     #1 / bcp47-extension-x
        .value_required:n = false,
     #1 / bcp47-extension-x
@@ -4711,7 +4855,7 @@
        .initial:n = {},
     % the BCP-47 casing alias
     #1 / bcp47-casing
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-casing}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-casing}{##1}},
     #1 / bcp47-casing
        .value_required:n = false,
     #1 / bcp47-casing
@@ -4720,7 +4864,7 @@
     #1 / hyphennames
     .code:n = {
       \clist_set:Nn{\l_tmpa_clist}{##1}
-      \prop_gput:Nne{\g_xpg_langsetup_prop}{#1/hyphennames}{\clist_use:Nn \l_tmpa_clist {,}}
+      \prop_put:Nne \l_xpg_langsetup_prop {#1/hyphennames}{\clist_use:Nn \l_tmpa_clist {,}}
     },
     #1 / hyphennames
        .value_required:n = true,
@@ -4733,8 +4877,8 @@
              {LR}{}
              {RL}{\RequireBidi}
            }
-           {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/direction}{##1}}
-           {\xpg at error{Unknown~ direction~ "##1"~ for~ language~ "#1"}}
+           { \prop_put:Nnn \l_xpg_langsetup_prop {#1/direction}{##1} }
+           { \xpg_error_msg:n {Unknown~ direction~ "##1"~ for~ language~ "#1"} }
        },
     #1 / direction
       .value_required:n = true,
@@ -4745,9 +4889,9 @@
     .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"}}
+        { \xpg_error_msg:n {hypenmins~should~be~a~list~of~two~entries,~got~"##1"} }
       % set prop
-      \prop_gput:Nnn \g_xpg_langsetup_prop {#1/hyphenmins} {##1}
+      \prop_put:Nnn \l_xpg_langsetup_prop {#1/hyphenmins} {##1}
     },
     #1 / hyphenmins
       .value_required:n = true,
@@ -4758,9 +4902,9 @@
     .code:n = {
       % check syntax
       \int_compare:nNnF { \clist_count:n {##1} } = {1}
-        {\xpg at error{totalhyphenhypenmin~should~be~a~single~entry,~got~"##1"}}
+        { \xpg_error_msg:n {totalhyphenhypenmin~should~be~a~single~entry,~got~"##1"} }
       % set prop
-      \prop_gput:Nnn \g_xpg_langsetup_prop {#1/totalhyphenmin} {##1}
+      \prop_put:Nnn \l_xpg_langsetup_prop {#1/totalhyphenmin} {##1}
     },
     #1 / totalhyphenmin
       .value_required:n = false,
@@ -4779,7 +4923,7 @@
     % environment name
     #1 / envname
        .code:n = {
-           \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/envname}{##1}
+           \prop_put:Nnn \l_xpg_langsetup_prop {#1/envname}{##1}
        },
     #1/ envname.value_required:n = true,
     #1/ envname.initial:n = {#1},
@@ -4786,7 +4930,7 @@
     % babel name
     #1 / babelname
        .code:n = {
-           \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/babelname}{##1}
+           \prop_put:Nnn \l_xpg_langsetup_prop {#1/babelname}{##1}
        },
     #1/ babelname.value_required:n = true,
     #1/ babelname.initial:n = {#1},
@@ -4793,21 +4937,21 @@
     % default numerals
     #1 / localnumeral
          . code:n =  {
-            \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/localnumeral}{##1}
-            \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/Localnumeral}{##1}
+            \prop_put:Nnn \l_xpg_langsetup_prop {#1/localnumeral}{##1}
+            \prop_put:Nnn \l_xpg_langsetup_prop {#1/Localnumeral}{##1}
          },
     #1 / localnumeral.value_required:n = true,
-    #1 / localnumeral.initial:n = {polyglossia at C@localnumeral},
+    #1 / localnumeral.initial:n = {xpg_C_localnumeral:nn},
     % uppercased
     #1 / Localnumeral
          . code:n =  {
-            \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/Localnumeral}{##1}
+            \prop_put:Nnn \l_xpg_langsetup_prop {#1/Localnumeral}{##1}
          },
     #1 / Localnumeral.value_required:n = true,
-    #1 / Localnumeral.initial:n = {polyglossia at C@localnumeral},
+    #1 / Localnumeral.initial:n = {xpg_C_localnumeral:nn},
     % environment define command (by default create the environment)
     #1 / DefineCommandsCmd
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/DefineCommandsCmd}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/DefineCommandsCmd}{##1}},
     #1 / DefineCommandsCmd
        .value_required:n = true,
     #1 / DefineCommandsCmd
@@ -4815,9 +4959,20 @@
   }
 }
 
+\DeclareExpandableDocumentCommand \babelname { }
+  {
+    \prop_item:Ne  \l_xpg_langsetup_prop { \languagename / babelname }
+  }
+  
+\DeclareExpandableDocumentCommand \mainbabelname { }
+  {
+    \prop_item:Ne  \l_xpg_langsetup_prop { \mainlanguagename / babelname }
+  }
+
 % TODO move to C module
-\newcommand*{\polyglossia at C@localnumeral}[2]{
-   \polyglossia at Clang@@arabic{#2}
+\cs_new:Nn \xpg_C_localnumeral:nn
+{
+   \xpg_Clang_arabic{#2}
 }
 
 \cs_new:Npn \__xpg_localnumeral_parse:nn #1 #2
@@ -4841,7 +4996,7 @@
 			\__xpg_localnumeral_parse:nn
 	  	  } { #2 }
 	  }
-	{ \use:c { \prop_item:Ne \g_xpg_langsetup_prop
+	{ \use:c { \prop_item:Ne \l_xpg_langsetup_prop
 	{ \languagename / #3 } } { } { #1 } } 
   }
   
@@ -4876,18 +5031,18 @@
 \cs_new_nopar:Npn \__xpg_indent_first:n #1
   {
 	\bool_if:cTF { g__xpg_#1_if_bool }
-	{ \french at indent } { \nofrench at indent }
+	{ \__xpg_french_indent: } { \__xpg_no_french_indent: }
   }
 
 \cs_new:Nn \__xpg_lang_set_par_direction:n
 {
-  \prop_get:NeNTF \g_xpg_langsetup_prop {#1/direction} \l_tmpa_tl
+  \prop_get:NeNTF \l_xpg_langsetup_prop {#1/direction} \l_tmpa_tl
       {
         \__xpg_set_par_direction:n{\l_tmpa_tl}
       }
       {
-        \xpg at error{Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
-        \prop_show:N{\g_xpg_langsetup_prop}
+        \xpg_error_msg:n {Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
+        \prop_show:N{\l_xpg_langsetup_prop}
       }
 }
 
@@ -4894,13 +5049,13 @@
 
 \cs_new:Nn \__xpg_lang_set_text_direction:nn
 {
-  \prop_get:NeNTF \g_xpg_langsetup_prop {#1/direction} \l_tmpa_tl
+  \prop_get:NeNTF \l_xpg_langsetup_prop {#1/direction} \l_tmpa_tl
       {
         \__xpg_set_text_direction:n{\l_tmpa_tl}{#2}
       }
       {
-        \xpg at error{Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
-        \prop_show:N{\g_xpg_langsetup_prop}
+        \xpg_error_msg:n {Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
+        \prop_show:N{\l_xpg_langsetup_prop}
       }
 }
 
@@ -4931,7 +5086,7 @@
   {
     \bool_gset_true:N \g__xpg_hyphenation_disabled_bool
     \tl_gset:Ne \g__xpg_lastlanguage_tl { \the\language }
-    % We do not call \xpg at set@hyphenation at patterns here to avoid a warning message.
+    % We do not call \xpg_set_hyphenation_patterns:n here to avoid a warning message.
     % "nohyphenation" is not listed in language.dat.lua.
     \language=\l at nohyphenation
   }
@@ -4943,7 +5098,7 @@
   {
     \bool_gset_false:N \g__xpg_hyphenation_disabled_bool
     \language=\tl_use:N{\g__xpg_lastlanguage_tl}
-  }%
+  }
 }
 
 \cs_new:Npn \__xpg_auto_setupfont:n #1
@@ -4950,12 +5105,12 @@
 {
   \bool_if:cTF { g__xpg_#1_fontsetup_bool }
   {
-    \str_if_eq:eeTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/lcscript}}{latin}
-         {\xpg at fontsetup@latin{#1}}
-         {\xpg at fontsetup@nonlatin{#1}}
+    \str_if_eq:eeTF{\prop_item:Nn{\l_xpg_langsetup_prop}{#1/lcscript}}{latin}
+         {\SetupLatinPolyglossiaFont{#1}}
+         {\SetupNonLatinPolyglossiaFont{#1}}
   }
   {
-    \xpg at info{Skipping~ automatic~ font~ setup~ for~ language~ #1}
+    \xpg_info_msg:n{Skipping~ automatic~ font~ setup~ for~ language~ #1}
   }
 }
 
@@ -4967,40 +5122,40 @@
   \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~ main~ font~
+    \xpg_warning_msg:n{Asking~ to~ add~ empty~ feature~to~ main~ font~
       (Language="#2"~ to~ langtag~ "#1")}
   }
   {
-    \str_if_eq:nnTF{#2}{Turkish}{
+    \str_if_eq:nnTF{#2}{Turkish}
+    {
       \fontspec_if_language:nTF {TRK}
       {
         \addfontfeature{Language=Turkish}
       }
       {
-        \fontspec_if_language:nTF {TUR}
+        \fontspec_if_language:nT {TUR}
         {
           \addfontfeature{Language=Turkish}
-        }{}
+        }
       }
     }{
-      \fontspec_if_language:nTF{#1}
+      \fontspec_if_language:nT{#1}
       {
         \addfontfeature{Language=#2}
       }
-      {}
     }
   }
 }
-\cs_generate_variant:Nn  \__xpg_add_font_feature_language:nn { on , no, oo , Vn, nV, VV , xn, nx, xx}
+\cs_generate_variant:Nn  \__xpg_add_font_feature_language:nn { ee }
 
-% add fontfeature Script=#2 to scripttag #1
-% do nothing if #1 or #2 is empty
+% add fontfeature Script=#3 to scripttag #2 for family #1
+% do nothing if #2 or #3 is empty
 \cs_new:Nn \__xpg_add_font_feature_script:nnn
 {
   \bool_if:nTF{\tl_if_empty_p:n{#2} || \tl_if_empty_p:n{#3}}
   {
     % maybe an error ?
-    \xpg at warning{Asking~ to~ add~ empty~ feature~to~ main~ font
+    \xpg_warning_msg:n{Asking~ to~ add~ empty~ feature~to~ main~ font
                  (Script="#3"~ to~ scripttag~ "#2")}
   }
   {
@@ -5036,119 +5191,59 @@
         \regex_replace_once:nnN { \.[^\.]* \Z } { } \xpg_fname_str
         % ... and, finally, quotation marks
         \regex_replace_once:nnN { " } { } \xpg_fname_str
-        \xpg at error{
-          The~ current~ main ~ \xpg_ffamily_tl\space font,~ \xpg_fname_str,~ does~ not~ contain~ the~"#3"~ script!\MessageBreak
-          Please~ define~\csname\tl_if_empty:nF{#3}{\str_lowercase:n{#3}}font\xpg_ffamilysh_tl\endcsname~
-          with~ \string\newfontfamily\space command
+        \xpg_error_msg:n
+          {
+            The~ current~ main ~ \xpg_ffamily_tl\space font,~ \xpg_fname_str,~ does~ not~ contain~ the~"#3"~ script! \iow_newline:
+            Please~ define~\csname\tl_if_empty:nF{#3}{\str_lowercase:n{#3}}font\xpg_ffamilysh_tl\endcsname~
+            with~ \string\newfontfamily\space command
           }
         }
   }
 }
-\cs_generate_variant:Nn  \__xpg_add_font_feature_script:nnn { non , nno, noo , nVn, nnV, nVV , nxn, nnx, nxx}
+\cs_generate_variant:Nn  \__xpg_add_font_feature_script:nnn { nee }
 
-\def\xpg at fontsetup@latin#1{
-  \begingroup
-  \csgdef{#1 at font@rm}{
-    \cs_if_exist_use:cF{#1font}{
-      \rmfamilylatin
-      \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                         {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-    }
-  }
-  \csgdef{#1 at font@sf}{
-    \cs_if_exist_use:cF{#1fontsf}{
-      \sffamilylatin
-      \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                         {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-    }
-  }
-  \csgdef{#1 at font@tt}{
-    \cs_if_exist_use:cF{#1fonttt}{
-      \ttfamilylatin
-      \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                         {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-    }
-  }
-  \endgroup
-}
-
-\def\xpg at fontsetup@nonlatin#1{
-  \begingroup
-  \csgdef{#1 at font@rm}{
-    \cs_if_exist_use:cF{#1font}
+%% TODO: probably can be cleaned a little more
+\cs_new_protected:Npn \__xpg_setup_font:nnnnn #1 #2 #3 #4 #5 % #1 = lang, #2 = family, #3 = family, #4 = gobble, #5 gobble
+  {
+    \cs_set_protected_nopar:cpn { #1 at font@#2 }
       {
-       \providetoggle{#1 at use@script at font}
-       \str_if_eq:nnTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-        {\rmfamilylatin}
-        {\cs_if_exist_use:cTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/lcscript} font}
+        \cs_if_exist_use:cF{ #1font#3 }
           {
-             \toggletrue{#1 at use@script at font}
-           }
-           {
-             \rmfamilylatin
-           }
-       }
-       \iftoggle{#1 at use@script at font}{}{
-           \__xpg_add_font_feature_script:nxx{rm}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/scripttag}}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}
-       }%
-       \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                          {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-      }%
-      \def\familytype{rm}
-  }%
-  \csgdef{#1 at font@sf}{
-    \cs_if_exist_use:cF{#1fontsf}
-      {
-       \providetoggle{#1 at use@script at fontsf}
-       \str_if_eq:nnTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-        {\sffamilylatin}
-        {\cs_if_exist_use:cTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/lcscript} fontsf}
-          {
-             \toggletrue{#1 at use@script at fontsf}
-           }
-           {
-             \sffamilylatin
-           }
-       }
-       \iftoggle{#1 at use@script at fontsf}{}{
-           \__xpg_add_font_feature_script:nxx{sf}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/scripttag}}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}
-       }%
-       \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                          {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-      }%
-      \def\familytype{sf}
-  }%
-  \csgdef{#1 at font@tt}{
-    \cs_if_exist_use:cF{#1fonttt}
-      {
-       \providetoggle{#1 at use@script at fonttt}
-       \str_if_eq:nnTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-       {\ttfamilylatin}
-       {\cs_if_exist_use:cTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/lcscript} fonttt}
-           {
-             \toggletrue{#1 at use@script at fonttt}
-           }
-           {
-             \ttfamilylatin
-           }
-       }
-       \iftoggle{#1 at use@script at fonttt}{}{
-           \__xpg_add_font_feature_script:nxx{tt}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/scripttag}}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}
-       }
-       \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                          {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
+           \cs_if_exist_use:cF { \prop_item:Nn \l_xpg_langsetup_prop { #1 / lc-bcp47-script } font#3 }
+              {
+                #4 { \prop_item:Nn \l_xpg_langsetup_prop { #1 / lcscript } font#3 }
+                  { 
+                    \use:c { #2familylatin } 
+                    #5
+                      {
+                        \__xpg_add_font_feature_script:nee { #2 }
+                            { \prop_item:Nn \l_xpg_langsetup_prop { #1 / scripttag } }
+                            { \prop_item:Nn \l_xpg_langsetup_prop { #1 / script } }
+                      }
+                  }
+              }
+           \__xpg_add_font_feature_language:ee 
+               { \prop_item:Nn \l_xpg_langsetup_prop { #1 / langtag } }
+               { \prop_item:Nn \l_xpg_langsetup_prop { #1 / language } }
+          }
+        \tl_set:Nn \familytype { #2 }
       }
-      \def\familytype{tt}
   }
-  \endgroup
-}
 
+\NewDocumentCommand \SetupLatinPolyglossiaFont { m }
+  {
+    \__xpg_setup_font:nnnnn { #1 } { rm } { } { \use_ii:nn } { \use_none:n }
+    \__xpg_setup_font:nnnnn { #1 } { sf } { sf } { \use_ii:nn } { \use_none:n }
+    \__xpg_setup_font:nnnnn { #1 } { tt } { tt } { \use_ii:nn } { \use_none:n }
+  }
+
+\NewDocumentCommand \SetupNonLatinPolyglossiaFont { m }
+  {
+    \__xpg_setup_font:nnnnn { #1 } { rm } { } { \cs_if_exist_use:cF } { \use:n }
+    \__xpg_setup_font:nnnnn { #1 } { sf } { sf } { \cs_if_exist_use:cF } { \use:n }
+    \__xpg_setup_font:nnnnn { #1 } { tt } { tt } { \cs_if_exist_use:cF } { \use:n }
+  }
+
 %%% END OF PolyglossiaSetup
 
 %% ensure localization of \markright and \markboth commands
@@ -5156,40 +5251,53 @@
 \cs_new_nopar:Nn \__xpg_local_marks:n { }
 \cs_new_nopar:Nn \__xpg_enable_local_marks:
 {
-  \xpg at info{Option:~ localmarks}
+  \xpg_info_msg:n{Option:~ localmarks}
   \cs_gset_nopar:Nn \__xpg_local_marks:n
   {
-	 \def\xpg at tmp@lang{##1}
-	 \DeclareRobustCommand\markboth[2]{
-		\begingroup
-		   \let\label\relax \let\index\relax \let\glossary\relax
-		   \unrestored at protected@xdef\@themark
-		   {
-			{\lowercase{\foreignlanguage{\xpg at tmp@lang}}{\protect\@@ensure at maindir{####1}}}
-			{\lowercase{\foreignlanguage{\xpg at tmp@lang}}{\protect\@@ensure at maindir{####2}}}
-		   }
-		   \@temptokena \expandafter{\@themark}
-		   \mark{\the\@temptokena}
-		\endgroup
-		\if at nobreak\ifvmode\nobreak\fi\fi
-	 }
-	 \DeclareRobustCommand\markright[1]{
-		\begingroup
-		   \let\label\relax \let\index\relax \let\glossary\relax
-		   \expandafter\@markright\@themark
-		   {\lowercase{\foreignlanguage{\xpg at tmp@lang}}{\protect\@@ensure at maindir{####1}}}
-		   \@temptokena \expandafter{\@themark}
-		   \mark{\the\@temptokena}
-		\endgroup
-		\if at nobreak\ifvmode\nobreak\fi\fi
-	 }
+	 \DeclareDocumentCommand \markboth { m m }
+	 {
+	     \group_begin:
+                \cs_set_eq:cc { label } { relax }
+                \cs_set_eq:cc { index } { relax }
+                \cs_set_eq:cc { glossary } { relax }
+                \unrestored at protected@xdef\@themark
+		  {
+		     {\foreignlanguage{##1}{\protect\@@ensure at maindir{####1}}}
+		     {\foreignlanguage{##1}{\protect\@@ensure at maindir{####2}}}
+		  }
+                \@temptokena \expandafter{\@themark}
+                \mark_insert:nn{2e-left}{####1}
+                \mark_insert:nn{2e-right}{####2}
+                \tl_if_empty:nF{####2}{ \mark_insert:nn{2e-right-nonempty}{####2} }
+                \mark{\the\@temptokena}
+              \group_end:
+              \if at nobreak\ifvmode\nobreak\fi\fi
+         }
+	 \DeclareDocumentCommand \markright { m }
+	 {
+	     \group_begin:
+               \cs_set_eq:cc { label } { relax }
+               \cs_set_eq:cc { index } { relax }
+               \cs_set_eq:cc { glossary } { relax }
+               \expandafter\@markright\@themark
+		   {\foreignlanguage{##1}{\protect\@@ensure at maindir{####1}}}
+               \@temptokena \expandafter{\@themark}
+               \mark_insert:nn{2e-right}{####1}
+               \tl_if_empty:nF{####1}{ \mark_insert:nn{2e-right-nonempty}{####1} }
+               \mark{\the\@temptokena}
+            \group_end:
+            \if at nobreak\ifvmode\nobreak\fi\fi
+         }
   }
 }
 
 %we call this macro when a gloss file is not found for a given language
-\def\xpg at nogloss#1{
-   \xpg at warning{File~ gloss-#1.ldf~ do~ not~  exists!\MessageBreak
-   I~ will~ nevertheless~ try~ to~ use~ hyphenation~ patterns~ for~ #1.}
+\cs_new_nopar:Nn \__xpg_no_gloss:n
+{
+   \xpg_warning_msg:n
+      {File~ gloss-#1.ldf~ do~ not~  exists! \iow_newline:
+       I~ will~ nevertheless~ try~ to~ use~ hyphenation~ patterns~ for~ #1.}
+
   \PolyglossiaSetup{#1}{hyphenmins={2,3},hyphennames={#1},fontsetup=true}
   % the above amounts to:
   %\ifcsundef{l@#1}%
@@ -5198,52 +5306,57 @@
   %\csdef{#1 at language}{\language=\csname l@#1\endcsname}%
 }
 
-\newcommand{\xpg at input}[1]{
+\cs_new_nopar:Nn \xpg_input:n
+{
   % Store catcode of @ before making at letter
-  \chardef\xpg at saved@at at catcode\catcode`\@
-  \makeatletter
-  \input{#1}
+  \cs_set_protected_nopar:Npx \__xpg_restore_at_catcode:
+      { \char_set_catcode:nn { `@ } { \char_value_catcode:n {`\@ } } }
+  \char_set_catcode_letter:N @
+  \file_input:n { #1 }
   % restore former @ catcode
-  \catcode`\@=\xpg at saved@at at catcode
+  \__xpg_restore_at_catcode:
 }
 
 % try to load a language file
-\cs_new:Nn \__xpg_load_lang_definition:nn {
-	\file_if_exist:nTF{gloss-#2.ldf}
+\cs_new:Nn \__xpg_load_lang_definition:nn
+{
+    \file_if_exist:nTF{gloss-#2.ldf}
 	{
-	  % Temporarily force catcode of ~ to 13 since babelsh.def
+	  \tl_set:Nn \xpg__tmp_default_options_tl { #1 }
+	  % Temporarily force catcode of ~ to 13 (active) since babelsh.def
 	  % requires it. This is needed particularly with LaTeX3
 	  % packages which force \ExplSyntaxOn (#425)
-	  \protected\edef\xpg at restore@tilde at catcode{\catcode 126 = \the\catcode 126\relax}
-	  \catcode 126 = 13
-	  \xpg at input{gloss-#2.ldf}
-	  \setkeys{#2}{#1}
+	  \cs_gset_protected:Npx \__xpg_restore_tilde_catcode:
+               { \char_set_catcode:nn { 126 } { \char_value_catcode:n { 126 } } }
+          \char_set_catcode_active:n { 126 }
+	  \xpg_input:n {gloss-#2.ldf}
 	  % restore former ~ catcode
-	  \xpg at restore@tilde at catcode
+	  \__xpg_restore_tilde_catcode:
 	}
 	{
-	  \xpg at nogloss{#2}
+	  \__xpg_no_gloss:n {#2}
 	}
 }
 \cs_generate_variant:Nn \__xpg_load_lang_definition:nn { ee }
 
 % load a master language from an alias file
-\newcommand*\xpg at load@master at language[1] {
-  \xpg at input{gloss-#1.ldf}
+\NewDocumentCommand \InheritGlossFile { m }
+{
   \seq_if_in:NeF \__xpg_langs_loaded {#1}
   {
+    \xpg_input:n {gloss-#1.ldf}
     % define environment and command if not alias
     \str_if_eq:eeT {\prop_item:Ne \__xpg_alias {#1/target}} {#1} {
-      \use:c{\prop_item:Nn{\g_xpg_langsetup_prop}
+      \use:c{\prop_item:Nn{\l_xpg_langsetup_prop}
                           {#1/DefineCommandsCmd}}
                           {#1}
       }
+    \seq_gput_right:Nn \__xpg_langs_loaded {#1}
   }
   \__xpg_register_language:nn{}{#1}
-  \seq_gput_right:Nn \__xpg_langs_loaded {#1}
 }
 
-\prop_new:N \__xpg_alias
+\prop_new_linked:N \__xpg_alias
 
 % define environment and command if not alias
 \cs_new:Nn \xpg_define_language_commands:n {
@@ -5250,7 +5363,7 @@
   \str_if_eq:eeT {\prop_item:Ne \__xpg_alias {#1/target}} {#1}
   {
     \exp_args:Ne
-    \NewDocumentEnvironment {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/envname}} { O{} }
+    \NewDocumentEnvironment {\prop_item:Nn{\l_xpg_langsetup_prop}{#1/envname}} { O{} }
     {
       \otherlanguage [ ##1 ] { #1 }
     }
@@ -5278,7 +5391,7 @@
       % target to self fall back to language table
       \str_if_eq:eeTF { \prop_item:Ne \__xpg_alias {#1/target} } { #1 }
       {
-        \prop_item:Nn{\g_xpg_langsetup_prop} {#1/#2}
+        \prop_item:Nn{\l_xpg_langsetup_prop} {#1/#2}
       }
       % load alias by recursion
       {
@@ -5401,20 +5514,29 @@
   \clist_if_in:NeF \xpg at loaded {#2}{
     \clist_gput_right:Ne \xpg at loaded {#2}
   }
-  % Register the language options
-  \__xpg_set_language_options:nnn {#2} {#1} {@xpg at set@langvariant}
+  \group_begin:
+  % set language options
+  \__xpg_set_language_options:nn {#2} {#1}
   % register babelname
-  \prop_get:NeN \g_xpg_langsetup_prop {#2/babelname} \l_tmpa_tl
+  \prop_get:NeN \l_xpg_langsetup_prop {#2/babelname} \l_tmpa_tl
   \clist_if_in:NeF \xpg at bloaded {\l_tmpa_tl}{
     \clist_gput_right:Ne \xpg at bloaded {\l_tmpa_tl}
   }
   % register BCP-47 ID
-  \prop_get:NeN \g_xpg_langsetup_prop {#2/bcp47} \l_tmpa_tl
+  \prop_get:NeN \l_xpg_langsetup_prop {#2/bcp47} \l_tmpa_tl
   \clist_if_in:NeF \xpg at bcp@loaded {\l_tmpa_tl}{
     \clist_gput_right:Ne \xpg at bcp@loaded {\l_tmpa_tl}
   }
+  % register variant
+  \prop_get:NnNT \l_xpg_curropt_prop {#2/variant} \l_tmpa_tl {
+  \clist_if_in:NeF \xpg at vloaded {\l_tmpa_tl}{
+    \clist_gput_right:Ne \xpg at vloaded {\l_tmpa_tl}
+  }}
+  \group_end:
 }
 
+\prop_new_linked:N \l_xpg_curropt_prop
+
 \DeclareDocumentCommand \setdefaultlanguage { O{} m }
 {
   % latex is an internal language, so do not record
@@ -5429,12 +5551,13 @@
     \__xpg_load_lang_definition:nn{#1}{#2}
     % define environment and command if not alias
     \str_if_eq:eeT {\prop_item:Ne \__xpg_alias {#2/target}} {#2} {
-       \use:c{\prop_item:Ne{\g_xpg_langsetup_prop}
+       \use:c{\prop_item:Ne{\l_xpg_langsetup_prop}
             {#2/DefineCommandsCmd}}
             {#2}
     }
     \seq_gput_right:Ne \__xpg_langs_loaded {#2}
   }
+  \cs_set_nopar:Npe \mainlanguagevariant { \prop_item:Ne \l_xpg_curropt_prop { \xpg_alias_base_lang:n{#2} / variant } }
    \exp_args:Nee \__xpg_set_default_language:nn {\xpg_alias_add_to_option_i:nn{#2}{#1}}
     {\xpg_alias_base_lang:n{#2}}
 }
@@ -5442,70 +5565,22 @@
 
 \cs_new:Nn \__xpg_set_default_language:nn
 {
-  \gdef\xpg at main@language{#2}
-  \tl_if_blank:nTF {#1}
-  {
-    \cs_gset_nopar:Npn \mainlanguagevariant {}
-  }
-  {
-     % Register the language options
-     \__xpg_set_language_options:nnn {#2} {#1} {@xpg at main@langvariant}
-  }
-  \csgdef{#2 at gvar}{\mainlanguagevariant}
+  \tl_gset:Nn \xpg_main_language_tl {#2}
   %% The following settings are for the default language and script
   % this tells bidi.sty or luabidi.sty that the document is RTL
-  \__xpg_if_LR_str:eF{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/direction}}
+  \__xpg_if_LR_str:eF{\prop_item:Nn{\l_xpg_langsetup_prop}{#2/direction}}
   {
     \__xpg_setRTLmain:
   }
   \cs_gset_nopar:Nn \__xpg_at_begin_document_selectlanguage: {
     \selectbackgroundlanguage{#2}
-    \selectlanguage[#1]{#2}%
+    \selectlanguage[#1]{#2}
   }
-  \xpg at info{Default~ language~ is~ #2}
-  \polyglossia at set@language at name[#1]{#2}
+  \str_if_eq:eeF { #2 } { latex }
+      { \xpg_info_msg:n{Default~ language~ is~ #2} }
+  \xpg_set_language_name:n { #2 }
 
   \cs_gset_nopar:Npn \mainlanguagename {#2}
-  % Store babelname of main language (for external packages such as biblatex)
-  \cs_gset_nopar:Npe \mainbabelname { \prop_item:Nn  \g_xpg_langsetup_prop {#2/babelname} }
-  % Store babelname of current language (for external packages such as biblatex)
-  \cs_gset_eq:NN \babelname \mainbabelname
-  \cs_gset_eq:cc{#2 at gbabelname}{babelname}%
-  % Store BCP-47 ID and subtags of main language:
-  % 1. store main.* (sub)tags
-  \cs_gset_nopar:cpe {bcp47.main.tag} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47 } }
-  \cs_gset_nopar:cpe {bcp47.main.language} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-language } }
-  \cs_gset_nopar:cpe {bcp47.main.region} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-region } }
-  \cs_gset_nopar:cpe {bcp47.main.script} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-script } }
-  \cs_gset_nopar:cpe {bcp47.main.variant} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-variant } }
-  \cs_gset_nopar:cpe {bcp47.main.extension.t} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47extension-t } }
-  \cs_gset_nopar:cpe {bcp47.main.extension.u} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-extension-u } }
-  \cs_gset_nopar:cpe {bcp47.main.extension.x} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-extension-x } }
-  % For casing, we fall back to language if bcp47-casing is not explicitly set
-  \cs_set_nopar:cpx {tmpcasing} { \prop_item:Ne \g_xpg_langsetup_prop { #2 / bcp47-casing } }
-  \str_if_empty:NTF \tmpcasing
-           { \cs_gset_nopar:cpe {bcp47.main.casing} { \prop_item:Nn  \g_xpg_langsetup_prop {#2 / bcp47-language} } }
-           { \cs_gset_nopar:cpe {bcp47.main.casing} { \tmpcasing } }
-  % 2. Store lang (sub)tags
-  \cs_gset_eq:cc {bcp47.tag} {bcp47.main.tag}
-  \cs_gset_eq:cc {bcp47.language} {bcp47.main.language}
-  \cs_gset_eq:cc {bcp47.region} {bcp47.main.region}
-  \cs_gset_eq:cc {bcp47.script} {bcp47.main.script}
-  \cs_gset_eq:cc {bcp47.variant} {bcp47.main.variant}
-  \cs_gset_eq:cc {bcp47.extension.t} {bcp47.main.extension.t}
-  \cs_gset_eq:cc {bcp47.extension.u} {bcp47.main.extension.u}
-  \cs_gset_eq:cc {bcp47.extension.x} {bcp47.main.extension.x}
-  \cs_gset_eq:cc {bcp47.casing} {bcp47.main.casing}
-  % 3. Store global language BCP47 settings (with default subtags as set by main language options)
-  \cs_gset_eq:cc{#2 at g.bcp47.tag}{bcp47.tag}
-  \cs_gset_eq:cc{#2 at g.bcp47.language}{bcp47.language}
-  \cs_gset_eq:cc{#2 at g.bcp47.region}{bcp47.region}
-  \cs_gset_eq:cc{#2 at g.bcp47.script}{bcp47.script}
-  \cs_gset_eq:cc{#2 at g.bcp47.variant}{bcp47.variant}
-  \cs_gset_eq:cc{#2 at g.bcp47.extension.t}{bcp47.extension.t}
-  \cs_gset_eq:cc{#2 at g.bcp47.extension.u}{bcp47.extension.u}
-  \cs_gset_eq:cc{#2 at g.bcp47.extension.x}{bcp47.extension.x}
-  \cs_gset_eq:cc{#2 at g.bcp47.casing}{bcp47.casing}
 }
 
 \DeclareCommandCopy \setmainlanguage \setdefaultlanguage
@@ -5516,11 +5591,11 @@
 {
     \str_case:nnF {#1}
       {
-        {bcp-47}    { \csuse{bcp47.tag} }
-        {bcp47}     { \csuse{bcp47.tag} }
+        {bcp-47}    { \use:c{bcp47.tag} }
+        {bcp47}     { \use:c{bcp47.tag} }
       }
       {
-        \xpg at error{Invalid~ \string\languageid\space argument:~ #1}
+        \xpg_ill_arg_msg:nn { #1 } { \languageid }
       }
 }
 
@@ -5530,11 +5605,11 @@
 {
     \str_case:nnF {#1}
       {
-        {bcp-47}    { \csuse{bcp47.main.tag} }
-        {bcp47}     { \csuse{bcp47.main.tag} }
+        {bcp-47}    { \use:c{bcp47.main.tag} }
+        {bcp47}     { \use:c{bcp47.main.tag} }
       }
       {
-        \xpg at error{Invalid~ \string\mainlanguageid\space argument:~ #1}
+        \xpg_ill_arg_msg:nn { #1 } { \mainlanguageid }
       }
 }
 % Kernel command to access to BCP-47 data.
@@ -5554,281 +5629,205 @@
 % and main.* variants thereof
 % See https://github.com/latex3/latex2e/issues/1035
 \DeclareExpandableDocumentCommand \BCPdata {m}
-{
-   \cs_if_exist_use:cF{bcp47.#1}
-        { \xpg at error{Invalid~ \string\BCPdata\space argument:~ #1} }
-}
+  {
+    \cs_if_exist_use:cF{bcp47.#1}
+        { \xpg_ill_arg_msg:nn { #1 } { \BCPdata } }
+  }
 
-% main babel name
-\cs_new_nopar:Npn \mainlanguagename {}
-\cs_new_nopar:Npn \mainbabelname {}
-\cs_new_nopar:cpn {bcp47.main.tag} {}
-\cs_new_nopar:cpn {bcp47.main.language} {}
-\cs_new_nopar:cpn {bcp47.main.region} {}
-\cs_new_nopar:cpn {bcp47.main.script} {}
-\cs_new_nopar:cpn {bcp47.main.variant} {}
-\cs_new_nopar:cpn {bcp47.main.extension.t} {}
-\cs_new_nopar:cpn {bcp47.main.extension.u} {}
-\cs_new_nopar:cpn {bcp47.main.extension.x} {}
-\cs_new_nopar:cpn {bcp47.main.casing} {}
-\cs_new_nopar:Npn \mainlanguagevariant {}%
-% Store main language variant for external packages
-\define at key{xpg at main@langvariant}{variant}{
-  \cs_gset_nopar:Npn \mainlanguagevariant {#1}
-}
+\clist_map_inline:nn 
+  {  
+   language, region, script, variant,
+   extension.t, extension.u, extension.x
+  }{
+     \tl_set:Nn \l_tmpa_tl { #1 }
+     \tl_replace_once:Nnn \l_tmpa_tl { . } { - }
+     \cs_gset_nopar:cpe { bcp47.#1 }
+       {
+         \exp_not:n { \prop_item:Ne  \l_xpg_langsetup_prop } { \exp_not:N \languagename / bcp47-\l_tmpa_tl }
+       }
+     \cs_gset_nopar:cpe { bcp47.main.#1 }
+       {
+         \exp_not:n { \prop_item:Ne  \l_xpg_langsetup_prop } { \exp_not:N \mainlanguagename / bcp47-\l_tmpa_tl } 
+       }
+  }
+\cs_gset_nopar:cpn { bcp47.casing } 
+  {
+    \tl_if_empty:eTF { \prop_item:Ne  \l_xpg_langsetup_prop { \languagename / bcp47-casing } }
+      {
+        \prop_item:Ne  \l_xpg_langsetup_prop { \languagename / bcp47-language }
+      }{
+        \prop_item:Ne  \l_xpg_langsetup_prop { \languagename / bcp47-casing }
+      }
+  }
+\cs_gset_nopar:cpn { bcp47.main.casing } 
+  {
+    \tl_if_empty:eTF { \prop_item:Ne  \l_xpg_langsetup_prop { \mainlanguagename / bcp47-casing } }
+      {
+        \prop_item:Ne  \l_xpg_langsetup_prop { \mainlanguagename / bcp47-language }
+      }{
+        \prop_item:Ne  \l_xpg_langsetup_prop { \mainlanguagename / bcp47-casing }
+      }
+  }
+\cs_gset_nopar:cpn { bcp47.tag } 
+  {
+    \prop_item:Ne  \l_xpg_langsetup_prop { \languagename / bcp47 }
+  }
+\cs_gset_nopar:cpn { bcp47.main.tag } 
+  {
+    \prop_item:Ne  \l_xpg_langsetup_prop { \mainlanguagename / bcp47 }
+  }
 
-\cs_new_nopar:Npn \babelname {}
-\def\languagevariant{}
-% Store current language variant for external packages
-\define at key{xpg at set@langvariant}{variant}{
-  \def\languagevariant{#1}
-}
+\cs_new_nopar:Npn \languagevariant 
+  {
+    \prop_item:Ne  \l_xpg_curropt_prop { \languagename / variant }
+  }
 
-\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}}}
-   }{
-     % Register the language options
-     \__xpg_set_language_options:nnn {#2} {#1} {@xpg at set@langvariant}
-     \cs_set_eq:cc{#2 at var}{languagevariant}
-  }%
+\cs_new:Nn \xpg_set_language_name:n
+{
+  \cs_set:Npn \languagename { #1 }
 }
 
-
-\newcommand*{\resetdefaultlanguage}[2][]{
+\NewDocumentCommand \resetdefaultlanguage { O{} m }
+{
   \__xpg_reset_default_language:nn
     {\xpg_alias_add_to_option_i:nn{#2}{#1}}
     {\xpg_alias_base_lang:n{#2}}
 }
 
-\cs_new:Nn \__xpg_store_bcp_info:nn
-{
-  % Store BCP-47 ID and subtags of current language
-  \tl_if_blank:nTF {#1}{
-    % tag (e.g., en-US)
-    \ifcsundef{#2 at g.bcp47.tag}{
-       \csedef{bcp47.tag}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47 } }
-    }{
-       \csedef{bcp47.tag}{\csuse{#2 at g.bcp47.tag}}
-    }
-    % language (e.g., en)
-    \ifcsundef{#2 at g.bcp47.language}{
-       \csedef{bcp47.language}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-language } }
-    }{
-       \csedef{bcp47.language}{\csuse{#2 at g.bcp47.language}}
-    }
-    % region (e.g., US)
-    \ifcsundef{#2 at g.bcp47.region}{%
-       \csedef{bcp47.region}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-region } }
-    }{
-       \csedef{bcp47.region}{\csuse{#2 at g.bcp47.region}}%
-    }
-    % script (e.g., Latn)
-    \ifcsundef{#2 at g.bcp47.script}{
-       \csedef{bcp47.script}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-script } }
-    }{
-       \csedef{bcp47.script}{\csuse{#2 at g.bcp47.script}}
-    }
-    % variant (e.g., 1996)
-    \ifcsundef{#2 at g.bcp47.variant}{
-       \csedef{bcp47.variant}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-variant } }
-    }{
-       \csedef{bcp47.variant}{\csuse{#2 at g.bcp47.variant}}
-    }
-    % extension.t (tranformation)
-    \ifcsundef{#2 at g.bcp47.extension.t}{%
-       \csedef{bcp47.extension.t}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-t } }
-    }{
-       \csedef{bcp47.extension.t}{\csuse{#2 at g.bcp47.extension.t}}
-    }
-    % extension.u (additional locale information)
-    \ifcsundef{#2 at g.bcp47.extension.u}{%
-       \csedef{bcp47.extension.u}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-u } }
-    }{
-       \csedef{bcp47.extension.u}{\csuse{#2 at g.bcp47.extension.u}}
-    }
-    % extension.x (private use area)
-    \ifcsundef{#2 at g.bcp47.extension.x}{
-       \csedef{bcp47.extension.x}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-x } }
-    }{
-       \csedef{bcp47.extension.x}{\csuse{#2 at g.bcp47.extension.x}}
-    }
-    % casing
-    \ifcsundef{#2 at g.bcp47.casing}{
-       % For casing, we fall back to language if bcp47-casing is not explicitly set
-       \cs_set_nopar:cpx {tmpcasing} { \prop_item:Ne \g_xpg_langsetup_prop { #2 / bcp47-casing } }
-       \str_if_empty:NTF \tmpcasing
-           { \cs_gset_eq:cc {bcp47.casing} {bcp47.language} }
-           { \csedef{bcp47.casing}{ \tmpcasing } }
-    }{
-       \csedef{bcp47.casing}{\csuse{#2 at g.bcp47.casing}}
-    }
-  }{
-    \csedef{bcp47.tag}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47 } }
-    \csedef{bcp47.language}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-language } }
-    \csedef{bcp47.region}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-region } }
-    \csedef{bcp47.script}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-script } }
-    \csedef{bcp47.variant}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-variant } }
-    \csedef{bcp47.extension.t}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-t } }
-    \csedef{bcp47.extension.u}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-u } }
-    \csedef{bcp47.extension.x}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-x } }
-    % For casing, we fall back to language if bcp47-casing is not explicitly set
-    \cs_set_nopar:cpx {tmpcasing} { \prop_item:Ne \g_xpg_langsetup_prop { #2 / bcp47-casing } }
-    \str_if_empty:NTF \tmpcasing
-         { \cs_gset_eq:cc {bcp47.casing} {bcp47.language} }
-         { \csedef{bcp47.casing}{ \tmpcasing } }
-  }
-}
-
 \cs_new:Nn \__xpg_reset_default_language:nn
 {
   \xpg_error_if_lang_not_loaded:n{#2}
   % disable globalnumbers of previously defined default language
-  \csuse{no\xpg at main@language @globalnumbers}
-  \csuse{noextras@\xpg at main@language}%
+  \use:c{no\xpg_main_language_tl @globalnumbers}
+  \use:c{noextras@\xpg_main_language_tl}
   % 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}%
-  \__xpg_if_LR_str:eF{\prop_item:Ne{\g_xpg_langsetup_prop}{#2/direction}}
+  \cs_if_exist_use:c{noextras at bbl@\mainbabelname}
+  \use:c{init at noextras@\xpg_main_language_tl}
+  \xpg_set_language_name:n { #2 }
+  \__xpg_if_LR_str:eF{\prop_item:Ne{\l_xpg_langsetup_prop}{#2/direction}}
   {
     \@rlmaintrue\@rl at footnotetrue
   }
-  \selectlanguage[#1]{#2}%
-  \selectbackgroundlanguage{#2}%
-  % Store babelname of current language (for external packages such as biblatex)
-  \tl_if_blank:nTF {#1}{%
-    \ifcsundef{#2 at gbabelname}{
-       \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-    }{
-       \edef\babelname{\csuse{#2 at gbabelname}}
-    }
-  }{
-    \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-  }
-  % Store variant
-  \tl_if_blank:nTF {#1}
-  {
-    \cs_gset_nopar:Npn \mainlanguagevariant {}
-  }
-  {
-     % Register the language options
-     \__xpg_set_language_options:nnn {#2} {#1} {@xpg at main@langvariant}
-  }
-  \csgdef{#2 at gvar}{\mainlanguagevariant}
-  % Store BCP-47 id of current language
-  \__xpg_store_bcp_info:nn {#1}{#2}
+  \selectlanguage[#1]{#2}
+  \selectbackgroundlanguage{#2}
+  \cs_set_nopar:Npe \mainlanguagevariant { \prop_item:Ne \l_xpg_curropt_prop { \xpg_alias_base_lang:n{#2} / variant } }
 }
 
 % This saves the normalfont for the latin script since we may change normalfont in other scripts
-\let\normalfontlatin=\normalfont
+\cs_set_eq:cc { normalfontlatin } { normalfont }
 
 % Provide default fonts (as set with \setmainfont, \setsansfont and \setmonofont)
 % for Latin scripts and as a fallback for non-Latin scripts.
-\DeclareRobustCommand\xpg at defaultfont@rm{
+\cs_set_protected:Nn \xpg_defaultfont_rm:
+{
    \tl_if_empty:NF{\g__fontspec_nfss_enc_tl}{\fontencoding{\g__fontspec_nfss_enc_tl}}
    \fontfamily\rmdefault
-   \ifdefined\UseHook\UseHook{rmfamily}\fi
+   \hook_use:n { rmfamily }
    \selectfont
 }
-\DeclareRobustCommand\xpg at defaultfont@sf{
+
+\cs_set_protected:Nn \xpg_defaultfont_sf:
+{
    \tl_if_empty:NF{\g__fontspec_nfss_enc_tl}{\fontencoding{\g__fontspec_nfss_enc_tl}}
    \fontfamily\sfdefault
-   \ifdefined\UseHook\UseHook{sffamily}\fi
+   \hook_use:n { sffamily }
    \selectfont
 }
-\DeclareRobustCommand\xpg at defaultfont@tt{
+
+\cs_set_protected:Nn \xpg_defaultfont_tt:
+{
    \tl_if_empty:NF{\g__fontspec_nfss_enc_tl}{\fontencoding{\g__fontspec_nfss_enc_tl}}
    \fontfamily\ttdefault
-   \ifdefined\UseHook\UseHook{ttfamily}\fi
+   \hook_use:n { ttfamily } 
    \selectfont
 }
 
-\def\xpg at patch@fontfamilies{
+\cs_new:Nn \__xpg_patch_fontfamilies:
+{
   % 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}}
+  \tl_put_right:cn {rmfamily~} {\tl_set:Nn \familytype {rm}}
+  \tl_put_right:cn {sffamily~} {\tl_set:Nn \familytype {sf}}
+  \tl_put_right:cn {ttfamily~} {\tl_set:Nn \familytype {tt}}
 }
 
 % These switches activate the default fonts
 % Note that a simple \let\rmfamilylatin=\rmfamily
 % does not work reliably (see #24)
-\cs_gset_eq:cc{rmfamilylatin}{xpg at defaultfont@rm}
-\cs_gset_eq:cc{sffamilylatin}{xpg at defaultfont@sf}
-\cs_gset_eq:cc{ttfamilylatin}{xpg at defaultfont@tt}
+\cs_set_eq:cc{rmfamilylatin}{xpg_defaultfont_rm:}
+\cs_set_eq:cc{sffamilylatin}{xpg_defaultfont_sf:}
+\cs_set_eq:cc{ttfamilylatin}{xpg_defaultfont_tt:}
 
-\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}}}
-  \xpg at patch@fontfamilies
+\cs_new:Nn \xpg_set_familydefault:
+{
+  \tl_set:Ne \l_tmpa_tl { \familydefault }
+  \tl_set:Ne \l_tmpb_tl { \sfdefault }
+  \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl
+     { \tl_set:Nn \familytype {sf} }
+     { \tl_set_eq:NN \l_tmpb_tl \ttdefault
+       \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl
+           { \tl_set:Nn \familytype {tt} }
+           { \tl_set:Nn \familytype {rm} }
+     }
+  \__xpg_patch_fontfamilies:
   % This (re-)saves the normalfont for the latin script since we may
   % change normalfont in other scripts
-  \let\normalfontlatin=\normalfont
+  \cs_set_eq:cc{ normalfontlatin }{ normalfont }
   % And for all cases, we also reset \<xx>familylatin
-  \cs_gset_eq:cc{rmfamilylatin}{xpg at defaultfont@rm}
-  \cs_gset_eq:cc{sffamilylatin}{xpg at defaultfont@sf}
-  \cs_gset_eq:cc{ttfamilylatin}{xpg at defaultfont@tt}
+  \cs_set_eq:cc{ rmfamilylatin }{ xpg_defaultfont_rm: }
+  \cs_set_eq:cc{ sffamilylatin }{ xpg_defaultfont_sf: }
+  \cs_set_eq:cc{ ttfamilylatin }{ xpg_defaultfont_tt: }
 }
 
-\def\resetfontlatin{
-  \DeclareRobustCommand\rmfamily{\xpg at defaultfont@rm}
-  \DeclareRobustCommand\sffamily{\xpg at defaultfont@sf}
-  \DeclareRobustCommand\ttfamily{\xpg at defaultfont@tt}
-  \xpg at patch@fontfamilies
-  \global\let\normalfont=\normalfontlatin
+\cs_set_nopar:Nn \xpg_select_fontfamily:n
+{
+  \str_if_eq:VnTF \familytype { tt }
+    { \__xpg_use_or_warn:c { #1 at font@tt } }
+    { \str_if_eq:VnTF \familytype { sf }
+        { \__xpg_use_or_warn:c { #1 at font@sf } }
+        { \__xpg_use_or_warn:c { #1 at font@rm } }
+    }
 }
 
-\def\selectfontfamilylatin{
-  \def\tmp at tt{tt}\def\tmp at sf{sf}
-  \ifx\familytype\tmp at tt
-    \ttfamilylatin
-    \else\ifx\familytype\tmp at sf
-      \sffamilylatin
-      \else\rmfamilylatin\fi\fi}
+\cs_set_protected:Npn \xpg_select_default_fontfamily:n #1
+  {
+    \tl_set:Ne \l_tmpa_tl { \familydefault }
+    \tl_set:Ne \l_tmpb_tl { \sfdefault }
+    \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl
+       { \tl_set:Nn \familytype {sf} }
+       { \tl_set_eq:NN \l_tmpb_tl \ttdefault
+         \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl
+             { \tl_set:Nn \familytype {tt} }
+             { \tl_set:Nn \familytype {rm} }
+       }
+     \xpg_select_fontfamily:n{#1}
+  }
 
-\def\xpg at select@fontfamily#1{
-  \def\tmp at tt{tt}\def\tmp at sf{sf}
-  \ifx\familytype\tmp at tt
-    \__xpg_use_or_warn:c{#1 at font@tt}
-  \else\ifx\familytype\tmp at sf
-    \__xpg_use_or_warn:c{#1 at font@sf}
-      \else\__xpg_use_or_warn:c{#1 at font@rm}\fi\fi}
-
-\def\xpg at set@normalfont#1{
-  \letcs{\rmfamily}{#1 at font@rm}
-  \letcs{\sffamily}{#1 at font@sf}
-  \letcs{\ttfamily}{#1 at font@tt}
-  \robustify\rmfamily
-  \robustify\sffamily
-  \robustify\ttfamily
-  \gdef\normalfont{\protect\xpg at select@fontfamily{#1}
-                   \fontseries{\seriesdefault}\selectfont
-                   \fontshape{\shapedefault}
-                   \ifdefined\UseHook\UseHook{normalfont}\fi
-                   \selectfont}
-  \gdef\reset at font{\protect\normalfont}
+\cs_new_nopar:Nn \xpg_set_normalfont:n
+{
+  \cs_set_eq:cc { rmfamily } { #1 at font@rm }
+  \cs_set_eq:cc { sffamily } { #1 at font@sf }
+  \cs_set_eq:cc { ttfamily } { #1 at font@tt }
+  \cs_set_nopar:Npn \normalfont 
+      { \xpg_select_default_fontfamily:n {#1}
+        \fontseries{\seriesdefault}\selectfont
+        \fontshape{\shapedefault}
+        \hook_use:n { normalfont }
+        \selectfont
+      }
+  \cs_set_nopar:Npn \reset at font {\protect\normalfont}
 }
 
-\let\@@fterindentfalse\@afterindentfalse
-\def\french at indent{
-    \let\@afterindentfalse\@afterindenttrue
+\cs_gset_eq:cc { @@fterindentfalse } { @afterindentfalse }
+\cs_new_nopar:Nn \__xpg_french_indent:
+{
+    \cs_set_eq:cc { @afterindentfalse } { @afterindenttrue }
     \@afterindenttrue
 }
-\def\nofrench at indent{
-    \let\@afterindentfalse\@@fterindentfalse
+\cs_new_nopar:Nn \__xpg_no_french_indent:
+{
+    \cs_set_eq:cc { @afterindentfalse } { @@fterindentfalse }
     \@afterindentfalse
 }
 
@@ -5839,10 +5838,10 @@
 
 \cs_new:Nn \__xpg_select_background_language:n
 {
-  \str_if_eq:eeTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/lcscript}}{latin}
+  \str_if_eq:eeTF { \prop_item:Nn{\l_xpg_langsetup_prop}{#1/lcscript} } { latin }
                    {}
-                   {\xpg at set@normalfont{#1}}
-  \csuse{#1 at globalnumbers}
+                   { \xpg_set_normalfont:n{#1} }
+  \use:c{#1 at globalnumbers}
 }
 \cs_generate_variant:Nn \__xpg_select_background_language:n {e}
 %  Declare secondary language #2 with language options #1
@@ -5853,7 +5852,7 @@
     \__xpg_load_lang_definition:ee {#1} {#2}
     % define environment and command if not alias
     \str_if_eq:eeT {\prop_item:Ne \__xpg_alias {#2/target}} {#2} {
-       \use:c{\prop_item:Ne{\g_xpg_langsetup_prop}
+       \use:c{\prop_item:Ne{\l_xpg_langsetup_prop}
              {#2/DefineCommandsCmd}}
              {#2}
     }
@@ -5866,28 +5865,13 @@
 \cs_new:Nn \__xpg_set_otherlanguage:nn
 {
   \__xpg_register_language:nn{#1}{#2}
-  % If a variant is set, store it.
-  \gdef\otherlanguagevariant{}
-  % Register the language options
-  \__xpg_set_language_options:nnn {#2} {#1} {@xpg at other@langvariant}
-
-  \csgdef{#2 at gvar}{\otherlanguagevariant}
-  \prop_get:NeNT \g_xpg_langsetup_prop {#2/babelname} \l_tmpa_tl
-    { \xdef\otherlanguagebabelname{\l_tmpa_tl} }
-  \cs_gset_eq:cc{#2 at gbabelname}{otherlanguagebabelname}
 }
 \cs_generate_variant:Nn  \__xpg_set_otherlanguage:nn { ee }
 
-
-% Store main language variant for external packages
-\define at key{xpg at other@langvariant}{variant}{
-  \gdef\otherlanguagevariant{#1}
-}
-
 \NewDocumentCommand \setotherlanguages { m }
-  {
+{
    \clist_map_function:eN { #1 } \setotherlanguage
-  }
+}
 
 \cs_set:Nn \xpg_common_language:
 {% FIXME is this really needed???
@@ -5910,7 +5894,8 @@
 % for specific (esp. tag-based) aliases
 % where \text<alias> would cause clashes
 % (e.g., \textit)
-\newcommand\textlang[3][]{
+\NewDocumentCommand \textlang { O{} m +m }
+{
   \__xpg_textlanguage:een {#1} {#2} {#3}
 }
 
@@ -5919,45 +5904,20 @@
 % inside case changing commands (e.g. \MakeUppercase)
 \tl_put_right:Nn \l_text_case_exclude_arg_tl { \textlang }
 
-% Alias to {<lang>}, but more suitable
-% for specific (esp. tag-based) aliases
-% where {<alias>} would cause clashes
-% (e.g., \fi)
-\DeclareEnvironmentCopy { lang } { otherlanguage }
-
 % wrapper for foreignlanguage and otherlanguage*
-\newcommand*\polyglossia at setforeignlanguage[2][]{
-  \select@@language[#1]{#2}
+\cs_new_nopar:Nn \xpg_set_foreign_language:nn
+{
+  \xpg_select_language:nn { #1 } { #2 }
   \__xpg_register_language:nn{#1}{#2}
-  % Store babelname of current language (for external packages such as biblatex)
-  \tl_if_blank:nTF {#1}{
-    \ifcsundef{#2 at gbabelname}{
-       \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-    }{
-       \edef\babelname{\csuse{#2 at gbabelname}}
-    }
-  }{
-    \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-  }
-  % Store BCP-47 id of current language
-  \__xpg_store_bcp_info:nn {#1}{#2}
 }
 
-% Expandable lowercasing. We use this to assure keyval
-% options are lowercased (also when used in \MakeUppercase
-% contexts e.g. in headings)
-% Macro adapted from tudscr.sty
-\newcommand*\xpg at str@lowercase[2]{
-  \protected at edef#1{
-    \lowercase{\def\noexpand#1{#2}}
-  }#1
-}
-
 % lowercase options before passing to setkeys
-\cs_new:Nn \__xpg_set_keys:nn
+\NewDocumentCommand \SetGlossOptions { m m }
 {
-    \xpg at str@lowercase{\xpg at tmp@opts}{#2}
-    \exp_args:Nne \setkeys{#1}{\xpg at tmp@opts}
+    % \text_lowercase:n fully expands
+    % (as opposed to \str_lowercase:n)
+   \use:c { xpg_#1_default_options_tl }
+   \exp_args:Ne \keys_set:ne{ polyglossia / gloss / #1 }{ \text_lowercase:n {#2} }
 }
 
 % joint code of \foreignlanguage, otherlanguage*
@@ -5967,12 +5927,12 @@
 \cs_new:Nn \xpg_otherlanguage:nn
 {
   \xpg_error_if_lang_not_loaded:n{#2}
-  \__xpg_set_keys:nn{#2}{#1}
-  \polyglossia at setforeignlanguage[#1]{#2}
+  \SetGlossOptions{#2}{#1}
+  \xpg_set_foreign_language:nn { #1 } { #2 }
   % Hook for external packages such as biblatex
   \polyglossia at language@switched
   % buggy restoration heure
-  \csuse{inlineextras@#2}
+  \use:c{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}
@@ -5979,44 +5939,20 @@
 }
 
 \DeclareDocumentCommand { \foreignlanguage } { O{} m +m }
-  {
+{
 	\__xpg_foreignlanguage:eeen {#1} {#2} {\xpg_alias_base_lang:n{#2}} {#3}
-  }
+}
 
 % prevent case changing of language name in \foreignlanguage
 \tl_put_right:Nn \l_text_case_exclude_arg_tl { \foreignlanguage }
 
-% Direct access to polyglossia at setforeignlanguage
+% Direct access to \xpg_set_foreign_language:nn
 % used in captions
-\newcommand{\setforeignlanguage}[2][]
+\NewDocumentCommand \setforeignlanguage { O{} m }
 {
-  \polyglossia at setforeignlanguage[#1]{#2}
+  \xpg_set_foreign_language:nn { #1 } { #2 }
 }
 
-% Stack to store matrix languages
-\seq_new:N \__xpg_current_matrixlang_stack
-
-% Store embedding language when an embedded language is switched to
-\cs_new_nopar:Nn \__xpg_store_matrixlang:
-{
-   \seq_gput_left:Nn \__xpg_current_matrixlang_stack \languagename
-}
-
-% When an embedded language is closed, reset to the embedding language
-% and remove stored matrix language from stack
-\cs_new_nopar:Nn \__xpg_reset_to_matrixlang:
-{
-  % if stack is empty, use main language
-  \seq_gpop_left:NNTF \__xpg_current_matrixlang_stack \l_tmpa_tl
-     { \cs_set_eq:NN \__xpg_current_matrixlang \l_tmpa_tl }
-     { \cs_set_eq:NN \__xpg_current_matrixlang \mainlanguagename }
-  % Reset the language's/script's font families if the embedding script is latin
-  \str_if_eq:eeT{\prop_item:Ne{\g_xpg_langsetup_prop}{\__xpg_current_matrixlang/lcscript}}{latin}
-       {\resetfontlatin}
-  % In case a \<lang>font is defined, re-activate that
-  \exp_args:Ne \xpg at set@normalfont{\__xpg_current_matrixlang}
-}
-
 % internal wrapper for foreign language
 % #1 option
 % #2 alias
@@ -6028,12 +5964,10 @@
   {
     \msg_show:nnn { polyglossia } { languagenotloaded } {#2}
   }{
-    \__xpg_store_matrixlang:
     \group_begin:
       \xpg_otherlanguage:nn{ \xpg_alias_add_to_option_i:nn{#2}{#1} }{ #3 }
       \__xpg_lang_set_text_direction:nn{#3}{#4}
     \group_end:
-    \__xpg_reset_to_matrixlang:
   }
 }
 \cs_generate_variant:Nn \__xpg_foreignlanguage:nnnn {eeen}
@@ -6042,11 +5976,9 @@
 % otherlanguage* is the environment equivalent of \foreignlanguage
 \DeclareDocumentEnvironment { otherlanguage* } { O{} m }
   {
-	\__xpg_store_matrixlang:
 	\__xpg_otherlanguage:eee { #1 } { #2 } { \xpg_alias_base_lang:n { #2 } }
   }{
-	\egroup% \group_end: does not work here!
-	\__xpg_reset_to_matrixlang:
+	\c_group_end_token% \group_end: does not work here!
   }
 
 % internal wrapper
@@ -6061,7 +5993,7 @@
   }{
     \xpg_otherlanguage:nn{ \xpg_alias_add_to_option_i:nn{#2}{#1} }{ #3 }
     \__xpg_lang_set_text_direction:nn{#3}%
-    \bgroup% \group_begin: does not work here!
+    \c_group_begin_token% \group_begin: does not work here!
   }
 }
 \cs_generate_variant:Nn \__xpg_otherlanguage:nnn { eee }
@@ -6077,9 +6009,6 @@
 }
 \cs_generate_variant:Nn \__xpg_textlanguage:nnn {een}
 
-% Track whether we are in an inline lang (\text...) switch
-\bool_new:N \l__xpg_inline_lang_bool
-
 % use by \text<lang> and \textlang. Equivalent to \foreignlanguage,
 % except that dates are localized.
 % #1: option
@@ -6093,29 +6022,27 @@
     \msg_show:nnn { polyglossia } { languagenotloaded } {#2}
   }
   {
-    \__xpg_store_matrixlang:
     \group_begin:
-      \bool_set_true:N \l__xpg_inline_lang_bool
       \xpg_otherlanguage:nn{#1}{#3}
-      \csuse{date#3}
+      \use:c{date#3}
       % 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}
       \__xpg_lang_set_text_direction:nn{#3}{#4}
     \group_end:
-    \__xpg_reset_to_matrixlang:
   }
 }
 \cs_generate_variant:Nn \__xpg_textlanguage:nnnn {nnen}
 
 % Define language-specific hyphenation exceptions
-\newcommand\pghyphenation[3][]{
-  \bgroup
-  \xpg_error_if_lang_not_loaded:n{#2}
-  \setkeys{#2}{#1}
-  \select@@language[#1]{#2}
+\NewDocumentCommand \pghyphenation {O{} m m}
+{
+  \c_group_begin_token
+  \xpg_error_if_lang_not_loaded:n { #2 }
+  \SetGlossOptions{#2}{#1}
+  \xpg_select_language:nn { #1 } { #2 }
   \hyphenation{#3}
-  \egroup
+  \c_group_end_token
 }
 
 
@@ -6122,12 +6049,16 @@
 % Hook that other package authors can use
 % (for instance biblatex):
 % Do not rename!
-\newcommand*{\xpg at hook@setlanguage}{}
+\cs_set_nopar:Npn \xpg at hook@setlanguage {}
 
-\def\xpg at pop@language at i#1#2{
-  \xpg at set@language at aux[#1]{#2}
+\cs_set_nopar:Nn \__xpg_pop_language:nn
+{
+  \xpg_set_language_aux:nn { #1 } { #2 }
   \xpg at hook@setlanguage
-  \let\emp at langname\@undefined}
+% FIXME This seems to be a very old relict. 
+%       The macro is nowhere used. Probably remove.
+%  \let\emp at langname\@undefined
+}
 
 \DeclareDocumentCommand \selectlanguage {s O{} m}
   {
@@ -6146,113 +6077,113 @@
 \cs_new:Nn \__xpg_select_language:nnn
 {
   % Register the language options
-  \__xpg_set_language_options:nnn {#3} {#2} {@xpg at set@langvariant}
+  \__xpg_set_language_options:nn {#3} {#2}
   \IfBooleanTF { #1 }   % The starred variant does not write to the aux
     {
-	  \xpg at set@language at nonaux[#2]{#3}
+	  \xpg_set_language_nonaux:nn { #2 } { #3 }
     }{
-      \cs_set_nopar:Npe \xpg at pop@language { \exp_not:N \xpg at pop@language at i {#2} {#3} }
-      \group_insert_after:N \xpg at pop@language
-	  \xpg at set@language at aux[#2]{#3}
+      \cs_set_nopar:Ne \xpg_pop_language: { \exp_not:N \__xpg_pop_language:nn { #2 } { #3 } }
+      \group_insert_after:N \xpg_pop_language:
+	  \xpg_set_language_aux:nn { #2 } { #3 }
     }
-  \__xpg_register_language:nn{#2}{#3}
+  \__xpg_register_language:nn { #2 } { #3 }
 }
 \cs_generate_variant:Nn \__xpg_select_language:nnn { nee, nne }
 
-
 % set lang option #2 for lang #1
-\cs_new:Nn \__xpg_set_language_options:nnn
+\cs_new:Nn \__xpg_set_language_options:nn
 {
-  \tl_if_blank:nF {#2}
+  \cs_if_exist:cT { xpg_#1_default_options_prop }
   {
-    % 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=#3:#1\relax
-    }%
-    \__xpg_set_keys:nn{#1}{#2}
+  \prop_concat:ccc { l_xpg_curropt_prop } { l_xpg_curropt_prop }
+                   { xpg_#1_default_options_prop }
   }
+  \xpg__keyval_parser:eeN { #2 } { #1 } \l_xpg_curropt_prop 
+  \SetGlossOptions{#1}{#2}
 }
 
 % Initialize default language options, so that
 % \iflanguageoption has the info it needs also
 % for default settings
-\newcommand*\xpg at initialize@gloss at options[2]{
-   \__xpg_set_language_options:nnn {#1} {#2} {@xpg at set@langvariant}
+\NewDocumentCommand \InitializeGlossOptions { m m }
+{
+   \tl_new:c { xpg_#1_default_options_tl }
+   \prop_new:c { xpg_#1_default_options_prop }
+   \keys_precompile:nec { polyglossia / gloss / #1 } 
+                        { \text_lowercase:n { #2, \xpg__tmp_default_options_tl } } 
+                        { xpg_#1_default_options_tl }
+   \xpg__keyval_parser:enc { #2, \xpg__tmp_default_options_tl } { #1 } 
+                           { xpg_#1_default_options_prop }
+   \prop_concat:ccc { l_xpg_curropt_prop } { l_xpg_curropt_prop }
+                    { xpg_#1_default_options_prop }
+   \use:c { xpg_#1_default_options_tl }
+   \__xpg_set_language_options:nn {#1} {#2}
 }
+\tl_new:N \xpg__tmp_default_options_tl
+\cs_generate_variant:Nn \keys_precompile:nnN { nec }
 
 % Record synonymous keyvals such as variant=us and variant=american
-% Syntax: \xpg at set@alias at values{<lang>}{<key>}{<val>}{<alias vals, comma-separated>}
-\newcommand*\xpg at set@alias at values[4]{%
-   \prop_if_exist:cF { xpg at alias@keyvals@#1@#3 }
-      { \prop_new:c {xpg at alias@keyvals@#1@#3} }
-   \prop_put:cnn { xpg at alias@keyvals@#1@#3 }
-      {#2}{#4}
-   \prop_if_exist:cF { xpg at alias@keyvals@#1@#4 }
-      { \prop_new:c {xpg at alias@keyvals@#1@#4} }
-   \prop_put:cnn { xpg at alias@keyvals@#1@#4 }
-      {#2}{#3}
+% Syntax: \SetLanguageAliasValues{<lang>}{<key>}{<alias vals, comma-separated>}
+\int_new:N \l_xpg_alias_keyvals_int
+\int_set:Nn \l_xpg_alias_keyvals_int { 2 }
+\NewDocumentCommand \SetLanguageAliasValues { m m m }
+{
+  \clist_map_inline:nn { #3 }
+    {
+      \int_const:cn { c_xpg_alias_keyvals_#1_#2_##1_int } { \l_xpg_alias_keyvals_int }
+    }
+  \int_incr:N \l_xpg_alias_keyvals_int
 }
 
-% Patch xkeyval to record default values of keys
-\pretocmd{\XKV at define@default}{%
-   \csgdef{xpg at default@opt@\XKV at header #1}{#2}
-}{}{\xpg at warning{Patching xkeyval failed!}}
+\cs_new:Npn \xpg__keyval_parser:nnN #1 #2 #3 % #1 = key-vals, #2 = language, #3 = prop
+  {
+    \keyval_parse:nnn 
+      { \xpg__keyval_parser_default:nnn { #2 } { #3 } }
+      { \xpg__keyval_parser_nondefault:nnnn { #2 } { #3 } }
+      { #1 }
+  }
+\cs_generate_variant:Nn \xpg__keyval_parser:nnN { eeN, enc }
+  
+\cs_new:Npn \xpg__keyval_parser_default:nnn #1 #2 #3 % #1 = lang, #2 = prop, #3 = key
+  {
+    \str_set:Nn \l_tempa_str { #1 / #3 }
+    \str_concat:NNN \l_tempa_str \c__keys_default_root_str \l_tempa_str
+    \prop_put:Nne #2 { #1 / #3 } { \use:c { \l_tempa_str } }
+  }
+  
+\cs_new:Npn \xpg__keyval_parser_nondefault:nnnn #1 #2 #3 #4 % #1 = lang, #2 = prop, #3 = key, #4 = value
+  {
+    \prop_put:Nnn #2 { #1 / #3 } { #4 }
+  }
 
-% Helper to get and register option keyvals
-\def\xpg at parsevariantkeyvalue#1=#2@#3:#4\relax{
-   \def\@tmpa{#1}
-   \def\@tmpb{variant}
-   % variant values are stored in specific macros
-   % (\xpg at main@langvariant, \xpg at other@langvariant
-   % and \xpg at set@langvariant)
-   \ifx\@tmpa\@tmpb\setkeys{#3}{#1=#2}\fi
-   \tl_if_empty:nTF{#2}
+\prg_set_conditional:Npnn \__xpg_check_option_value:NNN #1#2#3 { p , T , F , TF }
+  {
+    \bool_lazy_or:nnTF
       {
-        \ifcsdef{xpg at default@opt at KV@#4@#1}
-           {\xpg at store@opt at keyval#1:\csuse{xpg at default@opt at KV@#4@#1}=:#4\relax}
-           {}%
-      }
-      { \xpg at store@opt at keyval#1:#2:#4\relax }
-}%
+        \str_if_eq_p:ee { \prop_item:Nn \l_xpg_curropt_prop { #1 / #2 } }  { #3 }
+      } {
+        \int_compare_p:nNn
+          {
+            \cs_if_exist_use:cF { c_xpg_alias_keyvals_#1_#2_#3_int } { 0 }
+          } = {
+            \cs_if_exist_use:cF { c_xpg_alias_keyvals_#1_#2_\prop_item:Nn \l_xpg_curropt_prop { #1 / #2 }_int } { 1 }
+          }
+      } { \prg_return_true: } { \prg_return_false: }
+  }
 
-% Store option keys and values
-% This strips trailing '=' from values.
-\def\xpg at store@opt at keyval#1:#2=:#3\relax{
-   \prop_if_exist:cF { xpg at current@options@#3 }
-      { \prop_new:c {xpg at current@options@#3} }
-   \prop_put:cnn { xpg at current@options@#3 }
-      {#1}{#2}
+\prg_set_conditional:Npnn \xpg_if_main_language:n #1 { T, F, TF }
+{
+   \str_if_eq:VnTF \xpg_main_language_tl { #1 }
+        { \prg_return_true: }
+        { \prg_return_false: }
 }
 
+\cs_set_eq:NN \IfMainLanguageTF \xpg_if_main_language:nTF
 
-\prg_set_conditional:Npnn \__xpg_check_option_value:NNN #1#2#3 { p , T , F , TF }
-{
-  \prop_get:cnNTF {xpg at current@options@#1} {#2} \l_tmpa_tl
-     {
-       \str_if_eq:eeTF{\l_tmpa_tl}{#3}
-          {\prg_return_true:}
-          {
-            \prop_get:cnNTF {xpg at alias@keyvals@#1@#3} {#2} \l_tmpb_tl
-               {
-                \clist_set:Ne{\l_tmpa_clist}{\l_tmpb_tl}
-                \providetoggle{xpgvalfound}
-                \togglefalse{xpgvalfound}
-                \clist_map_inline:Nn \l_tmpa_clist {
-                   \str_if_eq:eeT{##1}{\l_tmpa_tl}
-                      { \toggletrue{xpgvalfound} }
-                }
-                \iftoggle{xpgvalfound}{\prg_return_true:}{\prg_return_false:}
-              }
-              {
-                \prg_return_false:
-              }
-         }
-     }
-     {
-       \prg_return_false:
-     }
-}
+\cs_set_eq:NN \IfMainLanguageT \xpg_if_main_language:nT
 
+\cs_set_eq:NN \IfMainLanguageF \xpg_if_main_language:nF
+
 % Test if option value is set
 \DeclareDocumentCommand \iflanguageoption { m m m m m }
 {
@@ -6259,18 +6190,11 @@
   \__xpg_check_option_value:NNNTF{#1}{#2}{#3}{#4}{#5}
 }
 
-
-% Append any variant to csv list of variants
-\define at key{xpg at langvariant}{variant}{
-  \clist_if_in:NeF \xpg at vloaded {#1}{
-    \clist_gput_right:Ne \xpg at vloaded {#1}
-  }
-}
-
 % Test if language is loaded
 \DeclareDocumentCommand \iflanguageloaded { m m m }
 {
-   \AddToHook{begindocument/end}{
+   \hook_gput_code:nnn {begindocument/end} {.}
+   {
      \clist_if_in:NeTF \xpg at loaded{#1}{#2}{#3}
    }
 }
@@ -6278,7 +6202,8 @@
 % Same for babellanguage is loaded
 \DeclareDocumentCommand \ifbabellanguageloaded { m m m }
 {
-  \AddToHook{begindocument/end}{
+  \hook_gput_code:nnn {begindocument/end} {.}
+  {
      \clist_if_in:NeTF \xpg at bloaded{#1}{#2}{#3}
   }
 }
@@ -6286,7 +6211,8 @@
 % Same for languageid
 \DeclareDocumentCommand \iflanguageidloaded { m m m m }
 {
-  \AddToHook{begindocument/end}{
+  \hook_gput_code:nnn {begindocument/end} {.}
+  {
     \str_case:nnTF {#1}
       {
         {bcp-47}    { \clist_if_in:NeTF \xpg at bcp@loaded{#2}{#3}{#4} }
@@ -6294,7 +6220,7 @@
       }
       {}
       {
-        \xpg at error{Invalid~ \string\iflanguageidloaded\space argument:~ #1}
+        \xpg_ill_arg_msg:nn { #1 } { \iflanguageidloaded }
       }
    }%
 }
@@ -6324,30 +6250,21 @@
   }
 
 
-\newcommand*{\xpg at set@language at nonaux}[2][]{
-   \@select at language[#1]{#2}
+\cs_new_nopar:Nn \xpg_set_language_nonaux:nn
+{
+   \__xpg_start_language:nn { #1 } { #2 }
 }
 
 
-\newcommand*{\xpg at set@language at aux}[2][]{
-   % Store babelname of current language (for external packages such as biblatex)
-   \tl_if_blank:nTF {#1}{
-     \ifcsundef{#2 at gbabelname}{
-        \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-     }{
-        \edef\babelname{\csuse{#2 at gbabelname}}
-     }
-   }{
-     \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-   }
-   % Store BCP-47 id of current language
-   \__xpg_store_bcp_info:nn {#1}{#2}
-   \@select at language[#1]{#2}
+\cs_new_nopar:Nn \xpg_set_language_aux:nn
+{
+   \__xpg_start_language:nn { #1 } { #2 }
     % Write to the aux
-   \xpg at set@language at only@aux[#1]{#2}
+   \xpg_set_language_only_aux:nn { #1 } { #2 }
 }
 
-\newcommand*{\xpg at set@language at only@aux}[2][]{
+\cs_new_nopar:Nn \xpg_set_language_only_aux:nn
+{
     % Write to the aux (toc files)
    \if at filesw
         \addtocontents{toc}{\selectlanguage*[#1]{#2}}
@@ -6354,16 +6271,18 @@
    \fi
 }
 
-\AtBeginDocument{
+\hook_gput_code:nnn {begindocument} {.}
+{
    \if at filesw
-		\immediate\write\@mainaux
-		{\ProvideDocumentCommand\selectlanguage{sO{}m}{}}
+	\immediate\write\@mainaux
+	{\ProvideDocumentCommand\selectlanguage{sO{}m}{}}
    \fi
 }
 
 % Since captions might float to other language regions,
 % we need to change the language here (#542)
-\AddToHook{cmd/caption/before}{
+\hook_gput_code:nnn {cmd/caption/before} {.}
+{
     \ifhmode\unskip\fi
     \addtocontents{lof}{\protect\setforeignlanguage{\languagename}}
     \addtocontents{lot}{\protect\setforeignlanguage{\languagename}}
@@ -6370,7 +6289,7 @@
 }
 
 % check if language is defined
-\prg_set_conditional:Npnn \__xpg_check_if_exist_l@:n #1 { F, TF }
+\prg_set_conditional:Npnn \__xpg_pattern_check_if_exists:n #1 { F, TF }
   {
 	\bool_lazy_and:nnTF 
 	  { \cs_if_exist_p:c { l@#1 }  }
@@ -6379,34 +6298,75 @@
       { \prg_return_false: }
   }
 
-\def\polyglossia at luatex@load at lang#1{
+\cs_new_nopar:Nn \__xpg_luatex_load_lang:n
+{
   % if \l@#1 is not properly defined, call lua function newloader(#1),
   % and assign the returned number to \l@#1
-  \__xpg_check_if_exist_l@:nF {#1}
+  \__xpg_pattern_check_if_exists:nF {#1}
   {
     \directlua { token.set_char('l@#1', polyglossia.newloader'#1') }
   }
 }
 
-% This check is also used by biblatex, so don't
-% rename silently.
-\newcommand\xpg at ifdefined[3]{
+% check if language is defined
+\prg_set_conditional:Npnn \xpg_if_language_defined:n #1 { T, F, TF }
+{
   % With luatex, we first need to define \l@#1.
   \sys_if_engine_luatex:T
   {
-    \polyglossia at luatex@load at lang{#1}
+    \__xpg_luatex_load_lang:n {#1}
   }
-  \__xpg_check_if_exist_l@:nTF{#1}{#2}{#3}
+  \__xpg_pattern_check_if_exists:nTF{#1}
+        { \prg_return_true: }
+        { \prg_return_false: } 
 }
 
+% Aliases for gloss files
+\cs_gset_eq:cc { IfLanguageDefinedTF } { xpg_if_language_defined:nTF }
+\cs_gset_eq:cc { IfLanguageDefinedT }  { xpg_if_language_defined:nT }
+\cs_gset_eq:cc { IfLanguageDefinedF }  { xpg_if_language_defined:nF }
+
+% Check if patterns for language #1 is defined. If not, try
+% the comma-separated list of fallbacks in #2
+\NewDocumentCommand \TryPatternWithFallback { m m }
+{
+   \xpg_if_language_defined:nF { #1 }
+     {
+        \clist_clear_new:N \l_xpg_lang_patterns
+        \clist_set:Ne \l_xpg_lang_patterns { #2 }
+        \bool_set_false:N \l_tmpa_bool
+        \clist_map_inline:Nn \l_xpg_lang_patterns
+          {
+             \xpg_if_language_defined:nT { ##1 }
+                {
+                   \cs_gset_eq:cc { l@#1 }  { l@##1 }
+                   \bool_set_true:N \l_tmpa_bool
+                   \clist_map_break:
+                }
+          }
+        \bool_if:NF \l_tmpa_bool
+           {
+            \xpg_warning_msg:n
+              {No~ hyphenation~ patterns~ for~ #1~ found \iow_newline:
+               Falling~ back~ to~ the~ default~ patterns~ (=~English)!}
+               \exp_args:Nc \adddialect {l@#1} 0
+           }
+     }
+}
+
+% This old term is used by biblatex, so don't drop!
+\cs_gset_eq:cc { xpg at ifdefined } { xpg_if_language_defined:nTF }
+
 % 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]{
+\cs_new:Nn \xpg_set_bbl_hyphendata:n
+{
   \sys_if_engine_luatex:T
   {
-    \ifcsdef{bbl at hyphendata@#1}{}{
-      \global\@namedef{bbl at hyphendata@\the\language}{}
+    \cs_if_exist:cF {bbl at hyphendata@#1}
+    {
+      \cs_gset:cpn {bbl at hyphendata@\the\language} {}
     }
   }
 }
@@ -6413,48 +6373,50 @@
 
 % 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]{
-  \sys_if_engine_luatex:T { \polyglossia at luatex@load at lang{#1} }
+\cs_new:Nn \xpg_set_hyphenation_patterns:n
+{
+  \sys_if_engine_luatex:T { \__xpg_luatex_load_lang:n {#1} }
   \language=\csname l@#1\endcsname
 }
 
-\newcommand*\@select at language[2][]{
+\cs_new:Nn \__xpg_start_language:nn
+{
    % hook for compatibility with biblatex
-   \select at language{#2}
-   \xpg at set@bbl at hyphendata{\the\language}
+   \select at language { #2 }
+   \xpg_set_bbl_hyphendata:n {\the\language}
    \xpg_initial_setup:
-   \select@@language[#1]{#2}%
+   \xpg_select_language:nn { #1 } { #2 }
    % Hook for external packages such as biblatex
-   \polyglossia at language@switched%
-   \__xpg_lang_set_par_direction:n{#2}
-   \csuse{captions#2}%
-   \csuse{date#2}%
+   \polyglossia at language@switched
+   \__xpg_lang_set_par_direction:n {#2}
+   \use:c {captions#2}
+   \use:c {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}
-   \__xpg_local_marks:n{#2}
-   \csuse{init at extras@#2}%
+   \cs_if_exist_use:c {captions at bbl@\babelname}
+   \cs_if_exist_use:c {date at bbl@\babelname}
+   \__xpg_local_marks:n {#2}
+   \use:c {init at extras@#2}
    \__xpg_indent_first:n { #2 }
-   \csuse{blockextras@#2}%
+   \cs_if_exist_use:c {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}
- }
+   \cs_if_exist_use:c {blockextras at bbl@\babelname}
+}
 
 % hook for compatibility with biblatex
 % (probably no longer used due to the
 %  more general hook that follows, but
 %  we keep it for backwards comp.)
-\def\select at language#1{}
+\cs_set:Npn \select at language #1 {}
 
 % Hook for external packages such as biblatex
 % do not rename!
-\def\polyglossia at language@switched{}
+\cs_new:Npn \polyglossia at language@switched {}
 
-% remove all custumization for language #1
+% remove all customization for language #1
 \cs_new:Npn \noextrascurrent #1
-{%
+{
   \cs_if_exist_use:c{noextras@#1}%
   % This is a hook for external packages which want to access variants
   % via babelname (such as biblatex)
@@ -6462,7 +6424,8 @@
 }
 
 % Common code for `\select at language' and `\foreignlanguage'.
-\newcommand{\select@@language}[2][]{%
+\cs_new:Nn \xpg_select_language:nn
+{
   % disable the extras and number settings of the previous language
   \cs_if_exist:cT{languagename}
   {
@@ -6469,153 +6432,97 @@
     \noextrascurrent{\languagename}
     \cs_if_exist_use:c{no\languagename @numbers}
     \sys_if_engine_xetex:T{
-      \__xpg_if_LR_str:eTF{\prop_item:Ne{\g_xpg_langsetup_prop}{\languagename/direction}}
+      \__xpg_if_LR_str:eTF{\prop_item:Ne{\l_xpg_langsetup_prop}{\languagename/direction}}
       {
-        \__xpg_if_LR_str:eF{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/direction}}
+        \__xpg_if_LR_str:eF{\prop_item:Nn{\l_xpg_langsetup_prop}{#2/direction}}
           {\setnonlatin} % LTR -> RTL
       }
       {
-        \__xpg_if_LR_str:eT{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/direction}}
+        \__xpg_if_LR_str:eT{\prop_item:Nn{\l_xpg_langsetup_prop}{#2/direction}}
           {\setlatin} % RTL -> LTR
       }
     }
   }
-  \polyglossia at set@language at name[#1]{#2}
-  % Set the language's/script's font families
-  \str_if_eq:eeT{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/lcscript}} {latin}
-  {
-    \resetfontlatin
-  }
-  \bool_if:NF \l__xpg_inline_lang_bool
-  { % This for non-inline font switches
-    % in case a \<lang>font is defined
-    \xpg at set@normalfont{#2}
-  }
-  \xpg at select@fontfamily{#2}
+  \xpg_set_language_name:n { #2 }
+  \xpg_set_normalfont:n { #2 }
+  \xpg_select_fontfamily:n { #2 }
   \__xpg_use_or_warn:c{#2 at language}
   \cs_if_exist_use:c{#2 at numbers}
-  \use at localhyphenmins[#1]{#2}
+  \__xpg_use_localhyphenmins:nn { #1 } { #2 }
   \__xpg_french_spacing:n { #2 }
 }
 
 
-\let\xpg at pop@language\relax
+\cs_undefine:N \xpg_pop_language:
 
-%
-% Keep track of the active (nested) languages and options
-%
-\clist_new:N \l_xpg_lang_stack
+\DeclareDocumentEnvironment { otherlanguage } { O{} m }
+  {
+    \selectlanguage[#1]{#2}
+  } { }
 
-\cs_new:Nn \__xpg_stack_language:nn
-{
-  \clist_gpush:Nn \l_xpg_lang_stack {#1:#2}
-}
+% Alias to {<lang>}, but more suitable
+% for specific (esp. tag-based) aliases
+% where {<alias>} would cause clashes
+% (e.g., \fi)
+\DeclareEnvironmentCopy { lang } { otherlanguage }
 
-\cs_generate_variant:Nn \__xpg_stack_language:nn {nx}
-
-\cs_new:Nn \__xpg_unstack_language:n
+\NewDocumentCommand \setlocalhyphenmins { m m m }
 {
-  \clist_gpop:NNTF \l_xpg_lang_stack \l_tmpa_tl {
-     % Stored format = options:language => split:
-     \seq_set_split:Nne \l_tmpa_seq {:} \l_tmpa_tl
-     \seq_get_left:NN \l_tmpa_seq \l_tmpb_tl
-     \seq_get_right:NN \l_tmpa_seq \l_tmpc_tl
-     % Execute passed command with language and maybe options
-     % and re-set stored language's keys
-     \tl_if_empty:NTF \l_tmpb_tl {\cs_if_exist_use:c{#1}{\l_tmpc_tl}}
-                                 {\__xpg_set_keys:nn{\l_tmpc_tl}{\l_tmpb_tl}
-                                  \cs_if_exist_use:c{#1}[\l_tmpb_tl]{\l_tmpc_tl}
-                                 }
-  }
-  {}
-}
-
-\DeclareDocumentEnvironment { otherlanguage } { O{} m }
-  {
-    % Get real current (pre-switch) options (incl. defaults)
-    \clist_clear_new:N \l_xpg_current_options
-    \prop_if_exist:cF { xpg at current@options@\languagename }
-	{ \prop_new:c {xpg at current@options@\languagename} }
-    \prop_map_inline:cn {xpg at current@options@\languagename}
+   \xpg_if_language_defined:nTF{#1}
+   {
+      \cs_if_eq:ccTF { l@#1 } { l at nohyphenation }
       {
-        \clist_put_right:Nn \l_xpg_current_options {##1=##2}
+        \xpg_warning_msg:n {\string\setlocalhyphenmin\space~ useless~ for~ unhyphenated~ language~ #1}
+      }{
+        \providehyphenmins{#1}{#2#3}
       }
-    % Store current (pre-switch) options and language on stack
-    \__xpg_stack_language:nx{\clist_use:Nn \l_xpg_current_options {,}}{\languagename}
-    \selectlanguage[#1]{#2}
-  }
-  {
-    % restore previous language in aux file and remove closed one from stack
-    \__xpg_unstack_language:n{xpg at set@language at only@aux}
-  }
-
-\newcommand{\setlocalhyphenmins}[3]{
-   \xpg at ifdefined{#1}{
-      \expandafter\ifx\csname l@#1\endcsname\l at nohyphenation
-        \xpg at warning{\string\setlocalhyphenmin\space~ useless~ for~ unhyphenated~ language~ #1}
-      \else
-      \providehyphenmins{#1}{#2#3}
-      \fi
    }{
-     \xpg at warning{\string\setlocalhyphenmin\space~ useless~ for~ unknown~ language~ #1}
+     \xpg_warning_msg:n {\string\setlocalhyphenmin\space~ useless~ for~ unknown~ language~ #1}
    }
 }
 
 % \setlanghyphenmins[options]{lang}{l}{r}
-\newcommand*\setlanghyphenmins[4][]{%
+\NewDocumentCommand \setlanghyphenmins { O{} m m m }
+{
   % Check for real language name and options
-  \edef\xpg at tmp@opts{\xpg_alias_add_to_option_i:nn{#2}{#1}}
-  \edef\xpg at tmp@lang{\xpg_alias_base_lang:n{#2}}
-  \bgroup
-  \xpg_error_if_lang_not_loaded:n{\xpg at tmp@lang}
-  \__xpg_set_keys:nn{\xpg at tmp@lang}{\xpg at tmp@opts}
+  \tl_set:Nx \l_tmp_opts_tl { \xpg_alias_add_to_option_i:nn{#2}{#1} }
+  \tl_set:Nx \l_tmp_lang_tl { \xpg_alias_base_lang:n{#2} }
+  \c_group_begin_token
+  \xpg_error_if_lang_not_loaded:n{\l_tmp_lang_tl}
+  \SetGlossOptions{\l_tmp_lang_tl}{ \l_tmp_opts_tl }
   % Store bcp47.tag at hypenmins
-  \tl_if_blank:nTF {\xpg at tmp@opts}{%
-    \ifcsundef{\csname xpg at tmp@lang\endcsname @g.bcp47.tag}{
-       \csedef{tmp at bcp47.tag}{\prop_item:Ne{\g_xpg_langsetup_prop}{ \xpg at tmp@lang / bcp47 }}
-    }{
-       \csedef{tmp at bcp47.tag}{\csuse{#2 at g.bcp47.tag}}
-    }
-  }{
-    \csedef{tmp at bcp47.tag}{\prop_item:Ne{\g_xpg_langsetup_prop}{ \xpg at tmp@lang / bcp47 }}
-  }
-  \csgdef{\csname tmp at bcp47.tag\endcsname @hyphenmins}{{#3}{#4}}
-  \egroup
+  \cs_set_nopar:cpe {tmp at bcp47.tag} { \prop_item:Ne{\l_xpg_langsetup_prop}{ \l_tmp_lang_tl / bcp47 } }
+  \cs_gset:cpn {\csname tmp at bcp47.tag\endcsname @hyphenmins} {{#3}{#4}}
+  \c_group_end_token
 }
 
-% \use at localhypenmins[options]{lang}
-\newcommand*\use at localhyphenmins[2][]{
-  \bgroup
-  \xpg_error_if_lang_not_loaded:n{#2}
-  \__xpg_set_keys:nn{#2}{#1}
+% \__xpg_use_localhyphenmins:nn {options}{lang}
+\cs_new_nopar:Nn \__xpg_use_localhyphenmins:nn
+{
+  \c_group_begin_token
+  \xpg_error_if_lang_not_loaded:n {#2}
+  \SetGlossOptions {#2} {#1}
   % Use bcp47.tag at hypenmins
-  \tl_if_blank:nTF {#1}{
-    \ifcsundef{#2 at g.bcp47.tag}{
-       \csxdef{tmp at bcp47.tag}{\prop_item:Nn{\g_xpg_langsetup_prop}{ #2 / bcp47 }}
-    }{
-       \csxdef{tmp at bcp47.tag}{\csuse{#2 at g.bcp47.tag}}
-    }
-  }{
-    \csxdef{tmp at bcp47.tag}{\prop_item:Nn{\g_xpg_langsetup_prop}{ #2 / bcp47 }}
-  }
-  \egroup
-  \ifcsundef{\csname tmp at bcp47.tag\endcsname @hyphenmins}{
-     \ifcsundef{#2hyphenmins}{}
+  \cs_gset_nopar:cpe {tmp at bcp47.tag} { \prop_item:Nn{\l_xpg_langsetup_prop}{ #2 / bcp47 } }
+  \c_group_end_token
+  \cs_if_exist:cTF {\csname tmp at bcp47.tag\endcsname @hyphenmins}
+   {
+      \tl_set:Ne \l_tmpa_tl { \use:c{\csname tmp at bcp47.tag\endcsname @hyphenmins} }
+      \expandafter \set at hyphenmins \l_tmpa_tl
+   }{
+     \cs_if_exist:cT{#2hyphenmins}
         {
           \expandafter\expandafter\expandafter\set at hyphenmins\csname #2hyphenmins\endcsname\relax
         }
-   }{
-      \edef\tmpa{\csuse{\csname tmp at bcp47.tag\endcsname @hyphenmins}}
-      \expandafter\expandafter\expandafter\set at hyphenmins\tmpa\relax
    }
-   \sys_if_engine_luatex:T{
+   \sys_if_engine_luatex:T
+   {
      % Set \totalhyphenmin if specified
-     \prop_get:NeNTF \g_xpg_langsetup_prop {#2/totalhyphenmin} \l_tmpa_tl
+     \prop_get:NeNT \l_xpg_langsetup_prop {#2/totalhyphenmin} \l_tmpb_tl
      {
-        \xpg at info{totalhyphenmin: '\l_tmpa_tl'}
-        \expandafter\hyphenationmin \l_tmpa_tl
+        \xpg_info_msg:n {totalhyphenmin: '\l_tmpb_tl'}
+        \expandafter\hyphenationmin \l_tmpb_tl
      }
-     {}
    }
 }
 
@@ -6627,23 +6534,26 @@
 \DeclareDocumentEnvironment { hyphenrules } { O{} m }
   {
     % Check for real language name and options
-    \edef\xpg at tmp@opts{\xpg_alias_add_to_option_i:nn{#2}{#1}}
-    \edef\xpg at tmp@lang{\xpg_alias_base_lang:n{#2}}
+    \tl_set:Nx \l_tmp_opts_tl { \xpg_alias_add_to_option_i:nn{#2}{#1} }
+    \tl_set:Nx \l_tmp_lang_tl { \xpg_alias_base_lang:n{#2} }
     % Register the language options
-    \__xpg_set_language_options:nnn {\xpg at tmp@lang} {\xpg at tmp@opts} {@xpg at set@langvariant}
+    \__xpg_set_language_options:nn { \l_tmp_lang_tl } { \l_tmp_opts_tl }
     % Now switch patterns
-    \__xpg_use_or_warn:c{\use:c{xpg at tmp@lang}@language}
+    \__xpg_use_or_warn:c{\use:c{l_tmp_lang_tl}@language}
     % And activate hyphenmins
-    \use at localhyphenmins[\xpg at tmp@opts]{\xpg at tmp@lang}
+    \__xpg_use_localhyphenmins:nn { \l_tmp_opts_tl } { \l_tmp_lang_tl }
   }
   { }
 
-\AddToHook{begindocument/before}{
-   \IfPackageLoadedTF{bidi}{
-      \providecommand*{\aemph}[1]{$\overline{\hboxR{#1}}$}
+\hook_gput_code:nnn {begindocument/before} {.}
+{
+   \IfPackageLoadedTF{bidi}
+   {
+      \ProvideDocumentCommand \aemph { m } { $\overline{\hboxR{#1}}$ }
    }{}
-   \IfPackageLoadedTF{luabidi}{
-      \providecommand*{\aemph}[1]{$\overline{\hbox{\RL{#1}}}$}
+   \IfPackageLoadedTF{luabidi}
+   {
+      \ProvideDocumentCommand \aemph { m } { $\overline{\hbox{\RL{#1}}}$ }
    }{}
 }
 
@@ -6677,7 +6587,8 @@
      .value_required:n = true,
 }
 
-\keys_set:nn { polyglossia } {
+\keys_set:nn { polyglossia }
+{
   localmarks = false,
   verbose = true,
   babelshorthands = false,
@@ -6694,17 +6605,18 @@
 \sys_if_engine_luatex:T{
   \str_if_eq:eeF{\g_xpg_luatex_renderer_str}{none}
   {
-    \xpg at info{Setting~ LuaTeX~ font~ renderer~ to~ \g_xpg_luatex_renderer_str}
+    \xpg_info_msg:n{Setting~ LuaTeX~ font~ renderer~ to~ \g_xpg_luatex_renderer_str}
     \exp_args:Ne \defaultfontfeatures{Renderer=\g_xpg_luatex_renderer_str}
   }
 }
 
-\bool_if:nF \g_xpg_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
+\bool_if:nF \g_xpg_verbose_bool
+{
+   \cs_gset_nopar:Npn \@latex at info #1 { \relax } % no latex info
+   \cs_gset_nopar:Npn \@font at info #1 { \relax } % no latex font info
+   \cs_gset_nopar:Npn \@font at warning #1 { \relax } % no latex font warnings
+   \msg_redirect_module:nnn { fontspec } { info } { none } % no fontspec info
+   \msg_redirect_module:nnn { polyglossia } { info } { none } % no polyglossia info
 }
 
 \bool_if:nT \g_xpg_localmarks_bool {
@@ -6711,6 +6623,17 @@
   \__xpg_enable_local_marks:
 }
 
+% common code to initiate babelshordhands in glosses
+\cs_new:Npn \InitializeBabelShorthands
+{
+  \cs_if_exist:cF {initiate at active@char}
+  {
+    \file_input:n {babelsh.def}
+    \initiate at active@char{"}
+    \shorthandoff{"}
+  }
+}
+
 % Control shorthand (de-)activation
 % This checks that the shorthand char is only deactivated
 % if we have activated it ourselves and hence keeps
@@ -6738,7 +6661,8 @@
 % Inherit shorthands in other languages
 \NewDocumentCommand \inheritbabelshorthands { m m }
 {
-   \AddToHook{begindocument/before}{
+   \hook_gput_code:nnn {begindocument/before} {.}
+   {
        % Load the involved languages if necessary
        % Error if they do not exist
        \tl_set:Nn \l__xpg_tmpa_lang_tl { \xpg_alias_base_lang:n{#1} }
@@ -6745,7 +6669,7 @@
        \clist_if_in:NeF \xpg at loaded {\l__xpg_tmpa_lang_tl}{
            \file_if_exist:nTF{gloss-\l__xpg_tmpa_lang_tl .ldf}
               { \setotherlanguage{#1} }
-              { \xpg at error{ Source~ language~ #1,~ used~ in~
+              { \xpg_error_msg:n { Source~ language~ #1,~ used~ in~
                             \string\inheritbabelshorthands,~ does~ not~ exist } }
        }
        \tl_set:Nn \l__xpg_tmpb_lang_tl { \xpg_alias_base_lang:n{#2} }
@@ -6752,7 +6676,7 @@
        \clist_if_in:NeF \xpg at loaded {\l__xpg_tmpb_lang_tl}{
            \file_if_exist:nTF{gloss-\l__xpg_tmpb_lang_tl .ldf}
               { \setotherlanguage{#2} }
-              { \xpg at error{ Target~ language~ #2,~ used~ in~
+              { \xpg_error_msg:n { Target~ language~ #2,~ used~ in~
                             \string\inheritbabelshorthands,~ does~ not~ exist } }
        }
        % Test whether the requested shorthands exist
@@ -6764,7 +6688,7 @@
                        { \bool_set_true:N \l__xpg_no_shorthands_bool }
        \bool_if:nT { \l__xpg_no_shorthands_bool }
                    {
-                      \xpg at error{ No~ babel~ shorthands~ exist~ for~ language~ #1 }
+                      \xpg_error_msg:n { No~ babel~ shorthands~ exist~ for~ language~ #1 }
                    }
        % If so, apply:
        \bool_if:nF { \l__xpg_no_shorthands_bool }
@@ -6789,7 +6713,7 @@
        \iflanguageloaded{\l__xpg_tmpa_lang_tl}{
            \use:c{\l__xpg_tmpa_lang_tl @shorthands}
        }{
-           \xpg at error{ Language~ #1,~ requested~ in~
+           \xpg_error_msg:n { Language~ #1,~ requested~ in~
                        \string\startbabelshorthands,~ is~ not~ loaded }
        }
     }
@@ -7090,7 +7014,7 @@
        \ifnum#1<5000
          \Hebrewnumeral{#1}%
        \else
-         \ifnum#1<6000 % current millenium, print without thousands
+         \ifnum#1<6000 % current millennium, print without thousands
            \@tempcnta=#1\relax
            \if at xpg@hebrew at fullyear\else\advance\@tempcnta by -5000\fi
            \Hebrewnumeral{\@tempcnta}%
@@ -7419,7 +7343,7 @@
 \@ifundefined{@Remainder}{\input{cal-util.def}}{}
 
 %% The following functions are straightforward implementation 
-%% of Reingold & Dershowitz, Calendrical Calculations, The Millenium Edition
+%% of Reingold & Dershowitz, Calendrical Calculations, The Millennium Edition
 %%
 
 \def\@FixedFromHijri#1#2#3#4{% year,month,day,counter
@@ -7494,96 +7418,33 @@
 %    \end{macrocode}
 % \iffalse
 %</hijrical.sty>
-%<*polyglossia-french.lua>
+%<*polyglossia-cjk-spacing.lua>
 % \fi
 % \clearpage
 % 
-% \subsection{polyglossia-french.lua}
+% \subsection{polyglossia-cjk-spacing.lua}
 %    \begin{macrocode}
 --
--- polyglossia-punct.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- polyglossia-cjk-spacing.lua
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
-require('polyglossia-punct')
-
-local function set_left_space(lang, char, kern, rubber)
-    polyglossia.add_left_spaced_character(lang, char, kern, "space", rubber)
-end
-
-local function set_right_space(lang, char, kern, rubber)
-    polyglossia.add_right_spaced_character(lang, char, kern, "space", rubber)
-end
-
-local function activate_french_punct(thincolonspace, autospaceguillemets)
-    -- We need different language tags here to make switching of options possible
-    -- within a paragraph.
-    local lang = "french"
-    if thincolonspace then
-        lang = lang.."-thincolon"
-    end
-    if autospaceguillemets then
-        lang = lang.."-autospace"
-    end
-
-    polyglossia.activate_punct(lang)
-    polyglossia.clear_spaced_characters(lang)
-
-    if thincolonspace then
-        set_left_space(lang, ':', 0.5)
-    else
-        set_left_space(lang, ':', 1, true) -- stretchable and shrinkable space
-    end
-
-    set_left_space(lang, '!', 0.5)
-    set_left_space(lang, '?', 0.5)
-    set_left_space(lang, ';', 0.5)
-    set_left_space(lang, '‼', 0.5)
-    set_left_space(lang, '⁇', 0.5)
-    set_left_space(lang, '⁈', 0.5)
-    set_left_space(lang, '⁉', 0.5)
-    set_left_space(lang, '‽', 0.5) -- U+203D (interrobang)
-
-    if autospaceguillemets then
-        set_left_space(lang, '»', 0.5)
-        set_left_space(lang, '›', 0.5)
-        set_right_space(lang, '«', 0.5)
-        set_right_space(lang, '‹', 0.5)
-    end
-end
-
-local function deactivate_french_punct()
-    polyglossia.deactivate_punct()
-end
-
-polyglossia.activate_french_punct   = activate_french_punct
-polyglossia.deactivate_french_punct = deactivate_french_punct
-%    \end{macrocode}
-% \iffalse
-%</polyglossia-french.lua>
-%<*polyglossia-korean.lua>
-% \fi
-% \clearpage
-% 
-% \subsection{polyglossia-korean.lua}
-%    \begin{macrocode}
---
--- polyglossia-korean.lua
--- part of polyglossia v2.1 -- 2024/03/07
---
-
 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 whatsit_id = node.id"whatsit"
+local math_id  = node.id"math"
 
 --
--- attr_korean: variant = plain (0), classic (1), modern (2)
+-- attr_cjk: variant = plain: 0, JP/classic: 1, KR/modern: 2, SC: 3, TC: 4
 --
-local attr_korean = luatexbase.attributes["xpg at attr@korean"]
-local attr_josa   = luatexbase.attributes["xpg at attr@autojosa"]
+local attr_cjk = luatexbase.attributes["xpg at attr@cjkspacing"]
+--
+-- attr_josa: ONLY For Korean. DO NOT declare \newattribute for other langs
+--
+local attr_josa = luatexbase.attributes["xpg at attr@autojosa"]
 
 --
 -- characters after which linebreak is not allowed
@@ -7632,9 +7493,9 @@
 -- characters before which linebreak is not allowed
 --   (currently, not much differences among the followings)
 --   1: normal chars
---   2: hangul jamo vowels and trailing consonants
+--   2: hangul jamo vowels and trailing consonants plus combinings
 --   3: kana small letters
---   0: dashes (supress visible spacing)
+--   0: dashes (suppress visible spacing after this char)
 --
 local nobr_before = setmetatable({
     [0x21] = 1, -- ! EXCLAMATION MARK
@@ -7645,7 +7506,7 @@
     [0x2D] = 0, -- - HYPHEN-MINUS
     [0x2E] = 1, -- . FULL STOP
     [0x2F] = 0, -- / SOLIDUS
-    [0x3A] = 0, -- : COLON
+    [0x3A] = 1, -- : COLON
     [0x3B] = 1, -- ; SEMICOLON
     [0x3E] = 1, -- > GREATER-THAN SIGN
     [0x3F] = 1, -- ? QUESTION MARK
@@ -7657,11 +7518,11 @@
     [0xBB] = 1, -- » RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
     [0x2013] = 0, -- – EN DASH
     [0x2014] = 0, -- — EM DASH
-    [0x2015] = 1, -- ― HORIZONTAL BAR
+    [0x2015] = 0, -- ― HORIZONTAL BAR
     [0x2019] = 1, -- ’ RIGHT SINGLE QUOTATION MARK
     [0x201D] = 1, -- ” RIGHT DOUBLE QUOTATION MARK
-    [0x2025] = 1, -- ‥ TWO DOT LEADER
-    [0x2026] = 1, -- … HORIZONTAL ELLIPSIS
+    [0x2025] = 0, -- ‥ TWO DOT LEADER
+    [0x2026] = 0, -- … HORIZONTAL ELLIPSIS
     [0x232A] = 1, -- 〉 RIGHT-POINTING ANGLE BRACKET
     [0x3001] = 1, -- 、 IDEOGRAPHIC COMMA
     [0x3002] = 1, -- 。 IDEOGRAPHIC FULL STOP
@@ -7693,10 +7554,10 @@
     [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
+    [0x3099] = 2, --  COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
+    [0x309A] = 2, --  COMBINING KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
+    [0x309B] = 2, -- ゛ KATAKANA-HIRAGANA VOICED SOUND MARK
+    [0x309C] = 2, -- ゜ KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
     [0x309D] = 1, -- ゝ HIRAGANA ITERATION MARK
     [0x309E] = 1, -- ゞ HIRAGANA VOICED ITERATION MARK
     [0x30A0] = 1, -- ゠ KATAKANA-HIRAGANA DOUBLE HYPHEN
@@ -7716,9 +7577,9 @@
     [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
+    [0xFE30] = 0, -- ︰ PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
+    [0xFE31] = 0, -- ︱ PRESENTATION FORM FOR VERTICAL EM DASH
+    [0xFE32] = 0, -- ︲ 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
@@ -7745,18 +7606,18 @@
     [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
+    [0xFF9E] = 2, -- ゙ HALFWIDTH KATAKANA VOICED SOUND MARK
+    [0xFF9F] = 2, -- ゚ 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 >= 0x302A  and c <= 0x302F  then return 2 end -- tone marks
         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 >= 0xFE00  and c <= 0xFE0F  then return 2 end -- variation selectors
         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
+        if c >= 0xE0100 and c <= 0xE01EF then return 2 end -- variation selecters
     end
 })
 
@@ -7774,6 +7635,7 @@
     or     c >= 0xFF00  and c <= 0xFFEF
     or     c >= 0x1F100 and c <= 0x1F2FF
     or     c >= 0x20000 and c <= 0x2FA1F
+    or     c >= 0x30000 and c <= 0x323AF
     or     nobr_after[c]  and c > 0x2014
     or     nobr_before[c] and c > 0x2014
 end
@@ -7813,8 +7675,28 @@
 }, { __index = function() return 0 end })
 
 --
+-- get character class
+--      var : variant = plain, JP/classic, KR/modern, SC, TC
+--      c   : codepoint
+--
+local function get_charclass (var, c)
+    if var < 3 then
+        return charclass[c]
+    elseif var == 3 then
+        -- SC : these are left aligned
+        return (c == 0xFF01 or c == 0xFF1F) and 4 -- FULLWIDTH EXCLAMATION/QUESTION MARK
+        or     (c == 0xFF1A or c == 0xFF1B) and 2 -- FULLWIDTH COLON/SEMICOLON
+        or     charclass[c]
+    end
+    -- TC : these are center aligned
+    return (c == 0x3001 or c == 0xFF0C) and 3 -- IDEOGRAPHIC/FULLWIDTH COMMA
+    or     (c == 0x3002 or c == 0xFF0E) and 3 -- IDEOGRAPHIC/FULLWIDTH FULL STOP -- 5 ?
+    or     charclass[c]
+end
+
+--
 -- table for spacing between char classes
---   1 stands for 0.5*fontsize when variant=classic
+--   1 stands for 0.5*fontsize when variant = JP/classic or SC or TC
 --
 local intercharclass = { [0] =
     { [0] = nil,    {1,1},  nil,    {.5,.5} },
@@ -7846,7 +7728,7 @@
 
 --
 -- return 0.5*fontsize of given fontid
---   space: true if variant=modern; then 0.5*interword_space
+--   space: true if variant=KR/modern; then 0.5*interword_space
 --
 local function get_font_size (fid, space)
     local size = font.getparameters(fid)
@@ -7860,7 +7742,7 @@
 
 --
 -- charclass 1 thru 4 will be packed in \hbox to 0.5em{\hss? curr \hss?}
---   when variant=classic/modern
+--   when variant ~= plain
 --
 local function glyph_to_box (head, curr, class)
     local g, h = curr
@@ -7889,7 +7771,7 @@
 --
 -- insert spacing defined as charclass[a][b] between a and b
 --   f:    fontid
---   var:  variant = plain, classic, modern
+--   var:  variant = plain, JP/classic, KR/modern, SC, TC
 --   cc:   charclass of current char
 --   nc:   charclass of next char
 --   nobr: linebreak is not allowed
@@ -7908,12 +7790,16 @@
 
 --
 -- 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)
+--   f:    fontid
+--   var:  variant = plain, JP/classic, KR/modern, SC, TC
+--   nobr: no linebreak
+--   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 function insert_penalty_glue (head, curr, f, var, nobr, x)
+    if nobr then
+        local penalty = get_new_penalty(10000)
+        head, curr = node.insert_after(head, curr, penalty)
+    elseif var == 0 or var == 2 then
         local penalty = get_new_penalty(50)
         head, curr = node.insert_after(head, curr, penalty)
     end
@@ -7929,16 +7815,15 @@
 
 --
 -- main process for linebreak and inter-character spacing
---   lb: true if pre_linebreak_filter
 --
-local function korean_break (head, lb)
+local function cjk_break (head)
     local curr = head
     while curr do
-        if curr.id == glyph_id then
-            local var = node.has_attribute(curr, attr_korean)
+        if attr_cjk and (curr.id == glyph_id or curr.id == math_id and curr.subtype == 1) then
+            local var = node.has_attribute(curr, attr_cjk)
             if var then
-                local c, f = curr.char or 0, curr.font or 0
-                local cc, cjkc = charclass[c], is_cjk(c)
+                local c, f = curr.char or 0, curr.font
+                local cc, cjkc = get_charclass(var, c), is_cjk(c)
 
                 -- compress cjk punctuations when charclass is 1 thru 4
                 if var > 0 and cc > 0 and cc < 5 then
@@ -7945,10 +7830,21 @@
                     head, curr = glyph_to_box(head, curr, cc)
                 end
 
-                local next = curr.next
-                if next and next.id == glyph_id then
+                local next = node.getnext(curr)
+                while next and next.id == whatsit_id do -- skip whatsit nodes
+                    curr, next = next, node.getnext(next)
+                end
+
+                if next and (next.id == glyph_id or next.id == math_id and next.subtype == 0) then
                     local n = next.char or 0
-                    local nc = charclass[n]
+                    f = f or next.font or 0 -- in case of curr == math_off
+
+                    -- skip combining. or dash+dash case to suppress stretching
+                    if nobr_before[n] == 2 or (nobr_before[c] == 0 and nobr_before[n] == 0) then
+                        goto skip_combining
+                    end
+
+                    local nc = get_charclass(var, n)
                     local nobr = nobr_before[n] or nobr_after[c]
 
                     -- insert spacing as of intercharclass
@@ -7955,20 +7851,20 @@
                     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
+                    else
                         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)
+                            -- plain variant / cjk+cjk / nobr cjk+noncjk / after dash
+                            --      : insert a 0pt glue
+                            if var == 0 or (cjkc and cjkn) or nobr or nobr_before[c] == 0 then
+                                head, curr = insert_penalty_glue(head, curr, f, var, nobr)
 
-                            -- or under pre_linebreak_filter
-                            elseif lb then
-                                head, curr = insert_penalty_glue(head, curr, f, var)
+                            -- other cases: insert a small glue
+                            else
+                                head, curr = insert_penalty_glue(head, curr, f, var, nobr, true)
                             end
                         end
                     end
@@ -7975,7 +7871,8 @@
                 end
             end
         end
-        curr = curr.next
+        ::skip_combining::
+        curr = node.getnext(curr)
     end
     return head
 end
@@ -7989,7 +7886,7 @@
 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
+        if curr.id == glyph_id and node.has_attribute(curr, attr_cjk) then
             local f = font.getfont(curr.font) or font.fonts[curr.font]
             if f and f.hb then -- harfbuzz do the right thing
                 tone = nil
@@ -8005,7 +7902,7 @@
                 end
             end
         end
-        curr = curr.prev
+        curr = node.getprev(curr)
     end
     return head
 end
@@ -8092,7 +7989,7 @@
             local pc = get_prev_char(node.slide(p.head))
             if pc then return pc end
         end
-        p = p.prev
+        p = node.getprev(p)
     end
 end
 
@@ -8107,10 +8004,10 @@
             if josa then
                 local cc = curr.char or 0
                 if josa == 0 then
-                    josa = josa_code[get_prev_char(curr.prev) or 0x30]
+                    josa = josa_code[get_prev_char(node.getprev(curr)) or 0x30]
                 end
                 if cc == 0xC774 then
-                    local n = curr.next
+                    local n = node.getnext(curr)
                     if n and n.char and n.char >= 0xAC00 and n.char <= 0xD7A3 then
                     else
                         cc = 0xAC00
@@ -8129,7 +8026,7 @@
                 node.unset_attribute(curr, attr_josa)
             end
         end
-        curr = curr.next
+        curr = node.getnext(curr)
     end
     for _,v in ipairs(tofree) do node.free(v) end
     return head
@@ -8140,45 +8037,86 @@
 --   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)
+luatexbase.add_to_callback( "pre_shaping_filter",
+function(head)
+    if attr_josa then head = auto_josa(head) end
+    head = cjk_break(head)
+    if attr_josa then head = reorder_tm(head) end
+    return head
+end,
+"polyglossia.lang_cjk_spacing")
+
+-- vim:ft=lua:tw=0:sw=4:ts=4:expandtab
+%    \end{macrocode}
+% \iffalse
+%</polyglossia-cjk-spacing.lua>
+%<*polyglossia-french.lua>
+% \fi
+% \clearpage
+% 
+% \subsection{polyglossia-french.lua}
+%    \begin{macrocode}
+--
+-- polyglossia-punct.lua
+-- part of polyglossia v2.2 -- 2024/07/15
+--
+
+require('polyglossia-punct')
+
+local function set_left_space(lang, char, kern, rubber)
+    polyglossia.add_left_spaced_character(lang, char, kern, "space", rubber)
+end
+
+local function set_right_space(lang, char, kern, rubber)
+    polyglossia.add_right_spaced_character(lang, char, kern, "space", rubber)
+end
+
+local function activate_french_punct(thincolonspace, autospaceguillemets)
+    -- We need different language tags here to make switching of options possible
+    -- within a paragraph.
+    local lang = "french"
+    if thincolonspace then
+        lang = lang.."-thincolon"
     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
+    if autospaceguillemets then
+        lang = lang.."-autospace"
     end
+
+    polyglossia.activate_punct(lang)
+    polyglossia.clear_spaced_characters(lang)
+
+    if thincolonspace then
+        set_left_space(lang, ':', 0.5)
+    else
+        set_left_space(lang, ':', 1, true) -- stretchable and shrinkable space
+    end
+
+    set_left_space(lang, '!', 0.5)
+    set_left_space(lang, '?', 0.5)
+    set_left_space(lang, ';', 0.5)
+    set_left_space(lang, '‼', 0.5)
+    set_left_space(lang, '⁇', 0.5)
+    set_left_space(lang, '⁈', 0.5)
+    set_left_space(lang, '⁉', 0.5)
+    set_left_space(lang, '‽', 0.5) -- U+203D (interrobang)
+
+    if autospaceguillemets then
+        set_left_space(lang, '»', 0.5)
+        set_left_space(lang, '›', 0.5)
+        set_right_space(lang, '«', 0.5)
+        set_right_space(lang, '‹', 0.5)
+    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")
+local function deactivate_french_punct()
+    polyglossia.deactivate_punct()
+end
 
-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
+polyglossia.activate_french_punct   = activate_french_punct
+polyglossia.deactivate_french_punct = deactivate_french_punct
 %    \end{macrocode}
 % \iffalse
-%</polyglossia-korean.lua>
+%</polyglossia-french.lua>
 %<*polyglossia-latin.lua>
 % \fi
 % \clearpage
@@ -8187,7 +8125,7 @@
 %    \begin{macrocode}
 --
 -- polyglossia-latin.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia-punct')
@@ -8242,14 +8180,13 @@
 %    \begin{macrocode}
 --
 -- polyglossia-punct.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia') -- just in case...
 
 local add_to_callback      = luatexbase.add_to_callback
-local remove_from_callback = luatexbase.remove_from_callback
-local priority_in_callback = luatexbase.priority_in_callback
+local declare_callback_rule = luatexbase.declare_callback_rule
 local new_attribute        = luatexbase.new_attribute
 
 local node = node
@@ -8573,13 +8510,16 @@
     -- important to be able to intermix languages with different spacings
     -- in one paragraph.
     tex.setattribute(punct_attr, id)
-    for _, callback_name in ipairs{ "pre_linebreak_filter", "hpack_filter" } do
-        if not priority_in_callback(callback_name, "polyglossia-punct.process") then
-            add_to_callback(callback_name, process, "polyglossia-punct.process", 1)
-        end
-    end
 end
 
+add_to_callback("pre_linebreak_filter",process,"polyglossia-punct.process")
+add_to_callback("hpack_filter",process,"polyglossia-punct.process")
+declare_callback_rule("pre_linebreak_filter",
+    "polyglossia-punct.process", "before", "luaotfload.node_processor")
+declare_callback_rule("hpack_filter",
+    "polyglossia-punct.process", "before", "luaotfload.node_processor")
+
+
 local function deactivate()
     tex.setattribute(punct_attr, -0x7FFFFFFF) -- this value means "unset"
     -- Though it would make compilation slightly faster, it is not possible to
@@ -8610,7 +8550,7 @@
 %    \begin{macrocode}
 --
 -- polyglossia-sanskrit.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia-punct')
@@ -8660,7 +8600,7 @@
 %    \begin{macrocode}
 --
 -- polyglossia-tibt.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia') -- just in case...
@@ -8667,17 +8607,15 @@
 
 local add_to_callback = luatexbase.add_to_callback
 local remove_from_callback = luatexbase.remove_from_callback
+local declare_callback_rule = luatexbase.declare_callback_rule
 local priority_in_callback = luatexbase.priority_in_callback
 
 local next, type = next, type
+local node = node
 
-local nodes, fonts, node = nodes, fonts, node
-
-local nodecodes          = nodes.nodecodes --- <= preloaded node.types()
-
 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 copy_node          = node.copy
 local has_attribute      = node.has_attribute
 
@@ -8684,7 +8622,7 @@
 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 math_code      = node.id('math_char')
   local end_of_math = function (n)
     for n in traverse_nodes(math_code, n.next) do
       return n
@@ -8692,10 +8630,10 @@
   end
 end
 
--- node types as of April 2013
-local glyph_code         = nodecodes.glyph
-local penalty_code       = nodecodes.penalty
-local kern_code          = nodecodes.kern
+-- node types as of April 2024
+local glyph_code         = node.id('glyph')
+local penalty_code       = node.id('penalty')
+local kern_code          = node.id('kern')
 
 -- we make a new node, so that we can copy it later on
 local penalty_node  = node.new(penalty_code)
@@ -8726,7 +8664,6 @@
                 end
             end
         elseif id == math_code then
-            -- warning: this is a feature of luatex > 0.76
             start = end_of_math(start) -- weird, can return nil .. no math end?
         end
         if start then
@@ -8739,15 +8676,13 @@
 local callback_name = "pre_linebreak_filter"
 
 local function activate()
-  if not priority_in_callback (callback_name, "polyglossia-tibt.process") then
-    add_to_callback(callback_name, process, "polyglossia-tibt.process", 1)
-  end
+    add_to_callback(callback_name, process, "polyglossia-tibt.process")
+    declare_callback_rule(callback_name,
+    "polyglossia-tibt.process", "before", "luaotfload.node_processor")
 end
 
 local function desactivate()
-  if priority_in_callback (callback_name, "polyglossia-tibt.process") then
-    remove_from_callback(callback_name, "polyglossia-tibt.process")
-  end
+	remove_from_callback(callback_name, "polyglossia-tibt.process")
 end
 
 polyglossia.activate_tibt_eol    = activate
@@ -8763,7 +8698,7 @@
 %    \begin{macrocode}
 --
 -- polyglossia.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 local module_name = "polyglossia"
@@ -8839,7 +8774,7 @@
             end
 
             -- language info will be written into the .log file
-            local s = { "Language data for " .. langentry }
+            local s = { }
             for k, v in pairs(langdata) do
                 if type(v) == 'table' then -- for 'synonyms'
                     s[#s+1] = k .. "\t" .. table.concat(v,',')
@@ -8847,7 +8782,10 @@
                     s[#s+1] = k .. "\t" .. tostring(v)
                 end
             end
-            log_info(table.concat(s,"\n"))
+            local a = {}
+	    for _,n in pairs(s) do table.insert(a, n) end
+            table.sort(a)
+            log_info("Language data for " .. langentry .. "\n" .. table.concat(a,"\n"))
 
             --
             -- LaTeX's \newlanguage increases language register (count19),
@@ -8857,7 +8795,7 @@
             -- this possible situation, our newloader() function will
             -- unfortunately overwrite the language \lang at xyz.
             --
-            -- Threfore here we will compare LaTeX's \newlanguage number with
+            -- Therefore 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
@@ -8872,7 +8810,7 @@
             local newlangid = math.max(langcnt, langid)
             -- set language register for possible \newlanguage
             tex.setcount('global', lang_register, newlangid)
-            -- get new lang object if needeed
+            -- get new lang object if needed
             if langid ~= newlangid then
                 langobject = lang.new(newlangid)
             end
@@ -9716,7 +9654,7 @@
 
 
 %% This is an algorithm from Reingold & Dershowitz, 
-%% Calendrical Calculations, The Millenium Edition
+%% Calendrical Calculations, The Millennium Edition
 %%
 \def\@FixedFromGregorian#1#2#3#4{%
  \setcounter{tmpA}{(#1-1)*365}%
@@ -10069,23 +10007,23 @@
 %    \end{macrocode}
 % \iffalse
 %</xgreek-fixes.def>
-%<*gloss-acadien.ldf>
+%<*gloss-acadian.ldf>
 % \fi
 % \clearpage
 % 
-% \subsection{gloss-acadien.ldf}
+% \subsection{gloss-acadian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-acadien.ldf}[polyglossia: module for Canadian (Acadian) French]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 %    \end{macrocode}
 % \iffalse
-%</gloss-acadien.ldf>
+%</gloss-acadian.ldf>
 %<*gloss-aeb.ldf>
 % \fi
 % \clearpage
@@ -10092,13 +10030,13 @@
 % 
 % \subsection{gloss-aeb.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-aeb.ldf}[polyglossia: module for aeb (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 %    \end{macrocode}
 % \iffalse
@@ -10109,13 +10047,13 @@
 % 
 % \subsection{gloss-af.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-af.ldf}[polyglossia: module for af (Afrikaans)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{afrikaans}
+\InheritGlossFile{afrikaans}
 
 %    \end{macrocode}
 % \iffalse
@@ -10126,13 +10064,13 @@
 % 
 % \subsection{gloss-afb.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-afb.ldf}[polyglossia: module for afb (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 %    \end{macrocode}
 % \iffalse
@@ -10143,7 +10081,7 @@
 % 
 % \subsection{gloss-afrikaans.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-afrikaans.ldf}[polyglossia: module for Afrikaans]
 
@@ -10161,22 +10099,21 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{afrikaans}{af}
 
-\define at boolkey{afrikaans}[afrikaans@]{babelshorthands}[true]{}
-
+\DeclareKeys[polyglossia/gloss/afrikaans]
+  {
+    babelshorthands.if = afrikaans at babelshorthands,
+    babelshorthands.default:n = true,
+  }
 % Register default options
-\xpg at initialize@gloss at options{afrikaans}{babelshorthands=false}
+\InitializeGlossOptions{afrikaans}{babelshorthands=false}
 
 \ifsystem at babelshorthands
-  \setkeys{afrikaans}{babelshorthands=true}
+  \SetGlossOptions{afrikaans}{babelshorthands=true}
 \else
-  \setkeys{afrikaans}{babelshorthands=false}
+  \SetGlossOptions{afrikaans}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\afrikaans at shorthands{%
   \xpg at activate@shorthands%
@@ -10248,7 +10185,7 @@
 % 
 % \subsection{gloss-albanian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-albanian.ldf}[polyglossia: module for Albanian]
 
@@ -10305,13 +10242,13 @@
 % 
 % \subsection{gloss-am.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-am.ldf}[polyglossia: module for am (Amharic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{amharic}
+\InheritGlossFile{amharic}
 
 %    \end{macrocode}
 % \iffalse
@@ -10322,13 +10259,13 @@
 % 
 % \subsection{gloss-american.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-american.ldf}[polyglossia: module for American English]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 %    \end{macrocode}
 % \iffalse
@@ -10339,7 +10276,7 @@
 % 
 % \subsection{gloss-amharic.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-amharic.ldf}[polyglossia: module for Amharic]
 \PolyglossiaSetup{amharic}{
@@ -10559,13 +10496,13 @@
 % 
 % \subsection{gloss-apd.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-apd.ldf}[polyglossia: module for apd (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 %    \end{macrocode}
 % \iffalse
@@ -10576,13 +10513,13 @@
 % 
 % \subsection{gloss-ar-IQ.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-IQ.ldf}[polyglossia: module for ar-IQ (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-IQ,bcp47-language=ar,bcp47-region=IQ}%
 
@@ -10595,13 +10532,13 @@
 % 
 % \subsection{gloss-ar-JO.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-JO.ldf}[polyglossia: module for ar-JO (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-JO,bcp47-language=ar,bcp47-region=JO}%
 
@@ -10614,13 +10551,13 @@
 % 
 % \subsection{gloss-ar-LB.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-LB.ldf}[polyglossia: module for ar-LB (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-LB,bcp47-language=ar,bcp47-region=LB}%
 
@@ -10633,13 +10570,13 @@
 % 
 % \subsection{gloss-ar-MR.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-MR.ldf}[polyglossia: module for ar-MR (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-MR,bcp47-language=ar,bcp47-region=MR}%
 
@@ -10652,13 +10589,13 @@
 % 
 % \subsection{gloss-ar-PS.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-PS.ldf}[polyglossia: module for ar-PS (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-PS,bcp47-language=ar,bcp47-region=PS}%
 
@@ -10671,13 +10608,13 @@
 % 
 % \subsection{gloss-ar-SY.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-SY.ldf}[polyglossia: module for ar-SY (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-SY,bcp47-language=ar,bcp47-region=SY}%
 
@@ -10690,13 +10627,13 @@
 % 
 % \subsection{gloss-ar-YE.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-YE.ldf}[polyglossia: module for ar-YE (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-YE,bcp47-language=ar,bcp47-region=YE}%
 
@@ -10709,13 +10646,13 @@
 % 
 % \subsection{gloss-ar.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar.ldf}[polyglossia: module for ar (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 %    \end{macrocode}
 % \iffalse
@@ -10726,7 +10663,7 @@
 % 
 % \subsection{gloss-arabic.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-arabic.ldf}[polyglossia: module for Arabic]
 \RequireBidi
@@ -10766,104 +10703,112 @@
 \setlanguagealias*[locale=default]{arabic}{apd}
 \setlanguagealias*[locale=mashriq]{arabic}{ar-PS}
 
-\define at boolkey{arabic}[arabic@]{abjadalph}[true]{}
-
 \newif\ifeastern at numerals
-\define at choicekey*+{arabic}{numerals}[\xpg at val\xpg at nr]{mashriq,maghrib,eastern,western}[mashriq]{%
-   \ifcase\xpg at nr\relax
-      % mashriq:
-      \eastern at numeralstrue%
-   \or
-      % maghrib:
-      \eastern at numeralsfalse
-   \or
-      % eastern:
-      \eastern at numeralstrue%
-   \or
-      % western:
-      \eastern at numeralsfalse
-   \fi
-   \xpg at info{Option: Arabic, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Arabic numerals option `#1'}}
-
-%this is needed for \abjad in arabicnumbers.sty
-\define at boolkey{arabic}[arabic@]{abjadjimnotail}[true]{%
-  \ifarabic at abjadjimnotail
-    \abjad at jim@notailtrue%
-  \else
-    \abjad at jim@notailfalse
-  \fi}
-
-\define at choicekey*+{arabic}{locale}[\xpg at val\xpg at nr]{default,mashriq,libya,algeria,tunisia,morocco,mauritania}[default]{%
-   \ifcase\xpg at nr\relax
-      % default:
-      \eastern at numeralstrue%
-      \SetLanguageKeys{arabic}{bcp47=ar-YE,bcp47-language=ar}%
-      \xpg at info{Option: arabic, locale=default}%
-   \or
-      % mashriq:
-      \eastern at numeralstrue%
-      \SetLanguageKeys{arabic}{bcp47=ar-IQ,bcp47-language=ar}%
-      \xpg at info{Option: arabic, locale=mashriq}%
-   \or
-      % libya:
-      \eastern at numeralstrue%
-      \SetLanguageKeys{arabic}{bcp47=ayl,bcp47-language=ar,bcp47-region=LY}%
-      \xpg at info{Option: arabic, locale=libya}%
-   \or
-      % algeria:
-      \eastern at numeralsfalse%
-      \SetLanguageKeys{arabic}{bcp47=arq,bcp47-language=ar,bcp47-region=DZ,bcp47-extension-u=nu-latn}%
-      \xpg at info{Option: arabic, locale=algeria}%
-   \or
-      % tunisia:
-      \eastern at numeralsfalse%
-      \SetLanguageKeys{arabic}{bcp47=aeb,bcp47-language=ar,bcp47-region=TN,bcp47-extension-u=nu-latn}%
-      \xpg at info{Option: arabic, locale=tunisia}%
-   \or
-      % morocco:
-      \eastern at numeralsfalse%
-      \SetLanguageKeys{arabic}{bcp47=ary,bcp47-language=ar,bcp47-region=MA,bcp47-extension-u=nu-latn}%
-      \xpg at info{Option: arabic, locale=morocco}%
-   \or
-      % mauritania:
-      \eastern at numeralstrue%
-      \SetLanguageKeys{arabic}{bcp47=ar-MR,bcp47-language=ar,bcp47-region=MR}%
-      \xpg at info{Option: arabic, locale=mauritania}%
-   \fi
-   \gdef\@@arabic at month{\@arabic at month{#1}}
- }{\xpg at warning{Unknown Arabic locale `#1'}}
-
 \newif\if at hijrical
-\define at choicekey*+{arabic}{calendar}[\xpg at val\xpg at nr]{gregorian,hijri,islamic}[gregorian]{%
-   \ifcase\xpg at nr\relax
-      % gregorian:
-      \@hijricalfalse
-   \or
-      % hijri:
-      \@hijricaltrue
-   \or
-      % islamic:
-      \@hijricaltrue
-   \fi
-   \xpg at info{Option: Arabic, calendar=\xpg at val}%
-}{\xpg at warning{Unknown Arabic calendar option `#1'}}
+\newif\ifarabic at customsep\arabic at customsepfalse
 
+\DeclareKeys[polyglossia/gloss/arabic]
+  {
+    hijricorrection.code = \gdef\arabic at hijri@correction{#1},
+    hijricorrection.default:n = 0,
+    sectionsep.code = \gdef\xpg at sepmark{#1}\arabic at customseptrue,
+    sectionsep.default:n = .,
+    abjadalph.if = arabic at abjadalph,
+    abjadalph.default:n = true,
+    abjadjimnotail.if = abjad at jim@notail,
+    abjadjimnotail.default:n = true,
+    numerals.choice:,
+    numerals / mashriq.code =
+      {%
+        \eastern at numeralstrue
+      },
+    numerals / maghrib.code =
+      {%
+        \eastern at numeralsfalse
+      },
+    numerals / eastern.code =
+      {%
+        \eastern at numeralstrue
+      },
+    numerals / western.code =
+      {%
+        \eastern at numeralsfalse
+      },
+    numerals.default:n = mashriq,
+    numerals/unknown.code = \xpg at warning{Unknown Arabic numerals option `#1'},
+    locale.choice:,
+    locale / default.code =
+      {%
+        \eastern at numeralstrue
+        \def\abjad at one{ا}%
+        \SetLanguageKeys{arabic}{bcp47=ar-YE,bcp47-language=ar}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / mashriq.code =
+      {%
+        \eastern at numeralstrue
+        \def\abjad at one{ا}%
+        \SetLanguageKeys{arabic}{bcp47=ar-IQ,bcp47-language=ar}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / libya.code =
+      {%
+        \eastern at numeralstrue
+        \def\abjad at one{ا}%
+        \SetLanguageKeys{arabic}{bcp47=ayl,bcp47-language=ar,bcp47-region=LY}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / algeria.code =
+      {%
+        \eastern at numeralsfalse
+        \def\abjad at one{أ}%
+        \SetLanguageKeys{arabic}{bcp47=arq,bcp47-language=ar,bcp47-region=DZ,bcp47-extension-u=nu-latn}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / tunisia.code =
+      {%
+        \eastern at numeralsfalse
+        \def\abjad at one{أ}%
+        \SetLanguageKeys{arabic}{bcp47=aeb,bcp47-language=ar,bcp47-region=TN,bcp47-extension-u=nu-latn}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / morocco.code =
+      {%
+        \eastern at numeralsfalse
+        \def\abjad at one{أ}%
+        \SetLanguageKeys{arabic}{bcp47=ary,bcp47-language=ar,bcp47-region=MA,bcp47-extension-u=nu-latn}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / mauritania.code =
+      {%
+        \eastern at numeralstrue
+        \def\abjad at one{ا}%
+        \SetLanguageKeys{arabic}{bcp47=ar-MR,bcp47-language=ar,bcp47-region=MR}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale.default:n = default,
+    locale/unknown.code = \xpg at warning{Unknown Arabic locale `#1'},
+    calendar.choice:,
+    calendar / gregorian.code =
+      {%
+        \@hijricalfalse
+      },
+    calendar / hijri.code =
+      {%
+        \@hijricaltrue
+      },
+    calendar / islamic.code =
+      {%
+        \@hijricaltrue
+      },
+    calendar.default:n = gregorian,
+    calendar/unknown.code = \xpg at warning{Unknown Arabic calendar option `#1'}
+  }
 
-\define at key{arabic}{hijricorrection}[0]{%
-  \gdef\arabic at hijri@correction{#1}}%
-
-\newif\ifarabic at customsep\arabic at customsepfalse
-\def\xpg at sepmark{}
-\define at key{arabic}{sectionsep}[.]{%
-   \arabic at customseptrue%
-   \gdef\xpg at sepmark{#1}%
-}
-
 % Register default options
-\xpg at initialize@gloss at options{arabic}{locale=default,calendar=gregorian,numerals=mashriq,hijricorrection=0,abjadjimnotail=false}
+\InitializeGlossOptions{arabic}{locale=default,calendar=gregorian,numerals=mashriq,hijricorrection=0,abjadjimnotail=false}
 % Register alias options
-\xpg at set@alias at values{arabic}{calendar}{islamic}{hijri}
+\SetLanguageAliasValues{arabic}{calendar}{islamic,hijri}
 
 \def\arabicgregmonth at default#1{\ifcase#1%
   % Egypt, Sudan, Yemen and Golf states
@@ -10883,9 +10828,12 @@
 \def\arabicgregmonth at mauritania#1{\ifcase#1%
   \or يناير\or فبراير\or مارس\or إبريل\or مايو\or يونيو\or يوليو\or أغشت\or شتمبر\or أكتوبر\or نوفمبر\or دجمبر\fi}
 
-\def\@arabic at month#1{\ifcsdef{arabicgregmonth@#1}{\expandafter\csname arabicgregmonth@#1\endcsname}%
-{\xpg at warning{Option `locale=#1' is not defined for Arabic: using `default' instead}%
-\arabicgregmonth at default}}
+\def\@arabic at month#1{%
+  \@ifundefined{arabicgregmonth@#1}%
+     {\xpg at warning{Option `locale=#1' is not defined for Arabic: using `default' instead}%
+      \arabicgregmonth at default}%
+     {\expandafter\csname arabicgregmonth@#1\endcsname}%
+}
 
 %\Hijritoday is now locale-aware and will format the date with this macro:
 \DefineFormatHijriDate{arabic}{\@ensure at RTL{\arabicnumber{\value{Hijriday}}%
@@ -10917,18 +10865,18 @@
 }
 \def\datearabic{%
  \def\today{%
-  \if at hijrical%
+  \if at hijrical
     \Hijritoday[\arabic at hijri@correction]%
   \else%
-    \if at RTL%
+    \if at RTL
        \arabicnumber\day\space\@@arabic at month{\month}%
         \space\arabicnumber\year%
     \else% in LR environment we format the gregorian date within \textenglish
-       \ifcsdef{english at loaded}{\textenglish{\today}}%else US format
-       {\normalfontlatin\ifcase\month\or January\or February\or March\or April\or May\or June\or%
-       July\or August\or September\or October\or November\or December\fi%
+       \iflanguageloaded{english}{\textenglish{\today}}%else US format
+       {\normalfontlatin\ifcase\month\or January\or February\or March\or April\or May\or June\or
+       July\or August\or September\or October\or November\or December\fi
        \space\number\day,\space\number\year}%
-    \fi%
+    \fi
  \fi}}
 
 % Use \providecommand here as the ldf file might
@@ -10954,10 +10902,9 @@
    \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}{arabic at abjad@alph}\fi%
+   \else\xpg at ill@value{#1}{arabic at abjad@alph}\fi
 }
 
-
 \def\abjadmaghribi#1{%
 \ifnum#1>1999\xpg at ill@value{#1}{abjad}%
 \else
@@ -10980,30 +10927,30 @@
 
 %maghribi س -> ص ص -> ض ش -> س ض -> ظ ظ -> غ غ -> ش
 \def\abj at maghribi@num at ii#1{%
-  \ifcase#1\or ي\or ك\or ل\or م\or ن%
+  \ifcase#1\abjad at zero\or ي\or ك\or ل\or م\or ن%
            \or ص\or ع\or ف\or ض\fi
-  \ifnum#1=\z@\abjad at zero\fi\abj at num@i}
+  \abj at num@i}
 \def\abj at maghribi@num at iii#1{%
   \ifcase#1\or ق\or ر\or س\or ت\or ث%
            \or خ\or ذ\or ظ\or غ\fi
-  \ifnum#1=\z@\fi\abj at maghribi@num at ii}
+  \abj at maghribi@num at ii}
 \def\abj at maghribi@num at iv#1{%
   \ifcase#1\or ش\fi
-  \ifnum#1=\z@\fi\abj at maghribi@num at iii}
+  \abj at maghribi@num at iii}
 
 \def\arabic at numbers{%
  \ifarabic at abjadalph
-   \let\@alph\abjadalph%
-   \let\@Alph\abjadalph%
+   \let\@alph\abjadalph
+   \let\@Alph\abjadalph
  \else
-   \let\@alph\abjad%
-   \let\@Alph\abjad%
+   \let\@alph\abjad
+   \let\@Alph\abjad
  \fi
 }
 
 \def\noarabic at numbers{%
-  \let\@alph\latin at alph%
-  \let\@Alph\latin at Alph%
+  \let\@alph\latin at alph
+  \let\@Alph\latin at Alph
 }
 
 % Store original definition
@@ -11010,24 +10957,24 @@
 \let\xpg at save@arabic\@arabic
 
 \def\arabic at globalnumbers{%
-  \let\@arabic\arabicnumber%
+  \let\@arabic\arabicnumber
   \renewcommand\thefootnote{\localnumeral*{footnote}}%
   \renewcommand\theequation{\localnumeral*{equation}}%
 }
 
 \def\noarabic at globalnumbers{%
-   \let\@arabic\xpg at save@arabic%
+   \let\@arabic\xpg at save@arabic
 }
 
 \def\arabic at xetex@capsformat{%
-  \let\xpg at save@sepmark\@SepMark%
+  \let\xpg at save@sepmark\@SepMark
   \SepMark{\xpg at sepmark}
 }
 
 \def\noarabic at xetex@capsformat{%
-   \ifcsdef{xpg at save@sepmark}{%
+   \ifcsname xpg at save@sepmark\endcsname
      \SepMark{\xpg at save@sepmark}
-   }{}%
+   \fi
 }
 
 \def\arabic at luatex@capsformat{%
@@ -11034,57 +10981,57 @@
   %
   % change chapter and part headings
   \ifarabic at customsep
-     \ifcsdef{chapter}{%
-        \let\xpg at save@thesection\thesection%
+     \ifcsname chapter\endcsname
+        \let\xpg at save@thesection\thesection
         \renewcommand*\thesection{\thechapter\xpg at sepmark\@arabic\c at section}
-        \let\xpg at save@theequation\theequation%
+        \let\xpg at save@theequation\theequation
         \renewcommand*\theequation{%
 	    \ifnum \c at chapter>\z@ \thechapter\xpg at sepmark\fi\@arabic\c at equation}
-        \let\xpg at save@thefigure\thefigure%
+        \let\xpg at save@thefigure\thefigure
 	\renewcommand*\thefigure{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at figure}
-        \let\xpg at save@thetable\thetable%
+        \let\xpg at save@thetable\thetable
 	\renewcommand*\thetable{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at table}
-     }{}
-     \let\xpg at save@thesubsection\thesubsection%
+     \fi
+     \let\xpg at save@thesubsection\thesubsection
      \renewcommand\thesubsection
 	{\thesection\xpg at sepmark\@arabic\c at subsection}
-     \let\xpg at save@thesubsubsection\thesubsubsection%
+     \let\xpg at save@thesubsubsection\thesubsubsection
      \renewcommand\thesubsubsection{\thesubsection\xpg at sepmark\@arabic\c at subsubsection}
-     \let\xpg at save@theparagraph\theparagraph%
+     \let\xpg at save@theparagraph\theparagraph
      \renewcommand\theparagraph
          {\thesubsubsection\xpg at sepmark\@arabic\c at paragraph}
-     \let\xpg at save@thesubparagraph\thesubparagraph%
+     \let\xpg at save@thesubparagraph\thesubparagraph
      \renewcommand\thesubparagraph{\theparagraph\xpg at sepmark\@arabic\c at subparagraph}
-  \fi% (end \ifarabic at customsep)
+  \fi % (end \ifarabic at customsep)
 }
 
 \def\noarabic at luatex@capsformat{%
-   \ifcsdef{xpg at save@thesection}{%
-        \let\thesection\xpg at save@thesection%
-   }{}%
-   \ifcsdef{xpg at save@theequation}{%
-        \let\theequation\xpg at save@theequation%
-   }{}%
-   \ifcsdef{xpg at save@thefigure}{%
-        \let\thefigure\xpg at save@thefigure%
-   }{}%
-   \ifcsdef{xpg at save@thetable}{%
-        \let\thetable\xpg at save@thetable%
-   }{}%
-   \ifcsdef{xpg at save@thesubsection}{%
-        \let\thesubsection\xpg at save@thesubsection%
-   \ifcsdef{xpg at save@thesubsubsection}{%
-        \let\thesubsubsection\xpg at save@thesubsubsection%
-   }{}%
-   }{}%
-   \ifcsdef{xpg at save@theparagraph}{%
-        \let\theparagraph\xpg at save@theparagraph%
-   }{}%
-   \ifcsdef{xpg at save@thesubparagraph}{%
-        \let\thesubparagraph\xpg at save@thesubparagraph%
-   }{}%
+   \ifcsname xpg at save@thesection\endcsname
+        \let\thesection\xpg at save@thesection
+   \fi
+   \ifcsname xpg at save@theequation\endcsname
+        \let\theequation\xpg at save@theequation
+   \fi
+   \ifcsname xpg at save@thefigure\endcsname
+        \let\thefigure\xpg at save@thefigure
+   \fi
+   \ifcsname xpg at save@thetable\endcsname
+        \let\thetable\xpg at save@thetable
+   \fi
+   \ifcsname xpg at save@thesubsection\endcsname
+        \let\thesubsection\xpg at save@thesubsection
+      \ifcsname xpg at save@thesubsubsection\endcsname
+        \let\thesubsubsection\xpg at save@thesubsubsection
+      \fi
+   \fi
+   \ifcsname xpg at save@theparagraph\endcsname
+        \let\theparagraph\xpg at save@theparagraph
+   \fi
+   \ifcsname xpg at save@thesubparagraph\endcsname
+        \let\thesubparagraph\xpg at save@thesubparagraph
+   \fi
 }
 
 \def\blockextras at arabic{%
@@ -11096,7 +11043,7 @@
       \fi   
    \fi
 }
-%
+
 \def\noextras at arabic{%
     \ifarabic at customsep
       \ifxetex
@@ -11116,7 +11063,7 @@
 % 
 % \subsection{gloss-armenian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-armenian.ldf}[polyglossia: module for Armenian]
 
@@ -11139,43 +11086,49 @@
 
 \newif\if at eastern@armenian
 \@eastern at armenianfalse
-\define at choicekey*+{armenian}{variant}[\xpg at val\xpg at nr]{western,eastern}[western]{%
-   \ifcase\xpg at nr\relax
-      % western:
-      \@eastern at armenianfalse%
-   \or
-      % eastern:
-      \@eastern at armeniantrue%
-   \fi
-   \xpg at info{Option: Armenian, variant=\xpg at 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%
-     \SetLanguageKeys{armenian}{bcp47-extension-u=nu-latn}%
-   }{%
-     \@armenian at numeralstrue%
-     \SetLanguageKeys{armenian}{bcp47-extension-u={}}%
-   }%
-}
 
-\define at boolkey{armenian}[armenian@]{capitalyiwn}[true]{%
-  \ifarmenian at capitalyiwn
-     % MakeUppercase capitalizes the ligature of letters ech and yiwn (U+0587)
-     % to capital ech and yiwn (also the output if Armenian is not selected at all)
-     \SetLanguageKeys{armenian}{bcp47-casing=hy-x-yiwn,bcp47-extension-x=yiwn}
-  \else
-     % Capitalize ech and yiwn ligature to capital ech and vew,
-     % following Armenian spelling reform
-     \SetLanguageKeys{armenian}{bcp47-casing=hy,bcp47-extension-x={}}
-  \fi
-}
+\DeclareKeys[polyglossia/gloss/armenian]
+  {
+    variant.choice:,
+    variant / western.code =
+      {%
+        \@eastern at armenianfalse
+      },
+    variant / eastern.code =
+      {%
+        \@eastern at armeniantrue
+      },
+    variant.default:n = western,
+    variant/unknown.code = \xpg at warning{Unknown Armenian variant `#1'},
+    numerals.choice:,
+    numerals / armenian.code =
+      {%
+        \@armenian at numeralstrue
+        \SetLanguageKeys{armenian}{bcp47-extension-u={}}%
+      },
+    numerals / arabic.code =
+      {%
+        \@armenian at numeralsfalse
+        \SetLanguageKeys{armenian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = armenian,
+    capitalyiwn.choice:,
+    capitalyiwn / true.code =
+      {%
+        \SetLanguageKeys{armenian}{bcp47-casing=hy-x-yiwn,bcp47-extension-x=yiwn}%
+      },
+    capitalyiwn / false.code =
+      {%
+        \SetLanguageKeys{armenian}{bcp47-casing=hy,bcp47-extension-x={}}%
+      },
+    capitalyiwn.default:n = true
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{armenian}{numerals=armenian,variant=western}
+\InitializeGlossOptions{armenian}{numerals=armenian,variant=western}
 
 % Taken from ArmTeX. Audit!
 \def\captionsarmenian{%
@@ -11324,13 +11277,13 @@
 % 
 % \subsection{gloss-arq.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-arq.ldf}[polyglossia: module for arq (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 %    \end{macrocode}
 % \iffalse
@@ -11341,13 +11294,13 @@
 % 
 % \subsection{gloss-ary.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ary.ldf}[polyglossia: module for ary (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 %    \end{macrocode}
 % \iffalse
@@ -11358,13 +11311,13 @@
 % 
 % \subsection{gloss-arz.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-arz.ldf}[polyglossia: module for arz (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 %    \end{macrocode}
 % \iffalse
@@ -11375,13 +11328,13 @@
 % 
 % \subsection{gloss-ast.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ast.ldf}[polyglossia: module for ast (Asturian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{asturian}
+\InheritGlossFile{asturian}
 
 %    \end{macrocode}
 % \iffalse
@@ -11392,7 +11345,7 @@
 % 
 % \subsection{gloss-asturian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Translated by Xuacu <xuacusk8 at gmail dot com>
 % Contributed by Kevin Godby <godbyk at gmail dot com>
@@ -11452,13 +11405,13 @@
 % 
 % \subsection{gloss-australian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-australian.ldf}[polyglossia: module for Australian English]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 %    \end{macrocode}
 % \iffalse
@@ -11469,13 +11422,13 @@
 % 
 % \subsection{gloss-austrian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-austrian.ldf}[polyglossia: module for Austrian German (old spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -11486,13 +11439,13 @@
 % 
 % \subsection{gloss-ayl.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ayl.ldf}[polyglossia: module for ayl (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 %    \end{macrocode}
 % \iffalse
@@ -11503,13 +11456,13 @@
 % 
 % \subsection{gloss-bahasa.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bahasa.ldf}[polyglossia: module for Bahasa Indonesia]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{malay}
+\InheritGlossFile{malay}
 
 %    \end{macrocode}
 % \iffalse
@@ -11520,7 +11473,7 @@
 % 
 % \subsection{gloss-bahasai.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bahasai.ldf}[polyglossia: module for Bahasa Indonesia]
 
@@ -11527,7 +11480,7 @@
 % We only provide this gloss for babel compatibility. Since bahasai is 
 % a malay variety, we use 'malay' with variant 'indonesian' now.
 
-\xpg at load@master at language{malay}
+\InheritGlossFile{malay}
 
 %    \end{macrocode}
 % \iffalse
@@ -11538,7 +11491,7 @@
 % 
 % \subsection{gloss-bahasam.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bahasam.ldf}[polyglossia: module for Bahasa Melayu]
 
@@ -11545,7 +11498,7 @@
 % We only provide this gloss for babel compatibility. Since bahasam is 
 % a malay variety, we use 'malay' with variant 'malaysian' now.
 
-\xpg at load@master at language{malay}
+\InheritGlossFile{malay}
 
 %    \end{macrocode}
 % \iffalse
@@ -11556,7 +11509,7 @@
 % 
 % \subsection{gloss-basque.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-basque.ldf}[polyglossia: module for Basque]
 \PolyglossiaSetup{basque}{
@@ -11614,13 +11567,13 @@
 % 
 % \subsection{gloss-be-tarask.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-be-tarask.ldf}[polyglossia: module for be-tarask (Belarusian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{belarusian}
+\InheritGlossFile{belarusian}
 
 %    \end{macrocode}
 % \iffalse
@@ -11631,13 +11584,13 @@
 % 
 % \subsection{gloss-be.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-be.ldf}[polyglossia: module for be (Belarusian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{belarusian}
+\InheritGlossFile{belarusian}
 
 %    \end{macrocode}
 % \iffalse
@@ -11648,7 +11601,7 @@
 % 
 % \subsection{gloss-belarusian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-belarusian.ldf}[polyglossia: module for Belarusian]
 
@@ -11676,63 +11629,68 @@
 \setlanguagealias*{belarusian}{be}
 
 \def\belarusian at spelling{modern}
-\define at choicekey*+{belarusian}{spelling}[\xpg at val\xpg at nr]{modern,classic,tarask}[modern]{%
-   \ifcase\xpg at nr\relax
-      % modern:
-      \def\belarusian at spelling{modern}%
-      \SetLanguageKeys{belarusian}{bcp47=be,bcp47-variant=1959acad}%
-   \or
-      % classic:
-      \def\belarusian at spelling{tarask}%
-      \SetLanguageKeys{belarusian}{bcp47=be-tarask,bcp47-variant=tarask}%
-   \or
-      % tarask:
-      \def\belarusian at spelling{tarask}%
-      \SetLanguageKeys{belarusian}{bcp47=be-tarask,bcp47-variant=tarask}%
-   \fi
-}{\xpg at warning{Unknown Belarusian spelling `#1'}}
-
 \newif\ifcyrillic at numerals
 \newif\ifcyrillic at asbuk@numerals
-\define at choicekey*+{belarusian}{numerals}[\xpg at val\xpg at nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % arabic:
-      \cyrillic at numeralsfalse%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic-trad:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic-alph:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralstrue%
-   \fi
-   \xpg at info{Option: Belarusian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Belarusian numerals value `#1'}}
 
-\define at boolkey{belarusian}[belarusian@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/belarusian]
+  {
+    babelshorthands.if = belarusian at babelshorthands,
+    babelshorthands.default:n = true,
+    spelling.choice:,
+    spelling / modern.code =
+      {%
+        \def\belarusian at spelling{modern}%
+        \SetLanguageKeys{belarusian}{bcp47=be,bcp47-variant=1959acad}%
+      },
+    spelling / classic.code =
+      {%
+        \def\belarusian at spelling{tarask}%
+        \SetLanguageKeys{belarusian}{bcp47=be-tarask,bcp47-variant=tarask}%
+      },
+    spelling / tarask.code =
+      {%
+        \def\belarusian at spelling{tarask}%
+        \SetLanguageKeys{belarusian}{bcp47=be-tarask,bcp47-variant=tarask}%
+      },
+    spelling.default:n = modern,
+    spelling/unknown.code = \xpg at warning{Unknown Belarusian spelling `#1'},
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \cyrillic at numeralsfalse
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic-trad.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic-alph.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralstrue
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Belarusian numerals value `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{belarusian}{babelshorthands=false,numerals=arabic,spelling=modern}
+\InitializeGlossOptions{belarusian}{babelshorthands=false,numerals=arabic,spelling=modern}
 % Register alias options
-\xpg at set@alias at values{belarusian}{spelling}{classic}{tarask}
+\SetLanguageAliasValues{belarusian}{spelling}{classic,tarask}
 
 \ifsystem at babelshorthands
-  \setkeys{belarusian}{babelshorthands=true}
+  \SetGlossOptions{belarusian}{babelshorthands=true}
 \else
-  \setkeys{belarusian}{babelshorthands=false}
+  \SetGlossOptions{belarusian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\belarusian at shorthands{%
   \xpg at activate@shorthands%
@@ -11976,7 +11934,7 @@
 % 
 % \subsection{gloss-bengali.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Translations provided by সাজেদুর রহিম জোয়ারদার <toshazed at gmail.com>
 % TODO implement Bengali calendar
@@ -12005,30 +11963,36 @@
 
 \newif\ifbengali at devanagari@numerals
 \newif\ifbengali at bengali@numerals
-\define at choicekey*+{bengali}{numerals}[\xpg at val\xpg at nr]{Devanagari,Bengali,Western}[Devanagari]{%
-   \ifcase\xpg at nr\relax
-      % Devanagari:
-      \bengali at bengali@numeralsfalse%
-      \bengali at devanagari@numeralstrue%
-   \or
-      % Bengali:
-      \bengali at bengali@numeralstrue%
-      \bengali at devanagari@numeralsfalse%
-   \or
-      % Western:
-      \bengali at bengali@numeralsfalse%
-      \bengali at devanagari@numeralsfalse%
-   \fi
-   \xpg at info{Option: Bengali, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Bengali numeral `#1'}}
 
 \def\extras at bengali{}
 \def\noextras at bengali{}
 
-\define at boolkey{bengali}[bengali@]{changecounternumbering}[true]{}
+\DeclareKeys[polyglossia/gloss/bengali]
+  {
+    changecounternumbering.if = bengali at changecounternumbering,
+    changecounternumbering.default:n = true,
+    numerals.choice:,
+    numerals / devanagari.code =
+      {%
+        \bengali at bengali@numeralsfalse
+        \bengali at devanagari@numeralstrue
+      },
+    numerals / bengali.code =
+      {%
+        \bengali at bengali@numeralstrue
+        \bengali at devanagari@numeralsfalse
+      },
+    numerals / western.code =
+      {%
+        \bengali at bengali@numeralsfalse
+        \bengali at devanagari@numeralsfalse
+      },
+    numerals.default:n = devanagari,
+    numerals/unknown.code = \xpg at warning{Unknown Bengali numeral `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{bengali}{changecounternumbering=false,numerals=Devanagari}
+\InitializeGlossOptions{bengali}{changecounternumbering=false,numerals=Devanagari}
 
 \def\captionsbengali{%
   \def\refname{তথ্যসূত্রসমূহ}%
@@ -12117,13 +12081,13 @@
 % 
 % \subsection{gloss-bg.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bg.ldf}[polyglossia: module for bg (Bulgarian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{bulgarian}
+\InheritGlossFile{bulgarian}
 
 %    \end{macrocode}
 % \iffalse
@@ -12134,13 +12098,13 @@
 % 
 % \subsection{gloss-bn.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bn.ldf}[polyglossia: module for bn (Bengali)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{bengali}
+\InheritGlossFile{bengali}
 
 %    \end{macrocode}
 % \iffalse
@@ -12151,13 +12115,13 @@
 % 
 % \subsection{gloss-bo.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bo.ldf}[polyglossia: module for bo (Tibetan)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{tibetan}
+\InheritGlossFile{tibetan}
 
 %    \end{macrocode}
 % \iffalse
@@ -12168,7 +12132,7 @@
 % 
 % \subsection{gloss-bosnian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bosnian.ldf}[polyglossia: module for Bosnian]
 
@@ -12232,13 +12196,13 @@
 % 
 % \subsection{gloss-br.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-br.ldf}[polyglossia: module for br (Breton)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{breton}
+\InheritGlossFile{breton}
 
 %    \end{macrocode}
 % \iffalse
@@ -12249,7 +12213,7 @@
 % 
 % \subsection{gloss-brazil.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-brazil.ldf}[polyglossia: module for Brazilian Portuguese]
 
@@ -12257,7 +12221,7 @@
 % 'brazil' was selected in accordance with babel.
 % Since brazil is a variety of portuguese, we use 'portuguese' now.
 
-\xpg at load@master at language{portuguese}
+\InheritGlossFile{portuguese}
 
 %    \end{macrocode}
 % \iffalse
@@ -12268,7 +12232,7 @@
 % 
 % \subsection{gloss-breton.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-breton.ldf}[polyglossia: module for Breton]
 \PolyglossiaSetup{breton}{
@@ -12376,13 +12340,13 @@
 % 
 % \subsection{gloss-british.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-british.ldf}[polyglossia: module for British English]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 %    \end{macrocode}
 % \iffalse
@@ -12393,13 +12357,13 @@
 % 
 % \subsection{gloss-bs.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bs.ldf}[polyglossia: module for bs (Bosnian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{bosnian}
+\InheritGlossFile{bosnian}
 
 %    \end{macrocode}
 % \iffalse
@@ -12410,7 +12374,7 @@
 % 
 % \subsection{gloss-bulgarian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bulgarian.ldf}[polyglossia: module for Bulgarian]
 \PolyglossiaSetup{bulgarian}{
@@ -12473,15 +12437,15 @@
    \def\figurename{Фигура}%
    \def\tablename{Таблица}%
    %\def\thepart{}%
-   %\def\partname{}%
+   \def\partname{Част}%
    \def\pagename{Стр.}%
    \def\seename{вж.}%
    \def\alsoname{вж.\ също и}%
    \def\enclname{Приложения}%
    \def\ccname{копия}%
-   %\def\headtoname{}%
-   \def\proofname{Proof}%
-   \def\glossaryname{Glossary}%
+   \def\headtoname{За}%
+   \def\proofname{Доказателство}%
+   \def\glossaryname{Притурка}%
 }
 
 \def\datebulgarian{%
@@ -12512,13 +12476,13 @@
 % 
 % \subsection{gloss-ca.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ca.ldf}[polyglossia: module for ca (Catalan)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{catalan}
+\InheritGlossFile{catalan}
 
 %    \end{macrocode}
 % \iffalse
@@ -12529,13 +12493,13 @@
 % 
 % \subsection{gloss-canadian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-canadian.ldf}[polyglossia: module for Canadian English]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 %    \end{macrocode}
 % \iffalse
@@ -12546,13 +12510,13 @@
 % 
 % \subsection{gloss-canadien.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-canadien.ldf}[polyglossia: module for Canadian French]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 %    \end{macrocode}
 % \iffalse
@@ -12563,7 +12527,7 @@
 % 
 % \subsection{gloss-catalan.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-catalan.ldf}[polyglossia: module for Catalan]
 \PolyglossiaSetup{catalan}{
@@ -12581,21 +12545,21 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{catalan}{ca}
 
-\define at boolkey{catalan}[catalan@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/catalan]
+  {
+    babelshorthands.if = catalan at babelshorthands,
+    babelshorthands.default:n = true,
+  }
 \ifsystem at babelshorthands
-  \setkeys{catalan}{babelshorthands=true}
+  \SetGlossOptions{catalan}{babelshorthands=true}
 \else
-  \setkeys{catalan}{babelshorthands=false}
+  \SetGlossOptions{catalan}{babelshorthands=false}
 \fi
 
 % Register default options
-\xpg at initialize@gloss at options{catalan}{babelshorthands=false}
+\InitializeGlossOptions{catalan}{babelshorthands=false}
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 %%% adapted from Babel's catalan.ldf
 \newdimen\leftllkern \newdimen\rightllkern \newdimen\raiselldim
@@ -12732,7 +12696,7 @@
 % 
 % \subsection{gloss-chinese.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-chinese.ldf}[polyglossia: module for Chinese]
 
@@ -12756,51 +12720,60 @@
 \setlanguagealias*[variant=simplified]{chinese}{zh-CN}
 \setlanguagealias*[variant=traditional]{chinese}{zh-TW}
 
-\providebool{chinese at traditional}
+\@ifundefined{ifchinese at traditional}%
+  {\newif\ifchinese at traditional}{}
 
+\@ifundefined{ifchinese at numerals}%
+  {\newif\ifchinese at numerals}{}
+
 \def\chinese at variant{chinese}
 
-\newif\ifchinese at numerals
-\define at key{chinese}{numerals}[arabic]{%
-   \ifstrequal{#1}{chinese}%
-      {\chinese at numeralstrue%
-       \SetLanguageKeys{chinese}{bcp47-extension-u=nu-hant}%
-      }{\chinese at numeralsfalse%
-       \SetLanguageKeys{chinese}{bcp47-extension-u=nu-latn}%
-      }%
-}
+\DeclareKeys[polyglossia/gloss/chinese]
+  {
+    variant.choice:,
+    variant / cn.code =
+      {%
+        \chinese at traditionalfalse
+        \SetLanguageKeys{chinese}{language={Chinese Simplified},langtag=ZHS,bcp47=zh-CN,bcp47-language=zh,bcp47-region=CN,bcp47-script=Hans}%
+      },
+    variant / simplified.code =
+      {%
+        \chinese at traditionalfalse
+        \SetLanguageKeys{chinese}{language={Chinese Simplified},langtag=ZHS,bcp47=zh-CN,bcp47-language=zh,bcp47-region=CN,bcp47-script=Hans}%
+      },
+    variant / tw.code =
+      {%
+        \chinese at traditionaltrue
+        \SetLanguageKeys{chinese}{language={Chinese Traditional},langtag=ZHT,bcp47=zh-TW,bcp47-language=zh,bcp47-region=TW,bcp47-script=Hant}%
+      },
+    variant / traditional.code =
+      {%
+        \chinese at traditionaltrue
+        \SetLanguageKeys{chinese}{language={Chinese Traditional},langtag=ZHT,bcp47=zh-TW,bcp47-language=zh,bcp47-region=TW,bcp47-script=Hant}%
+      },
+    variant.default:n = cn,
+    variant/unknown.code = \xpg at warning{Unknown Chinese variant `#1'},
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \chinese at numeralsfalse
+        \SetLanguageKeys{chinese}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / chinese.code =
+      {%
+        \chinese at numeralstrue
+        \SetLanguageKeys{chinese}{bcp47-extension-u=nu-hant}%
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Chinese numerals value `#1'}
+  }
 
-
-\define at choicekey*+{chinese}{variant}[\xpg at val\xpg at nr]{cn,simplified,tw,traditional}[cn]{%
-   \ifcase\xpg at nr\relax
-      % cn:
-      \chinese at traditionalfalse
-      \SetLanguageKeys{chinese}{language={Chinese Simplified},langtag=ZHS,bcp47=zh-CN,bcp47-language=zh,bcp47-region=CN,bcp47-script=Hans}%
-      \xpg at info{Option: Chinese, variant=simplified}%
-   \or
-      % simplified:
-      \chinese at traditionalfalse
-      \SetLanguageKeys{chinese}{language={Chinese Simplified},langtag=ZHS,bcp47=zh-CN,bcp47-language=zh,bcp47-region=CN,bcp47-script=Hans}%
-      \xpg at info{Option: Chinese, variant=simplified}%
-   \or
-      % tw:
-      \chinese at traditionaltrue
-      \SetLanguageKeys{chinese}{language={Chinese Traditional},langtag=ZHT,bcp47=zh-TW,bcp47-language=zh,bcp47-region=TW,bcp47-script=Hant}%
-      \xpg at info{Option: Chinese, variant=traditional}%
-   \or
-      % traditional:
-      \chinese at traditionaltrue
-      \SetLanguageKeys{chinese}{language={Chinese Traditional},langtag=ZHT,bcp47=zh-TW,bcp47-language=zh,bcp47-region=TW,bcp47-script=Hant}%
-      \xpg at info{Option: Chinese, variant=traditional}%
-   \fi
-}{\xpg at warning{Unknown Chinese variant `#1'}}
-
 % Register default options
-\xpg at initialize@gloss at options{chinese}{variant=cn,numerals=arabic}
-%\xpg at initialize@gloss at options{chinese}{variant=tw,numerals=arabic}
+\InitializeGlossOptions{chinese}{variant=cn,numerals=arabic}
+%\InitializeGlossOptions{chinese}{variant=tw,numerals=arabic}
 % Register alias options
-\xpg at set@alias at values{chinese}{variant}{cn}{simplified}
-\xpg at set@alias at values{chinese}{variant}{tw}{traditional}
+\SetLanguageAliasValues{chinese}{variant}{cn,simplified}
+\SetLanguageAliasValues{chinese}{variant}{tw,traditional}
 
 
 \def\chinese at capsformat{%
@@ -12852,7 +12825,7 @@
     \def\enclname{附件}%
     \def\ccname{抄送}%
     \def\headtoname{收件人}%
-    \def\\glossaryname{詞彙表}%
+    \def\glossaryname{詞彙表}%
 }
 \def\captions at chinese@simplified{%
     \def\contentsname{目录}%
@@ -12875,7 +12848,7 @@
     \def\enclname{附件}%
     \def\ccname{抄送}%
     \def\headtoname{收件人}%
-    \def\\glossaryname{词汇表}%
+    \def\glossaryname{词汇表}%
 }
 
 \newcount\c at TempJNum%
@@ -13023,13 +12996,13 @@
 % 
 % \subsection{gloss-ckb-Arab.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ckb-Arab.ldf}[polyglossia: module for ckb-Arab (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 %    \end{macrocode}
 % \iffalse
@@ -13040,13 +13013,13 @@
 % 
 % \subsection{gloss-ckb-Latn.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ckb-Latn.ldf}[polyglossia: module for ckb-Latn (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 %    \end{macrocode}
 % \iffalse
@@ -13057,17 +13030,34 @@
 % 
 % \subsection{gloss-ckb.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ckb.ldf}[polyglossia: module for ckb (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 %    \end{macrocode}
 % \iffalse
 %</gloss-ckb.ldf>
+%<*gloss-classiclatin.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-classiclatin.ldf}
+%    \begin{macrocode}
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
+%
+\ProvidesFile{gloss-classiclatin.ldf}[polyglossia: module for classic Latin]
+
+% We provide this as a babel alias
+
+\InheritGlossFile{latin}
+
+%    \end{macrocode}
+% \iffalse
+%</gloss-classiclatin.ldf>
 %<*gloss-cop.ldf>
 % \fi
 % \clearpage
@@ -13074,13 +13064,13 @@
 % 
 % \subsection{gloss-cop.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-cop.ldf}[polyglossia: module for cop (Coptic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{coptic}
+\InheritGlossFile{coptic}
 
 %    \end{macrocode}
 % \iffalse
@@ -13091,7 +13081,7 @@
 % 
 % \subsection{gloss-coptic.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-coptic.ldf}[polyglossia: module for Coptic]
 \PolyglossiaSetup{coptic}{
@@ -13147,7 +13137,7 @@
 % 
 % \subsection{gloss-croatian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-croatian.ldf}[polyglossia: module for Croatian]
 \PolyglossiaSetup{croatian}{
@@ -13169,40 +13159,40 @@
   \RequirePackage{luavlna}
 \fi
 
-\define at boolkey{croatian}[croatian@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/croatian]
+  {
+    babelshorthands.if = croatian at babelshorthands,
+    babelshorthands.default:n = true,
+    disabledigraphs.if = croatian at disabledigraphs,
+    disabledigraphs.default:n = true,
+    splithyphens.if = croatian at splithyphens,
+    splithyphens.default:n = true,
+    localalph.if = croatian at localalph,
+    localalph.default:n = true,
+    disableligatures.choices:nn = { true, false }
+      {%
+        \xpg at warning{The option disableligatures is deprecated.\MessageBreak
+               Please use disabledigraphs instead}%
+        \ifcase\UseName{l_keys_choice_int}\or
+          \croatian at disabledigraphstrue
+        \or
+          \croatian at disabledigraphsfalse
+        \fi
+      },
+    disableligatures.default:n = true,
+  }
 
-\define at boolkey{croatian}[croatian@]{disabledigraphs}[true]{}
-
-% Alias kept for backwards compatibility. Please do not remove
-\define at boolkey{croatian}[croatian@]{disableligatures}[true]{%
-   \xpg at warning{The option disableligatures is deprected.\MessageBreak
-                Please use disabledigraphs instead}%
-   \ifcroatian at disableligatures
-      \croatian at disabledigraphstrue
-   \else
-      \croatian at disabledigraphsfalse
-   \fi
-}
-
-\define at boolkey{croatian}[croatian@]{splithyphens}[true]{}
-
-\define at boolkey{croatian}[croatian@]{localalph}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{croatian}{babelshorthands=false,disabledigraphs=false,
+\InitializeGlossOptions{croatian}{babelshorthands=false,disabledigraphs=false,
                                         splithyphens=true,localalph=true}
 
 \ifsystem at babelshorthands
-  \setkeys{croatian}{babelshorthands=true}
+  \SetGlossOptions{croatian}{babelshorthands=true}
 \else
-  \setkeys{croatian}{babelshorthands=false}
+  \SetGlossOptions{croatian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \let\xpg at hyphen@char-
 \def\croatian@@splhyphen#1{%
@@ -13423,13 +13413,13 @@
 % 
 % \subsection{gloss-cy.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-cy.ldf}[polyglossia: module for cy (Welsh)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{welsh}
+\InheritGlossFile{welsh}
 
 %    \end{macrocode}
 % \iffalse
@@ -13440,13 +13430,13 @@
 % 
 % \subsection{gloss-cz.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-cz.ldf}[polyglossia: module for cz (Czech)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{czech}
+\InheritGlossFile{czech}
 
 %    \end{macrocode}
 % \iffalse
@@ -13457,7 +13447,7 @@
 % 
 % \subsection{gloss-czech.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-czech.ldf}[polyglossia: module for Czech]
 
@@ -13480,26 +13470,26 @@
   \RequirePackage{luavlna}
 \fi
 
-\define at boolkey{czech}[czech@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/czech]
+  {
+    babelshorthands.if = czech at babelshorthands,
+    babelshorthands.default:n = true,
+    splithyphens.if = czech at splithyphens,
+    splithyphens.default:n = true,
+    vlna.if = czech at vlna,
+    vlna.default:n = true
+  }
 
-\define at boolkey{czech}[czech@]{splithyphens}[true]{}
-
-\define at boolkey{czech}[czech@]{vlna}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{czech}{babelshorthands=false,splithyphens=true,vlna=true}
+\InitializeGlossOptions{czech}{babelshorthands=false,splithyphens=true,vlna=true}
 
 \ifsystem at babelshorthands
-  \setkeys{czech}{babelshorthands=true}
+  \SetGlossOptions{czech}{babelshorthands=true}
 \else
-  \setkeys{czech}{babelshorthands=false}
+  \SetGlossOptions{czech}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\czech@@splithyphen#1{%
   \def\czech at sh@tmp{%
@@ -13716,13 +13706,13 @@
 % 
 % \subsection{gloss-da.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-da.ldf}[polyglossia: module for da (Danish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{danish}
+\InheritGlossFile{danish}
 
 %    \end{macrocode}
 % \iffalse
@@ -13733,7 +13723,7 @@
 % 
 % \subsection{gloss-danish.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-danish.ldf}[polyglossia: module for Danish]
 \PolyglossiaSetup{danish}{
@@ -13790,13 +13780,13 @@
 % 
 % \subsection{gloss-de-AT-1901.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT-1901.ldf}[polyglossia: module for de-AT-1901 (Austrian German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13807,13 +13797,13 @@
 % 
 % \subsection{gloss-de-AT-1996.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT-1996.ldf}[polyglossia: module for de-AT-1996 (Austrian German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13824,13 +13814,13 @@
 % 
 % \subsection{gloss-de-AT.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT.ldf}[polyglossia: module for de-AT (Austrian German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13841,13 +13831,13 @@
 % 
 % \subsection{gloss-de-CH-1901.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH-1901.ldf}[polyglossia: module for de-CH-1901 (Swiss German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13858,13 +13848,13 @@
 % 
 % \subsection{gloss-de-CH-1996.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH-1996.ldf}[polyglossia: module for de-CH-1996 (Swiss German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13875,13 +13865,13 @@
 % 
 % \subsection{gloss-de-CH.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH.ldf}[polyglossia: module for de-CH (Swiss German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13892,13 +13882,13 @@
 % 
 % \subsection{gloss-de-DE-1901.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE-1901.ldf}[polyglossia: module for de-DE-1901 (Germany's German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13909,13 +13899,13 @@
 % 
 % \subsection{gloss-de-DE-1996.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE-1996.ldf}[polyglossia: module for de-DE-1996 (Germany's German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13926,13 +13916,13 @@
 % 
 % \subsection{gloss-de-DE.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE.ldf}[polyglossia: module for de-DE (Germany's German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13943,13 +13933,13 @@
 % 
 % \subsection{gloss-de-Latf-AT-1901.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT-1901-Latf.ldf}[polyglossia: module for de-AT-1901-Latf (Austrian German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13960,13 +13950,13 @@
 % 
 % \subsection{gloss-de-Latf-AT-1996.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT-1996-Latf.ldf}[polyglossia: module for de-AT-1996-Latf (Austrian German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13977,13 +13967,13 @@
 % 
 % \subsection{gloss-de-Latf-AT.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT-Latf.ldf}[polyglossia: module for de-AT-Latf (Austrian German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -13994,13 +13984,13 @@
 % 
 % \subsection{gloss-de-Latf-CH-1901.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH-1901-Latf.ldf}[polyglossia: module for de-CH-1901-Latf (Swiss German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -14011,13 +14001,13 @@
 % 
 % \subsection{gloss-de-Latf-CH-1996.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH-1996-Latf.ldf}[polyglossia: module for de-CH-1996-Latf (Swiss German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -14028,13 +14018,13 @@
 % 
 % \subsection{gloss-de-Latf-CH.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH-Latf.ldf}[polyglossia: module for de-CH-Latf (Swiss German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -14045,13 +14035,13 @@
 % 
 % \subsection{gloss-de-Latf-DE-1901.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE-1901-Latf.ldf}[polyglossia: module for de-DE-1901-Latf (Germany's German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -14062,13 +14052,13 @@
 % 
 % \subsection{gloss-de-Latf-DE-1996.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE-1996-Latf.ldf}[polyglossia: module for de-DE-1996-Latf (Germany's German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -14079,13 +14069,13 @@
 % 
 % \subsection{gloss-de-Latf-DE.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE-Latf.ldf}[polyglossia: module for de-DE-Latf (Germany's German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -14096,13 +14086,13 @@
 % 
 % \subsection{gloss-de-Latf.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-Latf.ldf}[polyglossia: module for de-Latf (German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -14113,13 +14103,13 @@
 % 
 % \subsection{gloss-de.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de.ldf}[polyglossia: module for de (German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -14130,7 +14120,7 @@
 % 
 % \subsection{gloss-divehi.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-divehi.ldf}[polyglossia: module for Divehi]
 
@@ -14185,13 +14175,13 @@
 % 
 % \subsection{gloss-dsb.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-dsb.ldf}[polyglossia: module for dsb (Sorbian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 %    \end{macrocode}
 % \iffalse
@@ -14202,7 +14192,7 @@
 % 
 % \subsection{gloss-dutch.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-dutch.ldf}[polyglossia: module for Dutch]
 \PolyglossiaSetup{dutch}{
@@ -14219,24 +14209,24 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{dutch}{nl}
 
-\define at boolkey{dutch}[dutch@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/dutch]
+  {
+    babelshorthands.if = dutch at babelshorthands,
+    babelshorthands.default:n = true,
+    tremahyphenation.if = dutch at tremahyphenation,
+    tremahyphenation.default:n = true
+  }
 
-\define at boolkey{dutch}[dutch@]{tremahyphenation}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{dutch}{babelshorthands=false,tremahyphenation=true}
+\InitializeGlossOptions{dutch}{babelshorthands=false,tremahyphenation=true}
 
 \ifsystem at babelshorthands
-  \setkeys{dutch}{babelshorthands=true}
+  \SetGlossOptions{dutch}{babelshorthands=true}
 \else
-  \setkeys{dutch}{babelshorthands=false}
+  \SetGlossOptions{dutch}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\xpg at trema#1{\allowhyphens\discretionary{-}{#1}{\"{#1}}\allowhyphens}
 
@@ -14412,17 +14402,34 @@
 % 
 % \subsection{gloss-dv.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-dv.ldf}[polyglossia: module for dv (Divehi)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{divehi}
+\InheritGlossFile{divehi}
 
 %    \end{macrocode}
 % \iffalse
 %</gloss-dv.ldf>
+%<*gloss-ecclesiasticlatin.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-ecclesiasticlatin.ldf}
+%    \begin{macrocode}
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
+%
+\ProvidesFile{gloss-ecclesiasticlatin.ldf}[polyglossia: module for ecclesiastic Latin]
+
+% We provide this as a babel alias
+
+\InheritGlossFile{latin}
+
+%    \end{macrocode}
+% \iffalse
+%</gloss-ecclesiasticlatin.ldf>
 %<*gloss-el-monoton.ldf>
 % \fi
 % \clearpage
@@ -14429,13 +14436,13 @@
 % 
 % \subsection{gloss-el-monoton.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-el-monoton.ldf}[polyglossia: module for el-monoton (Greek)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{greek}
+\InheritGlossFile{greek}
 
 %    \end{macrocode}
 % \iffalse
@@ -14446,13 +14453,13 @@
 % 
 % \subsection{gloss-el-polyton.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-el-polyton.ldf}[polyglossia: module for el-polyton (Greek)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{greek}
+\InheritGlossFile{greek}
 
 %    \end{macrocode}
 % \iffalse
@@ -14463,13 +14470,13 @@
 % 
 % \subsection{gloss-el.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-el.ldf}[polyglossia: module for el (Greek)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{greek}
+\InheritGlossFile{greek}
 
 %    \end{macrocode}
 % \iffalse
@@ -14480,13 +14487,13 @@
 % 
 % \subsection{gloss-en-AU.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-en-AU.ldf}[polyglossia: module for en-AU (Australian English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 %    \end{macrocode}
 % \iffalse
@@ -14497,13 +14504,13 @@
 % 
 % \subsection{gloss-en-CA.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
-\ProvidesFile{gloss-en-CA.ldf}[polyglossia: module for en-CA (Canadan English)]
+\ProvidesFile{gloss-en-CA.ldf}[polyglossia: module for en-CA (Canadian English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 %    \end{macrocode}
 % \iffalse
@@ -14514,13 +14521,13 @@
 % 
 % \subsection{gloss-en-GB.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-en-GB.ldf}[polyglossia: module for en-GB (British English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 %    \end{macrocode}
 % \iffalse
@@ -14531,13 +14538,13 @@
 % 
 % \subsection{gloss-en-NZ.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-en-NZ.ldf}[polyglossia: module for en-NZ (Newzealand English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 %    \end{macrocode}
 % \iffalse
@@ -14548,13 +14555,13 @@
 % 
 % \subsection{gloss-en-US.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-en-US.ldf}[polyglossia: module for en-US (American English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 %    \end{macrocode}
 % \iffalse
@@ -14565,13 +14572,13 @@
 % 
 % \subsection{gloss-en.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-en.ldf}[polyglossia: module for en (English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 %    \end{macrocode}
 % \iffalse
@@ -14582,7 +14589,7 @@
 % 
 % \subsection{gloss-english.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-english.ldf}[polyglossia: module for English]
 
@@ -14614,9 +14621,12 @@
 \setlanguagealias[variant=canadian]{english}{canadian}
 \setlanguagealias[variant=newzealand]{english}{newzealand}
 
-\providebool{british at hyphen}
-\providebool{english at ordinalmonthday}
-\providebool{british at dateformat}
+\@ifundefined{ifbritish at hyphen}%
+  {\newif\ifbritish at hyphen}{}
+\@ifundefined{ifenglish at ordinalmonthday}%
+  {\newif\ifenglish at ordinalmonthday}{}
+\@ifundefined{ifbritish at dateformat}%
+  {\newif\ifbritish at dateformat}{}
 
 % US English (\l at english) is default
 % Initialize its settings
@@ -14625,17 +14635,18 @@
 \english at ordinalmonthdayfalse
 \british at dateformatfalse
 
-% Option ordinalmonthday
-\define at boolkey{english}[english@]{ordinalmonthday}[true]{}
-
-\define at choicekey*+{english}{variant}[\xpg at val\xpg at nr]{uk,british,us,american,usmax,australian,newzealand,canadian}[us]{%
-   \ifcase\xpg at nr\relax
+\DeclareKeys[polyglossia/gloss/english]
+  {
+    ordinalmonthday.if = english at ordinalmonthday,
+    ordinalmonthday.default:n = true,
+    variant.choices:nn = { uk, british, us, american, usmax, australian, newzealand, canadian }
+      {%
+        \ifcase\UseName{l_keys_choice_int}\or
       % uk:
       \british at hyphentrue
       \british at dateformattrue
       \english at ordinalmonthdaytrue
       \SetLanguageKeys{english}{babelname=british,bcp47=en-GB,bcp47-language=en,bcp47-region=GB}%
-      \xpg at info{Option: English, variant=british}%
    \or
       % british:
       \british at hyphentrue
@@ -14642,7 +14653,6 @@
       \british at dateformattrue
       \english at ordinalmonthdaytrue
       \SetLanguageKeys{english}{babelname=british,bcp47=en-GB,bcp47-language=en,bcp47-region=GB}%
-      \xpg at info{Option: english variant=british}%
    \or
       % us:
       \british at hyphenfalse
@@ -14649,7 +14659,6 @@
       \british at dateformatfalse
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=american,bcp47=en-US,bcp47-language=en,bcp47-region=US}%
-      \xpg at info{Option: English, variant=american}%
    \or
       % american:
       \british at hyphenfalse
@@ -14656,7 +14665,6 @@
       \british at dateformatfalse
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=american,bcp47=en-US,bcp47-language=en,bcp47-region=US}%
-      \xpg at info{Option: English, variant=american}%
    \or
       % usmax:
       \british at hyphenfalse
@@ -14663,11 +14671,10 @@
       \british at dateformatfalse
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=american,bcp47=en-US,bcp47-language=en,bcp47-region=US}%
-      \xpg at info{Option: english variant=american (with additional patterns)}%
-      \xpg at ifdefined{usenglishmax}{}%
+      \IfLanguageDefinedF{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%
+          \adddialect\l at usenglishmax\l at english
          }%
       \def\english at variant{usenglishmax}%
    \or
@@ -14678,8 +14685,7 @@
       \british at dateformattrue
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=australian,bcp47=en-AU,bcp47-language=en,bcp47-region=AU}%
-      \xpg at info{Option: English, variant=australian}%
-      \adddialect\l at australian\l at english%
+      \adddialect\l at australian\l at english
    \or
       % newzealand:
       % These use the british hyphenation patterns
@@ -14688,8 +14694,7 @@
       \british at dateformattrue
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=newzealand,bcp47=en-NZ,bcp47-language=en,bcp47-region=NZ}%
-      \xpg at info{Option: English, variant=newzealand}%
-      \adddialect\l at newzealand\l at english%
+      \adddialect\l at newzealand\l at english
    \or
       % canadian:
       % This is currently equivalent to usenglish (as in babel)
@@ -14697,45 +14702,35 @@
       \british at dateformatfalse
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=canadian,bcp47=en-CA,bcp47-language=en,bcp47-region=CA}%
-      \xpg at info{Option: English, variant=american}%
-      \adddialect\l at canadian\l at english%
+      \adddialect\l at canadian\l at english
    \fi
    \ifbritish at hyphen
-      \xpg at ifdefined{ukenglish}{}%
+      \IfLanguageDefinedF{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%
+          \adddialect\l at ukenglish\l at english
          }%
       \def\english at variant{ukenglish}%
    \fi
-}{\xpg at warning{Unknown English variant `#1'}}
+      },
+    variant.default:n = us,
+    variant/unknown.code = \xpg at warning{Unknown English variant `#1'},
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{english}{variant=us,ordinalmonthday=false}
+\InitializeGlossOptions{english}{variant=us,ordinalmonthday=false}
 % Register alias options
-\xpg at set@alias at values{english}{variant}{us}{american}
-\xpg at set@alias at values{english}{variant}{uk}{british}
+\SetLanguageAliasValues{english}{variant}{us,american}
+\SetLanguageAliasValues{english}{variant}{uk,british}
 
 \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}{}{}
-   }%
+   % (specific order as in the csv list), or null language if everything fails
+   \TryPatternWithFallback{english}{british, american, usenglishmax, australian, newzealand}
 \fi
 
 \def\english at language{%
-   \polyglossia at setup@language at patterns{\english at variant}%
+   \SetupPolyglossiaLangPatterns{\english at variant}%
 }%
 
 \def\captionsenglish{%
@@ -14793,13 +14788,13 @@
 % 
 % \subsection{gloss-eo.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-eo.ldf}[polyglossia: module for eo (Esperanto)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{esperanto}
+\InheritGlossFile{esperanto}
 
 %    \end{macrocode}
 % \iffalse
@@ -14810,13 +14805,13 @@
 % 
 % \subsection{gloss-es-ES.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-es-ES.ldf}[polyglossia: module for es-ES (Spain's Spanish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{spanish}
+\InheritGlossFile{spanish}
 
 %    \end{macrocode}
 % \iffalse
@@ -14827,13 +14822,13 @@
 % 
 % \subsection{gloss-es-MX.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-es-MX.ldf}[polyglossia: module for es-MX (Mexican Spanish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{spanish}
+\InheritGlossFile{spanish}
 
 %    \end{macrocode}
 % \iffalse
@@ -14844,13 +14839,13 @@
 % 
 % \subsection{gloss-es.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-es.ldf}[polyglossia: module for es (Spanish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{spanish}
+\InheritGlossFile{spanish}
 
 %    \end{macrocode}
 % \iffalse
@@ -14861,7 +14856,7 @@
 % 
 % \subsection{gloss-esperanto.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-esperanto.ldf}[polyglossia: module for Esperanto]
 \PolyglossiaSetup{esperanto}{
@@ -14892,10 +14887,10 @@
    \def\figurename{Figuro}%
    \def\tablename{Tabelo}%
    %\def\thepart{}%
-   %\def\partname{}%
+   \def\partname{Parto}%
    \def\pagename{Paĝo}%
    \def\seename{vidu}%
-   \def\alsoname{Parto}%
+   \def\alsoname{vidu ankaŭ}%
    \def\enclname{Aldono(j)}%
    \def\ccname{Kopie al}%
    \def\headtoname{Al}%
@@ -14941,7 +14936,7 @@
 % 
 % \subsection{gloss-estonian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-estonian.ldf}[polyglossia: module for Estonian]
 \PolyglossiaSetup{estonian}{
@@ -14981,7 +14976,7 @@
    \def\ccname{Koopia(d)}%
    %\def\headtoname{}%
    \def\proofname{Korrektuur}%
-   \def\glossaryname{Glossary}% <-- need translation
+   \def\glossaryname{Sõnastik}%
    }
 \def\dateestonian{%
    \def\today{\number\day.\space\ifcase\month\or
@@ -14998,13 +14993,13 @@
 % 
 % \subsection{gloss-et.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-et.ldf}[polyglossia: module for et (Estonian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{estonian}
+\InheritGlossFile{estonian}
 
 %    \end{macrocode}
 % \iffalse
@@ -15015,13 +15010,13 @@
 % 
 % \subsection{gloss-eu.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-eu.ldf}[polyglossia: module for eu (Basque)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{basque}
+\InheritGlossFile{basque}
 
 %    \end{macrocode}
 % \iffalse
@@ -15032,13 +15027,13 @@
 % 
 % \subsection{gloss-fa.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fa.ldf}[polyglossia: module for fa (Persian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{persian}
+\InheritGlossFile{persian}
 
 %    \end{macrocode}
 % \iffalse
@@ -15049,7 +15044,7 @@
 % 
 % \subsection{gloss-farsi.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-farsi.ldf}[polyglossia: module for Farsi]
 
@@ -15056,7 +15051,7 @@
 % We only provide this gloss for babel compatibility.
 % The proper English language name is Persian.
 
-\xpg at load@master at language{persian}
+\InheritGlossFile{persian}
 
 %    \end{macrocode}
 % \iffalse
@@ -15067,13 +15062,13 @@
 % 
 % \subsection{gloss-fi.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fi.ldf}[polyglossia: module for fi (Finnish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{finnish}
+\InheritGlossFile{finnish}
 
 %    \end{macrocode}
 % \iffalse
@@ -15084,7 +15079,7 @@
 % 
 % \subsection{gloss-finnish.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-finnish.ldf}[polyglossia: module for Finnish]
 \PolyglossiaSetup{finnish}{
@@ -15102,51 +15097,54 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{finnish}{fi}
 
-\define at boolkey{finnish}[finnish@]{babelshorthands}[true]{}
-
 \newif\if at finnish@schoolhyphens
 \newif\if at finnish@babelhyphens
-\define at choicekey*+{finnish}{hyphens}[\xpg at val\xpg at nr]{default,school,babel}[default]{%
-   \ifcase\xpg at nr\relax
-      % default:
-      \@finnish at schoolhyphensfalse
-      \@finnish at babelhyphensfalse
-   \or
-      % school:
-      \@finnish at schoolhyphenstrue
-      \@finnish at babelhyphensfalse
-   \or
-      % babel:
-      \@finnish at schoolhyphensfalse
-      \@finnish at babelhyphenstrue
-   \fi
-   \xpg at info{Option: Finnish, hyphens=\xpg at val}%
-}{\xpg at warning{Unknown Finnish hyphens `#1'}}
 
-% backwards compatibility
-\define at boolkey{finnish}[finnish@]{schoolhyphens}[true]{%
-  \iffinnish at schoolhyphens
-      \@finnish at schoolhyphenstrue
-      \@finnish at babelhyphensfalse
-  \else
-      \@finnish at schoolhyphensfalse
-  \fi
-}
+\DeclareKeys[polyglossia/gloss/finnish]
+  {
+    babelshorthands.if = finnish at babelshorthands,
+    babelshorthands.default:n = true,
+    hyphens.choice:,
+    hyphens / default.code =
+      {%
+        \@finnish at schoolhyphensfalse
+        \@finnish at babelhyphensfalse
+      },
+    hyphens / school.code =
+      {%
+        \@finnish at schoolhyphenstrue
+        \@finnish at babelhyphensfalse
+      },
+    hyphens / babel.code =
+      {%
+        \@finnish at schoolhyphensfalse
+        \@finnish at babelhyphenstrue
+      },
+    hyphens.default:n = default,
+    hyphens/unknown.code = \xpg at warning{Unknown Finnish hyphens `#1'},
+    schoolhyphens.choice:,
+    schoolhyphens / true.code =
+      {%
+        \@finnish at schoolhyphenstrue
+        \@finnish at babelhyphensfalse
+      },
+    schoolhyphens / false.code =
+      {%
+        \@finnish at schoolhyphensfalse
+      },
+    schoolhyphens.default:n = true
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{finnish}{babelshorthands=false,hyphens=default}
+\InitializeGlossOptions{finnish}{babelshorthands=false,hyphens=default}
 
 \ifsystem at babelshorthands
-  \setkeys{finnish}{babelshorthands=true}
+  \SetGlossOptions{finnish}{babelshorthands=true}
 \else
-  \setkeys{finnish}{babelshorthands=false}
+  \SetGlossOptions{finnish}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-    \input{babelsh.def}%
-    \initiate at active@char{"}%
-    \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\finnish at shorthands{%
   \xpg at activate@shorthands%
@@ -15191,15 +15189,15 @@
 
 \def\finnish at language{%
   \if at finnish@schoolhyphens
-      \xpg at ifdefined{schoolfinnish}{%
-         \polyglossia at setup@language at patterns{schoolfinnish}%
+      \IfLanguageDefinedTF{schoolfinnish}{%
+         \SetupPolyglossiaLangPatterns{schoolfinnish}%
       }{%
            \xpg at warning{Finnish 'School' hyphenation patterns (schoolfinnish) not available.\MessageBreak
 	                I will use the standard patterns for Finnish instead}%
-	   \polyglossia at setup@language at patterns{finnish}%
+	   \SetupPolyglossiaLangPatterns{finnish}%
      }%
   \else
-      \polyglossia at setup@language at patterns{finnish}%
+      \SetupPolyglossiaLangPatterns{finnish}%
   \fi
 }
 
@@ -15253,13 +15251,13 @@
 % 
 % \subsection{gloss-fr-CA-u-sd-canb.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fr-CA-u-sd-canb.ldf}[polyglossia: module for fr-CA-u-sd-canb (Canadian French, Acadian subvariety)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 %    \end{macrocode}
 % \iffalse
@@ -15270,13 +15268,13 @@
 % 
 % \subsection{gloss-fr-CA.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fr-CA.ldf}[polyglossia: module for fr-CA (Canadian French)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 %    \end{macrocode}
 % \iffalse
@@ -15287,13 +15285,13 @@
 % 
 % \subsection{gloss-fr-CH.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fr-CH.ldf}[polyglossia: module for fr-CH (Swiss French)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 %    \end{macrocode}
 % \iffalse
@@ -15304,13 +15302,13 @@
 % 
 % \subsection{gloss-fr-FR.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fr-FR.ldf}[polyglossia: module for fr-FR (France's French)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 %    \end{macrocode}
 % \iffalse
@@ -15321,13 +15319,13 @@
 % 
 % \subsection{gloss-fr.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fr.ldf}[polyglossia: module for fr (French)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 %    \end{macrocode}
 % \iffalse
@@ -15338,7 +15336,7 @@
 % 
 % \subsection{gloss-french.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-french.ldf}[polyglossia: module for French]
 
@@ -15368,43 +15366,9 @@
 \setlanguagealias[variant=canadian]{french}{canadien}
 
 \def\french at variant{french}
-\define at choicekey*+{french}{variant}[\xpg at val\xpg at nr]{french,canadian,acadian,swiss}[french]{%
-   \ifcase\xpg at nr\relax
-      % french:
-      \def\french at variant{french}%
-      \SetLanguageKeys{french}{babelname=french,bcp47=fr-FR,bcp47-language=fr,bcp47-region=FR}%
-      \french at thincolonspacefalse
-   \or
-      % canadian:
-      \def\french at variant{canadien}%
-      \SetLanguageKeys{french}{babelname=canadien,bcp47=fr-CA,bcp47-language=fr,bcp47-region=CA,bcp47-extension-u=sd-caqc}%
-      \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}%
-      \french at thincolonspacefalse
-   \or
-      % acadian:
-      \def\french at variant{acadian}%
-      \SetLanguageKeys{french}{babelname=acadian,bcp47=fr-CA-u-sd-canb,bcp47-language=fr,bcp47-region=CA,bcp47-extension-u=sd-canb}%
-      \xpg at ifdefined{acadian}{}%
-      {\xpg at warning{No hyphenation patterns were loaded for "French (Canada, Acadian)"\MessageBreak
-        I will use the standard patterns for French instead}%
-      \adddialect\l at acadian\l at french\relax}%
-      \french at thincolonspacefalse
-   \or
-      % swiss:
-      \def\french at variant{swissfrench}%
-      \SetLanguageKeys{french}{babelname=french,bcp47=fr-CH,bcp47-language=fr,bcp47-region=CH}%
-      \adddialect\l at swissfrench\l at french\relax%
-      \french at thincolonspacetrue
-   \fi
-   \xpg at info{Option: French, variant=\xpg at val}%
-}{\xpg at warning{Unknown French variant `#1'}}
 
-
 \def\french at language{%
-   \polyglossia at setup@language at patterns{\french at variant}%
+   \SetupPolyglossiaLangPatterns{\french at variant}%
 }%
 
 \ifluatex
@@ -15424,52 +15388,14 @@
 % Save original footnote definition
 % Do this at the end of the preamble to catch other
 % packages' footnote changes (#391)
-\AtEndPreamble{%
+\AddToHook{begindocument/before}{%
   \let\xpg at orig@makefntext\@makefntext
 }
 
-\define at boolkey{french}[french@]{frenchfootnote}[true]{}
-
-\define at boolkey{french}[french@]{autospacing}[true]{}
-\french at autospacingtrue
-
-\define at boolkey{french}[french@]{frenchpart}[true]{}
-\french at frenchparttrue
-
-\newif\iffrench at autospaceguillemets
-\define at boolkey{french}[french@]{autospaceguillemets}[true]{}
-\french at autospaceguillemetstrue
-
-\newif\iffrench at thincolonspace
-\define at boolkey{french}[french@]{thincolonspace}[true]{}
-\french at thincolonspacefalse
-
-% Backwards compatibility
-\define at boolkey{french}[french@]{automaticspacesaroundguillemets}[true]{%
-   \iffrench at automaticspacesaroundguillemets
-       \setkeys{french}{autospaceguillemets=true}%
-   \else
-       \setkeys{french}{autospaceguillemets=false}%
-   \fi
-}
-
 % 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
-}
-
 % Configuration of item labels
 \def\french at itemi{\textemdash}
 \def\french at itemii{\textemdash}
@@ -15476,39 +15402,89 @@
 \def\french at itemiii{\textemdash}
 \def\french at itemiv{\textemdash}
 
-\define at key{french}{itemlabels}[\textemdash]{%
-  \def\french at itemi{#1}
-  \def\french at itemii{#1}
-  \def\french at itemiii{#1}
-  \def\french at itemiv{#1}
-}
+\newif\iffrench at autospacetypewriter
+\french at autospacetypewriterfalse
+\newif\iffrench at autospacing
+\french at autospacingtrue
+\newif\iffrench at frenchpart
+\french at frenchparttrue
+\newif\iffrench at autospaceguillemets
+\french at autospaceguillemetstrue
 
-\define at key{french}{itemlabeli}[\textemdash]{%
-  \def\french at itemi{#1}
-}
+\DeclareKeys[polyglossia/gloss/french]
+  {
+    variant.choice:,
+    variant / french.code = 
+      {%
+        \def\french at variant{french}%
+        \SetLanguageKeys{french}{babelname=french,bcp47=fr-FR,bcp47-language=fr,bcp47-region=FR}%
+        \french at thincolonspacefalse
+      },
+    variant / canadian.code = 
+      {%
+          \def\french at variant{canadien}%
+          \SetLanguageKeys{french}{babelname=canadien,bcp47=fr-CA,bcp47-language=fr,bcp47-region=CA,bcp47-extension-u=sd-caqc}%
+          \IfLanguageDefinedF{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}%
+          \french at thincolonspacefalse
+      },
+    variant / acadian.code =
+      {%
+          \def\french at variant{acadian}%
+          \SetLanguageKeys{french}{babelname=acadian,bcp47=fr-CA-u-sd-canb,bcp47-language=fr,bcp47-region=CA,bcp47-extension-u=sd-canb}%
+          \IfLanguageDefinedF{acadian}%
+            {\xpg at warning{No hyphenation patterns were loaded for "French (Canada, Acadian)"\MessageBreak
+              I will use the standard patterns for French instead}%
+             \adddialect\l at acadian\l at french\relax}%
+          \french at thincolonspacefalse
+      },
+    variant / swiss.code =
+      {%
+          \def\french at variant{swissfrench}%
+          \SetLanguageKeys{french}{babelname=french,bcp47=fr-CH,bcp47-language=fr,bcp47-region=CH}%
+          \adddialect\l at swissfrench\l at french\relax%
+          \french at thincolonspacetrue
+      },
+    variant.default:n = french,
+    variant/unknown.code = \xpg at warning{Unknown French variant `#1'},
+    frenchfootnote.if = french at frenchfootnote,
+    frenchfootnote.default:n = true,
+    autospacing.if = french at autospacing,
+    autospacing.default:n = true,
+    frenchpart.if = french at frenchpart,
+    frenchpart.default:n = true,
+    autospaceguillemets.if = french at autospaceguillemets,
+    autospaceguillemets.default:n = true,
+    thincolonspace.if = french at thincolonspace,
+    thincolonspace.default:n = true,
+    automaticspacesaroundguillemets.meta:n = {autospaceguillemets=#1},
+    autospacetypewriter.if = french at autospacetypewriter,
+    autospacetypewriter.default:n = true,
+    originaltypewriter.meta:n = {autospacetypewriter=#1},
+    itemlabeli.store = \french at itemi,
+    itemlabelii.store = \french at itemii,
+    itemlabeliii.store = \french at itemiii,
+    itemlabeliv.store = \french at itemiv,
+    frenchitemlabels.if = french at frenchitemlabels,
+    frenchitemlabels.default:n = true,
+    itemlabels.code = 
+      \def\french at itemi{#1}%
+      \def\french at itemii{#1}%
+      \def\french at itemiii{#1}%
+      \def\french at itemiv{#1},
+    itemlabels.default:n = \textemdash
+  }
 
-\define at key{french}{itemlabelii}[\textemdash]{%
-  \def\french at itemii{#1}
-}
-
-\define at key{french}{itemlabeliii}[\textemdash]{%
-  \def\french at itemiii{#1}
-}
-
-\define at key{french}{itemlabeliv}[\textemdash]{%
-  \def\french at itemiv{#1}
-}
-
-\define at boolkey{french}[french@]{frenchitemlabels}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{french}{variant=french,autospacing=true,thincolonspace=false,
+\InitializeGlossOptions{french}{variant=french,autospacing=true,thincolonspace=false,
                                       autospaceguillemets=true,autospacetypewriter=false,
                                       frenchfootnote=false,frenchitemlabels=false,
                                       itemlabels=\textemdash,itemlabeli=\textemdash,itemlabelii=\textemdash,
                                       itemlabeliii=\textemdash,itemlabeliv=\textemdash}
 % Register alias options
-\xpg at set@alias at values{french}{variant}{canadian}{acadian}
+\SetLanguageAliasValues{french}{variant}{canadian,acadian}
 
 
 \def\french at fontsetup{%
@@ -15679,100 +15655,100 @@
 \def\french at capsformat{%
    % Change part heading
    % With titlesec
-   \ifcsdef{titleformat}{%
-     \ifcsdef{NR at part}{% Hyperref (nameref)
-        \let\xpg at save@part at format\NR at part%
-        \patchcmd{\NR at part}%
-                  {\partname\nobreakspace\thepart}%
-                  {\xpg at french@part\nobreakspace\partname}%
-                  {}%
-                  {\xpg at warning{Failed to patch part for French}}%
-     }{% not hyperref
-       \ifcsdef{@part}{%
-          \let\xpg at save@part at format\@part%
-          \patchcmd{\@part}%
+   \@ifundefined{titleformat}{%
+     % With KOMA
+     \@ifundefined{sectionformat}{%
+       % With memoir
+       \@ifundefined{@memptsize}{%  (not \ifdefined\@memptsize)
+         % With standard classes
+         \@ifundefined{NR at part}{% not hyperref
+            \@ifundefined{@part}{}{%
+              \let\xpg at save@part at format\@part%
+              \patchcmd{\@part}%
+                       {\partname\nobreakspace\thepart}%
+                       {\xpg at french@part\nobreakspace\partname}%
+                       {}%
+                       {\@ifundefined{part}{}{\xpg at warning{Failed to patch part for French}}}%
+            }%  (end \ifdefined \@part)
+         }{% Hyperref
+           \let\xpg at save@part at format\NR at part%
+           \patchcmd{\NR at part}%
                     {\partname\nobreakspace\thepart}%
                     {\xpg at french@part\nobreakspace\partname}%
                     {}%
                     {\xpg at warning{Failed to patch part for French}}%
-       }{}%
-     }%
-   }{% (not \ifdefined\titleformat)
-     % With KOMA
-     \ifcsdef{sectionformat}{%
-        \ifcsdef{partformat}{%
-          \let\xpg at save@part at format\partformat%
-          \renewcommand{\partformat}{\xpg at french@part~\partname}%
-        }{}%
-     }{%  (not \ifdefined\sectionformat)
-       % With memoir
-       \ifcsdef{@memptsize}{%
-         \ifcsdef{NR at part}{% Hyperref (nameref)
+         }%  (end \ifdefined\NR at part)
+       }{%
+         \@ifundefined{NR at part}{% not hyperref
+            \@ifundefined{@part}{}{%
+              \let\xpg at save@part at format\@part%
+              \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
+                               {\partnamefont\xpg at french@part\partnamenum\printpartname}%
+                               {}%
+                               {\xpg at warning{Failed to patch part for French}}%
+             }%
+          }{% Hyperref (nameref)
            \let\xpg at save@part at format\NR at part%
            \patchcmd{\NR at part}{\printpartname \partnamenum \printpartnum}%
                             {\partnamefont\xpg at french@part\partnamenum\printpartname}%
                             {}%
                             {\xpg at warning{Failed to patch part for French}}%
-          }{% not hyperref
-            \ifcsdef{@part}{%
-              \let\xpg at save@part at format\@part%
-              \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
-                               {\partnamefont\xpg at french@part\partnamenum\printpartname}%
-                               {}%
-                               {\xpg at warning{Failed to patch part for French}}%
-             }{}%
           }%
-       }{%  (not \ifdefined\@memptsize)
-         % With standard classes
-         \ifcsdef{NR at part}{% Hyperref
-           \let\xpg at save@part at format\NR at part%
-           \patchcmd{\NR at part}%
+       }% (end \ifdefined\@memptsize)
+     }{%  (\ifdefined\sectionformat)
+        \@ifundefined{partformat}{}{%
+          \let\xpg at save@part at format\partformat%
+          \renewcommand{\partformat}{\xpg at french@part~\partname}%
+        }%
+     }% (end \ifdefined\sectionformat)
+   }{%  (\ifdefined\titleformat)
+     \@ifundefined{NR at part}{% not hyperref
+       \@ifundefined{@part}{}{%
+          \let\xpg at save@part at format\@part%
+          \patchcmd{\@part}%
                     {\partname\nobreakspace\thepart}%
                     {\xpg at french@part\nobreakspace\partname}%
                     {}%
                     {\xpg at warning{Failed to patch part for French}}%
-         }{% not hyperref
-            \ifcsdef{@part}{%
-              \let\xpg at save@part at format\@part%
-              \patchcmd{\@part}%
-                       {\partname\nobreakspace\thepart}%
-                       {\xpg at french@part\nobreakspace\partname}%
-                       {}%
-                       {\ifcsdef{part}{\xpg at warning{Failed to patch part for French}}{}}%
-            }{}%  (end \ifdefined \NR at part)
-         }%  (end \ifdefined\@part)
-       }% (end \ifdefined\@memptsize)
-     }% (end \ifdefined\sectionformat)
+       }%
+     }{% Hyperref (nameref)
+        \let\xpg at save@part at format\NR at part%
+        \patchcmd{\NR at part}%
+                  {\partname\nobreakspace\thepart}%
+                  {\xpg at french@part\nobreakspace\partname}%
+                  {}%
+                  {\xpg at warning{Failed to patch part for French}}%
+     }%
    }% (end \ifdefined\titleformat)
 }
 
 \def\nofrench at capsformat{%
    % Reset chapter and part heading
-   \ifcsdef{titleformat}{%
-      % With titlesec
-     \ifcsdef{xpg at save@part at format}{%
-        \ifcsdef{NR at part}{%
-            \let\NR at part\xpg at save@part at format%
-        }{%
-            \let\@part\xpg at save@part at format%
+   \@ifundefined{titleformat}{%
+     \@ifundefined{sectionformat}{%
+        % With memoir and standard classes
+        \@ifundefined{xpg at save@part at format}{}{%
+           \@ifundefined{NR at part}{%
+              \let\@part\xpg at save@part at format%
+           }{%
+              \let\NR at part\xpg at save@part at format%
+           }%
         }%
-     }{}%
-   }{% (not \ifdefined\titleformat)
-     \ifcsdef{sectionformat}{%
+     }{%
         % With KOMA
-        \ifcsdef{xpg at save@part at format}{%
+        \@ifundefined{xpg at save@part at format}{}{%
            \let\partformat\xpg at save@part at format
-        }{}%
-     }{%
-        % With memoir and standard classes
-        \ifcsdef{xpg at save@part at format}{%
-           \ifcsdef{NR at part}{%
-              \let\NR at part\xpg at save@part at format%
-           }{%
-              \let\@part\xpg at save@part at format%
-           }%
-        }{}%
+        }%
      }% (end \ifdefined\sectionformat)
+   }{% (\ifdefined\titleformat)
+      % With titlesec
+     \@ifundefined{xpg at save@part at format}{}{%
+        \@ifundefined{NR at part}{%
+            \let\@part\xpg at save@part at format%
+        }{%
+            \let\NR at part\xpg at save@part at format%
+        }%
+     }%
    }% (end \ifdefined\titleformat)
 }
 
@@ -15783,7 +15759,7 @@
   \if at xpg@french at footnote@set%
   \else%
    \iffrench at frenchfootnote%
-      \ifdefstring{\xpg at main@language}{french}{%
+      \IfMainLanguageTF{french}{%
          \ifx\@makefntext\undefined\else%
              \long\def\french at makefntext##1{%
                 \parindent1em \noindent\quad%
@@ -15807,7 +15783,7 @@
   \if at xpg@french at itemlabels@set%
   \else%
      \iffrench at frenchitemlabels
-      \ifdefstring{\xpg at main@language}{french}{%
+      \IfMainLanguageTF{french}{%
          \renewcommand{\labelitemi}{\french at itemi}%
          \renewcommand{\labelitemii}{\french at itemii}%
          \renewcommand{\labelitemiii}{\french at itemiii}%
@@ -15882,13 +15858,13 @@
 % 
 % \subsection{gloss-friulan.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-friulan.ldf}[polyglossia: module for Friulian]
 
 % We only provide this gloss for babel compatibility.
 
-\xpg at load@master at language{friulian}
+\InheritGlossFile{friulian}
 
 %    \end{macrocode}
 % \iffalse
@@ -15899,7 +15875,7 @@
 % 
 % \subsection{gloss-friulian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-friulian.ldf}[polyglossia: module for Friulian]
 
@@ -15953,7 +15929,7 @@
       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
+\AddToHook{begindocument/before}{% the user or the class might define different values
   \edef\xpgfu at savedvalues{%
     \clubpenalty=\the\clubpenalty\space
     \@clubpenalty=\the\@clubpenalty\space
@@ -15985,13 +15961,13 @@
 % 
 % \subsection{gloss-fur.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fur.ldf}[polyglossia: module for fur (Friulian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{friulian}
+\InheritGlossFile{friulian}
 
 %    \end{macrocode}
 % \iffalse
@@ -16002,13 +15978,13 @@
 % 
 % \subsection{gloss-ga.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ga.ldf}[polyglossia: module for ga (Gaelic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{gaelic}
+\InheritGlossFile{gaelic}
 
 %    \end{macrocode}
 % \iffalse
@@ -16019,7 +15995,7 @@
 % 
 % \subsection{gloss-gaelic.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-gaelic.ldf}[polyglossia: module for Gaelic]
 
@@ -16043,23 +16019,28 @@
 \setlanguagealias[variant=scottish]{gaelic}{scottish}
 
 \def\gaelic at variant{irish}
-\define at choicekey*+{gaelic}{variant}[\xpg at val\xpg at nr]{irish,scottish}[irish]{%
-   \ifcase\xpg at nr\relax
-      % irish:
-      \gdef\gaelic at variant{irish}%
-      \SetLanguageKeys{gaelic}{language=Irish,langtag=IRI,babelname=irish,bcp47=ga,bcp47-language=ga}%
-      \xpg at fontsetup@latin{gaelic}%
-   \or
-      % scottish:
-      \gdef\gaelic at variant{scottish}%
-      \SetLanguageKeys{gaelic}{language=Gaelic,langtag=GAE,babelname=scottish,bcp47=gd,bcp47-language=gd}%
-      \xpg at fontsetup@latin{gaelic}%
-   \fi
-   \xpg at info{Option: gaelic, variant=\xpg at val}%
-}{\xpg at warning{Unknown gaelic variant `#1'}}
 
+\DeclareKeys[polyglossia/gloss/gaelic]
+  {
+    variant.choice:,
+    variant / irish.code = 
+      {%
+        \gdef\gaelic at variant{irish}%
+        \SetLanguageKeys{gaelic}{language=Irish,langtag=IRI,babelname=irish,bcp47=ga,bcp47-language=ga}%
+        \SetupLatinPolyglossiaFont{gaelic}%
+      },
+    variant / scottish.code =
+      {%
+        \gdef\gaelic at variant{scottish}%
+        \SetLanguageKeys{gaelic}{language=Gaelic,langtag=GAE,babelname=scottish,bcp47=gd,bcp47-language=gd}%
+        \SetupLatinPolyglossiaFont{gaelic}%
+      },
+    variant.default:n = irish,
+    variant/unknown.code = \xpg at warning{Unknown gaelic variant `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{gaelic}{variant=irish}
+\InitializeGlossOptions{gaelic}{variant=irish}
 
 \def\captionsgaelic at irish{%
    \def\refname{Tagairtí}%
@@ -16149,7 +16130,7 @@
 % 
 % \subsection{gloss-galician.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-galician.ldf}[polyglossia: module for Galician]
 \PolyglossiaSetup{galician}{
@@ -16206,13 +16187,13 @@
 % 
 % \subsection{gloss-gd.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-gd.ldf}[polyglossia: module for gd (Gaelic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{gaelic}
+\InheritGlossFile{gaelic}
 
 %    \end{macrocode}
 % \iffalse
@@ -16223,7 +16204,7 @@
 % 
 % \subsection{gloss-georgian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-georgian.ldf}[polyglossia: module for Georgian]
 
@@ -16243,34 +16224,37 @@
 \setlanguagealias*{georgian}{ka}
 
 \newif\ifgeorgian at numerals
-\define at key{georgian}{numerals}[arabic]{%
-   \ifstrequal{#1}{georgian}%
-      {\georgian at numeralstrue%
-       \SetLanguageKeys{georgian}{bcp47-extension-u=nu-geor}%
-      }%
-      {\georgian at numeralsfalse%
-       \SetLanguageKeys{georgian}{bcp47-extension-u=nu-latn}%
-      }%
-}
 
-\define at boolkey{georgian}[georgian@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/georgian]
+  {
+    babelshorthands.if = georgian at babelshorthands,
+    babelshorthands.default:n = true,
+    oldmonthnames.if = georgian at oldmonthnames,
+    oldmonthnames.default:n = true,
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \georgian at numeralsfalse
+        \SetLanguageKeys{georgian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / georgian.code =
+      {%
+        \georgian at numeralstrue
+        \SetLanguageKeys{georgian}{bcp47-extension-u=nu-geor}%
+      },
+    numerals.default:n = arabic
+  }
 
-\define at boolkey{georgian}[georgian@]{oldmonthnames}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{georgian}{babelshorthands=false,oldmonthnames=false,numerals=arabic}
+\InitializeGlossOptions{georgian}{babelshorthands=false,oldmonthnames=false,numerals=arabic}
 
 \ifsystem at babelshorthands
-  \setkeys{georgian}{babelshorthands=true}
+  \SetGlossOptions{georgian}{babelshorthands=true}
 \else
-  \setkeys{georgian}{babelshorthands=false}
+  \SetGlossOptions{georgian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\georgian at shorthands{%
   \xpg at activate@shorthands%
@@ -16471,7 +16455,7 @@
 % 
 % \subsection{gloss-german.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-german.ldf}[polyglossia: module for German]
 
@@ -16520,51 +16504,11 @@
 
 \newif\if at german@oldspelling
 \@german at oldspellingfalse
-\define at choicekey*+{german}{spelling}[\xpg at val\xpg at nr]{new,old,1901,1996}[new]{%
-   \ifcase\xpg at nr\relax
-      % new:
-      \@german at oldspellingfalse
-   \or
-      % old:
-      \@german at oldspellingtrue
-   \or
-      % 1901:
-      \@german at oldspellingtrue
-   \or
-      % 1996:
-      \@german at oldspellingfalse
-   \fi
-   \german at set@babelname%
-   \xpg at info{Option: German, spelling=\xpg at val}%
-}{\xpg at warning{Unknown German spelling `#1'}}
 
 \newif\if at austrian@locale
 \@austrian at localefalse
 \newif\if at swiss@locale
 \@swiss at localefalse
-\define at choicekey*+{german}{variant}[\xpg at val\xpg at nr]{german,austrian,swiss}[german]{%
-   \ifcase\xpg at 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=\xpg at val}%
-}{\xpg at warning{Unknown German variant `#1'}}
 
 \def\german at set@babelname{%
   \if at german@oldspelling
@@ -16613,58 +16557,110 @@
 }
 
 \newif\if at german@blackletter
-\define at choicekey*+{german}{script}[\xpg at val\xpg at nr]{latin,blackletter,fraktur}[latin]{%
-   \ifcase\xpg at nr\relax
-      % latin:
-      \@german at blackletterfalse%
-   \or
-      % blackletter:
-      \@german at blacklettertrue%
-   \or
-      % fraktur:
-      \@german at blacklettertrue%
-   \fi
-   \german at set@babelname%
-   \xpg at info{Option: German, script=\xpg at val}%
-}{\xpg at warning{Unknown German script `#1'}}
 
-\define at boolkey{german}[german@]{capitaleszett}[true]{%
-  \ifgerman at capitaleszett
-     % MakeUppercase capitalizes the eszett (U+00DF) with U+1E9E
-     \SetLanguageKeys{german}{bcp47-casing=de-x-eszett,bcp47-extension-x=eszett}
-  \else
-     % Capitalize eszett as <SS>
-     \SetLanguageKeys{german}{bcp47-casing=de,bcp47-extension-x={}}
-  \fi
-}
+\DeclareKeys[polyglossia/gloss/german]
+  {
+    babelshorthands.if = german at babelshorthands,
+    babelshorthands.default:n = true,
+    latesthyphen.if = german at latesthyphen,
+    latesthyphen.default:n = true,
+    capitaleszett.choice:,
+    capitaleszett / true.code = 
+      {% MakeUppercase capitalizes the eszett (U+00DF) with U+1E9E
+        \SetLanguageKeys{german}{bcp47-casing=de-x-eszett,bcp47-extension-x=eszett}%
+      },
+    capitaleszett / false.code =
+      {% Capitalize eszett as <SS>
+        \SetLanguageKeys{german}{bcp47-casing=de,bcp47-extension-x={}}%
+      },
+    capitaleszett.default:n = true,
+    script.choice:,
+    script / latin.code =
+      {%
+        \@german at blackletterfalse
+        \german at set@babelname
+      },
+    script / blackletter.code =
+      {%
+        \@german at blacklettertrue
+        \german at set@babelname
+      },
+    script / fraktur.code =
+      {%
+        \@german at blacklettertrue
+        \german at set@babelname
+      },
+    script.default:n = latin,
+    script/unknown.code = \xpg at warning{Unknown German script `#1'},
+    spelling.choice:,
+    spelling / new.code =
+      {%
+        \@german at oldspellingfalse
+        \german at set@babelname
+      },
+    spelling / old.code =
+      {%
+        \@german at oldspellingtrue
+        \german at set@babelname
+      },
+    spelling / 1901.code =
+      {%
+        \@german at oldspellingtrue
+        \german at set@babelname
+      },
+    spelling / 1996.code =
+      {%
+        \@german at oldspellingfalse
+        \german at set@babelname
+      },
+    spelling.default:n = new,
+    spelling/unknown.code = \xpg at warning{Unknown German spelling `#1'},
+    variant.choice:,
+    variant / german.code =
+      {%
+        \@swiss at localefalse
+        \@austrian at localefalse
+        \german at set@babelname
+      },
+    variant / austrian.code =
+      {%
+        \@austrian at localetrue
+        \@swiss at localefalse
+        \german at set@babelname
+      },
+    variant / swiss.code =
+      {%
+        \@swiss at localetrue
+        \@austrian at localefalse
+        \IfLanguageDefinedF{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
+           }%
+        \german at set@babelname
+      },
+    variant.default:n = german,
+    variant/unknown.code = \xpg at warning{Unknown German variant `#1'}
+  }
+  
 
+\SetGlossOptions{german}{spelling,script,variant}
 
-% Option defunc'ed, as both XeTeX and LuaTeX meanwhile
-% use the experimental German hyphenation patterns by default.
-\define at boolkey{german}[german@]{latesthyphen}[true]{}
-
-\define at boolkey{german}[german@]{babelshorthands}[true]{}
-
-\setkeys{german}{spelling,script,variant}
-
 % Register default options
-\xpg at initialize@gloss at options{german}{variant=german,spelling=new,script=latin,babelshorthands=false}
+\InitializeGlossOptions{german}{variant=german,spelling=new,script=latin,babelshorthands=false}
 % Register alias options
-\xpg at set@alias at values{german}{spelling}{new}{1996}
-\xpg at set@alias at values{german}{spelling}{old}{1901}
-\xpg at set@alias at values{german}{script}{blackletter}{fraktur}
+\SetLanguageAliasValues{german}{spelling}{new,1996}
+\SetLanguageAliasValues{german}{spelling}{old,1901}
+\SetLanguageAliasValues{german}{script}{blackletter,fraktur}
 
 \ifsystem at babelshorthands
-  \setkeys{german}{babelshorthands=true}
+  \SetGlossOptions{german}{babelshorthands=true}
 \else
-  \setkeys{german}{babelshorthands=false}
+  \SetGlossOptions{german}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\german at shorthands{%
   \xpg at activate@shorthands%
@@ -16786,15 +16782,15 @@
 \def\german at language{%
   \if at german@oldspelling
       \if at swiss@locale
-          \polyglossia at setup@language at patterns{swissgerman}%
+          \SetupPolyglossiaLangPatterns{swissgerman}%
       \else
-          \polyglossia at setup@language at patterns{german}%
+          \SetupPolyglossiaLangPatterns{german}%
       \fi
       \if at austrian@locale
          \adddialect\l at austrian\l at german%
       \fi
   \else
-      \polyglossia at setup@language at patterns{ngerman}%
+      \SetupPolyglossiaLangPatterns{ngerman}%
       \if at austrian@locale
          \adddialect\l at naustrian\l at ngerman%
       \fi
@@ -16825,13 +16821,13 @@
 % 
 % \subsection{gloss-germanb.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-germanb.ldf}[polyglossia: module for German (old spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -16842,13 +16838,13 @@
 % 
 % \subsection{gloss-gl.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-gl.ldf}[polyglossia: module for gl (Galician)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{galician}
+\InheritGlossFile{galician}
 
 %    \end{macrocode}
 % \iffalse
@@ -16859,13 +16855,13 @@
 % 
 % \subsection{gloss-grc.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-grc.ldf}[polyglossia: module for grc (Greek)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{greek}
+\InheritGlossFile{greek}
 
 %    \end{macrocode}
 % \iffalse
@@ -16876,7 +16872,7 @@
 % 
 % \subsection{gloss-greek.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-greek.ldf}[polyglossia: module for Greek]
 
@@ -16900,7 +16896,7 @@
 
 % BCP-47 compliant aliases
 \setlanguagealias*[variant=ancient]{greek}{grc}
-\setlanguagealias*[varant=polytonic]{greek}{el-polyton}
+\setlanguagealias*[variant=polytonic]{greek}{el-polyton}
 \setlanguagealias*[variant=monotonic]{greek}{el-monoton}
 \setlanguagealias*{greek}{el}
 
@@ -16920,44 +16916,9 @@
 \newif\if at greek@ancient\@greek at ancientfalse
 \newif\if at greek@poly\@greek at polyfalse
 
-\define at choicekey*+{greek}{variant}[\xpg at val\xpg at nr]{monotonic,mono,polytonic,poly,ancient,ancientgreek}[monotonic]{%
-   \xpg at ifdefined{greek}{}{%
-      \xpg at nopatterns{greek}%
-      \adddialect\l at greek\l at nohyphenation
-   }%
-   \ifcase\xpg at nr\relax
-      % monotonic:
-      \@greek at polyfalse
-      \@greek at ancientfalse
-   \or
-      % mono:
-      \@greek at polyfalse
-      \@greek at ancientfalse
-   \or
-      % polytonic:
-      \@greek at polytrue
-      \@greek at ancientfalse
-   \or
-      % poly:
-      \@greek at polytrue
-      \@greek at ancientfalse
-   \or
-      % ancient:
-      \@greek at polyfalse
-      \@greek at ancienttrue
-   \or
-      % ancientgreek:
-      \@greek at polyfalse
-      \@greek at ancienttrue
-   \fi
-   \greek at set@langdata
-   \xpg at info{Option: Greek, variant=\xpg at val}%
-}{\xpg at warning{Unknown Greek variant `#1'}}
-
-
 \def\greek at set@langdata{%
    \if at greek@ancient
-       \xpg at ifdefined{ancientgreek}{}%
+       \IfLanguageDefinedF{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}%
@@ -16967,7 +16928,7 @@
        \SetLanguageKeys{greek}{babelname=greek,bcp47=grc,bcp47-language=grc,bcp47-variant={}}%
    \else
       \if at greek@poly
-          \xpg at ifdefined{polygreek}{}%
+          \IfLanguageDefinedF{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}%
@@ -16976,7 +16937,7 @@
           \def\dategreek{\datepolygreek}%
           \SetLanguageKeys{greek}{babelname=polutonikogreek,bcp47=el-polyton,bcp47-language=el,bcp47-variant=polyton}%
       \else% monotonic greek
-          \xpg at ifdefined{monogreek}{}%
+          \IfLanguageDefinedF{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}%
@@ -16990,42 +16951,85 @@
 
 
 \def\greek at language{%
-  \polyglossia at setup@language at patterns{\greek at variant}%
+  \SetupPolyglossiaLangPatterns{\greek at variant}%
 }
 
 
 \newif\if at greek@numerals
-\define at choicekey*+{greek}{numerals}[\xpg at val\xpg at nr]{greek,arabic}[greek]{%
-   \ifcase\xpg at nr\relax
-      % greek:
-      \@greek at numeralstrue%
-      \SetLanguageKeys{greek}{bcp47-extension-u=nu-grek}%
-   \or
-      % arabic:
-      \@greek at numeralsfalse%
-      \SetLanguageKeys{greek}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Greek, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Greek numerals value `#1'}}
 
+\DeclareKeys[polyglossia/gloss/greek]
+  {
+    variant.choices:nn = { monotonic, mono,polytonic, poly,ancient, ancientgreek }
+      {%
+        \CheckHyphenationPatterns{greek}%
+        \ifcase\UseName{l_keys_choice_int}\or
+          % monotonic:
+          \@greek at polyfalse
+          \@greek at ancientfalse
+        \or
+          % mono:
+          \@greek at polyfalse
+          \@greek at ancientfalse
+        \or
+          % polytonic:
+          \@greek at polytrue
+          \@greek at ancientfalse
+        \or
+          % poly:
+          \@greek at polytrue
+          \@greek at ancientfalse
+        \or
+          % ancient:
+          \@greek at polyfalse
+          \@greek at ancienttrue
+        \or
+          % ancientgreek:
+          \@greek at polyfalse
+          \@greek at ancienttrue
+        \fi
+        \greek at set@langdata
+      },
+    variant.default:n = monotonic,
+    variant/unknown.code = \xpg at warning{Unknown Greek variant `#1'},
+    numerals.choice:,
+    numerals / greek.code =
+      {%      
+        \@greek at numeralstrue
+        \SetLanguageKeys{greek}{bcp47-extension-u=nu-grek}%
+      },
+    numerals / arabic.code =
+      {%
+        \@greek at numeralsfalse
+        \SetLanguageKeys{greek}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = greek,
+    numerals/unknown.code = \xpg at warning{Unknown Greek numerals value `#1'},
+    capitaliota.choice:,
+    capitaliota / true.code =
+      {%
+        \@greek at capitaliotatrue
+        % \MakeUppercase converts the ypogegrammeni (subscript muted iota) to capital iota
+        \SetLanguageKeys{greek}{bcp47-casing=el-x-iota,bcp47-extension-x=iota}%
+      },
+    capitaliota / false.code =
+      {%
+        \@greek at capitaliotafalse
+        % \MakeUppercase retains the subscript versions (default)
+        \SetLanguageKeys{greek}{bcp47-casing=el,bcp47-extension-x={}}%
+      },
+    capitaliota.default:n = true,
+    attic.choices:nn = { true, false }
+      {%
+        \xpg at warning{Greek option `attic' is no longer required.}
+      },
+    capitaliota.default:n = true,
+  }
 
-\define at boolkey{greek}[greek@]{capitaliota}[true]{%
-  \ifgreek at capitaliota
-     % \MakeUppercase converts the ypogegrammeni (subscript muted iota) to capital iota
-     \SetLanguageKeys{greek}{bcp47-casing=el-x-iota,bcp47-extension-x=iota}
-  \else
-     % \MakeUppercase retains the subscript versions (default)
-     \SetLanguageKeys{greek}{bcp47-casing=el,bcp47-extension-x={}}
-  \fi
-}
-
-\define at boolkey{greek}{attic}[true]{\xpg at warning{Greek option `attic' is no longer required.}}
-
 % Register default options
-\xpg at initialize@gloss at options{greek}{variant=monotonic,numerals=greek}
+\InitializeGlossOptions{greek}{variant=monotonic,numerals=greek}
 % Register alias options
-\xpg at set@alias at values{greek}{variant}{monotonic}{mono}
-\xpg at set@alias at values{greek}{variant}{polytonic}{poly}
+\SetLanguageAliasValues{greek}{variant}{monotonic,mono}
+\SetLanguageAliasValues{greek}{variant}{polytonic,poly}
 
 \def\monogreekcaptions{%
    \def\refname{Αναφορές}%
@@ -17344,13 +17348,13 @@
 % 
 % \subsection{gloss-he.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-he.ldf}[polyglossia: module for he (Hebrew)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{hebrew}
+\InheritGlossFile{hebrew}
 
 %    \end{macrocode}
 % \iffalse
@@ -17361,7 +17365,7 @@
 % 
 % \subsection{gloss-hebrew.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hebrew.ldf}[polyglossia: module for Hebrew]
 
@@ -17387,41 +17391,48 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{hebrew}{he}
 
-% hebrewcal options
-\define at key{hebrew}{marcheshvan}[true]{\setkeys{hebrewcal}{marcheshvan=#1}}
-\define at key{hebrew}{transliteration}[alt]{\setkeys{hebrewcal}{transliteration=#1}}
-\define at key{hebrew}{fullyear}[true]{\setkeys{hebrewcal}{fullyear=#1}}
-
 \newif\if at calendar@hebrew
-\define at choicekey*+{hebrew}{calendar}[\xpg at val\xpg at nr]{hebrew,gregorian}[gregorian]{%
-   \ifcase\xpg at nr\relax
-      % hebrew:
-      \@calendar at hebrewtrue
-   \or
-      % gregorian:
-      \@calendar at hebrewfalse
-   \fi
-   \xpg at info{Option: Hebrew, calendar=\xpg at val}%
-}{\xpg at warning{Unknown Hebrew calendar `#1'}}
-
 \newif\if at hebrew@numerals
-\define at choicekey*+{hebrew}{numerals}[\xpg at val\xpg at nr]{hebrew,arabic}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % hebrew:
-      \@hebrew at numeralstrue
-      \SetLanguageKeys{hebrew}{bcp47-extension-u=nu-hebr}%
-   \or
-      % arabic:
-      \@hebrew at numeralsfalse
-      \SetLanguageKeys{hebrew}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Hebrew, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Hebrew numerals value `#1'}}
 
-\setkeys{hebrew}{numerals}
+\DeclareKeys[polyglossia/gloss/hebrew]
+  {
+    marcheshvan.code = \setkeys{hebrewcal}{marcheshvan=#1},
+    marcheshvan.default:n = true,
+    transliteration.code = \setkeys{hebrewcal}{transliteration=#1},
+    transliteration.default:n = alt,
+    fullyear.code = \setkeys{hebrewcal}{fullyear=#1},
+    fullyear.default:n = true,
+    calendar.choice:,
+    calendar / hebrew.code =
+      {%
+        \@calendar at hebrewtrue
+      },
+    calendar / gregorian.code =
+      {%
+        \@calendar at hebrewfalse
+      },
+    calendar.default:n = gregorian,
+    calendar/unknown.code = \xpg at warning{Unknown Hebrew calendar `#1'},
+    numerals.choice:,
+    numerals / hebrew.code =
+      {%
+        \@hebrew at numeralstrue
+        \SetLanguageKeys{hebrew}{bcp47-extension-u=nu-hebr}%
+      },
+    numerals / arabic.code =
+      {%
+        \@hebrew at numeralsfalse
+        \SetLanguageKeys{hebrew}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Hebrew numerals value `#1'}
+  }
 
+
+\SetGlossOptions{hebrew}{numerals}
+
 % Register default options
-\xpg at initialize@gloss at options{hebrew}{numerals=arabic,calendar=gregorian,marcheshvan=false,fullyear=false}
+\InitializeGlossOptions{hebrew}{numerals=arabic,calendar=gregorian,marcheshvan=false,fullyear=false}
 
 \def\captionshebrew{%
   \def\prefacename{מבוא}%
@@ -17535,13 +17546,13 @@
 % 
 % \subsection{gloss-hi.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hi.ldf}[polyglossia: module for hi (Hindi)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{hindi}
+\InheritGlossFile{hindi}
 
 %    \end{macrocode}
 % \iffalse
@@ -17552,7 +17563,7 @@
 % 
 % \subsection{gloss-hindi.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % UTF-8 strings kindly provided by Zdenĕk Wagner, 10-03-2008
 % with corrections and additional contributions by Anshuman Pandey
@@ -17579,8 +17590,7 @@
 
 \ifx\l at hindi\@undefined%
   \ifx\l at sanskrit\@undefined%
-    \xpg at nopatterns{Hindi}%
-    \adddialect\l at hindi\l at nohyphenation%
+    \XPGNoPatternsFallback{hindi}%
   \else
     \xpg at warning{No hyphenation patterns were loaded for Hindi\MessageBreak
     I will use the patterns for Sanskrit instead}
@@ -17589,26 +17599,31 @@
 \fi
 
 \def\hindi at language{%
-  \polyglossia at setup@language at patterns{hindi}%
+  \SetupPolyglossiaLangPatterns{hindi}%
 }
 
 \newif\ifhindi at devanagari@numerals
 \hindi at devanagari@numeralstrue
-\define at choicekey*+{hindi}{numerals}[\xpg at val\xpg at nr]{Devanagari,Western}[Devanagari]{%
-   \ifcase\xpg at nr\relax
-      % Devanagari:
-      \hindi at devanagari@numeralstrue%
-      \SetLanguageKeys{hindi}{bcp47-extension-u=nu-deva}%
-   \or
-      % Western:
-      \hindi at devanagari@numeralsfalse%
-      \SetLanguageKeys{hindi}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Hindi, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Hindi numeral `#1'}}
 
+\DeclareKeys[polyglossia/gloss/hindi]
+  {
+    numerals.choice:,
+    numerals / devanagari.code =
+      {%
+        \hindi at devanagari@numeralstrue
+        \SetLanguageKeys{hindi}{bcp47-extension-u=nu-deva}%
+      },
+    numerals / western.code =
+      {%
+          \hindi at devanagari@numeralsfalse
+          \SetLanguageKeys{hindi}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = devanagari,
+    numerals/unknown.code = \xpg at warning{Unknown Hindi numeral `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{hindi}{numerals=devanagari}
+\InitializeGlossOptions{hindi}{numerals=devanagari}
 
 \newcommand{\hindinumerals}[2]{\hindinumber{#2}}
 
@@ -17628,6 +17643,7 @@
      \def\contentsname{विषय सूची}%
      \def\enclname{}%
      \def\figurename{चित्र}% रेखाचित्र
+     \def\glossaryname{शब्दार्थ सूची}%
      \def\headpagename{पृष्ठ}%
      \def\headtoname{}%
      \def\indexname{सूची}%
@@ -17639,6 +17655,7 @@
      \def\pagename{पृष्ठ}%
      \def\partname{खण्ड}%
      \def\prefacename{प्रस्तावना}% प्राक्कथन
+     \def\proofname{प्रमाण}%
      \def\refname{हवाले}%
      \def\tablename{तालिका}%
      \def\seename{देखिए}%
@@ -17671,13 +17688,13 @@
 % 
 % \subsection{gloss-hr.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hr.ldf}[polyglossia: module for hr (Croatian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{croatian}
+\InheritGlossFile{croatian}
 
 %    \end{macrocode}
 % \iffalse
@@ -17688,13 +17705,13 @@
 % 
 % \subsection{gloss-hsb.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hsb.ldf}[polyglossia: module for hsb (Higher Sorbian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 %    \end{macrocode}
 % \iffalse
@@ -17705,13 +17722,13 @@
 % 
 % \subsection{gloss-hu.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hu.ldf}[polyglossia: module for hu (Hungarian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{hungarian}
+\InheritGlossFile{hungarian}
 
 %    \end{macrocode}
 % \iffalse
@@ -17722,7 +17739,7 @@
 % 
 % \subsection{gloss-hungarian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hungarian.ldf}[polyglossia: module for Hungarian]
 
@@ -17749,53 +17766,61 @@
 \newif\if at hungarian@swapcaptions
 \newif\if at hungarian@swapheadings
 \newif\if at hungarian@swapheaders
-\define at choicekey*+{hungarian}{swapstrings}[\xpg at val\xpg at nr]{all,captions,headings,headers,hheaders,none}[all]{%
-   \ifcase\xpg at nr\relax
-      % all:
-      \@hungarian at swapcaptionstrue%
-      \@hungarian at swapheadingstrue%
-      \@hungarian at swapheaderstrue%
-   \or
-      % captions:
-      \@hungarian at swapcaptionstrue%
-      \@hungarian at swapheadingsfalse%
-      \@hungarian at swapheadersfalse%
-   \or
-      % headings:
-      \@hungarian at swapcaptionsfalse%
-      \@hungarian at swapheadingstrue%
-      \@hungarian at swapheadersfalse%
-   \or
-      % headers:
-      \@hungarian at swapcaptionsfalse%
-      \@hungarian at swapheadingsfalse%
-      \@hungarian at swapheaderstrue%
-   \or
-      % hheaders:
-      \@hungarian at swapcaptionsfalse%
-      \@hungarian at swapheadingstrue%
-      \@hungarian at swapheaderstrue%
-   \or
-      % none:
-      \@hungarian at swapcaptionsfalse%
-      \@hungarian at swapheadingsfalse%
-      \@hungarian at swapheadersfalse%
-   \fi
-   \xpg at info{Option: Hungarian, swapstrings=\xpg at val}%
-}{\xpg at warning{Unknown Hungarian swapstrings value `#1'}}
 
-% Force punctuation: 1) after section type counters; 2) after @chapapp in the running head
-\define at boolkey{hungarian}[hungarian@]{forceheadingpunctuation}[true]{}
+\DeclareKeys[polyglossia/gloss/hungarian]
+  {
+    forceheadingpunctuation.if = hungarian at forceheadingpunctuation,
+    forceheadingpunctuation.default:n = true,
+    swapstrings.choice:,
+    swapstrings / all.code =
+      {%
+        \@hungarian at swapcaptionstrue
+        \@hungarian at swapheadingstrue
+        \@hungarian at swapheaderstrue
+      },
+    swapstrings / captions.code =
+      {%
+        \@hungarian at swapcaptionstrue
+        \@hungarian at swapheadingsfalse
+        \@hungarian at swapheadersfalse
+      },
+    swapstrings / headings.code = 
+      {%
+        \@hungarian at swapcaptionsfalse
+        \@hungarian at swapheadingstrue
+        \@hungarian at swapheadersfalse
+      },
+    swapstrings / headers.code =
+      {%
+        \@hungarian at swapcaptionsfalse
+        \@hungarian at swapheadingsfalse
+        \@hungarian at swapheaderstrue
+      },
+    swapstrings / hheaders.code =
+      {%
+        \@hungarian at swapcaptionsfalse
+        \@hungarian at swapheadingstrue
+        \@hungarian at swapheaderstrue
+      },
+    swapstrings / none.code = 
+      {%
+        \@hungarian at swapcaptionsfalse
+        \@hungarian at swapheadingsfalse
+        \@hungarian at swapheadersfalse
+      },
+    swapstrings.default:n = all,
+    swapstrings/unknown.code = \xpg at warning{Unknown Hungarian swapstrings value `#1'}
+  }
 
 % Register default options
 % forceheadinpunctuatin is recommended, but the default value is false for compatibility reasons
-\xpg at initialize@gloss at options{hungarian}{swapstrings=all,
+\InitializeGlossOptions{hungarian}{swapstrings=all,
                                          forceheadingpunctuation=false}
 
 
 \def\hungarian at language{%
-   \polyglossia at setup@language at patterns{hungarian}%
-   \xpg at ifdefined{hungarian}{\adddialect\l at magyar\l at hungarian}{}%
+   \SetupPolyglossiaLangPatterns{hungarian}%
+   \IfLanguageDefinedT{hungarian}{\adddialect\l at magyar\l at hungarian}%
 }%
 
 \def\captionshungarian{%
@@ -17867,69 +17892,13 @@
   % change chapter and part headings
   \if at hungarian@swapheadings
      % With titlesec
-     \ifcsdef{titleformat}{%
-       \ifcsdef{NR at part}{% Hyperref (nameref)
-            \let\xpg at save@part at format\NR at part%
-            \patchcmd{\NR at part}%
-                      {\partname\nobreakspace\thepart}%
-                      {\thepart.\nobreakspace\partname}%
-                      {}%
-                      {\xpg at warning{Failed to patch part for Hungarian}}%
-       }{% not hyperref
-         \ifcsdef{@part}{%
-            \let\xpg at save@part at format\@part%
-            \patchcmd{\@part}%
-                      {\partname\nobreakspace\thepart}%
-                      {\thepart.\nobreakspace\partname}%
-                      {}%
-                      {\xpg at warning{Failed to patch part for Hungarian}}%
-         }{}%
-       }
-       \ifcsdef{chapter}{%
-          \titleformat\chapter[display]%
-             {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
-             {\thechapter.\space\@chapapp}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
-       }{}%
-     }{% (not \ifdefined\titleformat)
+     \@ifundefined{titleformat}{%
        % With KOMA
-       \ifcsdef{sectionformat}{%
-          \ifcsdef{partformat}{%
-            \let\xpg at save@part at format\partformat%
-            \renewcommand{\partformat}{\thepart.~\partname}%
-          }{}%
-          \ifcsdef{chapterformat}{%
-            \let\xpg at save@chap at format\chapterformat%
-            \renewcommand{\chapterformat}{\mbox{\thechapter\autodot%
-                                          \IfUsePrefixLine{\nobreakspace\chapapp}{\enskip}}}%
-          }{}%
-       }{%  (not \ifdefined\sectionformat)
-         % With memoir
-         \ifcsdef{@memptsize}{%
-           \ifcsdef{@makechapterhead}{%
-              \let\xpg at save@chap at format\@makechapterhead%
-              \patchcmd{\@makechapterhead}{\printchaptername \chapternamenum \printchapternum}%
-                       {\printchapternum.\chapternamenum\printchaptername}%
-                       {}%
-                       {\xpg at warning{Failed to patch chapter for Hungarian}}%
-           }{}%
-           \ifcsdef{NR at part}{% Hyperref (nameref)
-                \let\xpg at save@part at format\NR at part%
-                \patchcmd{\NR at part}{\printpartname \partnamenum \printpartnum}%
-                                 {\printpartnum.\partnamenum\printpartname}%
-                                 {}%
-                                 {\xpg at warning{Failed to patch part for Hungarian}}%
-           }{% not hyperref
-             \ifcsdef{@part}{%
-                \let\xpg at save@part at format\@part%
-                \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
-                                 {\printpartnum.\partnamenum\printpartname}%
-                                 {}%
-                                 {\xpg at warning{Failed to patch part for Hungarian}}%
-             }{}%
-           }%
-         }{%  (not \ifdefined\@memptsize)
+       \@ifundefined{sectionformat}{%
+         % Memoir?
+         \@ifundefined{@memptsize}{%
            % With standard classes
-            \ifcsdef{@makechapterhead}{%
+            \@ifundefined{@makechapterhead}{}{%
               \let\xpg at save@chap at format\@makechapterhead%
               \patchcmd{\@makechapterhead}%
                        {\@chapapp\space \thechapter}%
@@ -17936,8 +17905,17 @@
                        {\thechapter.\space \@chapapp}%
                        {}%
                        {\xpg at warning{Failed to patch chapter for Hungarian}}%
-            }{}%
-            \ifcsdef{NR at part}{% Hyperref (nameref)
+            }%
+            \@ifundefined{NR at part}{% not hyperref
+              \@ifundefined{@part}{}{%
+                \let\xpg at save@part at format\@part%
+                \patchcmd{\@part}%
+                         {\partname\nobreakspace\thepart}%
+                         {\thepart.\nobreakspace\partname}%
+                         {}%
+                         {\@ifundefined{part}{}{\xpg at warning{Failed to patch part for Hungarian}}}%
+              }%  (end \ifdefined\@part)
+            }{% Hyperref (nameref)
               \let\xpg at save@part at format\NR at part%
               \patchcmd{\NR at part}%
                        {\partname\nobreakspace\thepart}%
@@ -17944,30 +17922,85 @@
                        {\thepart.\nobreakspace\partname}%
                        {}%
                        {\xpg at warning{Failed to patch part for Hungarian}}%
-            }{% not hyperref
-              \ifcsdef{@part}{%
+            }% (end not hyperref)
+          }{% with memoir (\ifdefined\@memptsize)
+           \@ifundefined{@makechapterhead}{}{%
+              \let\xpg at save@chap at format\@makechapterhead%
+              \patchcmd{\@makechapterhead}{\printchaptername \chapternamenum \printchapternum}%
+                       {\printchapternum.\chapternamenum\printchaptername}%
+                       {}%
+                       {\xpg at warning{Failed to patch chapter for Hungarian}}%
+           }%
+           \@ifundefined{NR at part}{% not hyperref
+             \@ifundefined{@part}{}{%
                 \let\xpg at save@part at format\@part%
-                \patchcmd{\@part}%
-                         {\partname\nobreakspace\thepart}%
-                         {\thepart.\nobreakspace\partname}%
-                         {}%
-                         {\ifcsdef{part}{\xpg at warning{Failed to patch part for Hungarian}}{}}%
-              }{}%  (end \ifdefined\@part)
-            }% (end not hyperref)
-          }% (end \ifdefined\@memptsize)
-        }% (end \ifdefined\sectionformat)
+                \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
+                                 {\printpartnum.\partnamenum\printpartname}%
+                                 {}%
+                                 {\xpg at warning{Failed to patch part for Hungarian}}%
+             }%
+           }{% Hyperref (nameref)
+                \let\xpg at save@part at format\NR at part%
+                \patchcmd{\NR at part}{\printpartname \partnamenum \printpartnum}%
+                                 {\printpartnum.\partnamenum\printpartname}%
+                                 {}%
+                                 {\xpg at warning{Failed to patch part for Hungarian}}%
+           }%
+         }% (end \ifdefined\@memptsize)
+        }{% (\ifdefined\sectionformat)
+          \@ifundefined{partformat}{}{%
+            \let\xpg at save@part at format\partformat%
+            \renewcommand{\partformat}{\thepart.~\partname}%
+          }%
+          \@ifundefined{chapterformat}{}{%
+            \let\xpg at save@chap at format\chapterformat%
+            \renewcommand{\chapterformat}{\mbox{\thechapter\autodot%
+                                          \IfUsePrefixLine{\nobreakspace\chapapp}{\enskip}}}%
+          }%
+       }% (end \ifdefined\sectionformat)
+     }{% (\ifdefined\titleformat)
+       \@ifundefined{NR at part}{% not hyperref
+         \@ifundefined{@part}{}{%
+            \let\xpg at save@part at format\@part%
+            \patchcmd{\@part}%
+                      {\partname\nobreakspace\thepart}%
+                      {\thepart.\nobreakspace\partname}%
+                      {}%
+                      {\xpg at warning{Failed to patch part for Hungarian}}%
+         }%
+       }{% Hyperref (nameref)
+            \let\xpg at save@part at format\NR at part%
+            \patchcmd{\NR at part}%
+                      {\partname\nobreakspace\thepart}%
+                      {\thepart.\nobreakspace\partname}%
+                      {}%
+                      {\xpg at warning{Failed to patch part for Hungarian}}%
+       }%
+       \@ifundefined{chapter}{}{%
+          \titleformat\chapter[display]%
+             {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
+             {\thechapter.\space\@chapapp}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
+       }%
      }% (end \ifdefined\titleformat)
   \fi% (end \if at hungarian@swapheadings)
   %
   % Change running headers
   \if at hungarian@swapheaders
-    \ifcsdef{chapterformat}{%
-      % With KOMA
-      \let\xpg at save@chaptermark at format\chaptermarkformat%
-      \renewcommand*\chaptermarkformat{%
-         \thechapter\autodot\ \IfChapterUsesPrefixLine{\chapapp\@hungarian at forced@dot\enskip}{}}
-    }{% (not \ifdefined\chapterformat)
-      \ifcsdef{@memptsize}{%
+    \@ifundefined{chapterformat}{%
+      \@ifundefined{@memptsize}{%
+        % With standard classes
+        \@ifundefined{chaptermark}{}{%
+          \ifpatchable{\chaptermark}%
+               {\@chapapp\ \thechapter.}%
+               {\let\xpg at save@chaptermark at format\chaptermark%
+                \patchcmd{\chaptermark}%
+                    {\@chapapp\ \thechapter.}%
+                    {\thechapter.\ \@chapapp\@hungarian at forced@dot}%
+                    {}%
+                    {\xpg at warning{Failed to patch chaptermark for Hungarian}}}%
+               {}%
+        }% (end \ifdefined\chaptermark)
+      }{% (\ifdefined\@memptsize)
         % With memoir
         \let\xpg at save@chaptermark at format\chaptermark%
         \renewcommand*\chaptermark[1]{%
@@ -17978,20 +18011,12 @@
               }{}%
             \fi
             ##1}}{}}%
-      }{% (not \ifdefined\@memptsize)
-        % With standard classes
-        \ifcsdef{chaptermark}{%
-          \ifpatchable{\chaptermark}%
-               {\@chapapp\ \thechapter.}%
-               {\let\xpg at save@chaptermark at format\chaptermark%
-                \patchcmd{\chaptermark}%
-                    {\@chapapp\ \thechapter.}%
-                    {\thechapter.\ \@chapapp\@hungarian at forced@dot}%
-                    {}%
-                    {\xpg at warning{Failed to patch chaptermark for Hungarian}}}%
-               {}%
-        }{}% (end \ifdefined\chaptermark)
       }% (end \ifdefined\@memptsize)
+    }{% (\ifdefined\chapterformat)
+      % With KOMA
+      \let\xpg at save@chaptermark at format\chaptermarkformat%
+      \renewcommand*\chaptermarkformat{%
+         \thechapter\autodot\ \IfChapterUsesPrefixLine{\chapapp\@hungarian at forced@dot\enskip}{}}
     }% (end \ifdefined\chapterformat)
   \fi% (end \if at hungarian@swapheaders)
 }
@@ -18003,58 +18028,58 @@
    \let\fnum at figure\xpg at save@fnum at figure%
    %
    % Reset chapter and part heading
-   \ifcsdef{titleformat}{%
+   \@ifundefined{titleformat}{%
+     \@ifundefined{sectionformat}{%
+        % With memoir and standard classes
+        \@ifundefined{xpg at save@part at format}{}{%
+           \@ifundefined{NR at part}{%
+               \let\@part\xpg at save@part at format%
+           }{%
+               \let\NR at part\xpg at save@part at format%
+           }%
+        }%
+        \@ifundefined{xpg at save@chap at format}{}{%
+          \let\@makechapterhead\xpg at save@chap at format
+        }%
+     }{%
+        % With KOMA
+        \@ifundefined{xpg at save@part at format}{}{%
+           \let\partformat\xpg at save@part at format
+        }%
+        \@ifundefined{xpg at save@chap at format}{}{%
+           \let\chapterformat\xpg at save@chap at format
+        }%
+     }% (end \ifdefined\sectionformat)
+   }{% (\ifdefined\titleformat)
       % With titlesec
-     \ifcsdef{xpg at save@part at format}{%
-        \ifcsdef{NR at part}{%
+     \@ifundefined{xpg at save@part at format}{}{%
+        \@ifundefined{NR at part}{%
+            \let\@part\xpg at save@part at format%
+        }{%
             \let\NR at part\xpg at save@part at format%
-        }{%
-            \let\@part\xpg at save@part at format%
         }%
-     }{}%
-     \ifcsdef{chapter}{%
+     }%
+     \@ifundefined{chapter}{}{%
         \titleformat\chapter[display]%
           {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
           {\@chapapp\space\thechapter}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
-     }{}%
-   }{% (not \ifdefined\titleformat)
-     \ifcsdef{sectionformat}{%
-        % With KOMA
-        \ifcsdef{xpg at save@part at format}{%
-           \let\partformat\xpg at save@part at format
-        }{}%
-        \ifcsdef{xpg at save@chap at format}{%
-           \let\chapterformat\xpg at save@chap at format
-        }{}%
-     }{%
-        % With memoir and standard classes
-        \ifcsdef{xpg at save@part at format}{%
-           \ifcsdef{NR at part}{%
-               \let\NR at part\xpg at save@part at format%
-           }{%
-               \let\@part\xpg at save@part at format%
-           }%
-        }{}%
-        \ifcsdef{xpg at save@chap at format}{%
-          \let\@makechapterhead\xpg at save@chap at format
-        }{}%
-     }% (end \ifdefined\sectionformat)
+     }%
    }% (end \ifdefined\titleformat)
   %
   % Reset headers
-  \ifcsdef{chaptermarkformat}{%
+  \@ifundefined{chaptermarkformat}{%
+     \@ifundefined{chaptermark}{}{%
+       % With memoir and standard classes
+       \@ifundefined{xpg at save@chaptermark at format}{}{%
+         \let\chaptermark\xpg at save@chaptermark at format%
+       }%
+     }% (end \ifdefined\chaptermark)
+  }{%
      % With KOMA
-     \ifcsdef{xpg at save@chaptermark at format}{%
+     \@ifundefined{xpg at save@chaptermark at format}{}{%
        \let\chaptermarkformat\xpg at save@chaptermark at format%
-     }{}%
-  }{%
-     \ifcsdef{chaptermark}{%
-       % With memoir and standard classes
-       \ifcsdef{xpg at save@chaptermark at format}{%
-         \let\chaptermark\xpg at save@chaptermark at format%
-       }{}%
-     }{}% (end \ifdefined\chaptermark)
-  }% (end \ifdefined\chapterformat)
+     }%
+  }% (end \ifdefined\chaptermarkformat)
 }
 % Hungarian needs 1) trailing dots in chapter headings; 2) trailing dot in section, subsection, etc, counters
 \def\@hungarian at forced@dot{}
@@ -18121,13 +18146,13 @@
 % 
 % \subsection{gloss-hy.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hy.ldf}[polyglossia: module for hy (Armenian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{armenian}
+\InheritGlossFile{armenian}
 
 %    \end{macrocode}
 % \iffalse
@@ -18138,13 +18163,13 @@
 % 
 % \subsection{gloss-ia.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ia.ldf}[polyglossia: module for ia (Interlingua)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{interlingua}
+\InheritGlossFile{interlingua}
 
 %    \end{macrocode}
 % \iffalse
@@ -18155,7 +18180,7 @@
 % 
 % \subsection{gloss-icelandic.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-icelandic.ldf}[polyglossia: module for Icelandic]
 \PolyglossiaSetup{icelandic}{
@@ -18213,13 +18238,13 @@
 % 
 % \subsection{gloss-id.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-id.ldf}[polyglossia: module for id (Malay)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{malay}
+\InheritGlossFile{malay}
 
 %    \end{macrocode}
 % \iffalse
@@ -18230,7 +18255,7 @@
 % 
 % \subsection{gloss-interlingua.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-interlingua.ldf}[polyglossia: module for Interlingua]
 \PolyglossiaSetup{interlingua}{
@@ -18288,7 +18313,7 @@
 % 
 % \subsection{gloss-irish.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-irish.ldf}[polyglossia: module for Irish]
 
@@ -18295,7 +18320,7 @@
 % We only provide this gloss for babel compatibility. Since irish is 
 % a gaelic variety, we use 'gaelic' with variant 'irish' now.
 
-\xpg at load@master at language{gaelic}
+\InheritGlossFile{gaelic}
 
 %    \end{macrocode}
 % \iffalse
@@ -18306,13 +18331,13 @@
 % 
 % \subsection{gloss-is.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-is.ldf}[polyglossia: module for is (Icelandic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{icelandic}
+\InheritGlossFile{icelandic}
 
 %    \end{macrocode}
 % \iffalse
@@ -18323,13 +18348,13 @@
 % 
 % \subsection{gloss-it.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-it.ldf}[polyglossia: module for it (Italian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{italian}
+\InheritGlossFile{italian}
 
 %    \end{macrocode}
 % \iffalse
@@ -18341,7 +18366,7 @@
 % \subsection{gloss-italian.ldf}
 %    \begin{macrocode}
 % !TEX encoding = UTF-8 Unicode
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-italian.ldf}[polyglossia: module for Italian]
 \PolyglossiaSetup{italian}{
@@ -18360,24 +18385,22 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{italian}{it}
 
+\DeclareKeys[polyglossia/gloss/italian]
+  {
+    babelshorthands.if = italian at babelshorthands,
+    babelshorthands.default:n = true,
+  }
 
-%%% CHANGES START %%% by Enrico Gregorio
-\define at boolkey{italian}[italian@]{babelshorthands}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{italian}{babelshorthands=false}
+\InitializeGlossOptions{italian}{babelshorthands=false}
 
 \ifsystem at babelshorthands
-  \setkeys{italian}{babelshorthands=true}
+  \SetGlossOptions{italian}{babelshorthands=true}
 \else
-  \setkeys{italian}{babelshorthands=false}
+  \SetGlossOptions{italian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\italian at shorthands{%
   \xpg at activate@shorthands%
@@ -18457,7 +18480,7 @@
 
 %%% CHANGES START %%% by Enrico Gregorio
 \let\xpgit at savedvalues\empty
-\AtEndPreamble{% the user or the class might define different values
+\AddToHook{begindocument/before}{% the user or the class might define different values
   \edef\xpgit at savedvalues{%
     \clubpenalty=\the\clubpenalty\space
     \@clubpenalty=\the\@clubpenalty\space
@@ -18493,13 +18516,13 @@
 % 
 % \subsection{gloss-ja.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ja.ldf}[polyglossia: module for ja (Japanese)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{japanese}
+\InheritGlossFile{japanese}
 
 %    \end{macrocode}
 % \iffalse
@@ -18510,7 +18533,7 @@
 % 
 % \subsection{gloss-japanese.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-japanese.ldf}[polyglossia: module for Japanese]
 
@@ -18749,13 +18772,13 @@
 % 
 % \subsection{gloss-ka.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ka.ldf}[polyglossia: module for ka (Georgian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{georgian}
+\InheritGlossFile{georgian}
 
 %    \end{macrocode}
 % \iffalse
@@ -18767,7 +18790,7 @@
 % \subsection{gloss-kannada.ldf}
 %    \begin{macrocode}
 %% gloss-kannada.ldf
-%% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+%% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %%
 %% Copyright 2011 Aravinda VK <hallimanearavind AT gmail.com>,
 %%                Shankar Prasad <prasad.mvs AT gmail.com>,
@@ -18821,13 +18844,21 @@
 \def\tmp at western{Western}
 \newif\ifkannada at numerals
 \kannada at numeralstrue
+  
+\DeclareKeys[polyglossia/gloss/kannada]
+  {
+    numerals.choice:,
+    numerals / kannada.code =
+      {%
+        \kannada at numeralstrue
+      },
+    numerals / western.code =
+      {%     
+        \kannada at numeralsfalse
+      },
+    numerals.default:n = kannada
+  }
 
-\define at key{kannada}{numerals}[Kannada]{%
-  \def\@tmpa{#1}%
-  \ifx\@tmpa\tmp at western
-    \kannada at numeralsfalse
-  \fi}
-
   
 \def\captionskannada{%
   \def\prefacename{ಮುನ್ನುಡಿ}%
@@ -18890,7 +18921,7 @@
 % 
 % \subsection{gloss-khmer.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-khmer.ldf}[polyglossia: module for Khmer]
 \PolyglossiaSetup{khmer}{
@@ -18911,19 +18942,25 @@
 
 \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%
-    \SetLanguageKeys{khmer}{bcp47-extension-u=nu-khmr}%
-  \else%
-    \@khmer at numeralsfalse%
-    \SetLanguageKeys{khmer}{bcp47-extension-u=nu-latn}%
-   \fi%
-}
 
-\setkeys{khmer}{numerals}
+\DeclareKeys[polyglossia/gloss/khmer]
+  {
+    numerals.choice:,
+    numerals / khmer.code =
+      {%
+        \@khmer at numeralstrue
+        \SetLanguageKeys{khmer}{bcp47-extension-u=nu-khmr}%
+      },
+    numerals / arabic.code =
+      {%
+        \@khmer at numeralsfalse
+        \SetLanguageKeys{khmer}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = arabic
+  }
 
+\SetGlossOptions{khmer}{numerals}
+
 \def\captionskhmer{%
   \def\prefacename{អារម្ភកថា}%
   \def\refname{ឯកសារយោង}%
@@ -19073,13 +19110,13 @@
 % 
 % \subsection{gloss-km.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-km.ldf}[polyglossia: module for km (Khmer)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{khmer}
+\InheritGlossFile{khmer}
 
 %    \end{macrocode}
 % \iffalse
@@ -19090,13 +19127,13 @@
 % 
 % \subsection{gloss-kmr-Arab.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-kmr-Arab.ldf}[polyglossia: module for kmr-Arab (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 %    \end{macrocode}
 % \iffalse
@@ -19107,13 +19144,13 @@
 % 
 % \subsection{gloss-kmr-Latn.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-kmr-Latn.ldf}[polyglossia: module for kmr-Latn (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 %    \end{macrocode}
 % \iffalse
@@ -19124,13 +19161,13 @@
 % 
 % \subsection{gloss-kmr.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-kmr.ldf}[polyglossia: module for kmr (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 %    \end{macrocode}
 % \iffalse
@@ -19141,13 +19178,13 @@
 % 
 % \subsection{gloss-kn.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-kn.ldf}[polyglossia: module for kn (Kannada)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kannada}
+\InheritGlossFile{kannada}
 
 %    \end{macrocode}
 % \iffalse
@@ -19158,13 +19195,13 @@
 % 
 % \subsection{gloss-ko.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ko.ldf}[polyglossia: module for ko (Korean)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{korean}
+\InheritGlossFile{korean}
 
 %    \end{macrocode}
 % \iffalse
@@ -19175,7 +19212,7 @@
 % 
 % \subsection{gloss-korean.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-korean.ldf}[polyglossia: module for Korean]
 
@@ -19195,40 +19232,48 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{korean}{ko}
 
-% variant : plain (0), classic (1), or modern (2)
-\define at choicekey{korean}{variant}[\xpg at val\xpg at nr]{plain,classic,modern}[plain]{%
-    \let\xpg at korean@variant\xpg at nr
-}
-% captions : hangul (0) or hanja (1)
-\define at choicekey{korean}{captions}[\xpg at val\xpg at nr]{hangul,hanja}[hangul]{%
-    \let\xpg at korean@captions\xpg at nr
-}
-% swapstrings: all (0), headings (1), headers (2), or none (3)
 \newif\if at korean@swapheadings
 \newif\if at korean@swapheaders
-\define at choicekey*+{korean}{swapstrings}[\xpg at val\xpg at nr]{all,headings,headers,none}[all]{%
-   \ifcase\xpg at nr\relax
-      % all:
-      \@korean at swapheadingstrue%
-      \@korean at swapheaderstrue%
-   \or
-      % headings:
-      \@korean at swapheadingstrue%
-      \@korean at swapheadersfalse%
-   \or
-      % headers:
-      \@korean at swapheadingsfalse%
-      \@korean at swapheaderstrue%
-   \or
-      % none:
-      \@korean at swapheadingsfalse%
-      \@korean at swapheadersfalse%
-   \fi
-   \xpg at info{Option: Korean, swapstrings=\xpg at val}%
-}{\xpg at warning{Unknown Korean swapstrings value `#1'}}
 
+\DeclareKeys[polyglossia/gloss/korean]
+  {
+    variant.choices:nn = { plain, classic, modern }
+      {%
+        \edef\xpg at korean@variant{\the\numexpr\UseName{l_keys_choice_int}-1\relax}
+      },
+    variant.default:n = plain,
+    captions.choices:nn = { hangul, hanja }
+      {%
+        \edef\xpg at korean@captions{\the\numexpr\UseName{l_keys_choice_int}-1\relax}
+      },
+    captions.default:n = hangul,
+    swapstrings.choice:,
+    swapstrings / all.code =
+      {%
+        \@korean at swapheadingstrue
+        \@korean at swapheaderstrue
+      },
+    swapstrings / headings.code =
+      {%
+        \@korean at swapheadingstrue
+        \@korean at swapheadersfalse
+      },
+    swapstrings / headers.code =
+      {%
+        \@korean at swapheadingsfalse
+        \@korean at swapheaderstrue
+      },
+    swapstrings / none.code =
+      {%
+        \@korean at swapheadingsfalse
+        \@korean at swapheadersfalse
+      },
+    swapstrings.default:n = all,
+    swapstrings/unknown.code = \xpg at warning{Unknown Korean swapstrings value `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{korean}{variant=plain,swapstrings=all,captions=hangul}
+\InitializeGlossOptions{korean}{variant=plain,swapstrings=all,captions=hangul}
 
 \def\captionskorean{%
     \ifcase\xpg at korean@captions\relax
@@ -19290,60 +19335,48 @@
   % change chapter and part headings
   \if at korean@swapheadings
     % With titlesec
-    \ifcsdef{titleformat}{%
-      \ifcsdef{NR at part}{% Hyperref (nameref)
-        \let\xpg at save@part at format\NR at part
-        \patchcmd{\NR at part}%
-                 {\partname\nobreakspace\thepart}%
-                 {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
-                 {}%
-                 {\xpg at warning{Failed to patch part for Korean}}%
-      }{% not hyperref
-        \ifcsdef{@part}{%
-            \let\xpg at save@part at format\@part
-            \patchcmd{\@part}%
+    \@ifundefined{titleformat}{%
+      % With KOMA
+      \@ifundefined{sectionformat}{%
+        % With memoir
+        \@ifundefined{@memptsize}{%
+          % With standard classes
+          \@ifundefined{@makechapterhead}{}{%
+            \let\xpg at save@chap at format\@makechapterhead
+            \patchcmd{\@makechapterhead}%
+                     {\@chapapp\space \thechapter}%
+                     {%
+                       \ifx\@chapapp\korean at appendix@chapapp
+                         \appendixname\space \thechapter
+                       \else
+                         \koreanTHEname\space \thechapter\space \@chapapp
+                       \fi
+                     }%
+                     {}%
+                     {\xpg at warning{Failed to patch chapter for Korean}}%
+          }%
+          \@ifundefined{NR at part}{% not hyperref
+            \@ifundefined{@part}{}{%
+              \ifpatchable{\@part}%
+                   {\partname\nobreakspace\thepart}%
+                   {\let\xpg at save@part at format\@part
+                    \patchcmd{\@part}%
+                             {\partname\nobreakspace\thepart}%
+                             {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
+                             {}%
+                             {\@ifundefined{part}{}{\xpg at warning{Failed to patch part for Korean}}}}%
+                   {}%
+            }%  (end \ifdefined\@part)
+          }{% Hyperref (nameref)
+            \let\xpg at save@part at format\NR at part
+            \patchcmd{\NR at part}%
                      {\partname\nobreakspace\thepart}%
                      {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
                      {}%
                      {\xpg at warning{Failed to patch part for Korean}}%
-        }{}%
-      }
-      \ifcsdef{chapter}{%
-        \titleformat\chapter[display]%
-          {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}%
-          {%
-            \ifx\@chapapp\korean at appendix@chapapp
-              \appendixname\space \thechapter
-            \else
-              \koreanTHEname\space \thechapter\space \@chapapp
-            \fi
-          }{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}%
-      }{}%
-    }{% (not \ifdefined\titleformat)
-      % With KOMA
-      \ifcsdef{sectionformat}{%
-        \ifcsdef{partformat}{%
-          \let\xpg at save@part at format\partformat
-          \renewcommand*{\partformat}{\koreanTHEname~\thepart~\partname}%
-        }{}%
-        \ifcsdef{chapterformat}{%
-          \let\xpg at save@chap at format\chapterformat
-          \renewcommand*{\chapterformat}{\mbox{%
-            \IfChapterUsesPrefixLine
-            {%
-              \ifx\@chapapp\korean at appendix@chapapp
-                \chapapp\nobreakspace \thechapter\autodot
-              \else
-                \koreanTHEname\nobreakspace \thechapter\nobreakspace \chapapp\autodot
-              \fi
-            }%
-            {\thechapter\autodot\enskip}%
-          }}%
-        }{}%
-      }{% (not \ifdefined\sectionformat)
-        % With memoir
-        \ifcsdef{@memptsize}{%
-          \ifcsdef{@makechapterhead}{%
+          }% (end not hyperref)
+        }{% (\ifdefined\@memptsize)
+          \@ifundefined{@makechapterhead}{}{%
             \let\xpg at save@chap at format\@makechapterhead
             \patchcmd{\@makechapterhead}%
                      {\printchaptername \chapternamenum \printchapternum}%
@@ -19361,19 +19394,9 @@
                 \ifpatchable\printchaptername\@chapapp
                   {\chapnamefont\koreanTHEname\chapternamenum}{}}%
             \fi
-          }{}%
-          \ifcsdef{NR at part}{% Hyperref (nameref)
-            \let\xpg at save@part at format\NR at part
-            \patchcmd{\NR at part}%
-                     {\printpartname \partnamenum \printpartnum}%
-                     {\printkoreanpartthe \printpartnum\partnamenum \printpartname}%
-                     {}%
-                     {\xpg at warning{Failed to patch part for Korean}}%
-            \ifdefined\printkoreanpartthe\else
-              \def\printkoreanpartthe{\partnamefont\koreanTHEname\partnamenum}%
-            \fi
-          }{% not hyperref
-            \ifcsdef{@part}{%
+          }%
+          \@ifundefined{NR at part}{% not hyperref
+            \@ifundefined{@part}{}{%
               \let\xpg at save@part at format\@part
               \patchcmd{\@part}%
                        {\printpartname \partnamenum \printpartnum}%
@@ -19383,84 +19406,77 @@
               \ifdefined\printkoreanpartthe\else
                 \def\printkoreanpartthe{\partnamefont\koreanTHEname\partnamenum}%
               \fi
-            }{}%
-          }%
-        }{% (not \ifdefined\@memptsize)
-          % With standard classes
-          \ifcsdef{@makechapterhead}{%
-            \let\xpg at save@chap at format\@makechapterhead
-            \patchcmd{\@makechapterhead}%
-                     {\@chapapp\space \thechapter}%
-                     {%
-                       \ifx\@chapapp\korean at appendix@chapapp
-                         \appendixname\space \thechapter
-                       \else
-                         \koreanTHEname\space \thechapter\space \@chapapp
-                       \fi
-                     }%
-                     {}%
-                     {\xpg at warning{Failed to patch chapter for Korean}}%
-          }{}%
-          \ifcsdef{NR at part}{% Hyperref (nameref)
+            }%
+          }{% Hyperref (nameref)
             \let\xpg at save@part at format\NR at part
             \patchcmd{\NR at part}%
+                     {\printpartname \partnamenum \printpartnum}%
+                     {\printkoreanpartthe \printpartnum\partnamenum \printpartname}%
+                     {}%
+                     {\xpg at warning{Failed to patch part for Korean}}%
+            \ifdefined\printkoreanpartthe\else
+              \def\printkoreanpartthe{\partnamefont\koreanTHEname\partnamenum}%
+            \fi
+          }%
+        }% (end \ifdefined\@memptsize)
+      }{% (\ifdefined\sectionformat)
+        \@ifundefined{partformat}{}{%
+          \let\xpg at save@part at format\partformat
+          \renewcommand*{\partformat}{\koreanTHEname~\thepart~\partname}%
+        }%
+        \@ifundefined{chapterformat}{}{%
+          \let\xpg at save@chap at format\chapterformat
+          \renewcommand*{\chapterformat}{\mbox{%
+            \IfChapterUsesPrefixLine
+            {%
+              \ifx\@chapapp\korean at appendix@chapapp
+                \chapapp\nobreakspace \thechapter\autodot
+              \else
+                \koreanTHEname\nobreakspace \thechapter\nobreakspace \chapapp\autodot
+              \fi
+            }%
+            {\thechapter\autodot\enskip}%
+          }}%
+        }%
+      }% (end \ifdefined\sectionformat)
+    }{% (\ifdefined\titleformat)
+      \@ifundefined{NR at part}{% not hyperref
+        \@ifundefined{@part}{}{%
+            \let\xpg at save@part at format\@part
+            \patchcmd{\@part}%
                      {\partname\nobreakspace\thepart}%
                      {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
                      {}%
                      {\xpg at warning{Failed to patch part for Korean}}%
-          }{% not hyperref
-            \ifcsdef{@part}{%
-              \ifpatchable{\@part}%
-                   {\partname\nobreakspace\thepart}%
-                   {\let\xpg at save@part at format\@part
-                    \patchcmd{\@part}%
-                             {\partname\nobreakspace\thepart}%
-                             {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
-                             {}%
-                             {\ifcsdef{part}{\xpg at warning{Failed to patch part for Korean}}{}}}%
-                   {}%
-            }{}%  (end \ifdefined\@part)
-          }% (end not hyperref)
-        }% (end \ifdefined\@memptsize)
-      }% (end \ifdefined\sectionformat)
+        }%
+      }{% Hyperref (nameref)
+        \let\xpg at save@part at format\NR at part
+        \patchcmd{\NR at part}%
+                 {\partname\nobreakspace\thepart}%
+                 {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
+                 {}%
+                 {\xpg at warning{Failed to patch part for Korean}}%
+      }%
+      \@ifundefined{chapter}{}{%
+        \titleformat\chapter[display]%
+          {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}%
+          {%
+            \ifx\@chapapp\korean at appendix@chapapp
+              \appendixname\space \thechapter
+            \else
+              \koreanTHEname\space \thechapter\space \@chapapp
+            \fi
+          }{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}%
+      }%
     }% (end \ifdefined\titleformat)
   \fi % (end \if at korean@swapheadings)
   %
   % Change running headers
   \if at korean@swapheaders
-    \ifcsdef{chapterformat}{%
-      % With KOMA
-      \let\xpg at save@chaptermark at format\chaptermarkformat
-      \renewcommand*\chaptermarkformat{%
-        \IfChapterUsesPrefixLine
-        {%
-          \ifx\@chapapp\korean at appendix@chapapp
-            \chapapp\ \thechapter\autodot
-          \else
-            \koreanTHEname\ \thechapter\ \chapapp\autodot
-          \fi
-        }%
-        {\thechapter\autodot}%
-        \enskip
-      }%
-    }{% (not \ifdefined\chapterformat)
-      \ifcsdef{@memptsize}{%
-        % With memoir
-        \let\xpg at save@chaptermark at format\chaptermark
-        \patchcmd{\chaptermark}%
-                 {\@chapapp\ \@nameuse{thechapter}}%
-                 {%
-                   \ifx\@chapapp\korean at appendix@chapapp
-                     \appendixname\ \@nameuse{thechapter}%
-                   \else
-                     \koreanTHEname\ \@nameuse{thechapter}\ \@chapapp
-                   \fi
-                 }%
-                 {}%
-                 {\xpg at warning{Failed to patch chaptermark for Korean}}%
-      }{% (not \ifdefined\@memptsize)
+    \@ifundefined{chapterformat}{%
+      \@ifundefined{@memptsize}{%
         % With standard classes
-        \ifcsdef{chaptermark}{%
+        \@ifundefined{chaptermark}{}{%
           \ifpatchable{\chaptermark}%
                {\@chapapp\ \thechapter}%
                {\let\xpg at save@chaptermark at format\chaptermark
@@ -19476,8 +19492,37 @@
                          {}%
                          {\xpg at warning{Failed to patch chaptermark for Korean}}}%
                {}%
-        }{}% (end \ifdefined\chaptermark)
+        }% (end \ifdefined\chaptermark)
+      }{% (\ifdefined\@memptsize)
+        % With memoir
+        \let\xpg at save@chaptermark at format\chaptermark
+        \patchcmd{\chaptermark}%
+                 {\@chapapp\ \@nameuse{thechapter}}%
+                 {%
+                   \ifx\@chapapp\korean at appendix@chapapp
+                     \appendixname\ \@nameuse{thechapter}%
+                   \else
+                     \koreanTHEname\ \@nameuse{thechapter}\ \@chapapp
+                   \fi
+                 }%
+                 {}%
+                 {\xpg at warning{Failed to patch chaptermark for Korean}}%
       }% (end \ifdefined\@memptsize)
+    }{% (\ifdefined\chapterformat)
+      % With KOMA
+      \let\xpg at save@chaptermark at format\chaptermarkformat
+      \renewcommand*\chaptermarkformat{%
+        \IfChapterUsesPrefixLine
+        {%
+          \ifx\@chapapp\korean at appendix@chapapp
+            \chapapp\ \thechapter\autodot
+          \else
+            \koreanTHEname\ \thechapter\ \chapapp\autodot
+          \fi
+        }%
+        {\thechapter\autodot}%
+        \enskip
+      }%
     }% (end \ifdefined\chapterformat)
   \fi % (end \if at korean@swapheaders)
 }
@@ -19484,57 +19529,57 @@
 
 \def\nokorean at headingsformat{%
   % Reset chapter and part heading
-  \ifcsdef{titleformat}{%
+  \@ifundefined{titleformat}{%
+    \@ifundefined{sectionformat}{%
+      % With memoir and standard classes
+      \@ifundefined{xpg at save@part at format}{}{%
+        \@ifundefined{NR at part}{%
+          \let\@part\xpg at save@part at format
+        }{%
+          \let\NR at part\xpg at save@part at format
+        }%
+      }%
+      \@ifundefined{xpg at save@chap at format}{}{%
+        \let\@makechapterhead\xpg at save@chap at format
+      }%
+    }{%
+      % With KOMA
+      \@ifundefined{xpg at save@part at format}{}{%
+        \let\partformat\xpg at save@part at format
+      }%
+      \@ifundefined{xpg at save@chap at format}{}{%
+        \let\chapterformat\xpg at save@chap at format
+      }%
+    }% (end \ifdefined\sectionformat)
+  }{% (\ifdefined\titleformat)
     % With titlesec
-    \ifcsdef{xpg at save@part at format}{%
-      \ifcsdef{NR at part}{%
+    \@ifundefined{xpg at save@part at format}{}{%
+      \@ifundefined{NR at part}{%
+        \let\@part\xpg at save@part at format
+      }{%
         \let\NR at part\xpg at save@part at format
-      }{%
-        \let\@part\xpg at save@part at format
       }%
-    }{}%
-    \ifcsdef{chapter}{%
+    }%
+    \@ifundefined{chapter}{}{%
       \titleformat\chapter[display]%
         {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}%
         {\@chapapp\space\thechapter}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}%
-    }{}%
-  }{% (not \ifdefined\titleformat)
-    \ifcsdef{sectionformat}{%
-      % With KOMA
-      \ifcsdef{xpg at save@part at format}{%
-        \let\partformat\xpg at save@part at format
-      }{}%
-      \ifcsdef{xpg at save@chap at format}{%
-        \let\chapterformat\xpg at save@chap at format
-      }{}%
-    }{%
-      % With memoir and standard classes
-      \ifcsdef{xpg at save@part at format}{%
-        \ifcsdef{NR at part}{%
-          \let\NR at part\xpg at save@part at format
-        }{%
-          \let\@part\xpg at save@part at format
-        }%
-      }{}%
-      \ifcsdef{xpg at save@chap at format}{%
-        \let\@makechapterhead\xpg at save@chap at format
-      }{}%
-    }% (end \ifdefined\sectionformat)
+    }%
   }% (end \ifdefined\titleformat)
   %
   % Reset headers
-  \ifcsdef{chaptermarkformat}{%
+  \@ifundefined{chaptermarkformat}{%
+    \@ifundefined{chaptermark}{}{%
+      % With memoir and standard classes
+      \@ifundefined{xpg at save@chaptermark at format}{}{%
+        \let\chaptermark\xpg at save@chaptermark at format
+      }%
+    }% (end \ifdefined\chaptermark)
+  }{%
     % With KOMA
-    \ifcsdef{xpg at save@chaptermark at format}{%
+    \@ifundefined{xpg at save@chaptermark at format}{}{%
       \let\chaptermarkformat\xpg at save@chaptermark at format
-    }{}%
-  }{%
-    \ifcsdef{chaptermark}{%
-      % With memoir and standard classes
-      \ifcsdef{xpg at save@chaptermark at format}{%
-        \let\chaptermark\xpg at save@chaptermark at format
-      }{}%
-    }{}% (end \ifdefined\chaptermark)
+    }%
   }% (end \ifdefined\chapterformat)
 }
 
@@ -19598,13 +19643,13 @@
         \XeTeXinterchartokenstate\z@
         \XeTeXlinebreakpenalty\z@
         \XeTeXlinebreakskip\z at skip
-        \XeTeXlinebreaklocale "en"
+        \XeTeXlinebreaklocale ""
         \noextras at korean@common
     }
 \else % luatex
-    \def\inlineextras at korean{\xpg at attr@korean\xpg at korean@variant\relax}
+    \def\inlineextras at korean{\xpg at attr@cjkspacing\xpg at korean@variant\relax}
     \def\noextras at korean{%
-        \unsetattribute\xpg at attr@korean
+        \unsetattribute\xpg at attr@cjkspacing
         \noextras at korean@common
     }
 \fi
@@ -19624,7 +19669,7 @@
     \let\newattribute\newluatexattribute
     \let\unsetattribute\unsetluatexattribute
 \fi
-\newattribute\xpg at attr@korean
+\newattribute\xpg at attr@cjkspacing
 \newattribute\xpg at attr@autojosa
 % user commands for Josa
 % Josa : particles in Korean grammar that immediately follow a noun or pronoun.
@@ -19645,7 +19690,7 @@
 \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" }
+\directlua{ require "polyglossia-cjk-spacing" }
 %    \end{macrocode}
 % \iffalse
 %</gloss-korean.ldf>
@@ -19655,13 +19700,13 @@
 % 
 % \subsection{gloss-ku-Arab.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ku-Arab.ldf}[polyglossia: module for ku-Arab (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 %    \end{macrocode}
 % \iffalse
@@ -19672,13 +19717,13 @@
 % 
 % \subsection{gloss-ku-Latn.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ku-Latn.ldf}[polyglossia: module for ku-Latn (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 %    \end{macrocode}
 % \iffalse
@@ -19689,13 +19734,13 @@
 % 
 % \subsection{gloss-ku.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ku.ldf}[polyglossia: module for ku (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 %    \end{macrocode}
 % \iffalse
@@ -19706,7 +19751,7 @@
 % 
 % \subsection{gloss-kurdish.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Created on September 1, 2019
 % Last updated on May 17, 2020
@@ -19749,37 +19794,10 @@
 
 \newif\if at kurdish@kurmanji
 \def\kurdish at variant{sorani}
-\define at choicekey*+{kurdish}{variant}[\xpg at val\xpg at nr]{sorani,kurmanji}[sorani]{%
-   \ifcase\xpg at 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=\xpg at val}%
-}{\xpg at warning{Unknown Kurdish variant `#1'}}
 
 \newif\if at kurdish@latin
 \newif\if at kurdish@arabic
-\define at choicekey*+{kurdish}{script}[\xpg at val\xpg at nr]{arabic,latin}{%
-   \ifcase\xpg at 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=\xpg at 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}
@@ -19795,7 +19813,7 @@
          \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurdish,bcp47=ckb-Arab,bcp47-language=ckb,bcp47-script=Arab,bcp47-casing=ckb-Arab}%
      \fi
      \def\kurdish at script{latin}
-     \xpg at fontsetup@latin{kurdish}%
+     \SetupLatinPolyglossiaFont{kurdish}%
   \else
      \if at kurdish@arabic% arabic explicitly set
         \if at kurdish@kurmanji
@@ -19805,16 +19823,16 @@
         \else
             \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurdish,bcp47=ckb-Arab,bcp47-language=ckb,bcp47-script=Arab,bcp47-casing=ckb-Arab}%
         \fi
-        \xpg at fontsetup@nonlatin{kurdish}%
+        \SetupNonLatinPolyglossiaFont{kurdish}%
      \else% sorani=arabic, kurmanji=latin
         \if at kurdish@kurmanji
             \@western at numeralstrue%
             \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurmanji,bcp47=kmr-Latn,bcp47-language=kmr,bcp47-script=Latn,bcp47-casing=kmr-Latn}%
-            \xpg at fontsetup@latin{kurdish}%
+            \SetupLatinPolyglossiaFont{kurdish}%
             \def\kurdish at script{latin}
         \else
             \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurdish,bcp47=ckb-Arab,bcp47-language=ckb,bcp47-script=Arab,bcp47-casing=ckb-Arab}%
-            \xpg at fontsetup@nonlatin{kurdish}%
+            \SetupNonLatinPolyglossiaFont{kurdish}%
         \fi
      \fi
   \fi
@@ -19821,45 +19839,68 @@
 }
 
 \newif\if at western@numerals
-\define at choicekey*+{kurdish}{numerals}[\xpg at val\xpg at nr]{eastern,western}[eastern]{%
-   \ifcase\xpg at nr\relax
-      % eastern:
-      \@western at numeralsfalse%
-   \or
-      % western:
-      \@western at numeralstrue%
-      \@force at western@numeralstrue%
-   \fi
-   \xpg at info{Option: Kurdish, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Kurdish numerals option `#1'}}
 
 \newif\ifkurdish at customsep\kurdish at customsepfalse
 \def\xpg at sepmark{}
-\define at key{kurdish}{sectionsep}[.]{%
-   \kurdish at customseptrue%
-   \gdef\xpg at sepmark{#1}%
-}
 
-%this is needed for \abjad in arabicnumbers.sty
-\define at boolkey{kurdish}[kurdish@]{abjadjimnotail}[true]{%
-  \ifkurdish at abjadjimnotail
-    \abjad at jim@notailtrue%
-  \else
-    \abjad at jim@notailfalse
-  \fi%
-}
+%TODO add option for CALENDAR
 
-% NOT YET USED
-\define at key{kurdish}{locale}[default]{%
-  \def\@kurdish at locale{#1}}
+\DeclareKeys[polyglossia/gloss/kurdish]
+  {
+    variant.choice:,
+    variant / sorani.code =
+      {%
+        \def\kurdish at variant{sorani}%
+        \@kurdish at kurmanjifalse
+        \kurdish at set@variety
+      },
+    variant / kurmanji.code =
+      {%
+        \def\kurdish at variant{kurmanji}%
+        \@kurdish at kurmanjitrue
+        \kurdish at set@variety
+      },
+    variant.default:n = sorani,
+    variant/unknown.code = \xpg at warning{Unknown Kurdish variant `#1'},
+    script.choice:,
+    script / arabic.code =
+      {%
+        \@kurdish at latinfalse
+        \@kurdish at arabictrue
+        \kurdish at set@variety
+      },
+    script / latin.code =
+      {%
+        \@kurdish at latintrue
+        \@kurdish at arabicfalse
+        \kurdish at set@variety
+      },
+    script.default:n = sorani,
+    script/unknown.code = \xpg at warning{Unknown Kurdish script `#1'},
+    numerals.choice:,
+    numerals / eastern.code =
+      {%
+        \@western at numeralsfalse
+      },
+    numerals / western.code =
+      {%
+        \@western at numeralstrue
+        \@force at western@numeralstrue
+      },
+    numerals.default:n = eastern,
+    numerals/unknown.code = \xpg at warning{Unknown Kurdish numerals value `#1'},
+    sectionsep.code = \gdef\xpg at sepmark{#1}\kurdish at customseptrue,
+    sectionsep.default:n = .,
+    abjadjimnotail.if = abjad at jim@notail,
+    abjadjimnotail.default:n = true,
+    locale.store = \@kurdish at locale
+  }
 
-%TODO add option for CALENDAR
-
 % Register default options
-\xpg at initialize@gloss at options{kurdish}{variant=sorani,locale=default,script=arabic,abjadjimnotail=false,numerals=eastern}
+\InitializeGlossOptions{kurdish}{variant=sorani,locale=default,script=arabic,abjadjimnotail=false,numerals=eastern}
 
 \def\kurdish at language{%
-   \polyglossia at setup@language at patterns{\kurdish at pattern}%
+   \SetupPolyglossiaLangPatterns{\kurdish at pattern}%
 }%
 
 \def\kurdishNativemonth#1{\ifcase#1%
@@ -20112,9 +20153,9 @@
 }
 
 \def\nokurdish at xetex@capsformat{%
-   \ifcsdef{xpg at save@sepmark}{%
+   \ifcsname xpg at save@sepmark\endcsname%
      \SepMark{\xpg at save@sepmark}
-   }{}%
+   \fi%
 }
 
 \def\kurdish at luatex@capsformat{%
@@ -20121,7 +20162,7 @@
   %
   % change chapter and part headings
   \ifkurdish at customsep
-     \ifcsdef{chapter}{%
+     \ifcsname chapter\endcsname%
         \let\xpg at save@thesection\thesection%
         \renewcommand*\thesection{\thechapter\xpg at sepmark\@arabic\c at section}
         \let\xpg at save@theequation\theequation%
@@ -20133,7 +20174,7 @@
         \let\xpg at save@thetable\thetable%
 	\renewcommand*\thetable{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at table}
-     }{}
+     \fi%
      \let\xpg at save@thesubsection\thesubsection%
      \renewcommand\thesubsection
 	{\thesection\xpg at sepmark\@arabic\c at subsection}
@@ -20148,30 +20189,30 @@
 }
 
 \def\nokurdish at luatex@capsformat{%
-   \ifcsdef{xpg at save@thesection}{%
+   \ifcsname xpg at save@thesection\endcsname%
         \let\thesection\xpg at save@thesection%
-   }{}%
-   \ifcsdef{xpg at save@theequation}{%
+   \fi%
+   \ifcsname xpg at save@theequation\endcsname%
         \let\theequation\xpg at save@theequation%
-   }{}%
-   \ifcsdef{xpg at save@thefigure}{%
+   \fi%
+   \ifcsname xpg at save@thefigure\endcsname%
         \let\thefigure\xpg at save@thefigure%
-   }{}%
-   \ifcsdef{xpg at save@thetable}{%
+   \fi%
+   \ifcsname xpg at save@thetable\endcsname%
         \let\thetable\xpg at save@thetable%
-   }{}%
-   \ifcsdef{xpg at save@thesubsection}{%
+   \fi%
+   \ifcsname xpg at save@thesubsection\endcsname%
         \let\thesubsection\xpg at save@thesubsection%
-   \ifcsdef{xpg at save@thesubsubsection}{%
+      \ifcsname xpg at save@thesubsubsection\endcsname%
         \let\thesubsubsection\xpg at save@thesubsubsection%
-   }{}%
-   }{}%
-   \ifcsdef{xpg at save@theparagraph}{%
+      \fi%
+   \fi%
+   \ifcsname xpg at save@theparagraph\endcsname%
         \let\theparagraph\xpg at save@theparagraph%
-   }{}%
-   \ifcsdef{xpg at save@thesubparagraph}{%
+   \fi%
+   \ifcsname xpg at save@thesubparagraph\endcsname%
         \let\thesubparagraph\xpg at save@thesubparagraph%
-   }{}%
+   \fi%
 }
 
 \def\blockextras at kurdish{%
@@ -20203,13 +20244,13 @@
 % 
 % \subsection{gloss-kurmanji.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-kurmanji.ldf}[polyglossia: module for Kurmanji Kurdish]
 
 % We provide this gloss for babel compatibility.
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 %    \end{macrocode}
 % \iffalse
@@ -20220,13 +20261,13 @@
 % 
 % \subsection{gloss-la-x-classic.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-la-xclassic.ldf}[polyglossia: module for la-xclassic (Latin)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{latin}
+\InheritGlossFile{latin}
 
 %    \end{macrocode}
 % \iffalse
@@ -20237,13 +20278,13 @@
 % 
 % \subsection{gloss-la-x-ecclesia.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-la-xecclesiastic.ldf}[polyglossia: module for la-xecclesiastic (Latin)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{latin}
+\InheritGlossFile{latin}
 
 %    \end{macrocode}
 % \iffalse
@@ -20254,13 +20295,13 @@
 % 
 % \subsection{gloss-la-x-medieval.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-la-xmedieval.ldf}[polyglossia: module for la-xmedieval (Latin)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{latin}
+\InheritGlossFile{latin}
 
 %    \end{macrocode}
 % \iffalse
@@ -20271,13 +20312,13 @@
 % 
 % \subsection{gloss-la.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-la.ldf}[polyglossia: module for la (Latin)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{latin}
+\InheritGlossFile{latin}
 
 %    \end{macrocode}
 % \iffalse
@@ -20288,7 +20329,7 @@
 % 
 % \subsection{gloss-lao.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lao.ldf}[polyglossia: module for Lao]
 
@@ -20312,14 +20353,23 @@
 
 \newif\if at lao@numerals
 \def\tmp at lao{lao}
-\define at key{lao}{numerals}[arabic]{%
-	\def\@tmpa{#1}%
-	\ifx\@tmpa\tmp at lao\@lao at numeralstrue\else
-	  \@lao at numeralsfalse\fi
-}
 
+\DeclareKeys[polyglossia/gloss/lao]
+  {
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \@lao at numeralsfalse
+      },
+    numerals / lao.code =
+      {%
+        \@lao at numeralstrue
+      },
+    numerals.default:n = arabic
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{lao}{numerals=arabic}
+\InitializeGlossOptions{lao}{numerals=arabic}
 
 % Translations provided by Brian Wilson <bountonw at gmail.com>
 \def\captionslao{%
@@ -20399,7 +20449,7 @@
 % 
 % \subsection{gloss-latex.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-latex.ldf}[polyglossia: module for default language]
 
@@ -20449,7 +20499,7 @@
 % 
 % \subsection{gloss-latin.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-latin.ldf}[polyglossia: module for Latin]
 
@@ -20484,6 +20534,9 @@
 \bool_new:N \l_polyglossia_latin_use_v_bool
 \bool_new:N \l_polyglossia_latin_use_ligatures_bool
 \bool_new:N \l_polyglossia_latin_capitalize_month_bool
+\bool_new:N \l_polyglossia_latin_babelshorthands_bool
+\bool_new:N \l_polyglossia_latin_prosodic_shorthands_bool
+\bool_new:N \l_polyglossia_latin_ecclesiastic_footnotes_bool
 
 \cs_new:Npn \polyglossia_latin_classical_character_codes:
   {
@@ -20519,11 +20572,11 @@
 
 \cs_new:Npn \polyglossia_latin_use_modern_patterns:
   {
-    \xpg at ifdefined {latin}
+    \IfLanguageDefinedTF {latin}
       {
         \def \latin at language
           {
-            \polyglossia at setup@language at patterns {latin}
+            \SetupPolyglossiaLangPatterns {latin}
             \str_case:Vn \l_polyglossia_latin_variant_str
               {
                 {classic}      { \adddialect \l at classiclatin \l at latin }
@@ -20547,11 +20600,11 @@
 \cs_new:Npn \polyglossia_latin_set_patterns:n #1
 % #1 may be "classiclatin" or "liturgicallatin"
   {
-    \xpg at ifdefined {#1}
+    \IfLanguageDefinedTF {#1}
       {
         \def \latin at language
           {
-            \polyglossia at setup@language at patterns {#1}
+            \SetupPolyglossiaLangPatterns {#1}
             \str_case:Vn \l_polyglossia_latin_variant_str
               {
                 {classic}      {
@@ -20767,7 +20820,8 @@
 % Save original footnote definition
 % Do this at the end of the preamble to catch other
 % packages' footnote changes (#391)
-\AtEndPreamble{%
+\hook_gput_code:nnn { begindocument / before } {.}
+{
   \cs_if_exist:NT \@makefntext
     {
       \cs_set_eq:NN \polyglossia_latin_original_footnote:n \@makefntext
@@ -20791,40 +20845,27 @@
 
 \cs_new:Npn \polyglossia_latin_apply_footnote_option:
   {
-    \str_if_eq:VnTF \xpg at main@language {latin}
+    \IfMainLanguageTF {latin}
       {
         \cs_if_exist:NT \@makefntext
           {
-            \iflatin at ecclesiasticfootnotes
+            \bool_if:NTF \l_polyglossia_latin_ecclesiastic_footnotes_bool
+             {
               \let \@makefntext \polyglossia_latin_variant_footnote:n
-            \else
+             }
+             {
               \let \@makefntext \polyglossia_latin_original_footnote:n
-            \fi
+             }
           }
       }
       {
-        \iflatin at ecclesiasticfootnotes
-          \msg_warning:nn {polyglossia} {latin / ineffective footnote option}
-        \fi
+        \bool_if:NT \l_polyglossia_latin_ecclesiastic_footnotes_bool
+          {
+            \msg_warning:nn {polyglossia} {latin / ineffective footnote option}
+          }
       }
   }
 
-\define at boolkey {latin} [latin@] {ecclesiasticfootnotes} [true]
-  {
-    \token_if_eq_meaning:NNTF \@onlypreamble \@notprerr
-      {
-        % within the document
-        \polyglossia_latin_apply_footnote_option:
-      }
-      {
-        % within the preamble
-        % The application of the option has to be postponed as the main
-        % language may be undefined when the option is called.
-        \AtBeginDocument { \polyglossia_latin_apply_footnote_option: }
-      }
-  }
-
-
 %%%%% Language variants: classic, medieval, modern, and ecclesiastic
 
 \str_new:N \l_polyglossia_latin_variant_str
@@ -20887,58 +20928,6 @@
     \polyglossia_latin_use_modern_patterns:
   }
 
-\define at key{latin}{variant}
-  {
-    \str_case:nnF {#1}
-      {
-        {classic}
-        {
-          \msg_info:nnn {polyglossia} {latin / language variant} {classic}
-          \polyglossia_latin_classic_settings:
-        }
-        {medieval}
-        {
-          \msg_info:nnn {polyglossia} {latin / language variant} {medieval}
-          \polyglossia_latin_medieval_settings:
-        }
-        {modern}
-        {
-          \msg_info:nnn {polyglossia} {latin / language variant} {modern}
-          \polyglossia_latin_modern_settings:
-        }
-        {ecclesiastic}
-        {
-          \msg_info:nnn {polyglossia} {latin / language variant} {ecclesiastic}
-          \polyglossia_latin_ecclesiastic_settings:
-        }
-      }
-      {
-        \msg_warning:nnn {polyglossia} {latin / illegal language variant} {#1}
-      }
-  }
-
-
-%%%%% Boolean options concerning spelling
-
-\define at boolkey{latin}[latin@]{usej}[true]
-  {
-    \iflatin at usej
-      \bool_set_true:N \l_polyglossia_latin_use_j_bool
-    \else
-      \bool_set_false:N \l_polyglossia_latin_use_j_bool
-    \fi
-  }
-
-\define at boolkey{latin}[latin@]{capitalizemonth}[true]
-  {
-    \iflatin at capitalizemonth
-      \bool_set_true:N \l_polyglossia_latin_capitalize_month_bool
-    \else
-      \bool_set_false:N \l_polyglossia_latin_capitalize_month_bool
-    \fi
-  }
-
-
 %%%%% Hyphenation variants: classic, liturgical, and modern
 
 \msg_new:nnn {polyglossia} {latin / hyphenation variant}
@@ -20951,23 +20940,6 @@
     The~Latin~hyphenation~variant~"#1"~is~undefined~\msg_line_context:.
   }
 
-\define at key {latin} {hyphenation}
-  {
-    \str_case:nnTF {#1}
-      {
-        {classic}    { \polyglossia_latin_set_patterns:n {classiclatin} }
-        {liturgical} { \polyglossia_latin_set_patterns:n {liturgicallatin} }
-        {modern}     { \polyglossia_latin_use_modern_patterns: }
-      }
-      {
-        \msg_info:nnn {polyglossia} {latin / hyphenation variant} {#1}
-      }
-      {
-        \msg_warning:nnn {polyglossia} {latin / illegal hyphenation variant} {#1}
-      }
-  }
-
-
 %%%%% Latin captions and date
 
 \def \captionslatin
@@ -21039,30 +21011,89 @@
       }
   }
 
-
-%%%%% Latin shorthands
-
-\define at boolkey{latin}[latin@]{babelshorthands}[true]
+\DeclareKeys[polyglossia/gloss/latin]
   {
+    babelshorthands.bool_set:N = \l_polyglossia_latin_babelshorthands_bool,
+    babelshorthands.default:n = true,
+    prosodicshorthands.bool_set:N = \l_polyglossia_latin_prosodic_shorthands_bool,
+    prosodicshorthands.default:n = true,
+    usej.bool_set:N = \l_polyglossia_latin_use_j_bool,
+    capitalizemonth.bool_set:N = \l_polyglossia_latin_capitalize_month_bool,
+    hyphenation.code = 
+    	\str_case:nnTF {#1}
+      {
+        {classic}    { \polyglossia_latin_set_patterns:n {classiclatin} }
+        {liturgical} { \polyglossia_latin_set_patterns:n {liturgicallatin} }
+        {modern}     { \polyglossia_latin_use_modern_patterns: }
+      }
+      {
+        \msg_info:nnn {polyglossia} {latin / hyphenation variant} {#1}
+      }
+      {
+        \msg_warning:nnn {polyglossia} {latin / illegal hyphenation variant} {#1}
+      },
+    variant.code = 
+    	  \str_case:nnF {#1}
+      {
+        {classic}
+        {
+          \msg_info:nnn {polyglossia} {latin / language variant} {classic}
+          \polyglossia_latin_classic_settings:
+        }
+        {medieval}
+        {
+          \msg_info:nnn {polyglossia} {latin / language variant} {medieval}
+          \polyglossia_latin_medieval_settings:
+        }
+        {modern}
+        {
+          \msg_info:nnn {polyglossia} {latin / language variant} {modern}
+          \polyglossia_latin_modern_settings:
+        }
+        {ecclesiastic}
+        {
+          \msg_info:nnn {polyglossia} {latin / language variant} {ecclesiastic}
+          \polyglossia_latin_ecclesiastic_settings:
+        }
+      }
+      {
+        \msg_warning:nnn {polyglossia} {latin / illegal language variant} {#1}
+      },
+    ecclesiasticfootnotes.choices:nn = { true, false }
+      { 
+        \ifcase\UseName{l_keys_choice_int}\or
+           \bool_set_true:N \l_polyglossia_latin_ecclesiastic_footnotes_bool
+        \else
+          \bool_set_false:N \l_polyglossia_latin_ecclesiastic_footnotes_bool
+        \fi
+        \xpg_if_in_preamble:TF
+          {
+            % within the preamble
+            % The application of the option has to be postponed as the main
+            % language may be undefined when the option is called.
+            \AtBeginDocument { \polyglossia_latin_apply_footnote_option: }
+          }
+          {
+            % within the document
+            \polyglossia_latin_apply_footnote_option:
+          }
+      },
+    ecclesiasticfootnotes.default:n = true
   }
 
-\define at boolkey{latin}[latin@]{prosodicshorthands}[true]
-  {
-  }
-
 % Register default options
-\xpg at initialize@gloss at options{latin}{variant=modern,hyphenation=modern,babelshorthands=false,
+\InitializeGlossOptions{latin}{variant=modern,hyphenation=modern,babelshorthands=false,
                                      prosodicshorthands=false,ecclesiasticfootnotes=false,
                                      usej=false,capitalizemonth=true}
 
 \ifsystem at babelshorthands
-  \setkeys{latin}{babelshorthands=true}
+  \SetGlossOptions{latin}{babelshorthands=true}
 \else
-  \setkeys{latin}{babelshorthands=false}
+  \SetGlossOptions{latin}{babelshorthands=false}
 \fi
 
 \ExplSyntaxOff % babelsh.def does not support expl3 syntax
-\ifcsundef{initiate at active@char}{\input{babelsh.def}}{}
+\@ifundefined{initiate at active@char}{\input{babelsh.def}}{}
 \ExplSyntaxOn
 
 \initiate at active@char {"}
@@ -21094,13 +21125,13 @@
 
 \AtBeginDocument
   {
-    \str_if_eq:VnTF \xpg at main@language {latin}
+    \IfMainLanguageTF {latin}
       {
-        \iflatin at prosodicshorthands
-        \else
+        \bool_if:NF \l_polyglossia_latin_prosodic_shorthands_bool
+         {
           \shorthandoff {=}
           \shorthandoff* {^}
-        \fi
+         }
       }
       {
         % The following command should not be called if the main language
@@ -21462,7 +21493,7 @@
 
 \let \xpgla at savedvalues \empty
 
-\AtEndPreamble
+\hook_gput_code:nnn { begindocument / before } {.}
   {
     \edef \xpgla at savedvalues
       {
@@ -21475,12 +21506,14 @@
 
 \def \noextras at latin
   {
-    \iflatin at babelshorthands
+    \bool_if:NT \l_polyglossia_latin_babelshorthands_bool
+     {
       \polyglossia_latin_no_shorthands:
-    \fi
-    \iflatin at prosodicshorthands
+     }
+    \bool_if:NT \l_polyglossia_latin_prosodic_shorthands_bool
+     {
       \polyglossia_latin_no_prosodic_shorthands:
-    \fi
+     }
     \xpgla at savedvalues
     \polyglossia_latin_no_punctuation_spacing:
     \polyglossia_latin_modern_character_codes:
@@ -21496,16 +21529,20 @@
       {
         \polyglossia_latin_punctuation_spacing:
       }
-    \iflatin at babelshorthands
+    \bool_if:NTF \l_polyglossia_latin_babelshorthands_bool
+     {
       \polyglossia_latin_shorthands:
-    \else
+     }
+     {
       \polyglossia_latin_no_shorthands:
-    \fi
-    \iflatin at prosodicshorthands
+     }
+    \bool_if:NTF \l_polyglossia_latin_prosodic_shorthands_bool
+     {
       \polyglossia_latin_prosodic_shorthands:
-    \else
+     }
+     { 
       \polyglossia_latin_no_prosodic_shorthands:
-    \fi
+     }
   }
 
 \def \blockextras at latin
@@ -21558,57 +21595,6 @@
 %    \end{macrocode}
 % \iffalse
 %</gloss-latin.ldf>
-%<*gloss-latinclassic.ldf>
-% \fi
-% \clearpage
-% 
-% \subsection{gloss-latinclassic.ldf}
-%    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
-%
-\ProvidesFile{gloss-latinclassic.ldf}[polyglossia: module for classic Latin]
-
-% We provide this as a babel alias
-
-\xpg at load@master at language{latin}
-
-%    \end{macrocode}
-% \iffalse
-%</gloss-latinclassic.ldf>
-%<*gloss-latinecclesiastic.ldf>
-% \fi
-% \clearpage
-% 
-% \subsection{gloss-latinecclesiastic.ldf}
-%    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
-%
-\ProvidesFile{gloss-latinecclesiastic.ldf}[polyglossia: module for ecclesiastic Latin]
-
-% We provide this as a babel alias
-
-\xpg at load@master at language{latin}
-
-%    \end{macrocode}
-% \iffalse
-%</gloss-latinecclesiastic.ldf>
-%<*gloss-latinmedieval.ldf>
-% \fi
-% \clearpage
-% 
-% \subsection{gloss-latinmedieval.ldf}
-%    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
-%
-\ProvidesFile{gloss-latinmedieval.ldf}[polyglossia: module for medieval Latin]
-
-% We provide this as a babel alias
-
-\xpg at load@master at language{latin}
-
-%    \end{macrocode}
-% \iffalse
-%</gloss-latinmedieval.ldf>
 %<*gloss-latvian.ldf>
 % \fi
 % \clearpage
@@ -21615,7 +21601,7 @@
 % 
 % \subsection{gloss-latvian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-latvian.ldf}[polyglossia: module for Latvian]
 \PolyglossiaSetup{latvian}{
@@ -21642,12 +21628,12 @@
    \def\contentsname{Saturs}%
    \def\listfigurename{Attēlu saraksts}%
    \def\listtablename{Tabulu saraksts}%
-   \def\indexname{Index}%
+   \def\indexname{Priekšmetu rādītājs}%
    \def\figurename{Att.}%
    \def\tablename{Tabula}%
    \def\partname{Daļa}%
-   \def\enclname{encl}%
-   \def\ccname{cc}%
+   \def\enclname{Pielikumā}%
+   \def\ccname{Kopija(s)}%
    \def\headtoname{To}%
    \def\pagename{lpp.}%
    \def\seename{sk.}%
@@ -21673,7 +21659,7 @@
 % 
 % \subsection{gloss-lithuanian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Translated by Paulius Sladkevičius <komsas at gmail.com>
 
@@ -21755,13 +21741,13 @@
 % 
 % \subsection{gloss-lo.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lo.ldf}[polyglossia: module for lo (Lao)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{lao}
+\InheritGlossFile{lao}
 
 %    \end{macrocode}
 % \iffalse
@@ -21772,13 +21758,13 @@
 % 
 % \subsection{gloss-lowersorbian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lowersorbian.ldf}[polyglossia: module for Lower Sorbian]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 %    \end{macrocode}
 % \iffalse
@@ -21789,7 +21775,7 @@
 % 
 % \subsection{gloss-lsorbian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lsorbian.ldf}[polyglossia: module for Lower Sorbian]
 
@@ -21796,7 +21782,7 @@
 % We only provide this gloss for babel compatibility. Since lsorbian is 
 % a sorbian variety, we use 'sorbian' with variant 'lower' now.
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 %    \end{macrocode}
 % \iffalse
@@ -21807,13 +21793,13 @@
 % 
 % \subsection{gloss-lt.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lt.ldf}[polyglossia: module for lt (Lithuanian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{lithuanian}
+\InheritGlossFile{lithuanian}
 
 %    \end{macrocode}
 % \iffalse
@@ -21824,13 +21810,13 @@
 % 
 % \subsection{gloss-lv.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lv.ldf}[polyglossia: module for lv (Latvian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{latvian}
+\InheritGlossFile{latvian}
 
 %    \end{macrocode}
 % \iffalse
@@ -21841,7 +21827,7 @@
 % 
 % \subsection{gloss-macedonian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-macedonian.ldf}[polyglossia: module for Macedonian]
 \PolyglossiaSetup{macedonian}{
@@ -21940,13 +21926,13 @@
 % 
 % \subsection{gloss-magyar.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-magyar.ldf}[polyglossia: module for Hungarian (Magyar)]
 
 % We only provide this gloss for babel compatibility.
 
-\xpg at load@master at language{hungarian}
+\InheritGlossFile{hungarian}
 
 %    \end{macrocode}
 % \iffalse
@@ -21957,7 +21943,7 @@
 % 
 % \subsection{gloss-malay.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-malay.ldf}[polyglossia: module for Malay]
 
@@ -21985,65 +21971,44 @@
 % Backwards compat. alias
 \setlanguagealias[variant=malaysian]{malay}{bahasam}
 
-\providebool{malay at melayu}
+\@ifundefined{ifmalay at melayu}%
+  {\newif\ifmalay at melayu}{}
 \malay at melayufalse
 \def\malay at variant{malay}
-\define at choicekey*+{malay}{variant}[\xpg at val\xpg at nr]{indonesian,malaysian}[malaysian]{%
-   \ifcase\xpg at 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,bcp47=zsm,bcp47-language=zsm}%
-      \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,bcp47=id,bcp47-language=id}%
-      \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=\xpg at val}%
-}{\xpg at warning{Unknown malay variant `#1'}}
 
+\DeclareKeys[polyglossia/gloss/malay]
+  {
+    variant.choice:,
+    variant / indonesian.code = 
+      {%
+        \def\malay at variant{indonesian}%
+        \malay at melayufalse
+        \SetLanguageKeys{malay}{language=Indonesian,langtag=IND,babelname=bahasa,bcp47=id,bcp47-language=id}%
+        \SetupLatinPolyglossiaFont{malay}%
+        % Check if \l at indonesian is defined. If not, try to set it to some variety
+        % (specific order as in the csv list), or null language if everything fails
+        \TryPatternWithFallback{indonesian}{indon,bahasai,bahasam,malay,melayu,bahasa}%
+      },
+    variant / malaysian.code =
+      {%
+        \def\malay at variant{malay}%
+        \malay at melayutrue
+        \SetLanguageKeys{malay}{language=Malay,langtag=MLY,babelname=bahasam,bcp47=zsm,bcp47-language=zsm}%
+        \SetupLatinPolyglossiaFont{malay}%
+        % Check if \l at malay is defined. If not, try to set it to some variety
+        % (specific order as in the csv list), or null language if everything fails
+        \TryPatternWithFallback{malay}{melayu,bahasam,bahasai,indonesian,indon,bahasa}%
+      },
+    variant.default:n = malaysian,
+    variant/unknown.code = \xpg at warning{Unknown malay variant `#1'},
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{malay}{variant=malaysian}
+\InitializeGlossOptions{malay}{variant=malaysian}
 
 
 \def\malay at language{%
-   \polyglossia at setup@language at patterns{\malay at variant}%
+   \SetupPolyglossiaLangPatterns{\malay at variant}%
 }%
 
 
@@ -22156,7 +22121,7 @@
 % 
 % \subsection{gloss-malayalam.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-malayalam.ldf}[polyglossia: module for Malayalam]
 
@@ -22226,7 +22191,7 @@
 % 
 % \subsection{gloss-marathi.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Translations provided by Abhijit Navale <abhi_navale at live.in>
 % Ordinals (1-100) added by Niranjan Tambe <niranjanvikastambe at gmail.com> on 14th December, 2019
@@ -22256,21 +22221,25 @@
 \newif\ifmarathi at devanagari@numerals
 \marathi at devanagari@numeralstrue
 
-\define at choicekey*+{marathi}{numerals}[\xpg at val\xpg at nr]{Western,Devanagari}[Devanagari]{%
-   \ifcase\xpg at nr\relax
-      % Western:
-      \marathi at devanagari@numeralsfalse%
-      \SetLanguageKeys{marathi}{bcp47-extension-u=nu-latn}%
-   \or
-      % Devanagari:
-      \marathi at devanagari@numeralstrue%
-      \SetLanguageKeys{marathi}{bcp47-extension-u=nu-deva}%
-   \fi
-   \xpg at info{Option: Marathi, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Marathi numerals value `#1'}}
+\DeclareKeys[polyglossia/gloss/marathi]
+  {
+    numerals.choice:,
+    numerals / western.code =
+      {%
+        \marathi at devanagari@numeralsfalse
+        \SetLanguageKeys{marathi}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / devanagari.code =
+      {%
+        \marathi at devanagari@numeralstrue
+        \SetLanguageKeys{marathi}{bcp47-extension-u=nu-deva}%
+      },
+    numerals.default:n = devanagari,
+    numerals/unknown.code = \xpg at warning{Unknown Marathi numerals value `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{marathi}{numerals=Devanagari}
+\InitializeGlossOptions{marathi}{numerals=Devanagari}
 
 \newcommand{\marathinumerals}[2]{\marathinumber{#2}}
 
@@ -22370,6 +22339,23 @@
 %    \end{macrocode}
 % \iffalse
 %</gloss-marathi.ldf>
+%<*gloss-medievallatin.ldf>
+% \fi
+% \clearpage
+% 
+% \subsection{gloss-medievallatin.ldf}
+%    \begin{macrocode}
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
+%
+\ProvidesFile{gloss-medievallatin.ldf}[polyglossia: module for medieval Latin]
+
+% We provide this as a babel alias
+
+\InheritGlossFile{latin}
+
+%    \end{macrocode}
+% \iffalse
+%</gloss-medievallatin.ldf>
 %<*gloss-mk.ldf>
 % \fi
 % \clearpage
@@ -22376,13 +22362,13 @@
 % 
 % \subsection{gloss-mk.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-mk.ldf}[polyglossia: module for mk (Macedonian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{macedonian}
+\InheritGlossFile{macedonian}
 
 %    \end{macrocode}
 % \iffalse
@@ -22393,13 +22379,13 @@
 % 
 % \subsection{gloss-ml.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ml.ldf}[polyglossia: module for ml (Malayalam)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{malayalam}
+\InheritGlossFile{malayalam}
 
 %    \end{macrocode}
 % \iffalse
@@ -22410,13 +22396,13 @@
 % 
 % \subsection{gloss-mn.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-mn.ldf}[polyglossia: module for mn (Mongolian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{mongolian}
+\InheritGlossFile{mongolian}
 
 %    \end{macrocode}
 % \iffalse
@@ -22427,7 +22413,7 @@
 % 
 % \subsection{gloss-mongolian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-mongolian.ldf}[polyglossia: module for Mongolian]
 
@@ -22459,43 +22445,46 @@
 
 \newif\ifcyrillic at numerals
 \newif\ifcyrillic at asbuk@numerals
-\define at choicekey*+{mongolian}{numerals}[\xpg at val\xpg at nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % arabic:
-      \cyrillic at numeralsfalse%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic-trad:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic-alph:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralstrue%
-   \fi
-   \xpg at info{Option: Mongolian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Mongolian numerals value `#1'}}
 
-\define at boolkey{mongolian}[mongolian@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/mongolian]
+  {
+    babelshorthands.if = mongolian at babelshorthands,
+    babelshorthands.default:n = true,
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \cyrillic at numeralsfalse
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic-trad.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic-alph.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralstrue
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Mongolian numerals value `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{mongolian}{babelshorthands=false,numerals=arabic}
+\InitializeGlossOptions{mongolian}{babelshorthands=false,numerals=arabic}
 
 \ifsystem at babelshorthands
-  \setkeys{mongolian}{babelshorthands=true}
+  \SetGlossOptions{mongolian}{babelshorthands=true}
 \else
-  \setkeys{mongolian}{babelshorthands=false}
+  \SetGlossOptions{mongolian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\mongolian at shorthands{%
   \xpg at activate@shorthands%
@@ -22548,7 +22537,7 @@
    \def\bibname{Номзүй}%
    \def\chaptername{Бүлэг}%
    \def\appendixname{Хавсралт}%
-   \ifcsundef{thechapter}%
+   \@ifundefined{thechapter}%
      {\def\contentsname{Агуулга}}%
      {\def\contentsname{Гарчиг}}%
    \def\listfigurename{Зургийн жагсаалт}%
@@ -22666,13 +22655,13 @@
 % 
 % \subsection{gloss-mr.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-mr.ldf}[polyglossia: module for mr (Marathi)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{marathi}
+\InheritGlossFile{marathi}
 
 %    \end{macrocode}
 % \iffalse
@@ -22683,13 +22672,13 @@
 % 
 % \subsection{gloss-naustrian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-naustrian.ldf}[polyglossia: module for Austrian German (current spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -22700,13 +22689,13 @@
 % 
 % \subsection{gloss-nb.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-nb.ldf}[polyglossia: module for nb (Norwegian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{norwegian}
+\InheritGlossFile{norwegian}
 
 %    \end{macrocode}
 % \iffalse
@@ -22717,13 +22706,13 @@
 % 
 % \subsection{gloss-newzealand.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-newzealand.ldf}[polyglossia: module for Newzealand English]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 %    \end{macrocode}
 % \iffalse
@@ -22734,13 +22723,13 @@
 % 
 % \subsection{gloss-ngerman.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ngerman.ldf}[polyglossia: module for German (current spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -22751,7 +22740,7 @@
 % 
 % \subsection{gloss-nko.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-nko.ldf}[Polyglossia: module for N’Ko]
 \PolyglossiaSetup{nko}{%
@@ -22849,7 +22838,7 @@
 % 
 % \subsection{gloss-norsk.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-norsk.ldf}[polyglossia: module for Norwegian (Bokmal)]
 
@@ -22856,7 +22845,7 @@
 % We only provide this gloss for babel compatibility. Since norsk is 
 % actually norwegian bokmal, we use 'norwegian' with variant 'bokmal' now.
 
-\xpg at load@master at language{norwegian}
+\InheritGlossFile{norwegian}
 
 %    \end{macrocode}
 % \iffalse
@@ -22867,7 +22856,7 @@
 % 
 % \subsection{gloss-norwegian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-norwegian.ldf}[polyglossia: module for Norwegian]
 \PolyglossiaSetup{norwegian}{
@@ -22889,28 +22878,32 @@
 \setlanguagealias[variant=nynorsk]{norwegian}{nynorsk}
 
 \def\norwegian at variant{nynorsk}
-\define at choicekey*+{norwegian}{variant}[\xpg at val\xpg at nr]{nynorsk,bokmal}[nynorsk]{%
-   \ifcase\xpg at nr\relax
-      % nynorsk:
-      \def\norwegian at variant{nynorsk}%
-      \SetLanguageKeys{norwegian}{langtag=NYN,babelname=nynorsk,bcp47=nn,bcp47-language=nn}%
-      \xpg at fontsetup@latin{norwegian}%
-   \or
-      % bokmal:
-      \def\norwegian at variant{norsk}%
-      \SetLanguageKeys{norwegian}{langtag=NOR,babelname=norsk,bcp47=nb,bcp47-language=nb}%
-      \xpg at fontsetup@latin{norwegian}%
-   \fi
-   \xpg at info{Option: norwegian, variant=\xpg at val}%
-}{\xpg at warning{Unknown norwegian variant `#1'}}
 
+\DeclareKeys[polyglossia/gloss/norwegian]
+  {
+    variant.choice:,
+    variant / nynorsk.code =
+      {%
+          \def\norwegian at variant{nynorsk}%
+          \SetLanguageKeys{norwegian}{langtag=NYN,babelname=nynorsk,bcp47=nn,bcp47-language=nn}%
+          \SetupLatinPolyglossiaFont{norwegian}%
+      },
+    variant / bokmal.code =
+      {%
+          \def\norwegian at variant{norsk}%
+          \SetLanguageKeys{norwegian}{langtag=NOR,babelname=norsk,bcp47=nb,bcp47-language=nb}%
+          \SetupLatinPolyglossiaFont{norwegian}%
+      },
+    variant.default:n = nynorsk,
+    variant/unknown.code = \xpg at warning{Unknown norwegian variant `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{norwegian}{variant=nynorsk}
+\InitializeGlossOptions{norwegian}{variant=nynorsk}
 
 
 \def\norwegian at language{%
-   \polyglossia at setup@language at patterns{\norwegian at variant}%
+   \SetupPolyglossiaLangPatterns{\norwegian at variant}%
 }%
 
 \def\captionsnorwegian at nynorsk{%
@@ -22994,13 +22987,13 @@
 % 
 % \subsection{gloss-nswissgerman.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-nswissgerman.ldf}[polyglossia: module for Swiss German (current spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -23011,7 +23004,7 @@
 % 
 % \subsection{gloss-nynorsk.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-nynorsk.ldf}[polyglossia: module for Norwegian (Nynorsk)]
 
@@ -23018,7 +23011,7 @@
 % We only provide this gloss for babel compatibility. Since nynorsk is 
 % a norwegian variety, we use 'norwegian' with variant 'nynorsk' now.
 
-\xpg at load@master at language{norwegian}
+\InheritGlossFile{norwegian}
 
 %    \end{macrocode}
 % \iffalse
@@ -23029,7 +23022,7 @@
 % 
 % \subsection{gloss-occitan.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 %%
 %% This is file `gloss-occitan.ldf',
@@ -23065,19 +23058,19 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{occitan}{oc}
 
-\define at boolkey{occitan}[occitan@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/occitan]
+  {
+    babelshorthands.if = occitan at babelshorthands,
+    babelshorthands.default:n = true
+  }
 
 \ifsystem at babelshorthands
-  \setkeys{occitan}{babelshorthands=true}
+  \SetGlossOptions{occitan}{babelshorthands=true}
 \else
-  \setkeys{occitan}{babelshorthands=false}
+  \SetGlossOptions{occitan}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\occitan at shorthands{%
   \xpg at activate@shorthands%
@@ -23169,7 +23162,7 @@
    \def\today{\occitanday\space \occitanmonth\space de~\number\year}%
 }
 \let\xpgoc at savedvalues\empty
-\AtEndPreamble{% the user or the class might define different values
+\AddToHook{begindocument/before}{% the user or the class might define different values
   \edef\xpgoc at savedvalues{%
     \clubpenalty=\the\clubpenalty\space
     \@clubpenalty=\the\@clubpenalty\space
@@ -23210,7 +23203,7 @@
 % 
 % \subsection{gloss-odia.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Translations provided by ଅଶୋକ ଦାସ୍ <das at pas.rochester.edu> and ଅଭିଷେକ ଜେନା <avisekjena at gmail.com>
 % TODO implement Odia calendar
@@ -23242,32 +23235,37 @@
 
 \newif\ifodia at devanagari@numerals
 \newif\ifodia at odia@numerals
-\define at choicekey*+{odia}{numerals}[\xpg at val\xpg at nr]{Devanagari,Odia,Western}[Devanagari]{%
-   \ifcase\xpg at nr\relax
-      % Devanagari:
-      \odia at odia@numeralsfalse%
-      \odia at devanagari@numeralstrue%
-      \SetLanguageKeys{odia}{bcp47=or,bcp47-language=or,bcp47-extension-u=nu-deva}%
-   \or
-      % Odia:
-      \odia at odia@numeralstrue%
-      \odia at devanagari@numeralsfalse%
-   \or
-      % Western:
-      \odia at odia@numeralsfalse%
-      \odia at devanagari@numeralsfalse%
-      \SetLanguageKeys{odia}{bcp47=or,bcp47-language=or,bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Odia, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Odia numeral `#1'}}
-
 \def\extras at odia{}
 \def\noextras at odia{}
 
-\define at boolkey{odia}[odia@]{changecounternumbering}[true]{}
+\DeclareKeys[polyglossia/gloss/odia]
+  {
+    changecounternumbering.if = odia at changecounternumbering,
+    changecounternumbering.default:n = true,
+    numerals.choice:,
+    numerals / devanagari.code =
+      {%
+        \odia at odia@numeralsfalse
+        \odia at devanagari@numeralstrue
+        \SetLanguageKeys{odia}{bcp47=or,bcp47-language=or,bcp47-extension-u=nu-deva}%
+      },
+    numerals / odia.code =
+      {%
+        \odia at odia@numeralstrue
+        \odia at devanagari@numeralsfalse
+      },
+    numerals / western.code =
+      {%
+        \odia at odia@numeralsfalse
+        \odia at devanagari@numeralsfalse
+        \SetLanguageKeys{odia}{bcp47=or,bcp47-language=or,bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = devanagari,
+    numerals/unknown.code = \xpg at warning{Unknown Odia numeral `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{odia}{changecounternumbering=false,numerals=Devanagari}
+\InitializeGlossOptions{odia}{changecounternumbering=false,numerals=Devanagari}
 
 \def\captionsodia{%
   \def\refname{ସନ୍ଦର୍ଭ}%
@@ -23370,13 +23368,13 @@
 % 
 % \subsection{gloss-or.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-odia.ldf}[polyglossia: module for or (Odia)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{odia}
+\InheritGlossFile{odia}
 
 %    \end{macrocode}
 % \iffalse
@@ -23387,13 +23385,13 @@
 % 
 % \subsection{gloss-pa.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-pa.ldf}[polyglossia: module for pa (Punjabi)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{punjabi}
+\InheritGlossFile{punjabi}
 
 %    \end{macrocode}
 % \iffalse
@@ -23404,7 +23402,7 @@
 % 
 % \subsection{gloss-persian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-persian.ldf}[polyglossia: module for Persian]
 
@@ -23433,42 +23431,36 @@
 \setlanguagealias{persian}{farsi}
 
 \newif\if at western@numerals
-\define at choicekey*+{persian}{numerals}[\xpg at val\xpg at nr]{eastern,western}[eastern]{%
-   \ifcase\xpg at nr\relax
-      % eastern:
-      \@western at numeralsfalse%
-      \SetLanguageKeys{persian}{bcp47-extension-u=nu-arab}%
-   \or
-      % western:
-      \@western at numeralstrue%
-      \SetLanguageKeys{persian}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Persian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Persian numerals option `#1'}}
-
 \newif\ifpersian at customsep\persian at customsepfalse
 \def\xpg at sepmark{}
-\define at key{persian}{sectionsep}[.]{%
-   \persian at customseptrue%
-   \gdef\xpg at sepmark{#1}%
-}
 
-%this is needed for \abjad in arabicnumbers.sty
-\define at boolkey{persian}[persian@]{abjadjimnotail}[true]{%
-  \ifpersian at abjadjimnotail
-    \abjad at jim@notailtrue%
-  \else
-    \abjad at jim@notailfalse
-  \fi}
+%TODO add option for CALENDAR
 
-% NOT YET USED
-\define at key{persian}{locale}[default]{%
-  \def\@persian at locale{#1}}
+\DeclareKeys[polyglossia/gloss/persian]
+  {
+    sectionsep.code = \gdef\xpg at sepmark{#1}\persian at customseptrue,
+    sectionsep.default:n = .,
+    abjadjimnotail.if = abjad at jim@notail,
+    abjadjimnotail.default:n = true,
+    locale.store = \@persian at locale,
+    locale.default:n = default,
+    numerals.choice:,
+    numerals / eastern.code =
+      {%
+          \@western at numeralsfalse
+          \SetLanguageKeys{persian}{bcp47-extension-u=nu-arab}%
+      },
+    numerals / western.code =
+      {%
+          \@western at numeralstrue
+          \SetLanguageKeys{persian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = eastern,
+    numerals/unknown.code = \xpg at warning{Unknown Persian numerals option `#1'}
+  }
 
-%TODO add option for CALENDAR
-
 % Register default options
-\xpg at initialize@gloss at options{persian}{locale=default,numerals=eastern,abjadjimnotail=false}
+\InitializeGlossOptions{persian}{locale=default,numerals=eastern,abjadjimnotail=false}
 
 \def\farsigregmonth#1{\ifcase#1%
   \or ژانویه\or فوریه\or مارس\or آوریل\or مه\or ژوئن\or ژوئیه\or اوت\or سپتامبر\or اکتبر\or نوامبر\or دسامبر\fi}
@@ -23553,9 +23545,9 @@
 }
 
 \def\nopersian at xetex@capsformat{%
-   \ifcsdef{xpg at save@sepmark}{%
+   \ifcsname xpg at save@sepmark\endcsname%
      \SepMark{\xpg at save@sepmark}
-   }{}%
+   \fi%
 }
 
 \def\persian at luatex@capsformat{%
@@ -23562,7 +23554,7 @@
   %
   % change chapter and part headings
   \ifpersian at customsep
-     \ifcsdef{chapter}{%
+     \ifcsname chapter\endcsname%
         \let\xpg at save@thesection\thesection%
         \renewcommand*\thesection{\thechapter\xpg at sepmark\@arabic\c at section}
         \let\xpg at save@theequation\theequation%
@@ -23574,7 +23566,7 @@
         \let\xpg at save@thetable\thetable%
 	\renewcommand*\thetable{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at table}
-     }{}
+     \fi%
      \let\xpg at save@thesubsection\thesubsection%
      \renewcommand\thesubsection
 	{\thesection\xpg at sepmark\@arabic\c at subsection}
@@ -23589,30 +23581,30 @@
 }
 
 \def\nopersian at luatex@capsformat{%
-   \ifcsdef{xpg at save@thesection}{%
+   \ifcsname xpg at save@thesection\endcsname%
         \let\thesection\xpg at save@thesection%
-   }{}%
-   \ifcsdef{xpg at save@theequation}{%
+   \fi%
+   \ifcsname xpg at save@theequation\endcsname%
         \let\theequation\xpg at save@theequation%
-   }{}%
-   \ifcsdef{xpg at save@thefigure}{%
+   \fi%
+   \ifcsname xpg at save@thefigure\endcsname%
         \let\thefigure\xpg at save@thefigure%
-   }{}%
-   \ifcsdef{xpg at save@thetable}{%
+   \fi%
+   \ifcsname xpg at save@thetable\endcsname%
         \let\thetable\xpg at save@thetable%
-   }{}%
-   \ifcsdef{xpg at save@thesubsection}{%
+   \fi%
+   \ifcsname xpg at save@thesubsection\endcsname%
         \let\thesubsection\xpg at save@thesubsection%
-   \ifcsdef{xpg at save@thesubsubsection}{%
+      \ifcsname xpg at save@thesubsubsection\endcsname%
         \let\thesubsubsection\xpg at save@thesubsubsection%
-   }{}%
-   }{}%
-   \ifcsdef{xpg at save@theparagraph}{%
+      \fi%
+   \fi%
+   \ifcsname xpg at save@theparagraph\endcsname%
         \let\theparagraph\xpg at save@theparagraph%
-   }{}%
-   \ifcsdef{xpg at save@thesubparagraph}{%
+   \fi%
+   \ifcsname xpg at save@thesubparagraph\endcsname%
         \let\thesubparagraph\xpg at save@thesubparagraph%
-   }{}%
+   \fi%
 }
 
 \def\blockextras at persian{%
@@ -23645,7 +23637,7 @@
 % \subsection{gloss-piedmontese.ldf}
 %    \begin{macrocode}
 % !TEX encoding = UTF-8 Unicode
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-piedmontese.ldf}[2013/02/12 v1.0 polyglossia: module for Piedmontese]
 \makeatletter
@@ -23663,19 +23655,19 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{piedmontese}{pms}
 
-\define at boolkey{piedmontese}[piedmontese@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/piedmontese]
+  {
+    babelshorthands.if = piedmontese at babelshorthands,
+    babelshorthands.default:n = true
+  }
 
 \ifsystem at babelshorthands
-  \setkeys{piedmontese}{babelshorthands=true}
+  \SetGlossOptions{piedmontese}{babelshorthands=true}
 \else
-  \setkeys{piedmontese}{babelshorthands=false}
+  \SetGlossOptions{piedmontese}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\piedmontese at shorthands{%
   \xpg at activate@shorthands%
@@ -23739,7 +23731,7 @@
       ëd luj\or d'agost\or dë stèmber\or d'otóber\or ëd novèmber\or dë dzèmber%
       \fi\space dal\space\number\year}}
       
-\AtEndPreamble{% 
+\AddToHook{begindocument/before}{% 
   \edef\xpgpms at savedvalues{%
     \clubpenalty=\the\clubpenalty\space
     \@clubpenalty=\the\@clubpenalty\space
@@ -23775,7 +23767,7 @@
 % 
 % \subsection{gloss-polish.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-polish.ldf}[polyglossia: module for Polish]
 
@@ -23797,26 +23789,26 @@
   \RequirePackage{luavlna}
 \fi
 
-\define at boolkey{polish}[polish@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/polish]
+  {
+    babelshorthands.if = polish at babelshorthands,
+    babelshorthands.default:n = true,
+    splithyphens.if = polish at splithyphens,
+    splithyphens.default:n = true,
+    vlna.if = polish at vlna,
+    vlna.default:n = true,
+  }
 
-\define at boolkey{polish}[polish@]{splithyphens}[true]{}
-
-\define at boolkey{polish}[polish@]{vlna}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{polish}{babelshorthands=false,splithyphens=true,vlna=true}
+\InitializeGlossOptions{polish}{babelshorthands=false,splithyphens=true,vlna=true}
 
 \ifsystem at babelshorthands
-  \setkeys{polish}{babelshorthands=true}
+  \SetGlossOptions{polish}{babelshorthands=true}
 \else
-  \setkeys{polish}{babelshorthands=false}
+  \SetGlossOptions{polish}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \let\xpg at hyphen@char-
 \def\polish@@splhyphen#1{%
@@ -24034,13 +24026,13 @@
 % 
 % \subsection{gloss-polutonikogreek.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-polutonikogreek.ldf}[polyglossia: module for polytonic Greek]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{greek}
+\InheritGlossFile{greek}
 
 %    \end{macrocode}
 % \iffalse
@@ -24051,7 +24043,7 @@
 % 
 % \subsection{gloss-portuges.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-portuges.ldf}[polyglossia: module for Portuguese]
 
@@ -24060,7 +24052,7 @@
 % introduced it in 8.3 filename times). Since polyglossia uses full
 % English language names, we use 'portuguese' now.
 
-\xpg at load@master at language{portuguese}
+\InheritGlossFile{portuguese}
      
 %    \end{macrocode}
 % \iffalse
@@ -24071,7 +24063,7 @@
 % 
 % \subsection{gloss-portuguese.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-portuguese.ldf}[polyglossia: module for Portuguese]
 
@@ -24101,41 +24093,42 @@
 \fi
 
 \def\portuguese at variant{portuges}
-\define at choicekey*+{portuguese}{variant}[\xpg at val\xpg at nr]{portuguese,brazilian}[portuguese]{%
-   \ifcase\xpg at nr\relax
-      % portuguese:
-      \def\portuguese at variant{portuges}%
-      \SetLanguageKeys{portuguese}{babelname=portuges,bcp47=pt-PT,bcp47-language=pt,bcp47-region=PT}%
-   \or
-      % brazilian:
-      \def\portuguese at variant{brazil}%
-      \SetLanguageKeys{portuguese}{babelname=brazil,bcp47=pt-BR,bcp47-language=pt,bcp47-region=BR}%
-      % There are no specific brazil patterns
-      \adddialect\l at brazil\l at portuges\relax%
-   \fi
-   \xpg at info{Option: portuguese, variant=\xpg at val}%
-}{\xpg at warning{Unknown portuguese variant `#1'}}
 
-\define at boolkey{portuguese}[portuguese@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/portuguese]
+  {
+    babelshorthands.if = portuguese at babelshorthands,
+    babelshorthands.default:n = true,
+    splithyphens.if = portuguese at splithyphens,
+    splithyphens.default:n = true,
+    variant.choice:,
+    variant / portuguese.code =
+      {%
+        \def\portuguese at variant{portuges}%
+        \SetLanguageKeys{portuguese}{babelname=portuges,bcp47=pt-PT,bcp47-language=pt,bcp47-region=PT}%
+      },
+    variant / brazilian.code =
+      {%
+        \def\portuguese at variant{brazil}%
+        \SetLanguageKeys{portuguese}{babelname=brazil,bcp47=pt-BR,bcp47-language=pt,bcp47-region=BR}%
+        % There are no specific brazil patterns
+        \adddialect\l at brazil\l at portuges\relax
+      },
+    variant.default:n = portuguese,
+    variant/unknown.code = \xpg at warning{Unknown portuguese variant `#1'},
+  }
 
-\define at boolkey{portuguese}[portuguese@]{splithyphens}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{portuguese}{variant=portuguese,
+\InitializeGlossOptions{portuguese}{variant=portuguese,
       babelshorthands=false,
       splithyphens=true}
 
 \ifsystem at babelshorthands
-  \setkeys{portuguese}{babelshorthands=true}
+  \SetGlossOptions{portuguese}{babelshorthands=true}
 \else
-  \setkeys{portuguese}{babelshorthands=false}
+  \SetGlossOptions{portuguese}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \let\xpg at hyphen@char-
 \def\portuguese@@splhyphen#1{%
@@ -24204,7 +24197,7 @@
 }
 
 \def\portuguese at language{%
-   \polyglossia at setup@language at patterns{\portuguese at variant}%
+   \SetupPolyglossiaLangPatterns{\portuguese at variant}%
 }%
 
 \def\captionsportuguese at portuges{%
@@ -24302,7 +24295,7 @@
 % 
 % \subsection{gloss-punjabi.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % UTF-8 strings kindly provided by 
 % Arvinder Singh Kang, <17-11-2022>
@@ -24329,26 +24322,31 @@
 
 \def\punjabi at language{%
   % patterns are spelled panjabi
-  \polyglossia at setup@language at patterns{panjabi}%
+  \SetupPolyglossiaLangPatterns{panjabi}%
 }
 
 \newif\ifpunjabi at gurmukhi@numerals
 \punjabi at gurmukhi@numeralstrue
-\define at choicekey*+{punjabi}{numerals}[\xpg at val\xpg at nr]{Gurmukhi,Western}[Gurmukhi]{%
-   \ifcase\xpg at nr\relax
-      % Gurmukhi:
-      \punjabi at gurmukhi@numeralstrue%
-      \SetLanguageKeys{punjabi}{bcp47-extension-u=nu-guru}%
-   \or
-      % Western:
-      \punjabi at gurmukhi@numeralsfalse%
-      \SetLanguageKeys{punjabi}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Punjabi, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Punjabi numeral `#1'}}
 
+\DeclareKeys[polyglossia/gloss/punjabi]
+  {
+    numerals.choice:,
+    numerals / gurmukhi.code =
+      {%
+        \punjabi at gurmukhi@numeralstrue
+        \SetLanguageKeys{punjabi}{bcp47-extension-u=nu-guru}%
+      },
+    numerals / western.code =
+      {%
+        \punjabi at gurmukhi@numeralsfalse
+        \SetLanguageKeys{punjabi}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = gurmukhi,
+    numerals/unknown.code = \xpg at warning{Unknown Punjabi numeral `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{punjabi}{numerals=gurmukhi}
+\InitializeGlossOptions{punjabi}{numerals=gurmukhi}
 
 \newcommand{\punjabinumerals}[2]{\punjabinumber{#2}}
 
@@ -24410,7 +24408,7 @@
 % 
 % \subsection{gloss-romanian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-romanian.ldf}[polyglossia: module for Romanian]
 
@@ -24469,7 +24467,7 @@
 % 
 % \subsection{gloss-romansh.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-romansh.ldf}[polyglossia: module for Romansh]
 \makeatletter
@@ -24527,7 +24525,7 @@
 % 
 % \subsection{gloss-russian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-russian.ldf}[polyglossia: module for Russian]
 
@@ -24556,11 +24554,6 @@
 \setlanguagealias*[spelling=old]{russian}{ru-petr1708}
 
 \newif\if at russian@modern
-\define at key{russian}{spelling}[modern]{%
-  \ifstrequal{#1}{old}%
-    {\@russian at modernfalse\SetLanguageKeys{russian}{bcp47=ru-petr1708,bcp47-variant=petr1708}}%
-    {\@russian at moderntrue\SetLanguageKeys{russian}{bcp47=ru,bcp47-variant=luna1918}}%
-}
 
 \def\captionsrussian{%
    \if at russian@modern\captionsrussian at modern\else\captionsrussian at old\fi%
@@ -24572,49 +24565,68 @@
 
 \newif\ifcyrillic at numerals
 \newif\ifcyrillic at asbuk@numerals
-\define at choicekey*+{russian}{numerals}[\xpg at val\xpg at nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % arabic:
-      \cyrillic at numeralsfalse%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{russian}{bcp47-extension-u=nu-latn}%
-   \or
-      % cyrillic:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-trad:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-alph:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralstrue%
-      \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
-   \fi
-   \xpg at info{Option: Russian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Russian numerals value `#1'}}
 
-\define at boolkey{russian}[russian@]{indentfirst}[true]{%
-  \ifrussian at indentfirst
-      \SetLanguageKeys{russian}{indentfirst=true}%
-  \else
-      \SetLanguageKeys{russian}{indentfirst=false}%
-  \fi%
-}
+\DeclareKeys[polyglossia/gloss/russian]
+  {
+    babelshorthands.if = russian at babelshorthands,
+    babelshorthands.default:n = true,
+    forceheadingpunctuation.if = russian at forceheadingpunctuation,
+    forceheadingpunctuation.default:n = true,
+    mathfunctions.if = russian at mathfunctions,
+    mathfunctions.default:n = true,
+    spelling.choice:,
+    spelling / modern.code =
+      {%
+        \@russian at moderntrue
+        \SetLanguageKeys{russian}{bcp47=ru,bcp47-variant=luna1918}%
+      },
+    spelling / old.code =
+      {%
+        \@russian at modernfalse
+        \SetLanguageKeys{russian}{bcp47=ru-petr1708,bcp47-variant=petr1708}%
+      },
+    spelling.default:n = modern,
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \cyrillic at numeralsfalse
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{russian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / cyrillic.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-trad.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-alph.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralstrue
+        \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Russian numerals value `#1'},
+    indentfirst.choice:,
+    indentfirst / true.code =
+      {%
+        \SetLanguageKeys{russian}{indentfirst=true}%
+      },
+    indentfirst / false.code =
+      {%
+        \SetLanguageKeys{russian}{indentfirst=false}%
+      },
+    indentfirst.default:n = true,
+  }
 
-\define at boolkey{russian}[russian@]{babelshorthands}[true]{}
-
-% Force punctuation after heading number
-\define at boolkey{russian}[russian@]{forceheadingpunctuation}[true]{}
-
-% Define some math functions
-\define at boolkey{russian}[russian@]{mathfunctions}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{russian}{babelshorthands=false,
+\InitializeGlossOptions{russian}{babelshorthands=false,
                                        spelling=modern,
                                        numerals=arabic,
                                        indentfirst=true,
@@ -24623,16 +24635,12 @@
 
 
 \ifsystem at babelshorthands
-  \setkeys{russian}{babelshorthands=true}
+  \SetGlossOptions{russian}{babelshorthands=true}
 \else
-  \setkeys{russian}{babelshorthands=false}
+  \SetGlossOptions{russian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\russian at shorthands{%
   \xpg at activate@shorthands%
@@ -24684,7 +24692,7 @@
    \def\bibname{Литература}%
    \def\chaptername{Глава}%
    \def\appendixname{Приложение}%
-   \ifcsundef{thechapter}%
+   \@ifundefined{thechapter}%
      {\def\contentsname{Содержание}}%
      {\def\contentsname{Оглавление}}%
    \def\listfigurename{Список иллюстраций}%
@@ -24727,7 +24735,7 @@
    \def\bibname{Библіографія}%
    \def\chaptername{Глава}%
    \def\appendixname{Приложеніе}%
-   \ifcsundef{thechapter}%
+   \@ifundefined{thechapter}%
      {\def\contentsname{Содержаніе}}%
      {\def\contentsname{Оглавленіе}}%
    \def\listfigurename{Списокъ иллюстрацій}%
@@ -24926,7 +24934,7 @@
 % 
 % \subsection{gloss-sami.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-sami.ldf}[polyglossia: module for Sami]
 
@@ -24956,12 +24964,12 @@
 %      % northern:
 %      \def\sami at variant{samin}%
 %      \SetLanguageKeys{sami}{language=Northern Sami,langtag=NSM}%
-%      \xpg at fontsetup@latin{sami}%
+%      \SetupLatinPolyglossiaFont{sami}%
 %   \or
 %      % other:
 %      \def\sami at variant{}%
 %      \SetLanguageKeys{sami}{language= Sami,langtag=}%
-%      \xpg at fontsetup@latin{sami}%
+%      \SetupLatinPolyglossiaFont{sami}%
 %   \fi
 %   \xpg at info{Option: sami, variant=\xpg at val}%
 %}{\xpg at warning{Unknown sami variant `#1'}}
@@ -24968,7 +24976,7 @@
 
 
 %\def\sami at language{%
-%   \polyglossia at setup@language at patterns{\sami at variant}%
+%   \SetupPolyglossiaLangPatterns{\sami at variant}%
 %}%
 
 \def\captionssami at northern{%
@@ -25030,7 +25038,7 @@
 % 
 % \subsection{gloss-samin.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-samin.ldf}[polyglossia: module for Northern Sami]
 
@@ -25037,7 +25045,7 @@
 % We only provide this gloss for babel compatibility. Since samin is 
 % a sami variety, we use 'sami' with variant 'northern' now.
 
-\xpg at load@master at language{sami}
+\InheritGlossFile{sami}
 
 %    \end{macrocode}
 % \iffalse
@@ -25048,7 +25056,7 @@
 % 
 % \subsection{gloss-sanskrit.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-sanskrit.ldf}[polyglossia: module for Sanskrit]
 
@@ -25077,56 +25085,55 @@
 \setlanguagealias*[script=gujarati]{sanskrit}{sa-Gujr}
 \setlanguagealias*[script=latin]{sanskrit}{sa-Latn}
 
-\define at key{sanskrit}{Script}[devanagari]{%
-  \ifcsdef{fontsetup at sanskrit@#1}%
-    {\csname fontsetup at sanskrit@#1\endcsname}%
-    {\xpg at error{`#1' is not a valid script for Sanskrit}%
-  }%
-}
-
-\define at key{sanskrit}{script}[devanagari]{\setkeys{sanskrit}{Script=#1}}
-
 \def\fontsetup at sanskrit@devanagari{%
   \SetLanguageKeys{sanskrit}{scripttag=deva,script=Devanagari,bcp47=sa-Deva,bcp47-language=sa,bcp47-script=Deva,bcp47-casing=sa-Deva}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@gujarati{%
   \SetLanguageKeys{sanskrit}{scripttag=gujr,script=Gujarati,bcp47=sa-Gujr,bcp47-language=sa,bcp47-script=Gujr,bcp47-casing=sa-Gujr}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@malayalam{%
   \SetLanguageKeys{sanskrit}{scripttag=mlym,script=Malayalam,bcp47=sa-Mlym,bcp47-language=sa,bcp47-script=Mlym,bcp47-casing=sa-Mlym}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@bengali{%
   \SetLanguageKeys{sanskrit}{scripttag=beng,script=Bengali,bcp47=sa-Beng,bcp47-language=sa,bcp47-script=Beng,bcp47-casing=sa-Beng}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@kannada{%
   \SetLanguageKeys{sanskrit}{scripttag=knda,script=Kannada,bcp47=sa-Knda,bcp47-language=sa,bcp47-script=Knda,bcp47-casing=sa-Knda}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@telugu{%
   \SetLanguageKeys{sanskrit}{scripttag=telu,script=Telugu,bcp47=sa-Relu,bcp47-language=sa,bcp47-script=Relu,bcp47-casing=sa-Relu}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@latin{%
   \SetLanguageKeys{sanskrit}{scripttag=latn,script=Latin,bcp47=sa-Latn,bcp47-language=sa,bcp47-script=Latn,bcp47-casing=sa-Latn}
-  \xpg at fontsetup@latin{sanskrit}}
+  \SetupLatinPolyglossiaFont{sanskrit}}
 
 
 \newif\ifsanskrit at devanagari@numerals
 \sanskrit at devanagari@numeralstrue
-\define at choicekey*+{sanskrit}{numerals}[\xpg at val\xpg at nr]{devanagari,western}[devanagari]{%
-   \ifcase\xpg at nr\relax
-      % devanagari:
-      \sanskrit at devanagari@numeralstrue%
-      \SetLanguageKeys{sanskrit}{bcp47-extension-u=nu-deva}%
-   \or
-      % western:
-      \sanskrit at devanagari@numeralsfalse%
-      \SetLanguageKeys{sanskrit}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Sanskrit, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Sanskrit numeral `#1'}}
 
+\DeclareKeys[polyglossia/gloss/sanskrit]
+  {
+    script.code = \@ifundefined{fontsetup at sanskrit@#1}%
+      {\xpg at error{`#1' is not a valid script for Sanskrit}}%
+      {\csname fontsetup at sanskrit@#1\endcsname},
+    script.default:n = devanagari,
+    numerals.choice:,
+    numerals / devanagari.code = 
+      {%
+        \sanskrit at devanagari@numeralstrue
+        \SetLanguageKeys{sanskrit}{bcp47-extension-u=nu-deva}%
+      },
+    numerals / western.code =
+      {%
+        \sanskrit at devanagari@numeralsfalse
+        \SetLanguageKeys{sanskrit}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = devanagari,
+    numerals/unknown.code = \xpg at warning{Unknown Sanskrit numeral `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{sanskrit}{script=devanagari,numerals=devanagari}
+\InitializeGlossOptions{sanskrit}{script=devanagari,numerals=devanagari}
 
 % Use \providecommand here as the ldf file might
 % be reloaded via BCP.
@@ -25207,7 +25214,7 @@
 % 
 % \subsection{gloss-scottish.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-scottish.ldf}[polyglossia: module for Scottish Gaelic]
 
@@ -25214,7 +25221,7 @@
 % We only provide this gloss for babel compatibility. Since scottish is 
 % a gaelic variety, we use 'gaelic' with variant 'scottish' now.
 
-\xpg at load@master at language{gaelic}
+\InheritGlossFile{gaelic}
 
 %    \end{macrocode}
 % \iffalse
@@ -25225,7 +25232,7 @@
 % 
 % \subsection{gloss-serbian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-serbian.ldf}[polyglossia: module for Serbian]
 %TODO split into gloss-serbiancyr.ldf and gloss-serbianlat.ldf
@@ -25266,68 +25273,11 @@
 \fi
 
 \newif\if at serbian@cyr
-\define at choicekey*+{serbian}{Script}[\xpg at val\xpg at nr]{cyrillic,latin}[cyrillic]{%
-   \ifcase\xpg at nr\relax
-      % cyrillic:
-      \@serbian at cyrtrue
-      \xpg at fontsetup@nonlatin{serbian}%
-   \or
-      % 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???
-   \fi
-   \serbian at set@languagekeys%
-   \xpg at info{Option: Serbian, script=\xpg at val}%
-}{\xpg at warning{Unknown Serbian script `#1'}}
-
-\define at key{serbian}{script}[cyrillic]{\setkeys{serbian}{Script=#1}}
-
 \newif\if at serbian@ijekavian
-\define at choicekey*+{serbian}{variant}[\xpg at val\xpg at nr]{ekavian,ijekavian}[ekavian]{%
-   \ifcase\xpg at nr\relax
-      % ekavian:
-      \@serbian at ijekavianfalse%
-   \or
-      % ijekavian:
-      \@serbian at ijekaviantrue%
-   \fi
-   \serbian at set@languagekeys%
-   \xpg at info{Option: Serbian, variant=\xpg at val}%
-}{\xpg at warning{Unknown Serbian variant `#1'}}
 
 \newif\ifcyrillic at numerals
 \newif\ifcyrillic at asbuk@numerals
-\define at choicekey*+{serbian}{numerals}[\xpg at val\xpg at nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % arabic:
-      \cyrillic at numeralsfalse%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{serbian}{bcp47-extension-u=nu-latn}%
-   \or
-      % cyrillic:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-trad:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-alph:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralstrue%
-      \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
-   \fi
-   \xpg at info{Option: Serbian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Serbian numerals value `#1'}}
 
-\define at boolkey{serbian}[serbian@]{splithyphens}[true]{}
-
-\define at boolkey{serbian}[serbian@]{datei}[true]{}
-
 \def\serbian at set@languagekeys{%
    \if at serbian@cyr
      \if at serbian@ijekavian
@@ -25344,10 +25294,75 @@
    \fi%
 }
 
-\setkeys{serbian}{Script,numerals}
+\DeclareKeys[polyglossia/gloss/serbian]
+  {
+    splithyphens.if = serbian at splithyphens,
+    splithyphens.default:n = true,
+    datei.if = serbian at datei,
+    datei.default:n = true,
+    variant.choice:,
+    variant / ekavian.code =
+      {%
+        \@serbian at ijekavianfalse
+        \serbian at set@languagekeys
+      },
+    variant / ijekavian.code =
+      {%
+        \@serbian at ijekaviantrue
+        \serbian at set@languagekeys
+      },
+    variant.default:n = ekavian,
+    variant/unknown.code = \xpg at warning{Unknown Serbian variant `#1'},
+    script.choice:,
+    script / cyrillic.code =
+      {%
+        \@serbian at cyrtrue
+        \SetupNonLatinPolyglossiaFont{serbian}%
+        \serbian at set@languagekeys
+      },
+    script / latin.code =
+      {%
+        \@serbian at cyrfalse
+        \SetupLatinPolyglossiaFont{serbian}%
+          %TODO \def\serbian at language{\language=\l at serbianlat}%
+          % or should we use Croatian patterns as a fallback for the time being???
+        \serbian at set@languagekeys
+      },
+    script.default:n = cyrillic,
+    script/unknown.code = \xpg at warning{Unknown Serbian script `#1'},
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \cyrillic at numeralsfalse
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{serbian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / cyrillic.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-trad.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-alph.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralstrue
+        \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Serbian numerals value `#1'}
+  }
 
+\SetGlossOptions{serbian}{script,numerals}
+
 % Register default options
-\xpg at initialize@gloss at options{serbian}{script=cyrillic,numerals=arabic,splithyphens=true}
+\InitializeGlossOptions{serbian}{script=cyrillic,numerals=arabic,splithyphens=true}
 
 \def\captionsserbian{%
    \if at serbian@cyr\captionsserbian at cyr\else\captionsserbian at lat\fi
@@ -25648,13 +25663,13 @@
 % 
 % \subsection{gloss-serbianc.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-serbianc.ldf}[polyglossia: module for Serbian (cyrillic)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{serbian}
+\InheritGlossFile{serbian}
 
 %    \end{macrocode}
 % \iffalse
@@ -25665,7 +25680,7 @@
 % 
 % \subsection{gloss-slovak.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-slovak.ldf}[polyglossia: module for Slovak]
 
@@ -25686,26 +25701,26 @@
   \RequirePackage{luavlna}
 \fi
 
-\define at boolkey{slovak}[slovak@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/slovak]
+  {
+    babelshorthands.if = slovak at babelshorthands,
+    babelshorthands.default:n = true,
+    splithyphens.if = slovak at splithyphens,
+    splithyphens.default:n = true,
+    vlna.if = slovak at vlna,
+    vlna.default:n = true,
+  }
 
-\define at boolkey{slovak}[slovak@]{splithyphens}[true]{}
-
-\define at boolkey{slovak}[slovak@]{vlna}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{slovak}{babelshorthands=false,splithyphens=true,vlna=true}
+\InitializeGlossOptions{slovak}{babelshorthands=false,splithyphens=true,vlna=true}
 
 \ifsystem at babelshorthands
-  \setkeys{slovak}{babelshorthands=true}
+  \SetGlossOptions{slovak}{babelshorthands=true}
 \else
-  \setkeys{slovak}{babelshorthands=false}
+  \SetGlossOptions{slovak}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \let\xpg at hyphen@char-
 \def\slovak@@splhyphen#1{%
@@ -25881,7 +25896,7 @@
    \def\contentsname{Obsah}%
    \def\listfigurename{Zoznam obrázkov}%
    \def\listtablename{Zoznam tabuliek}%
-   \def\indexname{Index}%
+   \def\indexname{Register}%
    \def\figurename{Obrázok}%
    \def\tablename{Tabuľka}%
    %\def\thepart{}%
@@ -25932,13 +25947,13 @@
 % 
 % \subsection{gloss-slovene.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-slovene.ldf}[polyglossia: module for Slovenian]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{slovenian}
+\InheritGlossFile{slovenian}
 
 %    \end{macrocode}
 % \iffalse
@@ -25949,7 +25964,7 @@
 % 
 % \subsection{gloss-slovenian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-slovenian.ldf}[polyglossia: module for Slovenian]
 
@@ -25970,10 +25985,14 @@
 % Babel aliases
 \setlanguagealias{slovenian}{slovene}
 
-\define at boolkey{slovenian}[slovenian@]{localalph}[true]{}
+\DeclareKeys[polyglossia/gloss/slovenian]
+  {
+    localalph.if = slovenian at localalph,
+    localalph.default:n = true
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{slovenian}{localalph=false}
+\InitializeGlossOptions{slovenian}{localalph=false}
 
 
 \def\captionsslovenian{%
@@ -26041,7 +26060,7 @@
 % 
 % \subsection{gloss-sorbian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-sorbian.ldf}[polyglossia: module for Sorbian]
 
@@ -26069,60 +26088,40 @@
 \setlanguagealias[variant=upper]{sorbian}{uppersorbian}
 
 \def\sorbian at variant{usorbian}
-\define at choicekey*+{sorbian}{variant}[\xpg at val\xpg at nr]{upper,lower}[upper]{%
-   \ifcase\xpg at nr\relax
-      % upper:
-      \def\sorbian at variant{usorbian}%
-      \SetLanguageKeys{sorbian}{language=Upper Sorbian,langtag=USB,babelname=uppersorbian,bcp47=hsb,bcp47-language=hsb}%
-      \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,bcp47=dsb,bcp47-language=dsb}%
-      \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=\xpg at val}%
-}{\xpg at warning{Unknown sorbian variant `#1'}}
 
+\DeclareKeys[polyglossia/gloss/sorbian]
+  {
+    olddate.if = sorbian at olddate,
+    olddate.default:n = true,
+    variant.choice:,
+    variant / upper.code = 
+      {%
+        \def\sorbian at variant{usorbian}%
+        \SetLanguageKeys{sorbian}{language=Upper Sorbian,langtag=USB,babelname=uppersorbian,bcp47=hsb,bcp47-language=hsb}%
+        \SetupLatinPolyglossiaFont{sorbian}%
+        % Check if \l at usorbian is defined. If not, try to set it to some variety
+        % (specific order as in the csv list), or null language if everything fails
+        \TryPatternWithFallback{usorbian}{uppersorbian}%
+      },
+    variant / lower.code = 
+      {%
+        \def\sorbian at variant{lsorbian}%
+        \SetLanguageKeys{sorbian}{language=Lower Sorbian,langtag=LSB,babelname=lowersorbian,bcp47=dsb,bcp47-language=dsb}%
+        \SetupLatinPolyglossiaFont{sorbian}%
+        % Check if \l at lsorbian is defined. If not, try to set it to some variety
+        % (specific order as in the csv list), or null language if everything fails
+        \TryPatternWithFallback{lsorbian}{lowersorbian,Lsorbian,usorbian,uppersorbian}%
+      },
+    variant.default:n = upper,
+    variant/unknown.code = \xpg at warning{Unknown sorbian variant `#1'}
+  }
 
-\define at boolkey{sorbian}[sorbian@]{olddate}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{sorbian}{variant=upper,olddate=false}
+\InitializeGlossOptions{sorbian}{variant=upper,olddate=false}
 
 
 \def\sorbian at language{%
-   \polyglossia at setup@language at patterns{\sorbian at variant}%
+   \SetupPolyglossiaLangPatterns{\sorbian at variant}%
 }%
 
 
@@ -26232,7 +26231,7 @@
 % 
 % \subsection{gloss-spanish.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-spanish.ldf}[polyglossia: module for Spanish]
 
@@ -26261,18 +26260,6 @@
 
 \newif\if at spanish@mexico
 \@spanish at mexicofalse
-\define at choicekey*+{spanish}{variant}[\xpg at val\xpg at nr]{spanish,mexican}[spanish]{%
-   \ifcase\xpg at nr\relax
-      % spanish:
-      \@spanish at mexicofalse%
-      \SetLanguageKeys{spanish}{babelname=spanish,bcp47=es-ES,bcp47-region=ES}%
-   \or
-      % mexican:
-      \@spanish at mexicotrue%
-      \SetLanguageKeys{spanish}{babelname=spanishmx,bcp47=es-MX,bcp47-region=MX}%
-   \fi
-   \xpg at info{Option: spanish, variant=\xpg at val}%
-}{\xpg at warning{Unknown spanish variant `#1'}}
 
 % Localized math operators à la babel
 \newif\ifspanish at accentedoperators
@@ -26279,34 +26266,52 @@
 \newif\ifspanish at spacedoperators
 \newif\ifspanish at locoperators
 
-\define at choicekey*+{spanish}{spanishoperators}[\xpg at val\xpg at nr]{all,accented,spaced,none}[all]{%
-   \ifcase\xpg at nr\relax
-      % all:
-      \spanish at locoperatorstrue%
-      \spanish at accentedoperatorstrue%
-      \spanish at spacedoperatorstrue%
-   \or
-      % accented:
-      \spanish at locoperatorsfalse%
-      \spanish at accentedoperatorstrue%
-      \spanish at spacedoperatorsfalse%
-   \or
-      % spaced:
-      \spanish at locoperatorsfalse%
-      \spanish at accentedoperatorsfalse%
-      \spanish at spacedoperatorstrue%
-   \or
-      % none:
-      \spanish at locoperatorsfalse%
-      \spanish at accentedoperatorsfalse%
-      \spanish at spacedoperatorsfalse%
-   \fi
-   \xpg at info{Option: Spanish, spanishoperators=\xpg at val}%
-}{\xpg at warning{Unknown spanishoperators value `#1'}}
+\DeclareKeys[polyglossia/gloss/spanish]
+  {
+    variant.choice:,
+    variant / spanish.code =
+      {%
+        \@spanish at mexicofalse
+        \SetLanguageKeys{spanish}{babelname=spanish,bcp47=es-ES,bcp47-region=ES}%
+      },
+    variant / mexican.code =
+      {%
+        \@spanish at mexicotrue
+        \SetLanguageKeys{spanish}{babelname=spanishmx,bcp47=es-MX,bcp47-region=MX}%
+      },
+    variant.default:n = spanish,
+    variant/unknown.code = \xpg at warning{Unknown spanish variant `#1'},
+    spanishoperators.choice:,
+    spanishoperators / all.code =
+      {%
+        \spanish at locoperatorstrue
+        \spanish at accentedoperatorstrue
+        \spanish at spacedoperatorstrue
+      },
+    spanishoperators / accented.code =
+      {%
+        \spanish at locoperatorsfalse
+        \spanish at accentedoperatorstrue
+        \spanish at spacedoperatorsfalse
+      },
+    spanishoperators / spaced.code =
+      {%
+        \spanish at locoperatorsfalse
+        \spanish at accentedoperatorsfalse
+        \spanish at spacedoperatorstrue
+      },
+    spanishoperators / none.code =
+      {%
+        \spanish at locoperatorsfalse
+        \spanish at accentedoperatorsfalse
+        \spanish at spacedoperatorsfalse
+      },
+    spanishoperators.default:n = all,
+    spanishoperators/unknown.code = \xpg at warning{Unknown spanishoperators value `#1'}
+  }
 
-
 % Register default options
-\xpg at initialize@gloss at options{spanish}{variant=spanish,spanishoperators=none}
+\InitializeGlossOptions{spanish}{variant=spanish,spanishoperators=none}
 
 \let\xpg at save@lim\lim
 \let\xpg at save@limsup\limsup
@@ -26472,13 +26477,13 @@
 % 
 % \subsection{gloss-spanishmx.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-spanishmx.ldf}[polyglossia: module for Mexican Spanish]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{spanish}
+\InheritGlossFile{spanish}
 
 %    \end{macrocode}
 % \iffalse
@@ -26489,7 +26494,7 @@
 % 
 % \subsection{gloss-swedish.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-swedish.ldf}[polyglossia: module for Swedish]
 
@@ -26554,13 +26559,13 @@
 % 
 % \subsection{gloss-swissgerman.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-swissgerman.ldf}[polyglossia: module for Swiss German (old spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 %    \end{macrocode}
 % \iffalse
@@ -26571,7 +26576,7 @@
 % 
 % \subsection{gloss-syriac.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-syriac.ldf}[polyglossia: module for Syriac]
 
@@ -26595,34 +26600,37 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{syriac}{syr}
 
-\def\syriacnumber#1{\@syriacnumber{#1}}%
+\def\syriacnumber#1{\@syriacnumber{#1}}
 
 \newif\if at eastern@numerals
-\define at choicekey*+{syriac}{numerals}[\xpg at val\xpg at nr]{eastern,western,abjad}[eastern]{%
-   \ifcase\xpg at nr\relax
-      % eastern:
-      \@eastern at numeralstrue
-      \SetLanguageKeys{syriac}{bcp47-extension-u=nu-syrc}%
-   \or
-      % western:
-      \@eastern at numeralsfalse
-      \SetLanguageKeys{syriac}{bcp47-extension-u=nu-latn}%
-   \or
-      % abjad:
-      \let\syriacnumber\abjadsyriac%
-   \fi
-   \xpg at info{Option: Syriac, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Syriac numerals option `#1'}}
-
 \newif\ifsyriac at customsep\syriac at customsepfalse
 \def\xpg at sepmark{}
-\define at key{syriac}{sectionsep}[.]{%
-   \syriac at customseptrue%
-   \gdef\xpg at sepmark{#1}%
-}
 
+\DeclareKeys[polyglossia/gloss/syriac]
+  {
+    sectionsep.code = \gdef\xpg at sepmark{#1}\syriac at customseptrue,
+    sectionsep.default:n = .,
+    numerals.choice:,
+    numerals / eastern.code =
+      {%
+        \@eastern at numeralstrue
+        \SetLanguageKeys{syriac}{bcp47-extension-u=nu-syrc}%
+      },
+    numerals / western.code =
+      {%
+        \@eastern at numeralsfalse
+        \SetLanguageKeys{syriac}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / abjad.code =
+      {%
+          \let\syriacnumber\abjadsyriac
+      },
+    numerals.default:n = eastern,
+    numerals/unknown.code = \xpg at warning{Unknown Syriac numerals option `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{syriac}{numerals=western}
+\InitializeGlossOptions{syriac}{numerals=western}
 	
 %\define at key{polyglossia}{syriaclocale}[default]{%
 %	\def\@syriac at locale{#1}}
@@ -26709,13 +26717,13 @@
       \IfCharIsAvailableTF{0661}%
           {\@ensure at LTR{\protect\arabicdigits{\number#1}}}%
           {\@ensure at LTR{\arabicdigits{\number#1}}
-           \ifcsdef{arabicfont}%
+           \@ifundefined{arabicfont}%
+	     {\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}}%
 	     {\@ensure at LTR{\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}}%
           }%
    \else
      %%\RL{\protect\reset at font\number#1}%
@@ -26753,9 +26761,9 @@
 }
 
 \def\nosyriac at xetex@capsformat{%
-   \ifcsdef{xpg at save@sepmark}{%
+   \ifcsname xpg at save@sepmark\endcsname%
      \SepMark{\xpg at save@sepmark}
-   }{}%
+   \fi%
 }
 
 \def\syriac at luatex@capsformat{%
@@ -26762,7 +26770,7 @@
   %
   % change chapter and part headings
   \ifsyriac at customsep
-     \ifcsdef{chapter}{%
+     \ifcsname chapter\endcsname%
         \let\xpg at save@thesection\thesection%
         \renewcommand*\thesection{\thechapter\xpg at sepmark\@arabic\c at section}
         \let\xpg at save@theequation\theequation%
@@ -26774,7 +26782,7 @@
         \let\xpg at save@thetable\thetable%
 	\renewcommand*\thetable{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at table}
-     }{}
+     \fi%
      \let\xpg at save@thesubsection\thesubsection%
      \renewcommand\thesubsection
 	{\thesection\xpg at sepmark\@arabic\c at subsection}
@@ -26789,30 +26797,30 @@
 }
 
 \def\nosyriac at luatex@capsformat{%
-   \ifcsdef{xpg at save@thesection}{%
+   \ifcsname xpg at save@thesection\endcsname%
         \let\thesection\xpg at save@thesection%
-   }{}%
-   \ifcsdef{xpg at save@theequation}{%
+   \fi%
+   \ifcsname xpg at save@theequation\endcsname%
         \let\theequation\xpg at save@theequation%
-   }{}%
-   \ifcsdef{xpg at save@thefigure}{%
+   \fi%
+   \ifcsname xpg at save@thefigure\endcsname%
         \let\thefigure\xpg at save@thefigure%
-   }{}%
-   \ifcsdef{xpg at save@thetable}{%
+   \fi%
+   \ifcsname xpg at save@thetable\endcsname%
         \let\thetable\xpg at save@thetable%
-   }{}%
-   \ifcsdef{xpg at save@thesubsection}{%
+   \fi%
+   \ifcsname xpg at save@thesubsection\endcsname%
         \let\thesubsection\xpg at save@thesubsection%
-   \ifcsdef{xpg at save@thesubsubsection}{%
+      \ifcsname xpg at save@thesubsubsection\endcsname%
         \let\thesubsubsection\xpg at save@thesubsubsection%
-   }{}%
-   }{}%
-   \ifcsdef{xpg at save@theparagraph}{%
+      \fi%
+   \fi%
+   \ifcsname xpg at save@theparagraph\endcsname%
         \let\theparagraph\xpg at save@theparagraph%
-   }{}%
-   \ifcsdef{xpg at save@thesubparagraph}{%
+   \fi%
+   \ifcsname xpg at save@thesubparagraph\endcsname%
         \let\thesubparagraph\xpg at save@thesubparagraph%
-   }{}%
+   \fi%
 }
 
 \def\blockextras at syriac{%
@@ -26844,7 +26852,7 @@
 % 
 % \subsection{gloss-tamil.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-tamil.ldf}[polyglossia: module for Tamil]
 
@@ -26914,7 +26922,7 @@
 % 
 % \subsection{gloss-telugu.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-telugu.ldf}[polyglossia: module for Telugu]
 
@@ -26987,7 +26995,7 @@
 % 
 % \subsection{gloss-thai.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-thai.ldf}[polyglossia: module for Thai]
 %% This is partly based on thai-latex for Babel:
@@ -27018,19 +27026,25 @@
 
 \newif\if at thai@numerals
 \def\tmp at thai{thai}
-\define at key{thai}{numerals}[arabic]{%
-	\def\@tmpa{#1}%
-	\ifx\@tmpa\tmp at thai
-	  \@thai at numeralstrue%
-          \SetLanguageKeys{thai}{bcp47-extension-u=nu-thai}%
-	\else
-	  \@thai at numeralsfalse%
-          \SetLanguageKeys{thai}{bcp47-extension-u=nu-latn}%
-	\fi
-}
 
+\DeclareKeys[polyglossia/gloss/thai]
+  {
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \@thai at numeralsfalse
+        \SetLanguageKeys{thai}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / thai.code =
+      {%
+        \@thai at numeralstrue
+        \SetLanguageKeys{thai}{bcp47-extension-u=nu-thai}%
+      },
+    numerals.default:n = arabic,
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{thai}{numerals=arabic}
+\InitializeGlossOptions{thai}{numerals=arabic}
 
 \def\captionsthai{%
    \def\refname{หนังสืออ้างอิง}%
@@ -27145,7 +27159,7 @@
 % 
 % \subsection{gloss-tibetan.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-tibetan.ldf}[polyglossia: module for Tibetan]
 %% Copyright 2013 Elie Roux
@@ -27171,20 +27185,18 @@
 \setlanguagealias*{tibetan}{bo}
 
 \newif\if at tibetan@numerals
-\def\tmp at tibetan{tibetan}
-\define at key{tibetan}{numerals}[tibetan]{%
-	\def\@tmpa{#1}%
-	\ifx\@tmpa\tmp at tibetan
-	   \@tibetan at numeralstrue%
-           \SetLanguageKeys{tibetan}{bcp47-extension-u=nu-tibt}%
-	\else
-	  \@tibetan at numeralsfalse%
-           \SetLanguageKeys{tibetan}{bcp47-extension-u=nu-latn}%
-	\fi%
-}
+\DeclareKeys[polyglossia/gloss/tibetan]
+  {
+    numerals.choice:,
+    numerals/tibetan.code = \@tibetan at numeralstrue
+    	   \SetLanguageKeys{tibetan}{bcp47-extension-u=nu-tibt},
+    numerals/arabic.code = \@tibetan at numeralsfalse
+           \SetLanguageKeys{tibetan}{bcp47-extension-u=nu-latn},
+    numerals.default:n = tibetan
+  }
 
 \ifluatex
-  \newluatexattribute\xpg at tibteol %
+  \newattribute\xpg at tibteol %
   \directlua{polyglossia.load_tibt_eol()}%
 \fi
 
@@ -27209,7 +27221,7 @@
 }
 
 % Register default options
-\xpg at initialize@gloss at options{tibetan}{numerals=tibetan}
+\InitializeGlossOptions{tibetan}{numerals=tibetan}
 
 % some are known, but very few
 % a few come from "Standardizing Tibetan Terms of Information Technology"
@@ -27371,7 +27383,7 @@
 % 
 % \subsection{gloss-turkish.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-turkish.ldf}[polyglossia: module for Turkish]
 \RequirePackage{hijrical}
@@ -27489,7 +27501,7 @@
 % 
 % \subsection{gloss-turkmen.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-turkmen.ldf}[polyglossia: module for Turkmen]
 %% Translations provided by Nazar Annagurban <nazartm at gmail dot com>
@@ -27547,12 +27559,12 @@
 % 
 % \subsection{gloss-ug.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ug.ldf}[polyglossia: module for ug (Uyghur)]
 % BCP 47 tag for Uyghur
 
-\xpg at load@master at language{uyghur}
+\InheritGlossFile{uyghur}
 
 %    \end{macrocode}
 % \iffalse
@@ -27563,7 +27575,7 @@
 % 
 % \subsection{gloss-ukrainian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ukrainian.ldf}[polyglossia: module for Ukrainian]
 % Strings taken from Babel
@@ -27591,51 +27603,52 @@
 
 \newif\ifcyrillic at numerals
 \newif\ifcyrillic at asbuk@numerals
-\define at choicekey*+{ukrainian}{numerals}[\xpg at val\xpg at nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % arabic:
-      \cyrillic at numeralsfalse%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-latn}%
-   \or
-      % cyrillic:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-trad:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-alph:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralstrue%
-      \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
-   \fi
-   \xpg at info{Option: Ukrainian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Ukrainian numerals value `#1'}}
 
+\DeclareKeys[polyglossia/gloss/ukrainian]
+  {
+    babelshorthands.if = ukrainian at babelshorthands,
+    babelshorthands.default:n = true,
+    mathfunctions.if = ukrainian at mathfunctions,
+    mathfunctions.default:n = true,
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \cyrillic at numeralsfalse
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / cyrillic.code =
+      {%  
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-trad.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-alph.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralstrue
+        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Ukrainian numerals value `#1'}
+  }
 
-% Define some math functions
-\define at boolkey{ukrainian}[ukrainian@]{mathfunctions}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{ukrainian}{numerals=arabic,mathfunctions=true}
+\InitializeGlossOptions{ukrainian}{numerals=arabic,mathfunctions=true}
 
-\define at boolkey{ukrainian}[ukrainian@]{babelshorthands}[true]{}
-
 \ifsystem at babelshorthands
-  \setkeys{ukrainian}{babelshorthands=true}
+  \SetGlossOptions{ukrainian}{babelshorthands=true}
 \else
-  \setkeys{ukrainian}{babelshorthands=false}
+  \SetGlossOptions{ukrainian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\ukrainian at shorthands{%
   \xpg at activate@shorthands%
@@ -27862,13 +27875,13 @@
 % 
 % \subsection{gloss-uppersorbian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-uppersorbian.ldf}[polyglossia: module for Upper Sorbian]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 %    \end{macrocode}
 % \iffalse
@@ -27879,7 +27892,7 @@
 % 
 % \subsection{gloss-urdu.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 %%% Adapted from a file contributed by Kamal Abdali
 \ProvidesFile{gloss-urdu.ldf}[polyglossia: module for Urdu]
@@ -27906,52 +27919,46 @@
 \setlanguagealias*{urdu}{ur}
 
 \newif\if at western@numerals
-\define at choicekey*+{urdu}{numerals}[\xpg at val\xpg at nr]{eastern,western}[eastern]{%
-   \ifcase\xpg at nr\relax
-      % eastern:
-      \@western at numeralsfalse%
-      \SetLanguageKeys{urdu}{bcp47-extension-u=nu-arab}%
-   \or
-      % western:
-      \@western at numeralstrue%
-      \SetLanguageKeys{urdu}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Urdu, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Urdu numerals option `#1'}}
-
 \newif\ifurdu at customsep\urdu at customsepfalse
 \def\xpg at sepmark{}
-\define at key{urdu}{sectionsep}[.]{%
-   \urdu at customseptrue%
-   \gdef\xpg at sepmark{#1}%
-}
-
-%this is needed for \abjad in arabicnumbers.sty
-\define at boolkey{urdu}[urdu@]{abjadjimnotail}[true]{%
-  \ifurdu at abjadjimnotail
-    \abjad at jim@notailtrue%
-  \else
-    \abjad at jim@notailfalse
-  \fi%
-}
-
 \newif\if at hijrical
-\define at choicekey*+{urdu}{calendar}[\xpg at val\xpg at nr]{gregorian,hijri}[gregorian]{%
-   \ifcase\xpg at nr\relax
-      % gregorian:
-      \@hijricalfalse
-   \or
-      % hijri:
-      \@hijricaltrue
-   \fi
-   \xpg at info{Option: Urdu, calendar=\xpg at val}%
-}{\xpg at warning{Unknown Urdu calendar option `#1'}}
 
-\define at key{urdu}{hijricorrection}[0]{%
-  \gdef\urdu at hijri@correction{#1}}%
+\DeclareKeys[polyglossia/gloss/urdu]
+  {
+    abjadjimnotail.if = abjad at jim@notail,
+    abjadjimnotail.default:n = true,
+    sectionsep.code = \gdef\xpg at sepmark{#1}\urdu at customseptrue,
+    sectionsep.default:n = .,
+    hijricorrection.code = \gdef\urdu at hijri@correction{#1},
+    hijricorrection.default:n = 0,
+    calendar.choice:,
+    calendar / gregorian.code =
+      {%
+        \@hijricalfalse
+      },
+    calendar / hijri.code =
+      {%
+        \@hijricaltrue
+      },
+    calendar.default:n = gregorian,
+    calendar/unknown.code = \xpg at warning{Unknown Urdu calendar option `#1'},
+    numerals.choice:,
+    numerals / eastern.code =
+      {%
+        \@western at numeralsfalse
+        \SetLanguageKeys{urdu}{bcp47-extension-u=nu-arab}%
+      },
+    numerals / western.code =
+      {%
+        \@western at numeralstrue
+        \SetLanguageKeys{urdu}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = eastern,
+    numerals/unknown.code = \xpg at warning{Unknown Urdu numerals option `#1'}
+  }
 
 % This should set the defaults
-\setkeys{urdu}{calendar,numerals,hijricorrection}
+\SetGlossOptions{urdu}{calendar,numerals,hijricorrection}
 
 \def\urdugregmonth#1{\ifcase#1%
   \or جنوری\or فروری\or مارچ\or اپریل\or مئی\or جون\or جولائی\or اگست\or  ستمبر\or اکتوبر\or نومبر\or دسمبر\fi}
@@ -28038,9 +28045,9 @@
 }
 
 \def\nourdu at xetex@capsformat{%
-   \ifcsdef{xpg at save@sepmark}{%
+   \ifcsname xpg at save@sepmark\endcsname%
      \SepMark{\xpg at save@sepmark}
-   }{}%
+   \fi%
 }
 
 \def\urdu at luatex@capsformat{%
@@ -28047,7 +28054,7 @@
   %
   % change chapter and part headings
   \ifurdu at customsep
-     \ifcsdef{chapter}{%
+     \ifcsname chapter\endcsname%
         \let\xpg at save@thesection\thesection%
         \renewcommand*\thesection{\thechapter\xpg at sepmark\@arabic\c at section}
         \let\xpg at save@theequation\theequation%
@@ -28059,7 +28066,7 @@
         \let\xpg at save@thetable\thetable%
 	\renewcommand*\thetable{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at table}
-     }{}
+     \fi%
      \let\xpg at save@thesubsection\thesubsection%
      \renewcommand\thesubsection
 	{\thesection\xpg at sepmark\@arabic\c at subsection}
@@ -28074,30 +28081,30 @@
 }
 
 \def\nourdu at luatex@capsformat{%
-   \ifcsdef{xpg at save@thesection}{%
+   \ifcsname xpg at save@thesection\endcsname%
         \let\thesection\xpg at save@thesection%
-   }{}%
-   \ifcsdef{xpg at save@theequation}{%
+   \fi%
+   \ifcsname xpg at save@theequation\endcsname%
         \let\theequation\xpg at save@theequation%
-   }{}%
-   \ifcsdef{xpg at save@thefigure}{%
+   \fi%
+   \ifcsname xpg at save@thefigure\endcsname%
         \let\thefigure\xpg at save@thefigure%
-   }{}%
-   \ifcsdef{xpg at save@thetable}{%
+   \fi%
+   \ifcsname xpg at save@thetable\endcsname%
         \let\thetable\xpg at save@thetable%
-   }{}%
-   \ifcsdef{xpg at save@thesubsection}{%
+   \fi%
+   \ifcsname xpg at save@thesubsection\endcsname%
         \let\thesubsection\xpg at save@thesubsection%
-   \ifcsdef{xpg at save@thesubsubsection}{%
+      \ifcsname xpg at save@thesubsubsection\endcsname%
         \let\thesubsubsection\xpg at save@thesubsubsection%
-   }{}%
-   }{}%
-   \ifcsdef{xpg at save@theparagraph}{%
+      \fi%
+   \fi%
+   \ifcsname xpg at save@theparagraph\endcsname%
         \let\theparagraph\xpg at save@theparagraph%
-   }{}%
-   \ifcsdef{xpg at save@thesubparagraph}{%
+   \fi%
+   \ifcsname xpg at save@thesubparagraph\endcsname%
         \let\thesubparagraph\xpg at save@thesubparagraph%
-   }{}%
+   \fi%
 }
 
 \def\blockextras at urdu{%
@@ -28129,7 +28136,7 @@
 % 
 % \subsection{gloss-usorbian.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-usorbian.ldf}[polyglossia: module for Upper Sorbian]
 
@@ -28136,7 +28143,7 @@
 % We only provide this gloss for babel compatibility. Since usorbian is 
 % a sorbian variety, we use 'sorbian' with variant 'upper' now.
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 %    \end{macrocode}
 % \iffalse
@@ -28147,7 +28154,7 @@
 % 
 % \subsection{gloss-uyghur.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-uyghur.ldf}[polyglossia: module for Uyghur]
 %% Translations provided by Osman Tursun (Github Account: neouyghur)
@@ -28171,62 +28178,72 @@
 \newif\if at uyghur@swapcaptions
 \newif\if at uyghur@swapheadings
 \newif\if at uyghur@swapheaders
-\define at choicekey*+{uyghur}{swapstrings}[\xpg at val\xpg at nr]{all,captions,headings,headers,hheaders,none}[all]{%
-   \ifcase\xpg at nr\relax
-      % all:
-      \@uyghur at swapcaptionstrue%
-      \@uyghur at swapheadingstrue%
-      \@uyghur at swapheaderstrue%
-   \or
-      % captions:
-      \@uyghur at swapcaptionstrue%
-      \@uyghur at swapheadingsfalse%
-      \@uyghur at swapheadersfalse%
-   \or
-      % headings:
-      \@uyghur at swapcaptionsfalse%
-      \@uyghur at swapheadingstrue%
-      \@uyghur at swapheadersfalse%
-   \or
-      % headers:
-      \@uyghur at swapcaptionsfalse%
-      \@uyghur at swapheadingsfalse%
-      \@uyghur at swapheaderstrue%
-   \or
-      % hheaders:
-      \@uyghur at swapcaptionsfalse%
-      \@uyghur at swapheadingstrue%
-      \@uyghur at swapheaderstrue%
-   \or
-      % none:
-      \@uyghur at swapcaptionsfalse%
-      \@uyghur at swapheadingsfalse%
-      \@uyghur at swapheadersfalse%
-   \fi
-   \xpg at info{Option: Uyghur, swapstrings=\xpg at val}%
-}{\xpg at warning{Unknown Uyghur swapstrings value `#1'}}
-
 \newif\if at uyghur@ordchapter
 \newif\if at uyghur@romchapter
-\define at choicekey*+{uyghur}{chapterformat}[\xpg at val\xpg at nr]{ordinal,roman,arabic}[ordinal]{%
-   \ifcase\xpg at nr\relax
-      % ordinal:
-      \@uyghur at ordchaptertrue%
-      \@uyghur at romchapterfalse%
-   \or
-      % roman:
-      \@uyghur at ordchapterfalse%
-      \@uyghur at romchaptertrue%
-   \or
-      % arabic:
-      \@uyghur at ordchapterfalse%
-      \@uyghur at romchapterfalse%
-   \fi
-   \xpg at info{Option: Uyghur, chapterformat=\xpg at val}%
-}{\xpg at warning{Unknown Uyghur chapterformat value `#1'}}
 
+\DeclareKeys[polyglossia/gloss/uyghur]
+  {
+    chapterformat.choice:,
+    chapterformat / ordinal.code =
+      {%
+        \@uyghur at ordchaptertrue
+        \@uyghur at romchapterfalse
+      },
+    chapterformat / roman.code =
+      {%
+        \@uyghur at ordchapterfalse
+        \@uyghur at romchaptertrue
+      },
+    chapterformat / arabic.code =
+      {%
+        \@uyghur at ordchapterfalse
+        \@uyghur at romchapterfalse
+      },
+    chapterformat.default:n = ordinal,
+    chapterformat/unknown.code = \xpg at warning{Unknown Uyghur chapterformat value `#1'},
+    swapstrings.choice:,
+    swapstrings / all.code = 
+      {%
+        \@uyghur at swapcaptionstrue
+        \@uyghur at swapheadingstrue
+        \@uyghur at swapheaderstrue
+      },
+    swapstrings / captions.code = 
+      {%
+        \@uyghur at swapcaptionstrue
+        \@uyghur at swapheadingsfalse
+        \@uyghur at swapheadersfalse
+      },
+    swapstrings / headings.code =
+      {%
+        \@uyghur at swapcaptionsfalse
+        \@uyghur at swapheadingstrue
+        \@uyghur at swapheadersfalse
+      },
+    swapstrings / headers.code = 
+      {%
+        \@uyghur at swapcaptionsfalse
+        \@uyghur at swapheadingsfalse
+        \@uyghur at swapheaderstrue
+      },
+    swapstrings / hheaders.code = 
+      {%
+        \@uyghur at swapcaptionsfalse
+        \@uyghur at swapheadingstrue
+        \@uyghur at swapheaderstrue
+      },
+    swapstrings / none.code = 
+      {%
+        \@uyghur at swapcaptionsfalse
+        \@uyghur at swapheadingsfalse
+        \@uyghur at swapheadersfalse
+      },
+    swapstrings.default:n = all,
+    swapstrings/unknown.code = \xpg at warning{Unknown Uyghur swapstrings value `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{uyghur}{swapstrings=all,chapterformat=ordinal}
+\InitializeGlossOptions{uyghur}{swapstrings=all,chapterformat=ordinal}
 
 
 \def\captionsuyghur{%
@@ -28274,69 +28291,13 @@
   % change chapter and part headings
   \if at uyghur@swapheadings
      % With titlesec
-     \ifcsdef{titleformat}{%
-       \ifcsdef{H at old@part}{% Hyperref
-            \let\xpg at save@part at format\H at old@part%
-            \patchcmd{\H at old@part}%
-                      {\partname\nobreakspace\thepart}%
-                      {\the at uyghur@part\nobreakspace\partname}%
-                      {}%
-                      {\xpg at warning{Failed to patch part for Uyghur}}%
-       }{% not hyperref
-         \ifcsdef{@part}{%
-            \let\xpg at save@part at format\@part%
-            \patchcmd{\@part}%
-                      {\partname\nobreakspace\thepart}%
-                      {\the at uyghur@part\nobreakspace\partname}%
-                      {}%
-                      {\xpg at warning{Failed to patch part for Uyghur}}%
-         }{}%
-       }
-       \ifcsdef{chapter}{%
-          \titleformat\chapter[display]%
-             {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
-             {\the at uyghur@chapter\space\@chapapp}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
-       }{}%
-     }{% (not \ifdefined\titleformat)
+     \@ifundefined{titleformat}{%
        % With KOMA
-       \ifcsdef{sectionformat}{%
-          \ifcsdef{partformat}{%
-            \let\xpg at save@part at format\partformat%
-            \renewcommand{\partformat}{\the at uyghur@part~\partname}%
-          }{}%
-          \ifcsdef{chapterformat}{%
-            \let\xpg at save@chap at format\chapterformat%
-            \renewcommand{\chapterformat}{\mbox{\the at uyghur@chapter%
-                                          \IfUsePrefixLine{\nobreakspace\chapapp}{\enskip}}}%
-          }{}%
-       }{%  (not \ifdefined\sectionformat)
+       \@ifundefined{sectionformat}{%
          % With memoir
-         \ifcsdef{@memptsize}{%
-           \ifcsdef{@makechapterhead}{%
-              \let\xpg at save@chap at format\@makechapterhead%
-              \patchcmd{\@makechapterhead}{\printchaptername \chapternamenum \printchapternum}%
-                       {\chapnumfont\the at uyghur@chapter\chapternamenum\printchaptername}%
-                       {}%
-                       {\xpg at warning{Failed to patch chapter for Uyghur}}%
-           }{}%
-           \ifcsdef{H at old@part}{% Hyperref
-                \let\xpg at save@part at format\H at old@part%
-                \patchcmd{\H at old@part}{\printpartname \partnamenum \printpartnum}%
-                                 {\chapnumfont\the at uyghur@part\partnamenum\printpartname}%
-                                 {}%
-                                 {\xpg at warning{Failed to patch part for Uyghur}}%
-           }{% not hyperref
-             \ifcsdef{@part}{%
-                \let\xpg at save@part at format\@part%
-                \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
-                                 {\chapnumfont\the at uyghur@part\partnamenum\printpartname}%
-                                 {}%
-                                 {\xpg at warning{Failed to patch part for Uyghur}}%
-             }{}%
-           }%
-         }{%  (not \ifdefined\@memptsize)
+         \@ifundefined{@memptsize}{%
            % With standard classes
-            \ifcsdef{@makechapterhead}{%
+            \@ifundefined{@makechapterhead}{}{%
               \let\xpg at save@chap at format\@makechapterhead%
               \patchcmd{\@makechapterhead}%
                        {\@chapapp\space \thechapter}%
@@ -28343,8 +28304,17 @@
                        {\the at uyghur@chapter\space \@chapapp}%
                        {}%
                        {\xpg at warning{Failed to patch chapter for Uyghur}}%
-            }{}%
-            \ifcsdef{H at old@part}{% Hyperref
+            }%
+            \@ifundefined{H at old@part}{% not hyperref
+              \@ifundefined{@part}{}{%
+                \let\xpg at save@part at format\@part%
+                \patchcmd{\@part}%
+                         {\partname\nobreakspace\thepart}%
+                         {\the at uyghur@part\nobreakspace\partname}%
+                         {}%
+                         {\@ifundefined{part}{}{\xpg at warning{Failed to patch part for Uyghur}}}%
+              }%  (end \ifdefined\@part)
+            }{% Hyperref
               \let\xpg at save@part at format\H at old@part%
               \patchcmd{\H at old@part}%
                        {\partname\nobreakspace\thepart}%
@@ -28351,30 +28321,97 @@
                        {\the at uyghur@part\nobreakspace\partname}%
                        {}%
                        {\xpg at warning{Failed to patch part for Uyghur}}%            
-            }{% not hyperref
-              \ifcsdef{@part}{%
+            }% (end not hyperref)
+          }{%  (\ifdefined\@memptsize)
+           \@ifundefined{@makechapterhead}{}{%
+              \let\xpg at save@chap at format\@makechapterhead%
+              \patchcmd{\@makechapterhead}{\printchaptername \chapternamenum \printchapternum}%
+                       {\chapnumfont\the at uyghur@chapter\chapternamenum\printchaptername}%
+                       {}%
+                       {\xpg at warning{Failed to patch chapter for Uyghur}}%
+           }%
+           \@ifundefined{H at old@part}{% not hyperref
+             \@ifundefined{@part}{}{%
                 \let\xpg at save@part at format\@part%
-                \patchcmd{\@part}%
-                         {\partname\nobreakspace\thepart}%
-                         {\the at uyghur@part\nobreakspace\partname}%
-                         {}%
-                         {\ifcsdef{part}{\xpg at warning{Failed to patch part for Uyghur}}{}}%
-              }{}%  (end \ifdefined\@part)
-            }% (end not hyperref)
-          }% (end \ifdefined\@memptsize)
-        }% (end \ifdefined\sectionformat)
+                \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
+                                 {\chapnumfont\the at uyghur@part\partnamenum\printpartname}%
+                                 {}%
+                                 {\xpg at warning{Failed to patch part for Uyghur}}%
+             }%
+           }{% Hyperref
+                \let\xpg at save@part at format\H at old@part%
+                \patchcmd{\H at old@part}{\printpartname \partnamenum \printpartnum}%
+                                 {\chapnumfont\the at uyghur@part\partnamenum\printpartname}%
+                                 {}%
+                                 {\xpg at warning{Failed to patch part for Uyghur}}%
+           }%
+         }% (end \ifdefined\@memptsize)
+        }{%  (\ifdefined\sectionformat)
+          \@ifundefined{partformat}{}{%
+            \let\xpg at save@part at format\partformat%
+            \renewcommand{\partformat}{\the at uyghur@part~\partname}%
+          }%
+          \@ifundefined{chapterformat}{}{%
+            \let\xpg at save@chap at format\chapterformat%
+            \renewcommand{\chapterformat}{\mbox{\the at uyghur@chapter%
+                                          \IfUsePrefixLine{\nobreakspace\chapapp}{\enskip}}}%
+          }%
+       }% (end \ifdefined\sectionformat)
+     }{% (\ifdefined\titleformat)
+       \@ifundefined{H at old@part}{% not hyperref
+         \@ifundefined{@part}{}{%
+            \let\xpg at save@part at format\@part%
+            \patchcmd{\@part}%
+                      {\partname\nobreakspace\thepart}%
+                      {\the at uyghur@part\nobreakspace\partname}%
+                      {}%
+                      {\xpg at warning{Failed to patch part for Uyghur}}%
+         }%
+       }{% Hyperref
+            \let\xpg at save@part at format\H at old@part%
+            \patchcmd{\H at old@part}%
+                      {\partname\nobreakspace\thepart}%
+                      {\the at uyghur@part\nobreakspace\partname}%
+                      {}%
+                      {\xpg at warning{Failed to patch part for Uyghur}}%
+       }%
+       \@ifundefined{chapter}{}{%
+          \titleformat\chapter[display]%
+             {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
+             {\the at uyghur@chapter\space\@chapapp}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
+       }%
      }% (end \ifdefined\titleformat)
   \fi% (end \if at uyghur@swapheadings)
   %
   % Change running headers
   \if at uyghur@swapheaders
-    \ifcsdef{chapterformat}{%
-      % With KOMA
-      \let\xpg at save@chaptermark at format\chaptermarkformat%
-      \renewcommand*\chaptermarkformat{%
-         \the at uyghur@chapter\ \IfChapterUsesPrefixLine{\chapapp\enskip}{}}
-    }{% (not \ifdefined\chapterformat)
-      \ifcsdef{@memptsize}{%
+    \@ifundefined{chapterformat}{%
+      \@ifundefined{@memptsize}{%
+        % With standard classes
+        \@ifundefined{chaptermark}{}{%
+          \ifpatchable{\chaptermark}%
+               {\@chapapp\ \thechapter.}%
+               {\let\xpg at save@chaptermark at format\chaptermark%
+                \patchcmd{\chaptermark}%
+                    {\@chapapp\ \thechapter.}%
+                    {\the at uyghur@chapter\ \@chapapp}%
+                    {}%
+                    {\xpg at warning{Failed to patch chaptermark for Uyghur}}}%
+               {}%
+        }% (end \ifdefined\sectionmark)
+        \@ifundefined{sectionmark}{}{%
+             \ifpatchable{\sectionmark}%
+                  {\thesection.}%
+                  {\let\xpg at save@sectionmark at format\sectionmark%
+                   \patchcmd{\sectionmark}%
+                      {\thesection.}%
+                      {\thesection}%
+                      {}%
+                      {\xpg at warning{Failed to patch sectionmark for Uyghur}}%
+                  }%
+                  {}%
+       }% (end \ifdefined\chaptermark)
+     }{% (\ifdefined\@memptsize)
         % With memoir
         \let\xpg at save@chaptermark at format\chaptermark%
         \renewcommand*\chaptermark[1]{%
@@ -28385,33 +28422,14 @@
               }{}%
             \fi
             ##1}}{}}%
-      }{% (not \ifdefined\@memptsize)
-        % With standard classes
-        \ifcsdef{chaptermark}{%
-          \ifpatchable{\chaptermark}%
-               {\@chapapp\ \thechapter.}%
-               {\let\xpg at save@chaptermark at format\chaptermark%
-                \patchcmd{\chaptermark}%
-                    {\@chapapp\ \thechapter.}%
-                    {\the at uyghur@chapter\ \@chapapp}%
-                    {}%
-                    {\xpg at warning{Failed to patch chaptermark for Uyghur}}}%
-               {}%
-        }{}% (end \ifdefined\sectionmark)
-                \ifcsdef{sectionmark}{%
-          \ifpatchable{\sectionmark}%
-               {\thesection.}%
-               {\let\xpg at save@sectionmark at format\sectionmark%
-                \patchcmd{\sectionmark}%
-                    {\thesection.}%
-                    {\thesection}%
-                    {}%
-                    {\xpg at warning{Failed to patch sectionmark for Uyghur}}}%
-               {}%
-        }{}% (end \ifdefined\chaptermark)
       }% (end \ifdefined\@memptsize)
+   }{% (\ifdefined\chapterformat)
+      % With KOMA
+      \let\xpg at save@chaptermark at format\chaptermarkformat%
+      \renewcommand*\chaptermarkformat{%
+         \the at uyghur@chapter\ \IfChapterUsesPrefixLine{\chapapp\enskip}{}}
     }% (end \ifdefined\chapterformat)
-  \fi% (end \if at uyghur@swapheaders)
+ \fi% (end \if at uyghur@swapheaders)
 }
 
 \def\nouyghur at capsformat{%
@@ -28421,62 +28439,62 @@
    \let\fnum at figure\xpg at save@fnum at figure%
    %
    % Reset chapter and part heading
-   \ifcsdef{titleformat}{%
+   \@ifundefined{titleformat}{%
+     \@ifundefined{sectionformat}{%
+        % With memoir and standard classes
+        \@ifundefined{xpg at save@part at format}{}{%
+           \@ifundefined{H at old@part}{%
+               \let\@part\xpg at save@part at format%
+           }{%
+               \let\H at old@part\xpg at save@part at format%
+           }%
+        }%
+        \@ifundefined{xpg at save@chap at format}{}{%
+          \let\@makechapterhead\xpg at save@chap at format
+        }%
+     }{%
+        % With KOMA
+        \@ifundefined{xpg at save@part at format}{}{%
+           \let\partformat\xpg at save@part at format
+        }%
+        \@ifundefined{xpg at save@chap at format}{}{%
+           \let\chapterformat\xpg at save@chap at format
+        }%
+     }% (end \ifdefined\sectionformat)
+   }{% (\ifdefined\titleformat)
       % With titlesec
-     \ifcsdef{xpg at save@part at format}{%
-        \ifcsdef{H at old@part}{%
+     \@ifundefined{xpg at save@part at format}{}{%
+        \@ifundefined{H at old@part}{%
+            \let\@part\xpg at save@part at format%
+        }{%
             \let\H at old@part\xpg at save@part at format%
-        }{%
-            \let\@part\xpg at save@part at format%
         }%
-     }{}%
-     \ifcsdef{chapter}{%
+     }%
+     \@ifundefined{chapter}{}{%
         \titleformat\chapter[display]%
           {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
           {\@chapapp\space\thechapter}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
-     }{}%
-   }{% (not \ifdefined\titleformat)
-     \ifcsdef{sectionformat}{%
-        % With KOMA
-        \ifcsdef{xpg at save@part at format}{%
-           \let\partformat\xpg at save@part at format
-        }{}%
-        \ifcsdef{xpg at save@chap at format}{%
-           \let\chapterformat\xpg at save@chap at format
-        }{}%
-     }{%
-        % With memoir and standard classes
-        \ifcsdef{xpg at save@part at format}{%
-           \ifcsdef{H at old@part}{%
-               \let\H at old@part\xpg at save@part at format%
-           }{%
-               \let\@part\xpg at save@part at format%
-           }%
-        }{}%
-        \ifcsdef{xpg at save@chap at format}{%
-          \let\@makechapterhead\xpg at save@chap at format
-        }{}%
-     }% (end \ifdefined\sectionformat)
+     }%
    }% (end \ifdefined\titleformat)
   %
   % Reset headers
-  \ifcsdef{chaptermarkformat}{%
-     % With KOMA
-     \ifcsdef{xpg at save@chaptermark at format}{%
-       \let\chaptermarkformat\xpg at save@chaptermark at format%
-     }{}%
-  }{%
-     \ifcsdef{chaptermark}{%
+  \@ifundefined{chaptermarkformat}{%
+     \@ifundefined{chaptermark}{}{%
        % With memoir and standard classes
-       \ifcsdef{xpg at save@chaptermark at format}{%
+       \@ifundefined{xpg at save@chaptermark at format}{}{%
          \let\chaptermark\xpg at save@chaptermark at format%
-       }{}%
-     }{}% (end \ifdefined\chaptermark)
-     \ifcsdef{sectionmark}{%
-       \ifcsdef{xpg at save@sectionmark at format}{%
+       }%
+     }% (end \ifdefined\chaptermark)
+     \@ifundefined{sectionmark}{}{%
+       \@ifundefined{xpg at save@sectionmark at format}{}{%
          \let\sectionmark\xpg at save@sectionmark at format%
-       }{}%
-     }{}% (end \ifdefined\sectionmark)
+       }%
+     }% (end \ifdefined\sectionmark)
+  }{%
+     % With KOMA
+     \@ifundefined{xpg at save@chaptermark at format}{}{%
+       \let\chaptermarkformat\xpg at save@chaptermark at format%
+     }%
   }% (end \ifdefined\chapterformat)
 }
 
@@ -28512,7 +28530,7 @@
 \let\the at uyghur@chapter\thechapter
 
 \def\uyghur at chapterformat{%
-   \ifcsdef{part}{%
+   \@ifundefined{part}{}{%
       \if at uyghur@ordchapter%
         \renewcommand{\the at uyghur@part}{\uyghurord{part}}%
       \fi%
@@ -28519,8 +28537,8 @@
       \if at uyghur@romchapter%
         \renewcommand{\the at uyghur@part}{\Roman{part}}%
       \fi%
-   }{}%
-   \ifcsdef{chapter}{%
+   }%
+   \@ifundefined{chapter}{}{%
       \if at uyghur@ordchapter%
         \renewcommand{\the at uyghur@chapter}{\uyghurord{chapter}}%
       \fi%
@@ -28527,7 +28545,7 @@
       \if at uyghur@romchapter%
         \renewcommand{\the at uyghur@chapter}{\Roman{chapter}}%
       \fi%
-   }{}%
+   }%
 }
 
 \def\uyghur at numbers{%
@@ -28588,7 +28606,7 @@
 % 
 % \subsection{gloss-vietnamese.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-vietnamese.ldf}[polyglossia: module for Vietnamese]
 %% Strings contributed by Daniel Owens < dhowens . pmbx . net >
@@ -28647,7 +28665,7 @@
 % 
 % \subsection{gloss-welsh.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-welsh.ldf}[polyglossia: module for Welsh]
 
@@ -28664,21 +28682,26 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{welsh}{cy}
 
-\providebool{welsh at formaldate}
+\@ifundefined{ifwelsh at formaldate}%
+  {\newif\ifwelsh at formaldate}{}
 
-\define at choicekey*+{welsh}{date}[\xpg at val\xpg at nr]{long,short}[short]{%
-   \ifcase\xpg at nr\relax
-      % long:
-      \welsh at formaldatetrue
-   \or
-      % accented:
-      \welsh at formaldatefalse
-   \fi
-   \xpg at info{Option: Welsh, date=\xpg at val}%
-}{\xpg at warning{Unknown date value `#1'}}
+\DeclareKeys[polyglossia/gloss/welsh]
+  {
+    date.choice:,
+    date / long.code =
+      {%
+        \welsh at formaldatetrue
+      },
+    date / short.code =
+      {%
+        \welsh at formaldatefalse
+      },
+    date.default:n = short,
+    date/unknown.code = \xpg at warning{Unknown date value `#1'},
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{welsh}{date=short}
+\InitializeGlossOptions{welsh}{date=short}
 
 \def\captionswelsh{%
   \def\refname{Cyfeiriadau}%
@@ -28747,13 +28770,13 @@
 % 
 % \subsection{gloss-zh-CN.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-zh-CN.ldf}[polyglossia: module for zh-CN (Chinese)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{chinese}
+\InheritGlossFile{chinese}
 
 %    \end{macrocode}
 % \iffalse
@@ -28764,282 +28787,44 @@
 % 
 % \subsection{gloss-zh-TW.ldf}
 %    \begin{macrocode}
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-zh-TW.ldf}[polyglossia: module for zh-TW (Chinese)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{chinese}
+\InheritGlossFile{chinese}
 
 %    \end{macrocode}
 % \iffalse
 %</gloss-zh-TW.ldf>
-%<*arabicdigits.map>
+%<*polyglossia-cjk-spacing.lua>
 % \fi
 % \clearpage
 % 
-% \subsection{arabicdigits.map}
+% \subsection{polyglossia-cjk-spacing.lua}
 %    \begin{macrocode}
-; FC ... 
-LHSName	"Digits"
-RHSName	"ArabicDigits"
-
-pass(Unicode)
-U+0030 <> U+0660 ;
-U+0031 <> U+0661 ;
-U+0032 <> U+0662 ;
-U+0033 <> U+0663 ;
-U+0034 <> U+0664 ;
-U+0035 <> U+0665 ;
-U+0036 <> U+0666 ;
-U+0037 <> U+0667 ;
-U+0038 <> U+0668 ;
-U+0039 <> U+0669 ;
-
-%    \end{macrocode}
-% \iffalse
-%</arabicdigits.map>
-%<*bengalidigits.map>
-% \fi
-% \clearpage
-% 
-% \subsection{bengalidigits.map}
-%    \begin{macrocode}
-; FC ... 
-LHSName	"Digits"
-RHSName	"BengaliDigits"
-
-pass(Unicode)
-U+0030 <> U+09E6 ;
-U+0031 <> U+09E7 ;
-U+0032 <> U+09E8 ;
-U+0033 <> U+09E9 ;
-U+0034 <> U+09EA ;
-U+0035 <> U+09EB ;
-U+0036 <> U+09EC ;
-U+0037 <> U+09ED ;
-U+0038 <> U+09EE ;
-U+0039 <> U+09EF ;
-
-%    \end{macrocode}
-% \iffalse
-%</bengalidigits.map>
-%<*devanagaridigits.map>
-% \fi
-% \clearpage
-% 
-% \subsection{devanagaridigits.map}
-%    \begin{macrocode}
-; FC ... 
-LHSName	"Digits"
-RHSName	"DevanagariDigits"
-
-pass(Unicode)
-U+0030 <> U+0966 ;
-U+0031 <> U+0967 ;
-U+0032 <> U+0968 ;
-U+0033 <> U+0969 ;
-U+0034 <> U+096A ;
-U+0035 <> U+096B ;
-U+0036 <> U+096C ;
-U+0037 <> U+096D ;
-U+0038 <> U+096E ;
-U+0039 <> U+096F ;
-
-%    \end{macrocode}
-% \iffalse
-%</devanagaridigits.map>
-%<*farsidigits.map>
-% \fi
-% \clearpage
-% 
-% \subsection{farsidigits.map}
-%    \begin{macrocode}
-; FC ... 
-LHSName	"Digits"
-RHSName	"FarsiDigits"
-
-pass(Unicode)
-U+0030 <> U+06F0 ;
-U+0031 <> U+06F1 ;
-U+0032 <> U+06F2 ;
-U+0033 <> U+06F3 ;
-U+0034 <> U+06F4 ;
-U+0035 <> U+06F5 ;
-U+0036 <> U+06F6 ;
-U+0037 <> U+06F7 ;
-U+0038 <> U+06F8 ;
-U+0039 <> U+06F9 ;
-
-%    \end{macrocode}
-% \iffalse
-%</farsidigits.map>
-%<*gurmukhidigits.map>
-% \fi
-% \clearpage
-% 
-% \subsection{gurmukhidigits.map}
-%    \begin{macrocode}
-; FC ... 
-LHSName	"Digits"
-RHSName	"GurmukhiDigits"
-
-pass(Unicode)
-U+0030 <> U+0A66 ;
-U+0031 <> U+0A67 ;
-U+0032 <> U+0A68 ;
-U+0033 <> U+0A69 ;
-U+0034 <> U+0A6A ;
-U+0035 <> U+0A6B ;
-U+0036 <> U+0A6C ;
-U+0037 <> U+0A6D ;
-U+0038 <> U+0A6E ;
-U+0039 <> U+0A6F ;
-
-%    \end{macrocode}
-% \iffalse
-%</gurmukhidigits.map>
-%<*odiadigits.map>
-% \fi
-% \clearpage
-% 
-% \subsection{odiadigits.map}
-%    \begin{macrocode}
-; FC ... 
-LHSName	"Digits"
-RHSName	"OdiaDigits"
-
-pass(Unicode)
-U+0030 <> U+0B66 ;
-U+0031 <> U+0B67 ;
-U+0032 <> U+0B68 ;
-U+0033 <> U+0B69 ;
-U+0034 <> U+0B6A ;
-U+0035 <> U+0B6B ;
-U+0036 <> U+0B6C ;
-U+0037 <> U+0B6D ;
-U+0038 <> U+0B6E ;
-U+0039 <> U+0B6F ;
-
-%    \end{macrocode}
-% \iffalse
-%</odiadigits.map>
-%<*thaidigits.map>
-% \fi
-% \clearpage
-% 
-% \subsection{thaidigits.map}
-%    \begin{macrocode}
-; FC ... 
-LHSName	"Digits"
-RHSName	"ThaiDigits"
-
-pass(Unicode)
-U+0030 <> U+0E50 ;
-U+0031 <> U+0E51 ;
-U+0032 <> U+0E52 ;
-U+0033 <> U+0E53 ;
-U+0034 <> U+0E54 ;
-U+0035 <> U+0E55 ;
-U+0036 <> U+0E56 ;
-U+0037 <> U+0E57 ;
-U+0038 <> U+0E58 ;
-U+0039 <> U+0E59 ;
-
-%    \end{macrocode}
-% \iffalse
-%</thaidigits.map>
-%<*polyglossia-french.lua>
-% \fi
-% \clearpage
-% 
-% \subsection{polyglossia-french.lua}
-%    \begin{macrocode}
 --
--- polyglossia-punct.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- polyglossia-cjk-spacing.lua
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
-require('polyglossia-punct')
-
-local function set_left_space(lang, char, kern, rubber)
-    polyglossia.add_left_spaced_character(lang, char, kern, "space", rubber)
-end
-
-local function set_right_space(lang, char, kern, rubber)
-    polyglossia.add_right_spaced_character(lang, char, kern, "space", rubber)
-end
-
-local function activate_french_punct(thincolonspace, autospaceguillemets)
-    -- We need different language tags here to make switching of options possible
-    -- within a paragraph.
-    local lang = "french"
-    if thincolonspace then
-        lang = lang.."-thincolon"
-    end
-    if autospaceguillemets then
-        lang = lang.."-autospace"
-    end
-
-    polyglossia.activate_punct(lang)
-    polyglossia.clear_spaced_characters(lang)
-
-    if thincolonspace then
-        set_left_space(lang, ':', 0.5)
-    else
-        set_left_space(lang, ':', 1, true) -- stretchable and shrinkable space
-    end
-
-    set_left_space(lang, '!', 0.5)
-    set_left_space(lang, '?', 0.5)
-    set_left_space(lang, ';', 0.5)
-    set_left_space(lang, '‼', 0.5)
-    set_left_space(lang, '⁇', 0.5)
-    set_left_space(lang, '⁈', 0.5)
-    set_left_space(lang, '⁉', 0.5)
-    set_left_space(lang, '‽', 0.5) -- U+203D (interrobang)
-
-    if autospaceguillemets then
-        set_left_space(lang, '»', 0.5)
-        set_left_space(lang, '›', 0.5)
-        set_right_space(lang, '«', 0.5)
-        set_right_space(lang, '‹', 0.5)
-    end
-end
-
-local function deactivate_french_punct()
-    polyglossia.deactivate_punct()
-end
-
-polyglossia.activate_french_punct   = activate_french_punct
-polyglossia.deactivate_french_punct = deactivate_french_punct
-%    \end{macrocode}
-% \iffalse
-%</polyglossia-french.lua>
-%<*polyglossia-korean.lua>
-% \fi
-% \clearpage
-% 
-% \subsection{polyglossia-korean.lua}
-%    \begin{macrocode}
---
--- polyglossia-korean.lua
--- part of polyglossia v2.1 -- 2024/03/07
---
-
 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 whatsit_id = node.id"whatsit"
+local math_id  = node.id"math"
 
 --
--- attr_korean: variant = plain (0), classic (1), modern (2)
+-- attr_cjk: variant = plain: 0, JP/classic: 1, KR/modern: 2, SC: 3, TC: 4
 --
-local attr_korean = luatexbase.attributes["xpg at attr@korean"]
-local attr_josa   = luatexbase.attributes["xpg at attr@autojosa"]
+local attr_cjk = luatexbase.attributes["xpg at attr@cjkspacing"]
+--
+-- attr_josa: ONLY For Korean. DO NOT declare \newattribute for other langs
+--
+local attr_josa = luatexbase.attributes["xpg at attr@autojosa"]
 
 --
 -- characters after which linebreak is not allowed
@@ -29088,9 +28873,9 @@
 -- characters before which linebreak is not allowed
 --   (currently, not much differences among the followings)
 --   1: normal chars
---   2: hangul jamo vowels and trailing consonants
+--   2: hangul jamo vowels and trailing consonants plus combinings
 --   3: kana small letters
---   0: dashes (supress visible spacing)
+--   0: dashes (suppress visible spacing after this char)
 --
 local nobr_before = setmetatable({
     [0x21] = 1, -- ! EXCLAMATION MARK
@@ -29101,7 +28886,7 @@
     [0x2D] = 0, -- - HYPHEN-MINUS
     [0x2E] = 1, -- . FULL STOP
     [0x2F] = 0, -- / SOLIDUS
-    [0x3A] = 0, -- : COLON
+    [0x3A] = 1, -- : COLON
     [0x3B] = 1, -- ; SEMICOLON
     [0x3E] = 1, -- > GREATER-THAN SIGN
     [0x3F] = 1, -- ? QUESTION MARK
@@ -29113,11 +28898,11 @@
     [0xBB] = 1, -- » RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
     [0x2013] = 0, -- – EN DASH
     [0x2014] = 0, -- — EM DASH
-    [0x2015] = 1, -- ― HORIZONTAL BAR
+    [0x2015] = 0, -- ― HORIZONTAL BAR
     [0x2019] = 1, -- ’ RIGHT SINGLE QUOTATION MARK
     [0x201D] = 1, -- ” RIGHT DOUBLE QUOTATION MARK
-    [0x2025] = 1, -- ‥ TWO DOT LEADER
-    [0x2026] = 1, -- … HORIZONTAL ELLIPSIS
+    [0x2025] = 0, -- ‥ TWO DOT LEADER
+    [0x2026] = 0, -- … HORIZONTAL ELLIPSIS
     [0x232A] = 1, -- 〉 RIGHT-POINTING ANGLE BRACKET
     [0x3001] = 1, -- 、 IDEOGRAPHIC COMMA
     [0x3002] = 1, -- 。 IDEOGRAPHIC FULL STOP
@@ -29149,10 +28934,10 @@
     [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
+    [0x3099] = 2, --  COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
+    [0x309A] = 2, --  COMBINING KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
+    [0x309B] = 2, -- ゛ KATAKANA-HIRAGANA VOICED SOUND MARK
+    [0x309C] = 2, -- ゜ KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
     [0x309D] = 1, -- ゝ HIRAGANA ITERATION MARK
     [0x309E] = 1, -- ゞ HIRAGANA VOICED ITERATION MARK
     [0x30A0] = 1, -- ゠ KATAKANA-HIRAGANA DOUBLE HYPHEN
@@ -29172,9 +28957,9 @@
     [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
+    [0xFE30] = 0, -- ︰ PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
+    [0xFE31] = 0, -- ︱ PRESENTATION FORM FOR VERTICAL EM DASH
+    [0xFE32] = 0, -- ︲ 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
@@ -29201,18 +28986,18 @@
     [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
+    [0xFF9E] = 2, -- ゙ HALFWIDTH KATAKANA VOICED SOUND MARK
+    [0xFF9F] = 2, -- ゚ 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 >= 0x302A  and c <= 0x302F  then return 2 end -- tone marks
         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 >= 0xFE00  and c <= 0xFE0F  then return 2 end -- variation selectors
         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
+        if c >= 0xE0100 and c <= 0xE01EF then return 2 end -- variation selecters
     end
 })
 
@@ -29230,6 +29015,7 @@
     or     c >= 0xFF00  and c <= 0xFFEF
     or     c >= 0x1F100 and c <= 0x1F2FF
     or     c >= 0x20000 and c <= 0x2FA1F
+    or     c >= 0x30000 and c <= 0x323AF
     or     nobr_after[c]  and c > 0x2014
     or     nobr_before[c] and c > 0x2014
 end
@@ -29269,8 +29055,28 @@
 }, { __index = function() return 0 end })
 
 --
+-- get character class
+--      var : variant = plain, JP/classic, KR/modern, SC, TC
+--      c   : codepoint
+--
+local function get_charclass (var, c)
+    if var < 3 then
+        return charclass[c]
+    elseif var == 3 then
+        -- SC : these are left aligned
+        return (c == 0xFF01 or c == 0xFF1F) and 4 -- FULLWIDTH EXCLAMATION/QUESTION MARK
+        or     (c == 0xFF1A or c == 0xFF1B) and 2 -- FULLWIDTH COLON/SEMICOLON
+        or     charclass[c]
+    end
+    -- TC : these are center aligned
+    return (c == 0x3001 or c == 0xFF0C) and 3 -- IDEOGRAPHIC/FULLWIDTH COMMA
+    or     (c == 0x3002 or c == 0xFF0E) and 3 -- IDEOGRAPHIC/FULLWIDTH FULL STOP -- 5 ?
+    or     charclass[c]
+end
+
+--
 -- table for spacing between char classes
---   1 stands for 0.5*fontsize when variant=classic
+--   1 stands for 0.5*fontsize when variant = JP/classic or SC or TC
 --
 local intercharclass = { [0] =
     { [0] = nil,    {1,1},  nil,    {.5,.5} },
@@ -29302,7 +29108,7 @@
 
 --
 -- return 0.5*fontsize of given fontid
---   space: true if variant=modern; then 0.5*interword_space
+--   space: true if variant=KR/modern; then 0.5*interword_space
 --
 local function get_font_size (fid, space)
     local size = font.getparameters(fid)
@@ -29316,7 +29122,7 @@
 
 --
 -- charclass 1 thru 4 will be packed in \hbox to 0.5em{\hss? curr \hss?}
---   when variant=classic/modern
+--   when variant ~= plain
 --
 local function glyph_to_box (head, curr, class)
     local g, h = curr
@@ -29345,7 +29151,7 @@
 --
 -- insert spacing defined as charclass[a][b] between a and b
 --   f:    fontid
---   var:  variant = plain, classic, modern
+--   var:  variant = plain, JP/classic, KR/modern, SC, TC
 --   cc:   charclass of current char
 --   nc:   charclass of next char
 --   nobr: linebreak is not allowed
@@ -29364,12 +29170,16 @@
 
 --
 -- 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)
+--   f:    fontid
+--   var:  variant = plain, JP/classic, KR/modern, SC, TC
+--   nobr: no linebreak
+--   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 function insert_penalty_glue (head, curr, f, var, nobr, x)
+    if nobr then
+        local penalty = get_new_penalty(10000)
+        head, curr = node.insert_after(head, curr, penalty)
+    elseif var == 0 or var == 2 then
         local penalty = get_new_penalty(50)
         head, curr = node.insert_after(head, curr, penalty)
     end
@@ -29385,16 +29195,15 @@
 
 --
 -- main process for linebreak and inter-character spacing
---   lb: true if pre_linebreak_filter
 --
-local function korean_break (head, lb)
+local function cjk_break (head)
     local curr = head
     while curr do
-        if curr.id == glyph_id then
-            local var = node.has_attribute(curr, attr_korean)
+        if attr_cjk and (curr.id == glyph_id or curr.id == math_id and curr.subtype == 1) then
+            local var = node.has_attribute(curr, attr_cjk)
             if var then
-                local c, f = curr.char or 0, curr.font or 0
-                local cc, cjkc = charclass[c], is_cjk(c)
+                local c, f = curr.char or 0, curr.font
+                local cc, cjkc = get_charclass(var, c), is_cjk(c)
 
                 -- compress cjk punctuations when charclass is 1 thru 4
                 if var > 0 and cc > 0 and cc < 5 then
@@ -29401,10 +29210,21 @@
                     head, curr = glyph_to_box(head, curr, cc)
                 end
 
-                local next = curr.next
-                if next and next.id == glyph_id then
+                local next = node.getnext(curr)
+                while next and next.id == whatsit_id do -- skip whatsit nodes
+                    curr, next = next, node.getnext(next)
+                end
+
+                if next and (next.id == glyph_id or next.id == math_id and next.subtype == 0) then
                     local n = next.char or 0
-                    local nc = charclass[n]
+                    f = f or next.font or 0 -- in case of curr == math_off
+
+                    -- skip combining. or dash+dash case to suppress stretching
+                    if nobr_before[n] == 2 or (nobr_before[c] == 0 and nobr_before[n] == 0) then
+                        goto skip_combining
+                    end
+
+                    local nc = get_charclass(var, n)
                     local nobr = nobr_before[n] or nobr_after[c]
 
                     -- insert spacing as of intercharclass
@@ -29411,20 +29231,20 @@
                     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
+                    else
                         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)
+                            -- plain variant / cjk+cjk / nobr cjk+noncjk / after dash
+                            --      : insert a 0pt glue
+                            if var == 0 or (cjkc and cjkn) or nobr or nobr_before[c] == 0 then
+                                head, curr = insert_penalty_glue(head, curr, f, var, nobr)
 
-                            -- or under pre_linebreak_filter
-                            elseif lb then
-                                head, curr = insert_penalty_glue(head, curr, f, var)
+                            -- other cases: insert a small glue
+                            else
+                                head, curr = insert_penalty_glue(head, curr, f, var, nobr, true)
                             end
                         end
                     end
@@ -29431,7 +29251,8 @@
                 end
             end
         end
-        curr = curr.next
+        ::skip_combining::
+        curr = node.getnext(curr)
     end
     return head
 end
@@ -29445,7 +29266,7 @@
 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
+        if curr.id == glyph_id and node.has_attribute(curr, attr_cjk) then
             local f = font.getfont(curr.font) or font.fonts[curr.font]
             if f and f.hb then -- harfbuzz do the right thing
                 tone = nil
@@ -29461,7 +29282,7 @@
                 end
             end
         end
-        curr = curr.prev
+        curr = node.getprev(curr)
     end
     return head
 end
@@ -29548,7 +29369,7 @@
             local pc = get_prev_char(node.slide(p.head))
             if pc then return pc end
         end
-        p = p.prev
+        p = node.getprev(p)
     end
 end
 
@@ -29563,10 +29384,10 @@
             if josa then
                 local cc = curr.char or 0
                 if josa == 0 then
-                    josa = josa_code[get_prev_char(curr.prev) or 0x30]
+                    josa = josa_code[get_prev_char(node.getprev(curr)) or 0x30]
                 end
                 if cc == 0xC774 then
-                    local n = curr.next
+                    local n = node.getnext(curr)
                     if n and n.char and n.char >= 0xAC00 and n.char <= 0xD7A3 then
                     else
                         cc = 0xAC00
@@ -29585,7 +29406,7 @@
                 node.unset_attribute(curr, attr_josa)
             end
         end
-        curr = curr.next
+        curr = node.getnext(curr)
     end
     for _,v in ipairs(tofree) do node.free(v) end
     return head
@@ -29596,45 +29417,86 @@
 --   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)
+luatexbase.add_to_callback( "pre_shaping_filter",
+function(head)
+    if attr_josa then head = auto_josa(head) end
+    head = cjk_break(head)
+    if attr_josa then head = reorder_tm(head) end
+    return head
+end,
+"polyglossia.lang_cjk_spacing")
+
+-- vim:ft=lua:tw=0:sw=4:ts=4:expandtab
+%    \end{macrocode}
+% \iffalse
+%</polyglossia-cjk-spacing.lua>
+%<*polyglossia-french.lua>
+% \fi
+% \clearpage
+% 
+% \subsection{polyglossia-french.lua}
+%    \begin{macrocode}
+--
+-- polyglossia-punct.lua
+-- part of polyglossia v2.2 -- 2024/07/15
+--
+
+require('polyglossia-punct')
+
+local function set_left_space(lang, char, kern, rubber)
+    polyglossia.add_left_spaced_character(lang, char, kern, "space", rubber)
+end
+
+local function set_right_space(lang, char, kern, rubber)
+    polyglossia.add_right_spaced_character(lang, char, kern, "space", rubber)
+end
+
+local function activate_french_punct(thincolonspace, autospaceguillemets)
+    -- We need different language tags here to make switching of options possible
+    -- within a paragraph.
+    local lang = "french"
+    if thincolonspace then
+        lang = lang.."-thincolon"
     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
+    if autospaceguillemets then
+        lang = lang.."-autospace"
     end
+
+    polyglossia.activate_punct(lang)
+    polyglossia.clear_spaced_characters(lang)
+
+    if thincolonspace then
+        set_left_space(lang, ':', 0.5)
+    else
+        set_left_space(lang, ':', 1, true) -- stretchable and shrinkable space
+    end
+
+    set_left_space(lang, '!', 0.5)
+    set_left_space(lang, '?', 0.5)
+    set_left_space(lang, ';', 0.5)
+    set_left_space(lang, '‼', 0.5)
+    set_left_space(lang, '⁇', 0.5)
+    set_left_space(lang, '⁈', 0.5)
+    set_left_space(lang, '⁉', 0.5)
+    set_left_space(lang, '‽', 0.5) -- U+203D (interrobang)
+
+    if autospaceguillemets then
+        set_left_space(lang, '»', 0.5)
+        set_left_space(lang, '›', 0.5)
+        set_right_space(lang, '«', 0.5)
+        set_right_space(lang, '‹', 0.5)
+    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")
+local function deactivate_french_punct()
+    polyglossia.deactivate_punct()
+end
 
-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
+polyglossia.activate_french_punct   = activate_french_punct
+polyglossia.deactivate_french_punct = deactivate_french_punct
 %    \end{macrocode}
 % \iffalse
-%</polyglossia-korean.lua>
+%</polyglossia-french.lua>
 %<*polyglossia-latin.lua>
 % \fi
 % \clearpage
@@ -29643,7 +29505,7 @@
 %    \begin{macrocode}
 --
 -- polyglossia-latin.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia-punct')
@@ -29698,14 +29560,13 @@
 %    \begin{macrocode}
 --
 -- polyglossia-punct.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia') -- just in case...
 
 local add_to_callback      = luatexbase.add_to_callback
-local remove_from_callback = luatexbase.remove_from_callback
-local priority_in_callback = luatexbase.priority_in_callback
+local declare_callback_rule = luatexbase.declare_callback_rule
 local new_attribute        = luatexbase.new_attribute
 
 local node = node
@@ -30029,13 +29890,16 @@
     -- important to be able to intermix languages with different spacings
     -- in one paragraph.
     tex.setattribute(punct_attr, id)
-    for _, callback_name in ipairs{ "pre_linebreak_filter", "hpack_filter" } do
-        if not priority_in_callback(callback_name, "polyglossia-punct.process") then
-            add_to_callback(callback_name, process, "polyglossia-punct.process", 1)
-        end
-    end
 end
 
+add_to_callback("pre_linebreak_filter",process,"polyglossia-punct.process")
+add_to_callback("hpack_filter",process,"polyglossia-punct.process")
+declare_callback_rule("pre_linebreak_filter",
+    "polyglossia-punct.process", "before", "luaotfload.node_processor")
+declare_callback_rule("hpack_filter",
+    "polyglossia-punct.process", "before", "luaotfload.node_processor")
+
+
 local function deactivate()
     tex.setattribute(punct_attr, -0x7FFFFFFF) -- this value means "unset"
     -- Though it would make compilation slightly faster, it is not possible to
@@ -30066,7 +29930,7 @@
 %    \begin{macrocode}
 --
 -- polyglossia-sanskrit.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia-punct')
@@ -30116,7 +29980,7 @@
 %    \begin{macrocode}
 --
 -- polyglossia-tibt.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia') -- just in case...
@@ -30123,17 +29987,15 @@
 
 local add_to_callback = luatexbase.add_to_callback
 local remove_from_callback = luatexbase.remove_from_callback
+local declare_callback_rule = luatexbase.declare_callback_rule
 local priority_in_callback = luatexbase.priority_in_callback
 
 local next, type = next, type
+local node = node
 
-local nodes, fonts, node = nodes, fonts, node
-
-local nodecodes          = nodes.nodecodes --- <= preloaded node.types()
-
 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 copy_node          = node.copy
 local has_attribute      = node.has_attribute
 
@@ -30140,7 +30002,7 @@
 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 math_code      = node.id('math_char')
   local end_of_math = function (n)
     for n in traverse_nodes(math_code, n.next) do
       return n
@@ -30148,10 +30010,10 @@
   end
 end
 
--- node types as of April 2013
-local glyph_code         = nodecodes.glyph
-local penalty_code       = nodecodes.penalty
-local kern_code          = nodecodes.kern
+-- node types as of April 2024
+local glyph_code         = node.id('glyph')
+local penalty_code       = node.id('penalty')
+local kern_code          = node.id('kern')
 
 -- we make a new node, so that we can copy it later on
 local penalty_node  = node.new(penalty_code)
@@ -30182,7 +30044,6 @@
                 end
             end
         elseif id == math_code then
-            -- warning: this is a feature of luatex > 0.76
             start = end_of_math(start) -- weird, can return nil .. no math end?
         end
         if start then
@@ -30195,15 +30056,13 @@
 local callback_name = "pre_linebreak_filter"
 
 local function activate()
-  if not priority_in_callback (callback_name, "polyglossia-tibt.process") then
-    add_to_callback(callback_name, process, "polyglossia-tibt.process", 1)
-  end
+    add_to_callback(callback_name, process, "polyglossia-tibt.process")
+    declare_callback_rule(callback_name,
+    "polyglossia-tibt.process", "before", "luaotfload.node_processor")
 end
 
 local function desactivate()
-  if priority_in_callback (callback_name, "polyglossia-tibt.process") then
-    remove_from_callback(callback_name, "polyglossia-tibt.process")
-  end
+	remove_from_callback(callback_name, "polyglossia-tibt.process")
 end
 
 polyglossia.activate_tibt_eol    = activate
@@ -30219,7 +30078,7 @@
 %    \begin{macrocode}
 --
 -- polyglossia.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 local module_name = "polyglossia"
@@ -30295,7 +30154,7 @@
             end
 
             -- language info will be written into the .log file
-            local s = { "Language data for " .. langentry }
+            local s = { }
             for k, v in pairs(langdata) do
                 if type(v) == 'table' then -- for 'synonyms'
                     s[#s+1] = k .. "\t" .. table.concat(v,',')
@@ -30303,7 +30162,10 @@
                     s[#s+1] = k .. "\t" .. tostring(v)
                 end
             end
-            log_info(table.concat(s,"\n"))
+            local a = {}
+	    for _,n in pairs(s) do table.insert(a, n) end
+            table.sort(a)
+            log_info("Language data for " .. langentry .. "\n" .. table.concat(a,"\n"))
 
             --
             -- LaTeX's \newlanguage increases language register (count19),
@@ -30313,7 +30175,7 @@
             -- this possible situation, our newloader() function will
             -- unfortunately overwrite the language \lang at xyz.
             --
-            -- Threfore here we will compare LaTeX's \newlanguage number with
+            -- Therefore 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
@@ -30328,7 +30190,7 @@
             local newlangid = math.max(langcnt, langid)
             -- set language register for possible \newlanguage
             tex.setcount('global', lang_register, newlangid)
-            -- get new lang object if needeed
+            -- get new lang object if needed
             if langid ~= newlangid then
                 langobject = lang.new(newlangid)
             end
@@ -30394,7 +30256,12 @@
 \setmainfont{Linux Libertine O}
 \defaultfontfeatures{Scale=MatchLowercase}
 \setmonofont{Inconsolata}
-\newfontfamily\arabicfont[Script=Arabic]{Amiri}
+\newfontfamily\arabicfont[Script=Arabic]{Amiri}[%
+ UprightFont = *-Regular,
+  BoldFont = *-Bold,
+  Extension = .ttf,
+  ItalicFont = *-Italic,
+  BoldItalicFont = *-BoldItalic]
 \newfontfamily\syriacfont[Script=Syriac]{Serto Jerusalem}
 \newfontfamily\hebrewfont[Script=Hebrew]{Ezra SIL}
 \newfontfamily\sanskritfont[Script=Devanagari]{Sanskrit 2003}
@@ -30530,7 +30397,12 @@
 \usepackage{xltxtra,url,amsmath}
 \setmainfont{Linux Libertine O}
 \defaultfontfeatures{Scale=MatchLowercase}
-\newfontfamily\arabicfont[Script=Arabic]{Amiri}
+\newfontfamily\arabicfont[Script=Arabic]{Amiri}[%
+ UprightFont = *-Regular,
+  BoldFont = *-Bold,
+  Extension = .ttf,
+  ItalicFont = *-Italic,
+  BoldItalicFont = *-BoldItalic]
 \newfontfamily\arabicfonttt[Script=Arabic,Scale=.75]{DejaVu Sans Mono}
 \newfontfamily\farsifont[Script=Arabic,Scale=1.1,WordSpace=2]{IranNastaliq}
 \let\XeTeX\undefined
@@ -30700,7 +30572,7 @@
 % \typeout{* To finish the installation you have to move the following}
 % \typeout{* file into a directory searched by TeX:}
 % \typeout{*}
-% \typeout{* \space\space all *.sty, *.lua, *.def, *.lde and *.ldf files}
+% \typeout{* \space\space\space all *.sty, *.lua, *.def and *.ldf files}
 % \typeout{*}
 % \typeout{* You also need to compile the *.map files with teckit_compile}
 % \typeout{* and place the resulting *.tec files under}

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/arabicnumbers.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/arabicnumbers.sty	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/arabicnumbers.sty	2024-07-15 21:38:31 UTC (rev 71813)
@@ -43,24 +43,23 @@
 \fi
 }
 \def\abjad at zero{}
-\def\abjad at three{ج\ifabjad at jim@notail\char"200D\fi}
+\def\abjad at one{ا}
+\def\abjad at three{ج\ifabjad at jim@notail\Uchar"200D\fi}
 \def\abj at num@i at iso#1{%
-  \ifcase#1\or ا\or ب\or\abjad at three\or د%
-           \or ه\char"200D\or و\or ز\or ح\or ط\fi%
-  \ifnum#1=\z@\abjad at zero\fi}
+  \ifcase#1\abjad at zero\or \abjad at one\or ب\or\abjad at three\or د%
+           \or ه\Uchar"200D\or و\or ز\or ح\or ط\fi}
 \def\abj at num@i#1{%
-  \ifcase#1\or ا\or ب\or\abjad at three\or د%
-           \or ه\or و\or ز\or ح\or ط\fi%
-  \ifnum#1=\z@\abjad at zero\fi}
+  \ifcase#1\abjad at zero\or\abjad at one\or ب\or\abjad at three\or د%
+           \or ه\or و\or ز\or ح\or ط\fi}
 \def\abj at num@ii#1{%
   \ifcase#1\or ي\or ك\or ل\or م\or ن%
-           \or س\or ع\or ف\or ص\fi% 
-  \ifnum#1=\z@\fi\abj at num@i}
+           \or س\or ع\or ف\or ص\fi 
+  \abj at num@i}
 \def\abj at num@iii#1{%
   \ifcase#1\or ق\or ر\or ش\or ت\or ث%
-            \or خ\or ذ\or ض\or ظ\fi%
-  \ifnum#1=\z@\fi\abj at num@ii}
+            \or خ\or ذ\or ض\or ظ\fi
+  \abj at num@ii}
 \def\abj at num@iv#1{%
   \ifcase#1\or غ\fi
-  \ifnum#1=\z@\fi\abj at num@iii}
+  \abj at num@iii}
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/cal-util.def
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/cal-util.def	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/cal-util.def	2024-07-15 21:38:31 UTC (rev 71813)
@@ -45,7 +45,7 @@
 
 
 %% This is an algorithm from Reingold & Dershowitz, 
-%% Calendrical Calculations, The Millenium Edition
+%% Calendrical Calculations, The Millennium Edition
 %%
 \def\@FixedFromGregorian#1#2#3#4{%
  \setcounter{tmpA}{(#1-1)*365}%

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-acadian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-acadian.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-acadian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -0,0 +1,9 @@
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
+%
+\ProvidesFile{gloss-acadien.ldf}[polyglossia: module for Canadian (Acadian) French]
+
+% We provide this as a babel alias
+
+\InheritGlossFile{french}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-acadian.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Deleted: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-acadien.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-acadien.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-acadien.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +0,0 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
-%
-\ProvidesFile{gloss-acadien.ldf}[polyglossia: module for Canadian (Acadian) French]
-
-% We provide this as a babel alias
-
-\xpg at load@master at language{french}
-
-\endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-aeb.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-aeb.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-aeb.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-aeb.ldf}[polyglossia: module for aeb (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-af.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-af.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-af.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-af.ldf}[polyglossia: module for af (Afrikaans)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{afrikaans}
+\InheritGlossFile{afrikaans}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-afb.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-afb.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-afb.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-afb.ldf}[polyglossia: module for afb (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-afrikaans.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-afrikaans.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-afrikaans.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-afrikaans.ldf}[polyglossia: module for Afrikaans]
 
@@ -16,22 +16,21 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{afrikaans}{af}
 
-\define at boolkey{afrikaans}[afrikaans@]{babelshorthands}[true]{}
-
+\DeclareKeys[polyglossia/gloss/afrikaans]
+  {
+    babelshorthands.if = afrikaans at babelshorthands,
+    babelshorthands.default:n = true,
+  }
 % Register default options
-\xpg at initialize@gloss at options{afrikaans}{babelshorthands=false}
+\InitializeGlossOptions{afrikaans}{babelshorthands=false}
 
 \ifsystem at babelshorthands
-  \setkeys{afrikaans}{babelshorthands=true}
+  \SetGlossOptions{afrikaans}{babelshorthands=true}
 \else
-  \setkeys{afrikaans}{babelshorthands=false}
+  \SetGlossOptions{afrikaans}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\afrikaans at shorthands{%
   \xpg at activate@shorthands%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-albanian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-albanian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-albanian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-albanian.ldf}[polyglossia: module for Albanian]
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-am.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-am.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-am.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-am.ldf}[polyglossia: module for am (Amharic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{amharic}
+\InheritGlossFile{amharic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-american.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-american.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-american.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-american.ldf}[polyglossia: module for American English]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-amharic.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-amharic.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-amharic.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-amharic.ldf}[polyglossia: module for Amharic]
 \PolyglossiaSetup{amharic}{

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-apd.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-apd.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-apd.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-apd.ldf}[polyglossia: module for apd (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-IQ.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-IQ.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-IQ.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,10 +1,10 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-IQ.ldf}[polyglossia: module for ar-IQ (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-IQ,bcp47-language=ar,bcp47-region=IQ}%
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-JO.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-JO.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-JO.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,10 +1,10 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-JO.ldf}[polyglossia: module for ar-JO (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-JO,bcp47-language=ar,bcp47-region=JO}%
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-LB.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-LB.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-LB.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,10 +1,10 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-LB.ldf}[polyglossia: module for ar-LB (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-LB,bcp47-language=ar,bcp47-region=LB}%
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-MR.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-MR.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-MR.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,10 +1,10 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-MR.ldf}[polyglossia: module for ar-MR (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-MR,bcp47-language=ar,bcp47-region=MR}%
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-PS.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-PS.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-PS.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,10 +1,10 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-PS.ldf}[polyglossia: module for ar-PS (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-PS,bcp47-language=ar,bcp47-region=PS}%
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-SY.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-SY.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-SY.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,10 +1,10 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-SY.ldf}[polyglossia: module for ar-SY (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-SY,bcp47-language=ar,bcp47-region=SY}%
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-YE.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-YE.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar-YE.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,10 +1,10 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar-YE.ldf}[polyglossia: module for ar-YE (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \SetLanguageKeys{arabic}{bcp47=ar-YE,bcp47-language=ar,bcp47-region=YE}%
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ar.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ar.ldf}[polyglossia: module for ar (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arabic.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arabic.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arabic.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-arabic.ldf}[polyglossia: module for Arabic]
 \RequireBidi
@@ -38,104 +38,112 @@
 \setlanguagealias*[locale=default]{arabic}{apd}
 \setlanguagealias*[locale=mashriq]{arabic}{ar-PS}
 
-\define at boolkey{arabic}[arabic@]{abjadalph}[true]{}
-
 \newif\ifeastern at numerals
-\define at choicekey*+{arabic}{numerals}[\xpg at val\xpg at nr]{mashriq,maghrib,eastern,western}[mashriq]{%
-   \ifcase\xpg at nr\relax
-      % mashriq:
-      \eastern at numeralstrue%
-   \or
-      % maghrib:
-      \eastern at numeralsfalse
-   \or
-      % eastern:
-      \eastern at numeralstrue%
-   \or
-      % western:
-      \eastern at numeralsfalse
-   \fi
-   \xpg at info{Option: Arabic, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Arabic numerals option `#1'}}
-
-%this is needed for \abjad in arabicnumbers.sty
-\define at boolkey{arabic}[arabic@]{abjadjimnotail}[true]{%
-  \ifarabic at abjadjimnotail
-    \abjad at jim@notailtrue%
-  \else
-    \abjad at jim@notailfalse
-  \fi}
-
-\define at choicekey*+{arabic}{locale}[\xpg at val\xpg at nr]{default,mashriq,libya,algeria,tunisia,morocco,mauritania}[default]{%
-   \ifcase\xpg at nr\relax
-      % default:
-      \eastern at numeralstrue%
-      \SetLanguageKeys{arabic}{bcp47=ar-YE,bcp47-language=ar}%
-      \xpg at info{Option: arabic, locale=default}%
-   \or
-      % mashriq:
-      \eastern at numeralstrue%
-      \SetLanguageKeys{arabic}{bcp47=ar-IQ,bcp47-language=ar}%
-      \xpg at info{Option: arabic, locale=mashriq}%
-   \or
-      % libya:
-      \eastern at numeralstrue%
-      \SetLanguageKeys{arabic}{bcp47=ayl,bcp47-language=ar,bcp47-region=LY}%
-      \xpg at info{Option: arabic, locale=libya}%
-   \or
-      % algeria:
-      \eastern at numeralsfalse%
-      \SetLanguageKeys{arabic}{bcp47=arq,bcp47-language=ar,bcp47-region=DZ,bcp47-extension-u=nu-latn}%
-      \xpg at info{Option: arabic, locale=algeria}%
-   \or
-      % tunisia:
-      \eastern at numeralsfalse%
-      \SetLanguageKeys{arabic}{bcp47=aeb,bcp47-language=ar,bcp47-region=TN,bcp47-extension-u=nu-latn}%
-      \xpg at info{Option: arabic, locale=tunisia}%
-   \or
-      % morocco:
-      \eastern at numeralsfalse%
-      \SetLanguageKeys{arabic}{bcp47=ary,bcp47-language=ar,bcp47-region=MA,bcp47-extension-u=nu-latn}%
-      \xpg at info{Option: arabic, locale=morocco}%
-   \or
-      % mauritania:
-      \eastern at numeralstrue%
-      \SetLanguageKeys{arabic}{bcp47=ar-MR,bcp47-language=ar,bcp47-region=MR}%
-      \xpg at info{Option: arabic, locale=mauritania}%
-   \fi
-   \gdef\@@arabic at month{\@arabic at month{#1}}
- }{\xpg at warning{Unknown Arabic locale `#1'}}
-
 \newif\if at hijrical
-\define at choicekey*+{arabic}{calendar}[\xpg at val\xpg at nr]{gregorian,hijri,islamic}[gregorian]{%
-   \ifcase\xpg at nr\relax
-      % gregorian:
-      \@hijricalfalse
-   \or
-      % hijri:
-      \@hijricaltrue
-   \or
-      % islamic:
-      \@hijricaltrue
-   \fi
-   \xpg at info{Option: Arabic, calendar=\xpg at val}%
-}{\xpg at warning{Unknown Arabic calendar option `#1'}}
+\newif\ifarabic at customsep\arabic at customsepfalse
 
+\DeclareKeys[polyglossia/gloss/arabic]
+  {
+    hijricorrection.code = \gdef\arabic at hijri@correction{#1},
+    hijricorrection.default:n = 0,
+    sectionsep.code = \gdef\xpg at sepmark{#1}\arabic at customseptrue,
+    sectionsep.default:n = .,
+    abjadalph.if = arabic at abjadalph,
+    abjadalph.default:n = true,
+    abjadjimnotail.if = abjad at jim@notail,
+    abjadjimnotail.default:n = true,
+    numerals.choice:,
+    numerals / mashriq.code =
+      {%
+        \eastern at numeralstrue
+      },
+    numerals / maghrib.code =
+      {%
+        \eastern at numeralsfalse
+      },
+    numerals / eastern.code =
+      {%
+        \eastern at numeralstrue
+      },
+    numerals / western.code =
+      {%
+        \eastern at numeralsfalse
+      },
+    numerals.default:n = mashriq,
+    numerals/unknown.code = \xpg at warning{Unknown Arabic numerals option `#1'},
+    locale.choice:,
+    locale / default.code =
+      {%
+        \eastern at numeralstrue
+        \def\abjad at one{ا}%
+        \SetLanguageKeys{arabic}{bcp47=ar-YE,bcp47-language=ar}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / mashriq.code =
+      {%
+        \eastern at numeralstrue
+        \def\abjad at one{ا}%
+        \SetLanguageKeys{arabic}{bcp47=ar-IQ,bcp47-language=ar}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / libya.code =
+      {%
+        \eastern at numeralstrue
+        \def\abjad at one{ا}%
+        \SetLanguageKeys{arabic}{bcp47=ayl,bcp47-language=ar,bcp47-region=LY}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / algeria.code =
+      {%
+        \eastern at numeralsfalse
+        \def\abjad at one{أ}%
+        \SetLanguageKeys{arabic}{bcp47=arq,bcp47-language=ar,bcp47-region=DZ,bcp47-extension-u=nu-latn}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / tunisia.code =
+      {%
+        \eastern at numeralsfalse
+        \def\abjad at one{أ}%
+        \SetLanguageKeys{arabic}{bcp47=aeb,bcp47-language=ar,bcp47-region=TN,bcp47-extension-u=nu-latn}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / morocco.code =
+      {%
+        \eastern at numeralsfalse
+        \def\abjad at one{أ}%
+        \SetLanguageKeys{arabic}{bcp47=ary,bcp47-language=ar,bcp47-region=MA,bcp47-extension-u=nu-latn}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale / mauritania.code =
+      {%
+        \eastern at numeralstrue
+        \def\abjad at one{ا}%
+        \SetLanguageKeys{arabic}{bcp47=ar-MR,bcp47-language=ar,bcp47-region=MR}%
+        \gdef\@@arabic at month{\@arabic at month{#1}}%
+      },
+    locale.default:n = default,
+    locale/unknown.code = \xpg at warning{Unknown Arabic locale `#1'},
+    calendar.choice:,
+    calendar / gregorian.code =
+      {%
+        \@hijricalfalse
+      },
+    calendar / hijri.code =
+      {%
+        \@hijricaltrue
+      },
+    calendar / islamic.code =
+      {%
+        \@hijricaltrue
+      },
+    calendar.default:n = gregorian,
+    calendar/unknown.code = \xpg at warning{Unknown Arabic calendar option `#1'}
+  }
 
-\define at key{arabic}{hijricorrection}[0]{%
-  \gdef\arabic at hijri@correction{#1}}%
-
-\newif\ifarabic at customsep\arabic at customsepfalse
-\def\xpg at sepmark{}
-\define at key{arabic}{sectionsep}[.]{%
-   \arabic at customseptrue%
-   \gdef\xpg at sepmark{#1}%
-}
-
 % Register default options
-\xpg at initialize@gloss at options{arabic}{locale=default,calendar=gregorian,numerals=mashriq,hijricorrection=0,abjadjimnotail=false}
+\InitializeGlossOptions{arabic}{locale=default,calendar=gregorian,numerals=mashriq,hijricorrection=0,abjadjimnotail=false}
 % Register alias options
-\xpg at set@alias at values{arabic}{calendar}{islamic}{hijri}
+\SetLanguageAliasValues{arabic}{calendar}{islamic,hijri}
 
 \def\arabicgregmonth at default#1{\ifcase#1%
   % Egypt, Sudan, Yemen and Golf states
@@ -155,9 +163,12 @@
 \def\arabicgregmonth at mauritania#1{\ifcase#1%
   \or يناير\or فبراير\or مارس\or إبريل\or مايو\or يونيو\or يوليو\or أغشت\or شتمبر\or أكتوبر\or نوفمبر\or دجمبر\fi}
 
-\def\@arabic at month#1{\ifcsdef{arabicgregmonth@#1}{\expandafter\csname arabicgregmonth@#1\endcsname}%
-{\xpg at warning{Option `locale=#1' is not defined for Arabic: using `default' instead}%
-\arabicgregmonth at default}}
+\def\@arabic at month#1{%
+  \@ifundefined{arabicgregmonth@#1}%
+     {\xpg at warning{Option `locale=#1' is not defined for Arabic: using `default' instead}%
+      \arabicgregmonth at default}%
+     {\expandafter\csname arabicgregmonth@#1\endcsname}%
+}
 
 %\Hijritoday is now locale-aware and will format the date with this macro:
 \DefineFormatHijriDate{arabic}{\@ensure at RTL{\arabicnumber{\value{Hijriday}}%
@@ -189,18 +200,18 @@
 }
 \def\datearabic{%
  \def\today{%
-  \if at hijrical%
+  \if at hijrical
     \Hijritoday[\arabic at hijri@correction]%
   \else%
-    \if at RTL%
+    \if at RTL
        \arabicnumber\day\space\@@arabic at month{\month}%
         \space\arabicnumber\year%
     \else% in LR environment we format the gregorian date within \textenglish
-       \ifcsdef{english at loaded}{\textenglish{\today}}%else US format
-       {\normalfontlatin\ifcase\month\or January\or February\or March\or April\or May\or June\or%
-       July\or August\or September\or October\or November\or December\fi%
+       \iflanguageloaded{english}{\textenglish{\today}}%else US format
+       {\normalfontlatin\ifcase\month\or January\or February\or March\or April\or May\or June\or
+       July\or August\or September\or October\or November\or December\fi
        \space\number\day,\space\number\year}%
-    \fi%
+    \fi
  \fi}}
 
 % Use \providecommand here as the ldf file might
@@ -226,10 +237,9 @@
    \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}{arabic at abjad@alph}\fi%
+   \else\xpg at ill@value{#1}{arabic at abjad@alph}\fi
 }
 
-
 \def\abjadmaghribi#1{%
 \ifnum#1>1999\xpg at ill@value{#1}{abjad}%
 \else
@@ -252,30 +262,30 @@
 
 %maghribi س -> ص ص -> ض ش -> س ض -> ظ ظ -> غ غ -> ش
 \def\abj at maghribi@num at ii#1{%
-  \ifcase#1\or ي\or ك\or ل\or م\or ن%
+  \ifcase#1\abjad at zero\or ي\or ك\or ل\or م\or ن%
            \or ص\or ع\or ف\or ض\fi
-  \ifnum#1=\z@\abjad at zero\fi\abj at num@i}
+  \abj at num@i}
 \def\abj at maghribi@num at iii#1{%
   \ifcase#1\or ق\or ر\or س\or ت\or ث%
            \or خ\or ذ\or ظ\or غ\fi
-  \ifnum#1=\z@\fi\abj at maghribi@num at ii}
+  \abj at maghribi@num at ii}
 \def\abj at maghribi@num at iv#1{%
   \ifcase#1\or ش\fi
-  \ifnum#1=\z@\fi\abj at maghribi@num at iii}
+  \abj at maghribi@num at iii}
 
 \def\arabic at numbers{%
  \ifarabic at abjadalph
-   \let\@alph\abjadalph%
-   \let\@Alph\abjadalph%
+   \let\@alph\abjadalph
+   \let\@Alph\abjadalph
  \else
-   \let\@alph\abjad%
-   \let\@Alph\abjad%
+   \let\@alph\abjad
+   \let\@Alph\abjad
  \fi
 }
 
 \def\noarabic at numbers{%
-  \let\@alph\latin at alph%
-  \let\@Alph\latin at Alph%
+  \let\@alph\latin at alph
+  \let\@Alph\latin at Alph
 }
 
 % Store original definition
@@ -282,24 +292,24 @@
 \let\xpg at save@arabic\@arabic
 
 \def\arabic at globalnumbers{%
-  \let\@arabic\arabicnumber%
+  \let\@arabic\arabicnumber
   \renewcommand\thefootnote{\localnumeral*{footnote}}%
   \renewcommand\theequation{\localnumeral*{equation}}%
 }
 
 \def\noarabic at globalnumbers{%
-   \let\@arabic\xpg at save@arabic%
+   \let\@arabic\xpg at save@arabic
 }
 
 \def\arabic at xetex@capsformat{%
-  \let\xpg at save@sepmark\@SepMark%
+  \let\xpg at save@sepmark\@SepMark
   \SepMark{\xpg at sepmark}
 }
 
 \def\noarabic at xetex@capsformat{%
-   \ifcsdef{xpg at save@sepmark}{%
+   \ifcsname xpg at save@sepmark\endcsname
      \SepMark{\xpg at save@sepmark}
-   }{}%
+   \fi
 }
 
 \def\arabic at luatex@capsformat{%
@@ -306,57 +316,57 @@
   %
   % change chapter and part headings
   \ifarabic at customsep
-     \ifcsdef{chapter}{%
-        \let\xpg at save@thesection\thesection%
+     \ifcsname chapter\endcsname
+        \let\xpg at save@thesection\thesection
         \renewcommand*\thesection{\thechapter\xpg at sepmark\@arabic\c at section}
-        \let\xpg at save@theequation\theequation%
+        \let\xpg at save@theequation\theequation
         \renewcommand*\theequation{%
 	    \ifnum \c at chapter>\z@ \thechapter\xpg at sepmark\fi\@arabic\c at equation}
-        \let\xpg at save@thefigure\thefigure%
+        \let\xpg at save@thefigure\thefigure
 	\renewcommand*\thefigure{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at figure}
-        \let\xpg at save@thetable\thetable%
+        \let\xpg at save@thetable\thetable
 	\renewcommand*\thetable{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at table}
-     }{}
-     \let\xpg at save@thesubsection\thesubsection%
+     \fi
+     \let\xpg at save@thesubsection\thesubsection
      \renewcommand\thesubsection
 	{\thesection\xpg at sepmark\@arabic\c at subsection}
-     \let\xpg at save@thesubsubsection\thesubsubsection%
+     \let\xpg at save@thesubsubsection\thesubsubsection
      \renewcommand\thesubsubsection{\thesubsection\xpg at sepmark\@arabic\c at subsubsection}
-     \let\xpg at save@theparagraph\theparagraph%
+     \let\xpg at save@theparagraph\theparagraph
      \renewcommand\theparagraph
          {\thesubsubsection\xpg at sepmark\@arabic\c at paragraph}
-     \let\xpg at save@thesubparagraph\thesubparagraph%
+     \let\xpg at save@thesubparagraph\thesubparagraph
      \renewcommand\thesubparagraph{\theparagraph\xpg at sepmark\@arabic\c at subparagraph}
-  \fi% (end \ifarabic at customsep)
+  \fi % (end \ifarabic at customsep)
 }
 
 \def\noarabic at luatex@capsformat{%
-   \ifcsdef{xpg at save@thesection}{%
-        \let\thesection\xpg at save@thesection%
-   }{}%
-   \ifcsdef{xpg at save@theequation}{%
-        \let\theequation\xpg at save@theequation%
-   }{}%
-   \ifcsdef{xpg at save@thefigure}{%
-        \let\thefigure\xpg at save@thefigure%
-   }{}%
-   \ifcsdef{xpg at save@thetable}{%
-        \let\thetable\xpg at save@thetable%
-   }{}%
-   \ifcsdef{xpg at save@thesubsection}{%
-        \let\thesubsection\xpg at save@thesubsection%
-   \ifcsdef{xpg at save@thesubsubsection}{%
-        \let\thesubsubsection\xpg at save@thesubsubsection%
-   }{}%
-   }{}%
-   \ifcsdef{xpg at save@theparagraph}{%
-        \let\theparagraph\xpg at save@theparagraph%
-   }{}%
-   \ifcsdef{xpg at save@thesubparagraph}{%
-        \let\thesubparagraph\xpg at save@thesubparagraph%
-   }{}%
+   \ifcsname xpg at save@thesection\endcsname
+        \let\thesection\xpg at save@thesection
+   \fi
+   \ifcsname xpg at save@theequation\endcsname
+        \let\theequation\xpg at save@theequation
+   \fi
+   \ifcsname xpg at save@thefigure\endcsname
+        \let\thefigure\xpg at save@thefigure
+   \fi
+   \ifcsname xpg at save@thetable\endcsname
+        \let\thetable\xpg at save@thetable
+   \fi
+   \ifcsname xpg at save@thesubsection\endcsname
+        \let\thesubsection\xpg at save@thesubsection
+      \ifcsname xpg at save@thesubsubsection\endcsname
+        \let\thesubsubsection\xpg at save@thesubsubsection
+      \fi
+   \fi
+   \ifcsname xpg at save@theparagraph\endcsname
+        \let\theparagraph\xpg at save@theparagraph
+   \fi
+   \ifcsname xpg at save@thesubparagraph\endcsname
+        \let\thesubparagraph\xpg at save@thesubparagraph
+   \fi
 }
 
 \def\blockextras at arabic{%
@@ -368,7 +378,7 @@
       \fi   
    \fi
 }
-%
+
 \def\noextras at arabic{%
     \ifarabic at customsep
       \ifxetex

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-armenian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-armenian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-armenian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-armenian.ldf}[polyglossia: module for Armenian]
 
@@ -21,43 +21,49 @@
 
 \newif\if at eastern@armenian
 \@eastern at armenianfalse
-\define at choicekey*+{armenian}{variant}[\xpg at val\xpg at nr]{western,eastern}[western]{%
-   \ifcase\xpg at nr\relax
-      % western:
-      \@eastern at armenianfalse%
-   \or
-      % eastern:
-      \@eastern at armeniantrue%
-   \fi
-   \xpg at info{Option: Armenian, variant=\xpg at 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%
-     \SetLanguageKeys{armenian}{bcp47-extension-u=nu-latn}%
-   }{%
-     \@armenian at numeralstrue%
-     \SetLanguageKeys{armenian}{bcp47-extension-u={}}%
-   }%
-}
 
-\define at boolkey{armenian}[armenian@]{capitalyiwn}[true]{%
-  \ifarmenian at capitalyiwn
-     % MakeUppercase capitalizes the ligature of letters ech and yiwn (U+0587)
-     % to capital ech and yiwn (also the output if Armenian is not selected at all)
-     \SetLanguageKeys{armenian}{bcp47-casing=hy-x-yiwn,bcp47-extension-x=yiwn}
-  \else
-     % Capitalize ech and yiwn ligature to capital ech and vew,
-     % following Armenian spelling reform
-     \SetLanguageKeys{armenian}{bcp47-casing=hy,bcp47-extension-x={}}
-  \fi
-}
+\DeclareKeys[polyglossia/gloss/armenian]
+  {
+    variant.choice:,
+    variant / western.code =
+      {%
+        \@eastern at armenianfalse
+      },
+    variant / eastern.code =
+      {%
+        \@eastern at armeniantrue
+      },
+    variant.default:n = western,
+    variant/unknown.code = \xpg at warning{Unknown Armenian variant `#1'},
+    numerals.choice:,
+    numerals / armenian.code =
+      {%
+        \@armenian at numeralstrue
+        \SetLanguageKeys{armenian}{bcp47-extension-u={}}%
+      },
+    numerals / arabic.code =
+      {%
+        \@armenian at numeralsfalse
+        \SetLanguageKeys{armenian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = armenian,
+    capitalyiwn.choice:,
+    capitalyiwn / true.code =
+      {%
+        \SetLanguageKeys{armenian}{bcp47-casing=hy-x-yiwn,bcp47-extension-x=yiwn}%
+      },
+    capitalyiwn / false.code =
+      {%
+        \SetLanguageKeys{armenian}{bcp47-casing=hy,bcp47-extension-x={}}%
+      },
+    capitalyiwn.default:n = true
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{armenian}{numerals=armenian,variant=western}
+\InitializeGlossOptions{armenian}{numerals=armenian,variant=western}
 
 % Taken from ArmTeX. Audit!
 \def\captionsarmenian{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arq.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arq.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arq.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-arq.ldf}[polyglossia: module for arq (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ary.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ary.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ary.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ary.ldf}[polyglossia: module for ary (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arz.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arz.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-arz.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-arz.ldf}[polyglossia: module for arz (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ast.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ast.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ast.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ast.ldf}[polyglossia: module for ast (Asturian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{asturian}
+\InheritGlossFile{asturian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-asturian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-asturian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-asturian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Translated by Xuacu <xuacusk8 at gmail dot com>
 % Contributed by Kevin Godby <godbyk at gmail dot com>

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-australian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-australian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-australian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-australian.ldf}[polyglossia: module for Australian English]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-austrian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-austrian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-austrian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-austrian.ldf}[polyglossia: module for Austrian German (old spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ayl.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ayl.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ayl.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ayl.ldf}[polyglossia: module for ayl (Arabic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{arabic}
+\InheritGlossFile{arabic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasa.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasa.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasa.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bahasa.ldf}[polyglossia: module for Bahasa Indonesia]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{malay}
+\InheritGlossFile{malay}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasai.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasai.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasai.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bahasai.ldf}[polyglossia: module for Bahasa Indonesia]
 
@@ -5,6 +5,6 @@
 % We only provide this gloss for babel compatibility. Since bahasai is 
 % a malay variety, we use 'malay' with variant 'indonesian' now.
 
-\xpg at load@master at language{malay}
+\InheritGlossFile{malay}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasam.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasam.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bahasam.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bahasam.ldf}[polyglossia: module for Bahasa Melayu]
 
@@ -5,6 +5,6 @@
 % We only provide this gloss for babel compatibility. Since bahasam is 
 % a malay variety, we use 'malay' with variant 'malaysian' now.
 
-\xpg at load@master at language{malay}
+\InheritGlossFile{malay}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-basque.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-basque.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-basque.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-basque.ldf}[polyglossia: module for Basque]
 \PolyglossiaSetup{basque}{

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-be-tarask.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-be-tarask.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-be-tarask.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-be-tarask.ldf}[polyglossia: module for be-tarask (Belarusian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{belarusian}
+\InheritGlossFile{belarusian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-be.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-be.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-be.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-be.ldf}[polyglossia: module for be (Belarusian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{belarusian}
+\InheritGlossFile{belarusian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-belarusian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-belarusian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-belarusian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-belarusian.ldf}[polyglossia: module for Belarusian]
 
@@ -26,63 +26,68 @@
 \setlanguagealias*{belarusian}{be}
 
 \def\belarusian at spelling{modern}
-\define at choicekey*+{belarusian}{spelling}[\xpg at val\xpg at nr]{modern,classic,tarask}[modern]{%
-   \ifcase\xpg at nr\relax
-      % modern:
-      \def\belarusian at spelling{modern}%
-      \SetLanguageKeys{belarusian}{bcp47=be,bcp47-variant=1959acad}%
-   \or
-      % classic:
-      \def\belarusian at spelling{tarask}%
-      \SetLanguageKeys{belarusian}{bcp47=be-tarask,bcp47-variant=tarask}%
-   \or
-      % tarask:
-      \def\belarusian at spelling{tarask}%
-      \SetLanguageKeys{belarusian}{bcp47=be-tarask,bcp47-variant=tarask}%
-   \fi
-}{\xpg at warning{Unknown Belarusian spelling `#1'}}
-
 \newif\ifcyrillic at numerals
 \newif\ifcyrillic at asbuk@numerals
-\define at choicekey*+{belarusian}{numerals}[\xpg at val\xpg at nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % arabic:
-      \cyrillic at numeralsfalse%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic-trad:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic-alph:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralstrue%
-   \fi
-   \xpg at info{Option: Belarusian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Belarusian numerals value `#1'}}
 
-\define at boolkey{belarusian}[belarusian@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/belarusian]
+  {
+    babelshorthands.if = belarusian at babelshorthands,
+    babelshorthands.default:n = true,
+    spelling.choice:,
+    spelling / modern.code =
+      {%
+        \def\belarusian at spelling{modern}%
+        \SetLanguageKeys{belarusian}{bcp47=be,bcp47-variant=1959acad}%
+      },
+    spelling / classic.code =
+      {%
+        \def\belarusian at spelling{tarask}%
+        \SetLanguageKeys{belarusian}{bcp47=be-tarask,bcp47-variant=tarask}%
+      },
+    spelling / tarask.code =
+      {%
+        \def\belarusian at spelling{tarask}%
+        \SetLanguageKeys{belarusian}{bcp47=be-tarask,bcp47-variant=tarask}%
+      },
+    spelling.default:n = modern,
+    spelling/unknown.code = \xpg at warning{Unknown Belarusian spelling `#1'},
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \cyrillic at numeralsfalse
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic-trad.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic-alph.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralstrue
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Belarusian numerals value `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{belarusian}{babelshorthands=false,numerals=arabic,spelling=modern}
+\InitializeGlossOptions{belarusian}{babelshorthands=false,numerals=arabic,spelling=modern}
 % Register alias options
-\xpg at set@alias at values{belarusian}{spelling}{classic}{tarask}
+\SetLanguageAliasValues{belarusian}{spelling}{classic,tarask}
 
 \ifsystem at babelshorthands
-  \setkeys{belarusian}{babelshorthands=true}
+  \SetGlossOptions{belarusian}{babelshorthands=true}
 \else
-  \setkeys{belarusian}{babelshorthands=false}
+  \SetGlossOptions{belarusian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\belarusian at shorthands{%
   \xpg at activate@shorthands%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bengali.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bengali.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bengali.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Translations provided by সাজেদুর রহিম জোয়ারদার <toshazed at gmail.com>
 % TODO implement Bengali calendar
@@ -27,30 +27,36 @@
 
 \newif\ifbengali at devanagari@numerals
 \newif\ifbengali at bengali@numerals
-\define at choicekey*+{bengali}{numerals}[\xpg at val\xpg at nr]{Devanagari,Bengali,Western}[Devanagari]{%
-   \ifcase\xpg at nr\relax
-      % Devanagari:
-      \bengali at bengali@numeralsfalse%
-      \bengali at devanagari@numeralstrue%
-   \or
-      % Bengali:
-      \bengali at bengali@numeralstrue%
-      \bengali at devanagari@numeralsfalse%
-   \or
-      % Western:
-      \bengali at bengali@numeralsfalse%
-      \bengali at devanagari@numeralsfalse%
-   \fi
-   \xpg at info{Option: Bengali, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Bengali numeral `#1'}}
 
 \def\extras at bengali{}
 \def\noextras at bengali{}
 
-\define at boolkey{bengali}[bengali@]{changecounternumbering}[true]{}
+\DeclareKeys[polyglossia/gloss/bengali]
+  {
+    changecounternumbering.if = bengali at changecounternumbering,
+    changecounternumbering.default:n = true,
+    numerals.choice:,
+    numerals / devanagari.code =
+      {%
+        \bengali at bengali@numeralsfalse
+        \bengali at devanagari@numeralstrue
+      },
+    numerals / bengali.code =
+      {%
+        \bengali at bengali@numeralstrue
+        \bengali at devanagari@numeralsfalse
+      },
+    numerals / western.code =
+      {%
+        \bengali at bengali@numeralsfalse
+        \bengali at devanagari@numeralsfalse
+      },
+    numerals.default:n = devanagari,
+    numerals/unknown.code = \xpg at warning{Unknown Bengali numeral `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{bengali}{changecounternumbering=false,numerals=Devanagari}
+\InitializeGlossOptions{bengali}{changecounternumbering=false,numerals=Devanagari}
 
 \def\captionsbengali{%
   \def\refname{তথ্যসূত্রসমূহ}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bg.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bg.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bg.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bg.ldf}[polyglossia: module for bg (Bulgarian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{bulgarian}
+\InheritGlossFile{bulgarian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bn.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bn.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bn.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bn.ldf}[polyglossia: module for bn (Bengali)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{bengali}
+\InheritGlossFile{bengali}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bo.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bo.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bo.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bo.ldf}[polyglossia: module for bo (Tibetan)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{tibetan}
+\InheritGlossFile{tibetan}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bosnian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bosnian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bosnian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bosnian.ldf}[polyglossia: module for Bosnian]
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-br.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-br.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-br.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-br.ldf}[polyglossia: module for br (Breton)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{breton}
+\InheritGlossFile{breton}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-brazil.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-brazil.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-brazil.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-brazil.ldf}[polyglossia: module for Brazilian Portuguese]
 
@@ -6,6 +6,6 @@
 % 'brazil' was selected in accordance with babel.
 % Since brazil is a variety of portuguese, we use 'portuguese' now.
 
-\xpg at load@master at language{portuguese}
+\InheritGlossFile{portuguese}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-breton.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-breton.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-breton.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-breton.ldf}[polyglossia: module for Breton]
 \PolyglossiaSetup{breton}{

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-british.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-british.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-british.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-british.ldf}[polyglossia: module for British English]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bs.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bs.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bs.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bs.ldf}[polyglossia: module for bs (Bosnian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{bosnian}
+\InheritGlossFile{bosnian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bulgarian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bulgarian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-bulgarian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-bulgarian.ldf}[polyglossia: module for Bulgarian]
 \PolyglossiaSetup{bulgarian}{
@@ -61,15 +61,15 @@
    \def\figurename{Фигура}%
    \def\tablename{Таблица}%
    %\def\thepart{}%
-   %\def\partname{}%
+   \def\partname{Част}%
    \def\pagename{Стр.}%
    \def\seename{вж.}%
    \def\alsoname{вж.\ също и}%
    \def\enclname{Приложения}%
    \def\ccname{копия}%
-   %\def\headtoname{}%
-   \def\proofname{Proof}%
-   \def\glossaryname{Glossary}%
+   \def\headtoname{За}%
+   \def\proofname{Доказателство}%
+   \def\glossaryname{Притурка}%
 }
 
 \def\datebulgarian{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ca.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ca.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ca.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ca.ldf}[polyglossia: module for ca (Catalan)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{catalan}
+\InheritGlossFile{catalan}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-canadian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-canadian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-canadian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-canadian.ldf}[polyglossia: module for Canadian English]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-canadien.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-canadien.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-canadien.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-canadien.ldf}[polyglossia: module for Canadian French]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-catalan.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-catalan.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-catalan.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-catalan.ldf}[polyglossia: module for Catalan]
 \PolyglossiaSetup{catalan}{
@@ -16,21 +16,21 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{catalan}{ca}
 
-\define at boolkey{catalan}[catalan@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/catalan]
+  {
+    babelshorthands.if = catalan at babelshorthands,
+    babelshorthands.default:n = true,
+  }
 \ifsystem at babelshorthands
-  \setkeys{catalan}{babelshorthands=true}
+  \SetGlossOptions{catalan}{babelshorthands=true}
 \else
-  \setkeys{catalan}{babelshorthands=false}
+  \SetGlossOptions{catalan}{babelshorthands=false}
 \fi
 
 % Register default options
-\xpg at initialize@gloss at options{catalan}{babelshorthands=false}
+\InitializeGlossOptions{catalan}{babelshorthands=false}
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 %%% adapted from Babel's catalan.ldf
 \newdimen\leftllkern \newdimen\rightllkern \newdimen\raiselldim

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-chinese.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-chinese.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-chinese.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-chinese.ldf}[polyglossia: module for Chinese]
 
@@ -22,51 +22,60 @@
 \setlanguagealias*[variant=simplified]{chinese}{zh-CN}
 \setlanguagealias*[variant=traditional]{chinese}{zh-TW}
 
-\providebool{chinese at traditional}
+\@ifundefined{ifchinese at traditional}%
+  {\newif\ifchinese at traditional}{}
 
+\@ifundefined{ifchinese at numerals}%
+  {\newif\ifchinese at numerals}{}
+
 \def\chinese at variant{chinese}
 
-\newif\ifchinese at numerals
-\define at key{chinese}{numerals}[arabic]{%
-   \ifstrequal{#1}{chinese}%
-      {\chinese at numeralstrue%
-       \SetLanguageKeys{chinese}{bcp47-extension-u=nu-hant}%
-      }{\chinese at numeralsfalse%
-       \SetLanguageKeys{chinese}{bcp47-extension-u=nu-latn}%
-      }%
-}
+\DeclareKeys[polyglossia/gloss/chinese]
+  {
+    variant.choice:,
+    variant / cn.code =
+      {%
+        \chinese at traditionalfalse
+        \SetLanguageKeys{chinese}{language={Chinese Simplified},langtag=ZHS,bcp47=zh-CN,bcp47-language=zh,bcp47-region=CN,bcp47-script=Hans}%
+      },
+    variant / simplified.code =
+      {%
+        \chinese at traditionalfalse
+        \SetLanguageKeys{chinese}{language={Chinese Simplified},langtag=ZHS,bcp47=zh-CN,bcp47-language=zh,bcp47-region=CN,bcp47-script=Hans}%
+      },
+    variant / tw.code =
+      {%
+        \chinese at traditionaltrue
+        \SetLanguageKeys{chinese}{language={Chinese Traditional},langtag=ZHT,bcp47=zh-TW,bcp47-language=zh,bcp47-region=TW,bcp47-script=Hant}%
+      },
+    variant / traditional.code =
+      {%
+        \chinese at traditionaltrue
+        \SetLanguageKeys{chinese}{language={Chinese Traditional},langtag=ZHT,bcp47=zh-TW,bcp47-language=zh,bcp47-region=TW,bcp47-script=Hant}%
+      },
+    variant.default:n = cn,
+    variant/unknown.code = \xpg at warning{Unknown Chinese variant `#1'},
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \chinese at numeralsfalse
+        \SetLanguageKeys{chinese}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / chinese.code =
+      {%
+        \chinese at numeralstrue
+        \SetLanguageKeys{chinese}{bcp47-extension-u=nu-hant}%
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Chinese numerals value `#1'}
+  }
 
-
-\define at choicekey*+{chinese}{variant}[\xpg at val\xpg at nr]{cn,simplified,tw,traditional}[cn]{%
-   \ifcase\xpg at nr\relax
-      % cn:
-      \chinese at traditionalfalse
-      \SetLanguageKeys{chinese}{language={Chinese Simplified},langtag=ZHS,bcp47=zh-CN,bcp47-language=zh,bcp47-region=CN,bcp47-script=Hans}%
-      \xpg at info{Option: Chinese, variant=simplified}%
-   \or
-      % simplified:
-      \chinese at traditionalfalse
-      \SetLanguageKeys{chinese}{language={Chinese Simplified},langtag=ZHS,bcp47=zh-CN,bcp47-language=zh,bcp47-region=CN,bcp47-script=Hans}%
-      \xpg at info{Option: Chinese, variant=simplified}%
-   \or
-      % tw:
-      \chinese at traditionaltrue
-      \SetLanguageKeys{chinese}{language={Chinese Traditional},langtag=ZHT,bcp47=zh-TW,bcp47-language=zh,bcp47-region=TW,bcp47-script=Hant}%
-      \xpg at info{Option: Chinese, variant=traditional}%
-   \or
-      % traditional:
-      \chinese at traditionaltrue
-      \SetLanguageKeys{chinese}{language={Chinese Traditional},langtag=ZHT,bcp47=zh-TW,bcp47-language=zh,bcp47-region=TW,bcp47-script=Hant}%
-      \xpg at info{Option: Chinese, variant=traditional}%
-   \fi
-}{\xpg at warning{Unknown Chinese variant `#1'}}
-
 % Register default options
-\xpg at initialize@gloss at options{chinese}{variant=cn,numerals=arabic}
-%\xpg at initialize@gloss at options{chinese}{variant=tw,numerals=arabic}
+\InitializeGlossOptions{chinese}{variant=cn,numerals=arabic}
+%\InitializeGlossOptions{chinese}{variant=tw,numerals=arabic}
 % Register alias options
-\xpg at set@alias at values{chinese}{variant}{cn}{simplified}
-\xpg at set@alias at values{chinese}{variant}{tw}{traditional}
+\SetLanguageAliasValues{chinese}{variant}{cn,simplified}
+\SetLanguageAliasValues{chinese}{variant}{tw,traditional}
 
 
 \def\chinese at capsformat{%
@@ -118,7 +127,7 @@
     \def\enclname{附件}%
     \def\ccname{抄送}%
     \def\headtoname{收件人}%
-    \def\\glossaryname{詞彙表}%
+    \def\glossaryname{詞彙表}%
 }
 \def\captions at chinese@simplified{%
     \def\contentsname{目录}%
@@ -141,7 +150,7 @@
     \def\enclname{附件}%
     \def\ccname{抄送}%
     \def\headtoname{收件人}%
-    \def\\glossaryname{词汇表}%
+    \def\glossaryname{词汇表}%
 }
 
 \newcount\c at TempJNum%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb-Arab.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb-Arab.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb-Arab.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ckb-Arab.ldf}[polyglossia: module for ckb-Arab (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb-Latn.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb-Latn.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb-Latn.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ckb-Latn.ldf}[polyglossia: module for ckb-Latn (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ckb.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ckb.ldf}[polyglossia: module for ckb (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 \endinput

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-classiclatin.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-classiclatin.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-classiclatin.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -0,0 +1,9 @@
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
+%
+\ProvidesFile{gloss-classiclatin.ldf}[polyglossia: module for classic Latin]
+
+% We provide this as a babel alias
+
+\InheritGlossFile{latin}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-classiclatin.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cop.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cop.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cop.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-cop.ldf}[polyglossia: module for cop (Coptic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{coptic}
+\InheritGlossFile{coptic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-coptic.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-coptic.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-coptic.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-coptic.ldf}[polyglossia: module for Coptic]
 \PolyglossiaSetup{coptic}{

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-croatian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-croatian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-croatian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-croatian.ldf}[polyglossia: module for Croatian]
 \PolyglossiaSetup{croatian}{
@@ -20,40 +20,40 @@
   \RequirePackage{luavlna}
 \fi
 
-\define at boolkey{croatian}[croatian@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/croatian]
+  {
+    babelshorthands.if = croatian at babelshorthands,
+    babelshorthands.default:n = true,
+    disabledigraphs.if = croatian at disabledigraphs,
+    disabledigraphs.default:n = true,
+    splithyphens.if = croatian at splithyphens,
+    splithyphens.default:n = true,
+    localalph.if = croatian at localalph,
+    localalph.default:n = true,
+    disableligatures.choices:nn = { true, false }
+      {%
+        \xpg at warning{The option disableligatures is deprecated.\MessageBreak
+               Please use disabledigraphs instead}%
+        \ifcase\UseName{l_keys_choice_int}\or
+          \croatian at disabledigraphstrue
+        \or
+          \croatian at disabledigraphsfalse
+        \fi
+      },
+    disableligatures.default:n = true,
+  }
 
-\define at boolkey{croatian}[croatian@]{disabledigraphs}[true]{}
-
-% Alias kept for backwards compatibility. Please do not remove
-\define at boolkey{croatian}[croatian@]{disableligatures}[true]{%
-   \xpg at warning{The option disableligatures is deprected.\MessageBreak
-                Please use disabledigraphs instead}%
-   \ifcroatian at disableligatures
-      \croatian at disabledigraphstrue
-   \else
-      \croatian at disabledigraphsfalse
-   \fi
-}
-
-\define at boolkey{croatian}[croatian@]{splithyphens}[true]{}
-
-\define at boolkey{croatian}[croatian@]{localalph}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{croatian}{babelshorthands=false,disabledigraphs=false,
+\InitializeGlossOptions{croatian}{babelshorthands=false,disabledigraphs=false,
                                         splithyphens=true,localalph=true}
 
 \ifsystem at babelshorthands
-  \setkeys{croatian}{babelshorthands=true}
+  \SetGlossOptions{croatian}{babelshorthands=true}
 \else
-  \setkeys{croatian}{babelshorthands=false}
+  \SetGlossOptions{croatian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \let\xpg at hyphen@char-
 \def\croatian@@splhyphen#1{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cy.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cy.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cy.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-cy.ldf}[polyglossia: module for cy (Welsh)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{welsh}
+\InheritGlossFile{welsh}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cz.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cz.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-cz.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-cz.ldf}[polyglossia: module for cz (Czech)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{czech}
+\InheritGlossFile{czech}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-czech.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-czech.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-czech.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-czech.ldf}[polyglossia: module for Czech]
 
@@ -21,26 +21,26 @@
   \RequirePackage{luavlna}
 \fi
 
-\define at boolkey{czech}[czech@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/czech]
+  {
+    babelshorthands.if = czech at babelshorthands,
+    babelshorthands.default:n = true,
+    splithyphens.if = czech at splithyphens,
+    splithyphens.default:n = true,
+    vlna.if = czech at vlna,
+    vlna.default:n = true
+  }
 
-\define at boolkey{czech}[czech@]{splithyphens}[true]{}
-
-\define at boolkey{czech}[czech@]{vlna}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{czech}{babelshorthands=false,splithyphens=true,vlna=true}
+\InitializeGlossOptions{czech}{babelshorthands=false,splithyphens=true,vlna=true}
 
 \ifsystem at babelshorthands
-  \setkeys{czech}{babelshorthands=true}
+  \SetGlossOptions{czech}{babelshorthands=true}
 \else
-  \setkeys{czech}{babelshorthands=false}
+  \SetGlossOptions{czech}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\czech@@splithyphen#1{%
   \def\czech at sh@tmp{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-da.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-da.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-da.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-da.ldf}[polyglossia: module for da (Danish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{danish}
+\InheritGlossFile{danish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-danish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-danish.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-danish.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-danish.ldf}[polyglossia: module for Danish]
 \PolyglossiaSetup{danish}{

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT-1901.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT-1901.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT-1901.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT-1901.ldf}[polyglossia: module for de-AT-1901 (Austrian German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT-1996.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT-1996.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT-1996.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT-1996.ldf}[polyglossia: module for de-AT-1996 (Austrian German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-AT.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT.ldf}[polyglossia: module for de-AT (Austrian German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH-1901.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH-1901.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH-1901.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH-1901.ldf}[polyglossia: module for de-CH-1901 (Swiss German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH-1996.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH-1996.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH-1996.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH-1996.ldf}[polyglossia: module for de-CH-1996 (Swiss German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-CH.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH.ldf}[polyglossia: module for de-CH (Swiss German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE-1901.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE-1901.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE-1901.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE-1901.ldf}[polyglossia: module for de-DE-1901 (Germany's German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE-1996.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE-1996.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE-1996.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE-1996.ldf}[polyglossia: module for de-DE-1996 (Germany's German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-DE.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE.ldf}[polyglossia: module for de-DE (Germany's German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT-1901.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT-1901.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT-1901.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT-1901-Latf.ldf}[polyglossia: module for de-AT-1901-Latf (Austrian German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT-1996.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT-1996.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT-1996.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT-1996-Latf.ldf}[polyglossia: module for de-AT-1996-Latf (Austrian German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-AT.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-AT-Latf.ldf}[polyglossia: module for de-AT-Latf (Austrian German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH-1901.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH-1901.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH-1901.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH-1901-Latf.ldf}[polyglossia: module for de-CH-1901-Latf (Swiss German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH-1996.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH-1996.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH-1996.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH-1996-Latf.ldf}[polyglossia: module for de-CH-1996-Latf (Swiss German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-CH.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-CH-Latf.ldf}[polyglossia: module for de-CH-Latf (Swiss German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE-1901.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE-1901.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE-1901.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE-1901-Latf.ldf}[polyglossia: module for de-DE-1901-Latf (Germany's German, old spelling)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE-1996.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE-1996.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE-1996.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE-1996-Latf.ldf}[polyglossia: module for de-DE-1996-Latf (Germany's German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf-DE.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-DE-Latf.ldf}[polyglossia: module for de-DE-Latf (Germany's German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de-Latf.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de-Latf.ldf}[polyglossia: module for de-Latf (German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-de.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-de.ldf}[polyglossia: module for de (German)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-divehi.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-divehi.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-divehi.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-divehi.ldf}[polyglossia: module for Divehi]
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dsb.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dsb.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dsb.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-dsb.ldf}[polyglossia: module for dsb (Sorbian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dutch.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dutch.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dutch.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-dutch.ldf}[polyglossia: module for Dutch]
 \PolyglossiaSetup{dutch}{
@@ -15,24 +15,24 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{dutch}{nl}
 
-\define at boolkey{dutch}[dutch@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/dutch]
+  {
+    babelshorthands.if = dutch at babelshorthands,
+    babelshorthands.default:n = true,
+    tremahyphenation.if = dutch at tremahyphenation,
+    tremahyphenation.default:n = true
+  }
 
-\define at boolkey{dutch}[dutch@]{tremahyphenation}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{dutch}{babelshorthands=false,tremahyphenation=true}
+\InitializeGlossOptions{dutch}{babelshorthands=false,tremahyphenation=true}
 
 \ifsystem at babelshorthands
-  \setkeys{dutch}{babelshorthands=true}
+  \SetGlossOptions{dutch}{babelshorthands=true}
 \else
-  \setkeys{dutch}{babelshorthands=false}
+  \SetGlossOptions{dutch}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\xpg at trema#1{\allowhyphens\discretionary{-}{#1}{\"{#1}}\allowhyphens}
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dv.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dv.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-dv.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-dv.ldf}[polyglossia: module for dv (Divehi)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{divehi}
+\InheritGlossFile{divehi}
 
 \endinput

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ecclesiasticlatin.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ecclesiasticlatin.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ecclesiasticlatin.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -0,0 +1,9 @@
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
+%
+\ProvidesFile{gloss-ecclesiasticlatin.ldf}[polyglossia: module for ecclesiastic Latin]
+
+% We provide this as a babel alias
+
+\InheritGlossFile{latin}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ecclesiasticlatin.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el-monoton.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el-monoton.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el-monoton.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-el-monoton.ldf}[polyglossia: module for el-monoton (Greek)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{greek}
+\InheritGlossFile{greek}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el-polyton.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el-polyton.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el-polyton.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-el-polyton.ldf}[polyglossia: module for el-polyton (Greek)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{greek}
+\InheritGlossFile{greek}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-el.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-el.ldf}[polyglossia: module for el (Greek)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{greek}
+\InheritGlossFile{greek}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-AU.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-AU.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-AU.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-en-AU.ldf}[polyglossia: module for en-AU (Australian English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-CA.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-CA.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-CA.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
-\ProvidesFile{gloss-en-CA.ldf}[polyglossia: module for en-CA (Canadan English)]
+\ProvidesFile{gloss-en-CA.ldf}[polyglossia: module for en-CA (Canadian English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-GB.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-GB.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-GB.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-en-GB.ldf}[polyglossia: module for en-GB (British English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-NZ.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-NZ.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-NZ.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-en-NZ.ldf}[polyglossia: module for en-NZ (Newzealand English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-US.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-US.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en-US.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-en-US.ldf}[polyglossia: module for en-US (American English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-en.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-en.ldf}[polyglossia: module for en (English)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-english.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-english.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-english.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-english.ldf}[polyglossia: module for English]
 
@@ -30,9 +30,12 @@
 \setlanguagealias[variant=canadian]{english}{canadian}
 \setlanguagealias[variant=newzealand]{english}{newzealand}
 
-\providebool{british at hyphen}
-\providebool{english at ordinalmonthday}
-\providebool{british at dateformat}
+\@ifundefined{ifbritish at hyphen}%
+  {\newif\ifbritish at hyphen}{}
+\@ifundefined{ifenglish at ordinalmonthday}%
+  {\newif\ifenglish at ordinalmonthday}{}
+\@ifundefined{ifbritish at dateformat}%
+  {\newif\ifbritish at dateformat}{}
 
 % US English (\l at english) is default
 % Initialize its settings
@@ -41,17 +44,18 @@
 \english at ordinalmonthdayfalse
 \british at dateformatfalse
 
-% Option ordinalmonthday
-\define at boolkey{english}[english@]{ordinalmonthday}[true]{}
-
-\define at choicekey*+{english}{variant}[\xpg at val\xpg at nr]{uk,british,us,american,usmax,australian,newzealand,canadian}[us]{%
-   \ifcase\xpg at nr\relax
+\DeclareKeys[polyglossia/gloss/english]
+  {
+    ordinalmonthday.if = english at ordinalmonthday,
+    ordinalmonthday.default:n = true,
+    variant.choices:nn = { uk, british, us, american, usmax, australian, newzealand, canadian }
+      {%
+        \ifcase\UseName{l_keys_choice_int}\or
       % uk:
       \british at hyphentrue
       \british at dateformattrue
       \english at ordinalmonthdaytrue
       \SetLanguageKeys{english}{babelname=british,bcp47=en-GB,bcp47-language=en,bcp47-region=GB}%
-      \xpg at info{Option: English, variant=british}%
    \or
       % british:
       \british at hyphentrue
@@ -58,7 +62,6 @@
       \british at dateformattrue
       \english at ordinalmonthdaytrue
       \SetLanguageKeys{english}{babelname=british,bcp47=en-GB,bcp47-language=en,bcp47-region=GB}%
-      \xpg at info{Option: english variant=british}%
    \or
       % us:
       \british at hyphenfalse
@@ -65,7 +68,6 @@
       \british at dateformatfalse
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=american,bcp47=en-US,bcp47-language=en,bcp47-region=US}%
-      \xpg at info{Option: English, variant=american}%
    \or
       % american:
       \british at hyphenfalse
@@ -72,7 +74,6 @@
       \british at dateformatfalse
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=american,bcp47=en-US,bcp47-language=en,bcp47-region=US}%
-      \xpg at info{Option: English, variant=american}%
    \or
       % usmax:
       \british at hyphenfalse
@@ -79,11 +80,10 @@
       \british at dateformatfalse
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=american,bcp47=en-US,bcp47-language=en,bcp47-region=US}%
-      \xpg at info{Option: english variant=american (with additional patterns)}%
-      \xpg at ifdefined{usenglishmax}{}%
+      \IfLanguageDefinedF{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%
+          \adddialect\l at usenglishmax\l at english
          }%
       \def\english at variant{usenglishmax}%
    \or
@@ -94,8 +94,7 @@
       \british at dateformattrue
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=australian,bcp47=en-AU,bcp47-language=en,bcp47-region=AU}%
-      \xpg at info{Option: English, variant=australian}%
-      \adddialect\l at australian\l at english%
+      \adddialect\l at australian\l at english
    \or
       % newzealand:
       % These use the british hyphenation patterns
@@ -104,8 +103,7 @@
       \british at dateformattrue
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=newzealand,bcp47=en-NZ,bcp47-language=en,bcp47-region=NZ}%
-      \xpg at info{Option: English, variant=newzealand}%
-      \adddialect\l at newzealand\l at english%
+      \adddialect\l at newzealand\l at english
    \or
       % canadian:
       % This is currently equivalent to usenglish (as in babel)
@@ -113,45 +111,35 @@
       \british at dateformatfalse
       \english at ordinalmonthdayfalse
       \SetLanguageKeys{english}{babelname=canadian,bcp47=en-CA,bcp47-language=en,bcp47-region=CA}%
-      \xpg at info{Option: English, variant=american}%
-      \adddialect\l at canadian\l at english%
+      \adddialect\l at canadian\l at english
    \fi
    \ifbritish at hyphen
-      \xpg at ifdefined{ukenglish}{}%
+      \IfLanguageDefinedF{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%
+          \adddialect\l at ukenglish\l at english
          }%
       \def\english at variant{ukenglish}%
    \fi
-}{\xpg at warning{Unknown English variant `#1'}}
+      },
+    variant.default:n = us,
+    variant/unknown.code = \xpg at warning{Unknown English variant `#1'},
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{english}{variant=us,ordinalmonthday=false}
+\InitializeGlossOptions{english}{variant=us,ordinalmonthday=false}
 % Register alias options
-\xpg at set@alias at values{english}{variant}{us}{american}
-\xpg at set@alias at values{english}{variant}{uk}{british}
+\SetLanguageAliasValues{english}{variant}{us,american}
+\SetLanguageAliasValues{english}{variant}{uk,british}
 
 \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}{}{}
-   }%
+   % (specific order as in the csv list), or null language if everything fails
+   \TryPatternWithFallback{english}{british, american, usenglishmax, australian, newzealand}
 \fi
 
 \def\english at language{%
-   \polyglossia at setup@language at patterns{\english at variant}%
+   \SetupPolyglossiaLangPatterns{\english at variant}%
 }%
 
 \def\captionsenglish{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-eo.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-eo.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-eo.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-eo.ldf}[polyglossia: module for eo (Esperanto)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{esperanto}
+\InheritGlossFile{esperanto}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es-ES.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es-ES.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es-ES.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-es-ES.ldf}[polyglossia: module for es-ES (Spain's Spanish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{spanish}
+\InheritGlossFile{spanish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es-MX.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es-MX.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es-MX.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-es-MX.ldf}[polyglossia: module for es-MX (Mexican Spanish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{spanish}
+\InheritGlossFile{spanish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-es.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-es.ldf}[polyglossia: module for es (Spanish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{spanish}
+\InheritGlossFile{spanish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-esperanto.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-esperanto.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-esperanto.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-esperanto.ldf}[polyglossia: module for Esperanto]
 \PolyglossiaSetup{esperanto}{
@@ -29,10 +29,10 @@
    \def\figurename{Figuro}%
    \def\tablename{Tabelo}%
    %\def\thepart{}%
-   %\def\partname{}%
+   \def\partname{Parto}%
    \def\pagename{Paĝo}%
    \def\seename{vidu}%
-   \def\alsoname{Parto}%
+   \def\alsoname{vidu ankaŭ}%
    \def\enclname{Aldono(j)}%
    \def\ccname{Kopie al}%
    \def\headtoname{Al}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-estonian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-estonian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-estonian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-estonian.ldf}[polyglossia: module for Estonian]
 \PolyglossiaSetup{estonian}{
@@ -38,7 +38,7 @@
    \def\ccname{Koopia(d)}%
    %\def\headtoname{}%
    \def\proofname{Korrektuur}%
-   \def\glossaryname{Glossary}% <-- need translation
+   \def\glossaryname{Sõnastik}%
    }
 \def\dateestonian{%
    \def\today{\number\day.\space\ifcase\month\or

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-et.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-et.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-et.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-et.ldf}[polyglossia: module for et (Estonian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{estonian}
+\InheritGlossFile{estonian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-eu.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-eu.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-eu.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-eu.ldf}[polyglossia: module for eu (Basque)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{basque}
+\InheritGlossFile{basque}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fa.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fa.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fa.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fa.ldf}[polyglossia: module for fa (Persian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{persian}
+\InheritGlossFile{persian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-farsi.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-farsi.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-farsi.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-farsi.ldf}[polyglossia: module for Farsi]
 
@@ -5,6 +5,6 @@
 % We only provide this gloss for babel compatibility.
 % The proper English language name is Persian.
 
-\xpg at load@master at language{persian}
+\InheritGlossFile{persian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fi.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fi.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fi.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fi.ldf}[polyglossia: module for fi (Finnish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{finnish}
+\InheritGlossFile{finnish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-finnish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-finnish.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-finnish.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-finnish.ldf}[polyglossia: module for Finnish]
 \PolyglossiaSetup{finnish}{
@@ -16,51 +16,54 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{finnish}{fi}
 
-\define at boolkey{finnish}[finnish@]{babelshorthands}[true]{}
-
 \newif\if at finnish@schoolhyphens
 \newif\if at finnish@babelhyphens
-\define at choicekey*+{finnish}{hyphens}[\xpg at val\xpg at nr]{default,school,babel}[default]{%
-   \ifcase\xpg at nr\relax
-      % default:
-      \@finnish at schoolhyphensfalse
-      \@finnish at babelhyphensfalse
-   \or
-      % school:
-      \@finnish at schoolhyphenstrue
-      \@finnish at babelhyphensfalse
-   \or
-      % babel:
-      \@finnish at schoolhyphensfalse
-      \@finnish at babelhyphenstrue
-   \fi
-   \xpg at info{Option: Finnish, hyphens=\xpg at val}%
-}{\xpg at warning{Unknown Finnish hyphens `#1'}}
 
-% backwards compatibility
-\define at boolkey{finnish}[finnish@]{schoolhyphens}[true]{%
-  \iffinnish at schoolhyphens
-      \@finnish at schoolhyphenstrue
-      \@finnish at babelhyphensfalse
-  \else
-      \@finnish at schoolhyphensfalse
-  \fi
-}
+\DeclareKeys[polyglossia/gloss/finnish]
+  {
+    babelshorthands.if = finnish at babelshorthands,
+    babelshorthands.default:n = true,
+    hyphens.choice:,
+    hyphens / default.code =
+      {%
+        \@finnish at schoolhyphensfalse
+        \@finnish at babelhyphensfalse
+      },
+    hyphens / school.code =
+      {%
+        \@finnish at schoolhyphenstrue
+        \@finnish at babelhyphensfalse
+      },
+    hyphens / babel.code =
+      {%
+        \@finnish at schoolhyphensfalse
+        \@finnish at babelhyphenstrue
+      },
+    hyphens.default:n = default,
+    hyphens/unknown.code = \xpg at warning{Unknown Finnish hyphens `#1'},
+    schoolhyphens.choice:,
+    schoolhyphens / true.code =
+      {%
+        \@finnish at schoolhyphenstrue
+        \@finnish at babelhyphensfalse
+      },
+    schoolhyphens / false.code =
+      {%
+        \@finnish at schoolhyphensfalse
+      },
+    schoolhyphens.default:n = true
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{finnish}{babelshorthands=false,hyphens=default}
+\InitializeGlossOptions{finnish}{babelshorthands=false,hyphens=default}
 
 \ifsystem at babelshorthands
-  \setkeys{finnish}{babelshorthands=true}
+  \SetGlossOptions{finnish}{babelshorthands=true}
 \else
-  \setkeys{finnish}{babelshorthands=false}
+  \SetGlossOptions{finnish}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-    \input{babelsh.def}%
-    \initiate at active@char{"}%
-    \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\finnish at shorthands{%
   \xpg at activate@shorthands%
@@ -105,15 +108,15 @@
 
 \def\finnish at language{%
   \if at finnish@schoolhyphens
-      \xpg at ifdefined{schoolfinnish}{%
-         \polyglossia at setup@language at patterns{schoolfinnish}%
+      \IfLanguageDefinedTF{schoolfinnish}{%
+         \SetupPolyglossiaLangPatterns{schoolfinnish}%
       }{%
            \xpg at warning{Finnish 'School' hyphenation patterns (schoolfinnish) not available.\MessageBreak
 	                I will use the standard patterns for Finnish instead}%
-	   \polyglossia at setup@language at patterns{finnish}%
+	   \SetupPolyglossiaLangPatterns{finnish}%
      }%
   \else
-      \polyglossia at setup@language at patterns{finnish}%
+      \SetupPolyglossiaLangPatterns{finnish}%
   \fi
 }
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CA-u-sd-canb.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CA-u-sd-canb.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CA-u-sd-canb.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fr-CA-u-sd-canb.ldf}[polyglossia: module for fr-CA-u-sd-canb (Canadian French, Acadian subvariety)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CA.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CA.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CA.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fr-CA.ldf}[polyglossia: module for fr-CA (Canadian French)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CH.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CH.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-CH.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fr-CH.ldf}[polyglossia: module for fr-CH (Swiss French)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-FR.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-FR.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr-FR.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fr-FR.ldf}[polyglossia: module for fr-FR (France's French)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fr.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fr.ldf}[polyglossia: module for fr (French)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{french}
+\InheritGlossFile{french}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-french.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-french.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-french.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-french.ldf}[polyglossia: module for French]
 
@@ -28,43 +28,9 @@
 \setlanguagealias[variant=canadian]{french}{canadien}
 
 \def\french at variant{french}
-\define at choicekey*+{french}{variant}[\xpg at val\xpg at nr]{french,canadian,acadian,swiss}[french]{%
-   \ifcase\xpg at nr\relax
-      % french:
-      \def\french at variant{french}%
-      \SetLanguageKeys{french}{babelname=french,bcp47=fr-FR,bcp47-language=fr,bcp47-region=FR}%
-      \french at thincolonspacefalse
-   \or
-      % canadian:
-      \def\french at variant{canadien}%
-      \SetLanguageKeys{french}{babelname=canadien,bcp47=fr-CA,bcp47-language=fr,bcp47-region=CA,bcp47-extension-u=sd-caqc}%
-      \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}%
-      \french at thincolonspacefalse
-   \or
-      % acadian:
-      \def\french at variant{acadian}%
-      \SetLanguageKeys{french}{babelname=acadian,bcp47=fr-CA-u-sd-canb,bcp47-language=fr,bcp47-region=CA,bcp47-extension-u=sd-canb}%
-      \xpg at ifdefined{acadian}{}%
-      {\xpg at warning{No hyphenation patterns were loaded for "French (Canada, Acadian)"\MessageBreak
-        I will use the standard patterns for French instead}%
-      \adddialect\l at acadian\l at french\relax}%
-      \french at thincolonspacefalse
-   \or
-      % swiss:
-      \def\french at variant{swissfrench}%
-      \SetLanguageKeys{french}{babelname=french,bcp47=fr-CH,bcp47-language=fr,bcp47-region=CH}%
-      \adddialect\l at swissfrench\l at french\relax%
-      \french at thincolonspacetrue
-   \fi
-   \xpg at info{Option: French, variant=\xpg at val}%
-}{\xpg at warning{Unknown French variant `#1'}}
 
-
 \def\french at language{%
-   \polyglossia at setup@language at patterns{\french at variant}%
+   \SetupPolyglossiaLangPatterns{\french at variant}%
 }%
 
 \ifluatex
@@ -84,52 +50,14 @@
 % Save original footnote definition
 % Do this at the end of the preamble to catch other
 % packages' footnote changes (#391)
-\AtEndPreamble{%
+\AddToHook{begindocument/before}{%
   \let\xpg at orig@makefntext\@makefntext
 }
 
-\define at boolkey{french}[french@]{frenchfootnote}[true]{}
-
-\define at boolkey{french}[french@]{autospacing}[true]{}
-\french at autospacingtrue
-
-\define at boolkey{french}[french@]{frenchpart}[true]{}
-\french at frenchparttrue
-
-\newif\iffrench at autospaceguillemets
-\define at boolkey{french}[french@]{autospaceguillemets}[true]{}
-\french at autospaceguillemetstrue
-
-\newif\iffrench at thincolonspace
-\define at boolkey{french}[french@]{thincolonspace}[true]{}
-\french at thincolonspacefalse
-
-% Backwards compatibility
-\define at boolkey{french}[french@]{automaticspacesaroundguillemets}[true]{%
-   \iffrench at automaticspacesaroundguillemets
-       \setkeys{french}{autospaceguillemets=true}%
-   \else
-       \setkeys{french}{autospaceguillemets=false}%
-   \fi
-}
-
 % 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
-}
-
 % Configuration of item labels
 \def\french at itemi{\textemdash}
 \def\french at itemii{\textemdash}
@@ -136,39 +64,89 @@
 \def\french at itemiii{\textemdash}
 \def\french at itemiv{\textemdash}
 
-\define at key{french}{itemlabels}[\textemdash]{%
-  \def\french at itemi{#1}
-  \def\french at itemii{#1}
-  \def\french at itemiii{#1}
-  \def\french at itemiv{#1}
-}
+\newif\iffrench at autospacetypewriter
+\french at autospacetypewriterfalse
+\newif\iffrench at autospacing
+\french at autospacingtrue
+\newif\iffrench at frenchpart
+\french at frenchparttrue
+\newif\iffrench at autospaceguillemets
+\french at autospaceguillemetstrue
 
-\define at key{french}{itemlabeli}[\textemdash]{%
-  \def\french at itemi{#1}
-}
+\DeclareKeys[polyglossia/gloss/french]
+  {
+    variant.choice:,
+    variant / french.code = 
+      {%
+        \def\french at variant{french}%
+        \SetLanguageKeys{french}{babelname=french,bcp47=fr-FR,bcp47-language=fr,bcp47-region=FR}%
+        \french at thincolonspacefalse
+      },
+    variant / canadian.code = 
+      {%
+          \def\french at variant{canadien}%
+          \SetLanguageKeys{french}{babelname=canadien,bcp47=fr-CA,bcp47-language=fr,bcp47-region=CA,bcp47-extension-u=sd-caqc}%
+          \IfLanguageDefinedF{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}%
+          \french at thincolonspacefalse
+      },
+    variant / acadian.code =
+      {%
+          \def\french at variant{acadian}%
+          \SetLanguageKeys{french}{babelname=acadian,bcp47=fr-CA-u-sd-canb,bcp47-language=fr,bcp47-region=CA,bcp47-extension-u=sd-canb}%
+          \IfLanguageDefinedF{acadian}%
+            {\xpg at warning{No hyphenation patterns were loaded for "French (Canada, Acadian)"\MessageBreak
+              I will use the standard patterns for French instead}%
+             \adddialect\l at acadian\l at french\relax}%
+          \french at thincolonspacefalse
+      },
+    variant / swiss.code =
+      {%
+          \def\french at variant{swissfrench}%
+          \SetLanguageKeys{french}{babelname=french,bcp47=fr-CH,bcp47-language=fr,bcp47-region=CH}%
+          \adddialect\l at swissfrench\l at french\relax%
+          \french at thincolonspacetrue
+      },
+    variant.default:n = french,
+    variant/unknown.code = \xpg at warning{Unknown French variant `#1'},
+    frenchfootnote.if = french at frenchfootnote,
+    frenchfootnote.default:n = true,
+    autospacing.if = french at autospacing,
+    autospacing.default:n = true,
+    frenchpart.if = french at frenchpart,
+    frenchpart.default:n = true,
+    autospaceguillemets.if = french at autospaceguillemets,
+    autospaceguillemets.default:n = true,
+    thincolonspace.if = french at thincolonspace,
+    thincolonspace.default:n = true,
+    automaticspacesaroundguillemets.meta:n = {autospaceguillemets=#1},
+    autospacetypewriter.if = french at autospacetypewriter,
+    autospacetypewriter.default:n = true,
+    originaltypewriter.meta:n = {autospacetypewriter=#1},
+    itemlabeli.store = \french at itemi,
+    itemlabelii.store = \french at itemii,
+    itemlabeliii.store = \french at itemiii,
+    itemlabeliv.store = \french at itemiv,
+    frenchitemlabels.if = french at frenchitemlabels,
+    frenchitemlabels.default:n = true,
+    itemlabels.code = 
+      \def\french at itemi{#1}%
+      \def\french at itemii{#1}%
+      \def\french at itemiii{#1}%
+      \def\french at itemiv{#1},
+    itemlabels.default:n = \textemdash
+  }
 
-\define at key{french}{itemlabelii}[\textemdash]{%
-  \def\french at itemii{#1}
-}
-
-\define at key{french}{itemlabeliii}[\textemdash]{%
-  \def\french at itemiii{#1}
-}
-
-\define at key{french}{itemlabeliv}[\textemdash]{%
-  \def\french at itemiv{#1}
-}
-
-\define at boolkey{french}[french@]{frenchitemlabels}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{french}{variant=french,autospacing=true,thincolonspace=false,
+\InitializeGlossOptions{french}{variant=french,autospacing=true,thincolonspace=false,
                                       autospaceguillemets=true,autospacetypewriter=false,
                                       frenchfootnote=false,frenchitemlabels=false,
                                       itemlabels=\textemdash,itemlabeli=\textemdash,itemlabelii=\textemdash,
                                       itemlabeliii=\textemdash,itemlabeliv=\textemdash}
 % Register alias options
-\xpg at set@alias at values{french}{variant}{canadian}{acadian}
+\SetLanguageAliasValues{french}{variant}{canadian,acadian}
 
 
 \def\french at fontsetup{%
@@ -339,100 +317,100 @@
 \def\french at capsformat{%
    % Change part heading
    % With titlesec
-   \ifcsdef{titleformat}{%
-     \ifcsdef{NR at part}{% Hyperref (nameref)
-        \let\xpg at save@part at format\NR at part%
-        \patchcmd{\NR at part}%
-                  {\partname\nobreakspace\thepart}%
-                  {\xpg at french@part\nobreakspace\partname}%
-                  {}%
-                  {\xpg at warning{Failed to patch part for French}}%
-     }{% not hyperref
-       \ifcsdef{@part}{%
-          \let\xpg at save@part at format\@part%
-          \patchcmd{\@part}%
+   \@ifundefined{titleformat}{%
+     % With KOMA
+     \@ifundefined{sectionformat}{%
+       % With memoir
+       \@ifundefined{@memptsize}{%  (not \ifdefined\@memptsize)
+         % With standard classes
+         \@ifundefined{NR at part}{% not hyperref
+            \@ifundefined{@part}{}{%
+              \let\xpg at save@part at format\@part%
+              \patchcmd{\@part}%
+                       {\partname\nobreakspace\thepart}%
+                       {\xpg at french@part\nobreakspace\partname}%
+                       {}%
+                       {\@ifundefined{part}{}{\xpg at warning{Failed to patch part for French}}}%
+            }%  (end \ifdefined \@part)
+         }{% Hyperref
+           \let\xpg at save@part at format\NR at part%
+           \patchcmd{\NR at part}%
                     {\partname\nobreakspace\thepart}%
                     {\xpg at french@part\nobreakspace\partname}%
                     {}%
                     {\xpg at warning{Failed to patch part for French}}%
-       }{}%
-     }%
-   }{% (not \ifdefined\titleformat)
-     % With KOMA
-     \ifcsdef{sectionformat}{%
-        \ifcsdef{partformat}{%
-          \let\xpg at save@part at format\partformat%
-          \renewcommand{\partformat}{\xpg at french@part~\partname}%
-        }{}%
-     }{%  (not \ifdefined\sectionformat)
-       % With memoir
-       \ifcsdef{@memptsize}{%
-         \ifcsdef{NR at part}{% Hyperref (nameref)
+         }%  (end \ifdefined\NR at part)
+       }{%
+         \@ifundefined{NR at part}{% not hyperref
+            \@ifundefined{@part}{}{%
+              \let\xpg at save@part at format\@part%
+              \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
+                               {\partnamefont\xpg at french@part\partnamenum\printpartname}%
+                               {}%
+                               {\xpg at warning{Failed to patch part for French}}%
+             }%
+          }{% Hyperref (nameref)
            \let\xpg at save@part at format\NR at part%
            \patchcmd{\NR at part}{\printpartname \partnamenum \printpartnum}%
                             {\partnamefont\xpg at french@part\partnamenum\printpartname}%
                             {}%
                             {\xpg at warning{Failed to patch part for French}}%
-          }{% not hyperref
-            \ifcsdef{@part}{%
-              \let\xpg at save@part at format\@part%
-              \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
-                               {\partnamefont\xpg at french@part\partnamenum\printpartname}%
-                               {}%
-                               {\xpg at warning{Failed to patch part for French}}%
-             }{}%
           }%
-       }{%  (not \ifdefined\@memptsize)
-         % With standard classes
-         \ifcsdef{NR at part}{% Hyperref
-           \let\xpg at save@part at format\NR at part%
-           \patchcmd{\NR at part}%
+       }% (end \ifdefined\@memptsize)
+     }{%  (\ifdefined\sectionformat)
+        \@ifundefined{partformat}{}{%
+          \let\xpg at save@part at format\partformat%
+          \renewcommand{\partformat}{\xpg at french@part~\partname}%
+        }%
+     }% (end \ifdefined\sectionformat)
+   }{%  (\ifdefined\titleformat)
+     \@ifundefined{NR at part}{% not hyperref
+       \@ifundefined{@part}{}{%
+          \let\xpg at save@part at format\@part%
+          \patchcmd{\@part}%
                     {\partname\nobreakspace\thepart}%
                     {\xpg at french@part\nobreakspace\partname}%
                     {}%
                     {\xpg at warning{Failed to patch part for French}}%
-         }{% not hyperref
-            \ifcsdef{@part}{%
-              \let\xpg at save@part at format\@part%
-              \patchcmd{\@part}%
-                       {\partname\nobreakspace\thepart}%
-                       {\xpg at french@part\nobreakspace\partname}%
-                       {}%
-                       {\ifcsdef{part}{\xpg at warning{Failed to patch part for French}}{}}%
-            }{}%  (end \ifdefined \NR at part)
-         }%  (end \ifdefined\@part)
-       }% (end \ifdefined\@memptsize)
-     }% (end \ifdefined\sectionformat)
+       }%
+     }{% Hyperref (nameref)
+        \let\xpg at save@part at format\NR at part%
+        \patchcmd{\NR at part}%
+                  {\partname\nobreakspace\thepart}%
+                  {\xpg at french@part\nobreakspace\partname}%
+                  {}%
+                  {\xpg at warning{Failed to patch part for French}}%
+     }%
    }% (end \ifdefined\titleformat)
 }
 
 \def\nofrench at capsformat{%
    % Reset chapter and part heading
-   \ifcsdef{titleformat}{%
-      % With titlesec
-     \ifcsdef{xpg at save@part at format}{%
-        \ifcsdef{NR at part}{%
-            \let\NR at part\xpg at save@part at format%
-        }{%
-            \let\@part\xpg at save@part at format%
+   \@ifundefined{titleformat}{%
+     \@ifundefined{sectionformat}{%
+        % With memoir and standard classes
+        \@ifundefined{xpg at save@part at format}{}{%
+           \@ifundefined{NR at part}{%
+              \let\@part\xpg at save@part at format%
+           }{%
+              \let\NR at part\xpg at save@part at format%
+           }%
         }%
-     }{}%
-   }{% (not \ifdefined\titleformat)
-     \ifcsdef{sectionformat}{%
+     }{%
         % With KOMA
-        \ifcsdef{xpg at save@part at format}{%
+        \@ifundefined{xpg at save@part at format}{}{%
            \let\partformat\xpg at save@part at format
-        }{}%
-     }{%
-        % With memoir and standard classes
-        \ifcsdef{xpg at save@part at format}{%
-           \ifcsdef{NR at part}{%
-              \let\NR at part\xpg at save@part at format%
-           }{%
-              \let\@part\xpg at save@part at format%
-           }%
-        }{}%
+        }%
      }% (end \ifdefined\sectionformat)
+   }{% (\ifdefined\titleformat)
+      % With titlesec
+     \@ifundefined{xpg at save@part at format}{}{%
+        \@ifundefined{NR at part}{%
+            \let\@part\xpg at save@part at format%
+        }{%
+            \let\NR at part\xpg at save@part at format%
+        }%
+     }%
    }% (end \ifdefined\titleformat)
 }
 
@@ -443,7 +421,7 @@
   \if at xpg@french at footnote@set%
   \else%
    \iffrench at frenchfootnote%
-      \ifdefstring{\xpg at main@language}{french}{%
+      \IfMainLanguageTF{french}{%
          \ifx\@makefntext\undefined\else%
              \long\def\french at makefntext##1{%
                 \parindent1em \noindent\quad%
@@ -467,7 +445,7 @@
   \if at xpg@french at itemlabels@set%
   \else%
      \iffrench at frenchitemlabels
-      \ifdefstring{\xpg at main@language}{french}{%
+      \IfMainLanguageTF{french}{%
          \renewcommand{\labelitemi}{\french at itemi}%
          \renewcommand{\labelitemii}{\french at itemii}%
          \renewcommand{\labelitemiii}{\french at itemiii}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulan.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulan.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulan.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,10 +1,10 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-friulan.ldf}[polyglossia: module for Friulian]
 
 % We only provide this gloss for babel compatibility.
 
-\xpg at load@master at language{friulian}
+\InheritGlossFile{friulian}
 
 \endinput
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-friulian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-friulian.ldf}[polyglossia: module for Friulian]
 
@@ -52,7 +52,7 @@
       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
+\AddToHook{begindocument/before}{% the user or the class might define different values
   \edef\xpgfu at savedvalues{%
     \clubpenalty=\the\clubpenalty\space
     \@clubpenalty=\the\@clubpenalty\space

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fur.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fur.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-fur.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-fur.ldf}[polyglossia: module for fur (Friulian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{friulian}
+\InheritGlossFile{friulian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ga.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ga.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ga.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ga.ldf}[polyglossia: module for ga (Gaelic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{gaelic}
+\InheritGlossFile{gaelic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gaelic.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gaelic.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gaelic.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-gaelic.ldf}[polyglossia: module for Gaelic]
 
@@ -22,23 +22,28 @@
 \setlanguagealias[variant=scottish]{gaelic}{scottish}
 
 \def\gaelic at variant{irish}
-\define at choicekey*+{gaelic}{variant}[\xpg at val\xpg at nr]{irish,scottish}[irish]{%
-   \ifcase\xpg at nr\relax
-      % irish:
-      \gdef\gaelic at variant{irish}%
-      \SetLanguageKeys{gaelic}{language=Irish,langtag=IRI,babelname=irish,bcp47=ga,bcp47-language=ga}%
-      \xpg at fontsetup@latin{gaelic}%
-   \or
-      % scottish:
-      \gdef\gaelic at variant{scottish}%
-      \SetLanguageKeys{gaelic}{language=Gaelic,langtag=GAE,babelname=scottish,bcp47=gd,bcp47-language=gd}%
-      \xpg at fontsetup@latin{gaelic}%
-   \fi
-   \xpg at info{Option: gaelic, variant=\xpg at val}%
-}{\xpg at warning{Unknown gaelic variant `#1'}}
 
+\DeclareKeys[polyglossia/gloss/gaelic]
+  {
+    variant.choice:,
+    variant / irish.code = 
+      {%
+        \gdef\gaelic at variant{irish}%
+        \SetLanguageKeys{gaelic}{language=Irish,langtag=IRI,babelname=irish,bcp47=ga,bcp47-language=ga}%
+        \SetupLatinPolyglossiaFont{gaelic}%
+      },
+    variant / scottish.code =
+      {%
+        \gdef\gaelic at variant{scottish}%
+        \SetLanguageKeys{gaelic}{language=Gaelic,langtag=GAE,babelname=scottish,bcp47=gd,bcp47-language=gd}%
+        \SetupLatinPolyglossiaFont{gaelic}%
+      },
+    variant.default:n = irish,
+    variant/unknown.code = \xpg at warning{Unknown gaelic variant `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{gaelic}{variant=irish}
+\InitializeGlossOptions{gaelic}{variant=irish}
 
 \def\captionsgaelic at irish{%
    \def\refname{Tagairtí}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-galician.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-galician.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-galician.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-galician.ldf}[polyglossia: module for Galician]
 \PolyglossiaSetup{galician}{

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gd.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gd.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gd.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-gd.ldf}[polyglossia: module for gd (Gaelic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{gaelic}
+\InheritGlossFile{gaelic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-georgian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-georgian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-georgian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-georgian.ldf}[polyglossia: module for Georgian]
 
@@ -18,34 +18,37 @@
 \setlanguagealias*{georgian}{ka}
 
 \newif\ifgeorgian at numerals
-\define at key{georgian}{numerals}[arabic]{%
-   \ifstrequal{#1}{georgian}%
-      {\georgian at numeralstrue%
-       \SetLanguageKeys{georgian}{bcp47-extension-u=nu-geor}%
-      }%
-      {\georgian at numeralsfalse%
-       \SetLanguageKeys{georgian}{bcp47-extension-u=nu-latn}%
-      }%
-}
 
-\define at boolkey{georgian}[georgian@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/georgian]
+  {
+    babelshorthands.if = georgian at babelshorthands,
+    babelshorthands.default:n = true,
+    oldmonthnames.if = georgian at oldmonthnames,
+    oldmonthnames.default:n = true,
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \georgian at numeralsfalse
+        \SetLanguageKeys{georgian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / georgian.code =
+      {%
+        \georgian at numeralstrue
+        \SetLanguageKeys{georgian}{bcp47-extension-u=nu-geor}%
+      },
+    numerals.default:n = arabic
+  }
 
-\define at boolkey{georgian}[georgian@]{oldmonthnames}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{georgian}{babelshorthands=false,oldmonthnames=false,numerals=arabic}
+\InitializeGlossOptions{georgian}{babelshorthands=false,oldmonthnames=false,numerals=arabic}
 
 \ifsystem at babelshorthands
-  \setkeys{georgian}{babelshorthands=true}
+  \SetGlossOptions{georgian}{babelshorthands=true}
 \else
-  \setkeys{georgian}{babelshorthands=false}
+  \SetGlossOptions{georgian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\georgian at shorthands{%
   \xpg at activate@shorthands%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-german.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-german.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-german.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-german.ldf}[polyglossia: module for German]
 
@@ -47,51 +47,11 @@
 
 \newif\if at german@oldspelling
 \@german at oldspellingfalse
-\define at choicekey*+{german}{spelling}[\xpg at val\xpg at nr]{new,old,1901,1996}[new]{%
-   \ifcase\xpg at nr\relax
-      % new:
-      \@german at oldspellingfalse
-   \or
-      % old:
-      \@german at oldspellingtrue
-   \or
-      % 1901:
-      \@german at oldspellingtrue
-   \or
-      % 1996:
-      \@german at oldspellingfalse
-   \fi
-   \german at set@babelname%
-   \xpg at info{Option: German, spelling=\xpg at val}%
-}{\xpg at warning{Unknown German spelling `#1'}}
 
 \newif\if at austrian@locale
 \@austrian at localefalse
 \newif\if at swiss@locale
 \@swiss at localefalse
-\define at choicekey*+{german}{variant}[\xpg at val\xpg at nr]{german,austrian,swiss}[german]{%
-   \ifcase\xpg at 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=\xpg at val}%
-}{\xpg at warning{Unknown German variant `#1'}}
 
 \def\german at set@babelname{%
   \if at german@oldspelling
@@ -140,58 +100,110 @@
 }
 
 \newif\if at german@blackletter
-\define at choicekey*+{german}{script}[\xpg at val\xpg at nr]{latin,blackletter,fraktur}[latin]{%
-   \ifcase\xpg at nr\relax
-      % latin:
-      \@german at blackletterfalse%
-   \or
-      % blackletter:
-      \@german at blacklettertrue%
-   \or
-      % fraktur:
-      \@german at blacklettertrue%
-   \fi
-   \german at set@babelname%
-   \xpg at info{Option: German, script=\xpg at val}%
-}{\xpg at warning{Unknown German script `#1'}}
 
-\define at boolkey{german}[german@]{capitaleszett}[true]{%
-  \ifgerman at capitaleszett
-     % MakeUppercase capitalizes the eszett (U+00DF) with U+1E9E
-     \SetLanguageKeys{german}{bcp47-casing=de-x-eszett,bcp47-extension-x=eszett}
-  \else
-     % Capitalize eszett as <SS>
-     \SetLanguageKeys{german}{bcp47-casing=de,bcp47-extension-x={}}
-  \fi
-}
+\DeclareKeys[polyglossia/gloss/german]
+  {
+    babelshorthands.if = german at babelshorthands,
+    babelshorthands.default:n = true,
+    latesthyphen.if = german at latesthyphen,
+    latesthyphen.default:n = true,
+    capitaleszett.choice:,
+    capitaleszett / true.code = 
+      {% MakeUppercase capitalizes the eszett (U+00DF) with U+1E9E
+        \SetLanguageKeys{german}{bcp47-casing=de-x-eszett,bcp47-extension-x=eszett}%
+      },
+    capitaleszett / false.code =
+      {% Capitalize eszett as <SS>
+        \SetLanguageKeys{german}{bcp47-casing=de,bcp47-extension-x={}}%
+      },
+    capitaleszett.default:n = true,
+    script.choice:,
+    script / latin.code =
+      {%
+        \@german at blackletterfalse
+        \german at set@babelname
+      },
+    script / blackletter.code =
+      {%
+        \@german at blacklettertrue
+        \german at set@babelname
+      },
+    script / fraktur.code =
+      {%
+        \@german at blacklettertrue
+        \german at set@babelname
+      },
+    script.default:n = latin,
+    script/unknown.code = \xpg at warning{Unknown German script `#1'},
+    spelling.choice:,
+    spelling / new.code =
+      {%
+        \@german at oldspellingfalse
+        \german at set@babelname
+      },
+    spelling / old.code =
+      {%
+        \@german at oldspellingtrue
+        \german at set@babelname
+      },
+    spelling / 1901.code =
+      {%
+        \@german at oldspellingtrue
+        \german at set@babelname
+      },
+    spelling / 1996.code =
+      {%
+        \@german at oldspellingfalse
+        \german at set@babelname
+      },
+    spelling.default:n = new,
+    spelling/unknown.code = \xpg at warning{Unknown German spelling `#1'},
+    variant.choice:,
+    variant / german.code =
+      {%
+        \@swiss at localefalse
+        \@austrian at localefalse
+        \german at set@babelname
+      },
+    variant / austrian.code =
+      {%
+        \@austrian at localetrue
+        \@swiss at localefalse
+        \german at set@babelname
+      },
+    variant / swiss.code =
+      {%
+        \@swiss at localetrue
+        \@austrian at localefalse
+        \IfLanguageDefinedF{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
+           }%
+        \german at set@babelname
+      },
+    variant.default:n = german,
+    variant/unknown.code = \xpg at warning{Unknown German variant `#1'}
+  }
+  
 
+\SetGlossOptions{german}{spelling,script,variant}
 
-% Option defunc'ed, as both XeTeX and LuaTeX meanwhile
-% use the experimental German hyphenation patterns by default.
-\define at boolkey{german}[german@]{latesthyphen}[true]{}
-
-\define at boolkey{german}[german@]{babelshorthands}[true]{}
-
-\setkeys{german}{spelling,script,variant}
-
 % Register default options
-\xpg at initialize@gloss at options{german}{variant=german,spelling=new,script=latin,babelshorthands=false}
+\InitializeGlossOptions{german}{variant=german,spelling=new,script=latin,babelshorthands=false}
 % Register alias options
-\xpg at set@alias at values{german}{spelling}{new}{1996}
-\xpg at set@alias at values{german}{spelling}{old}{1901}
-\xpg at set@alias at values{german}{script}{blackletter}{fraktur}
+\SetLanguageAliasValues{german}{spelling}{new,1996}
+\SetLanguageAliasValues{german}{spelling}{old,1901}
+\SetLanguageAliasValues{german}{script}{blackletter,fraktur}
 
 \ifsystem at babelshorthands
-  \setkeys{german}{babelshorthands=true}
+  \SetGlossOptions{german}{babelshorthands=true}
 \else
-  \setkeys{german}{babelshorthands=false}
+  \SetGlossOptions{german}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\german at shorthands{%
   \xpg at activate@shorthands%
@@ -313,15 +325,15 @@
 \def\german at language{%
   \if at german@oldspelling
       \if at swiss@locale
-          \polyglossia at setup@language at patterns{swissgerman}%
+          \SetupPolyglossiaLangPatterns{swissgerman}%
       \else
-          \polyglossia at setup@language at patterns{german}%
+          \SetupPolyglossiaLangPatterns{german}%
       \fi
       \if at austrian@locale
          \adddialect\l at austrian\l at german%
       \fi
   \else
-      \polyglossia at setup@language at patterns{ngerman}%
+      \SetupPolyglossiaLangPatterns{ngerman}%
       \if at austrian@locale
          \adddialect\l at naustrian\l at ngerman%
       \fi

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-germanb.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-germanb.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-germanb.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-germanb.ldf}[polyglossia: module for German (old spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gl.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gl.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-gl.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-gl.ldf}[polyglossia: module for gl (Galician)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{galician}
+\InheritGlossFile{galician}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-grc.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-grc.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-grc.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-grc.ldf}[polyglossia: module for grc (Greek)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{greek}
+\InheritGlossFile{greek}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-greek.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-greek.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-greek.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-greek.ldf}[polyglossia: module for Greek]
 
@@ -22,7 +22,7 @@
 
 % BCP-47 compliant aliases
 \setlanguagealias*[variant=ancient]{greek}{grc}
-\setlanguagealias*[varant=polytonic]{greek}{el-polyton}
+\setlanguagealias*[variant=polytonic]{greek}{el-polyton}
 \setlanguagealias*[variant=monotonic]{greek}{el-monoton}
 \setlanguagealias*{greek}{el}
 
@@ -42,44 +42,9 @@
 \newif\if at greek@ancient\@greek at ancientfalse
 \newif\if at greek@poly\@greek at polyfalse
 
-\define at choicekey*+{greek}{variant}[\xpg at val\xpg at nr]{monotonic,mono,polytonic,poly,ancient,ancientgreek}[monotonic]{%
-   \xpg at ifdefined{greek}{}{%
-      \xpg at nopatterns{greek}%
-      \adddialect\l at greek\l at nohyphenation
-   }%
-   \ifcase\xpg at nr\relax
-      % monotonic:
-      \@greek at polyfalse
-      \@greek at ancientfalse
-   \or
-      % mono:
-      \@greek at polyfalse
-      \@greek at ancientfalse
-   \or
-      % polytonic:
-      \@greek at polytrue
-      \@greek at ancientfalse
-   \or
-      % poly:
-      \@greek at polytrue
-      \@greek at ancientfalse
-   \or
-      % ancient:
-      \@greek at polyfalse
-      \@greek at ancienttrue
-   \or
-      % ancientgreek:
-      \@greek at polyfalse
-      \@greek at ancienttrue
-   \fi
-   \greek at set@langdata
-   \xpg at info{Option: Greek, variant=\xpg at val}%
-}{\xpg at warning{Unknown Greek variant `#1'}}
-
-
 \def\greek at set@langdata{%
    \if at greek@ancient
-       \xpg at ifdefined{ancientgreek}{}%
+       \IfLanguageDefinedF{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}%
@@ -89,7 +54,7 @@
        \SetLanguageKeys{greek}{babelname=greek,bcp47=grc,bcp47-language=grc,bcp47-variant={}}%
    \else
       \if at greek@poly
-          \xpg at ifdefined{polygreek}{}%
+          \IfLanguageDefinedF{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}%
@@ -98,7 +63,7 @@
           \def\dategreek{\datepolygreek}%
           \SetLanguageKeys{greek}{babelname=polutonikogreek,bcp47=el-polyton,bcp47-language=el,bcp47-variant=polyton}%
       \else% monotonic greek
-          \xpg at ifdefined{monogreek}{}%
+          \IfLanguageDefinedF{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}%
@@ -112,42 +77,85 @@
 
 
 \def\greek at language{%
-  \polyglossia at setup@language at patterns{\greek at variant}%
+  \SetupPolyglossiaLangPatterns{\greek at variant}%
 }
 
 
 \newif\if at greek@numerals
-\define at choicekey*+{greek}{numerals}[\xpg at val\xpg at nr]{greek,arabic}[greek]{%
-   \ifcase\xpg at nr\relax
-      % greek:
-      \@greek at numeralstrue%
-      \SetLanguageKeys{greek}{bcp47-extension-u=nu-grek}%
-   \or
-      % arabic:
-      \@greek at numeralsfalse%
-      \SetLanguageKeys{greek}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Greek, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Greek numerals value `#1'}}
 
+\DeclareKeys[polyglossia/gloss/greek]
+  {
+    variant.choices:nn = { monotonic, mono,polytonic, poly,ancient, ancientgreek }
+      {%
+        \CheckHyphenationPatterns{greek}%
+        \ifcase\UseName{l_keys_choice_int}\or
+          % monotonic:
+          \@greek at polyfalse
+          \@greek at ancientfalse
+        \or
+          % mono:
+          \@greek at polyfalse
+          \@greek at ancientfalse
+        \or
+          % polytonic:
+          \@greek at polytrue
+          \@greek at ancientfalse
+        \or
+          % poly:
+          \@greek at polytrue
+          \@greek at ancientfalse
+        \or
+          % ancient:
+          \@greek at polyfalse
+          \@greek at ancienttrue
+        \or
+          % ancientgreek:
+          \@greek at polyfalse
+          \@greek at ancienttrue
+        \fi
+        \greek at set@langdata
+      },
+    variant.default:n = monotonic,
+    variant/unknown.code = \xpg at warning{Unknown Greek variant `#1'},
+    numerals.choice:,
+    numerals / greek.code =
+      {%      
+        \@greek at numeralstrue
+        \SetLanguageKeys{greek}{bcp47-extension-u=nu-grek}%
+      },
+    numerals / arabic.code =
+      {%
+        \@greek at numeralsfalse
+        \SetLanguageKeys{greek}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = greek,
+    numerals/unknown.code = \xpg at warning{Unknown Greek numerals value `#1'},
+    capitaliota.choice:,
+    capitaliota / true.code =
+      {%
+        \@greek at capitaliotatrue
+        % \MakeUppercase converts the ypogegrammeni (subscript muted iota) to capital iota
+        \SetLanguageKeys{greek}{bcp47-casing=el-x-iota,bcp47-extension-x=iota}%
+      },
+    capitaliota / false.code =
+      {%
+        \@greek at capitaliotafalse
+        % \MakeUppercase retains the subscript versions (default)
+        \SetLanguageKeys{greek}{bcp47-casing=el,bcp47-extension-x={}}%
+      },
+    capitaliota.default:n = true,
+    attic.choices:nn = { true, false }
+      {%
+        \xpg at warning{Greek option `attic' is no longer required.}
+      },
+    capitaliota.default:n = true,
+  }
 
-\define at boolkey{greek}[greek@]{capitaliota}[true]{%
-  \ifgreek at capitaliota
-     % \MakeUppercase converts the ypogegrammeni (subscript muted iota) to capital iota
-     \SetLanguageKeys{greek}{bcp47-casing=el-x-iota,bcp47-extension-x=iota}
-  \else
-     % \MakeUppercase retains the subscript versions (default)
-     \SetLanguageKeys{greek}{bcp47-casing=el,bcp47-extension-x={}}
-  \fi
-}
-
-\define at boolkey{greek}{attic}[true]{\xpg at warning{Greek option `attic' is no longer required.}}
-
 % Register default options
-\xpg at initialize@gloss at options{greek}{variant=monotonic,numerals=greek}
+\InitializeGlossOptions{greek}{variant=monotonic,numerals=greek}
 % Register alias options
-\xpg at set@alias at values{greek}{variant}{monotonic}{mono}
-\xpg at set@alias at values{greek}{variant}{polytonic}{poly}
+\SetLanguageAliasValues{greek}{variant}{monotonic,mono}
+\SetLanguageAliasValues{greek}{variant}{polytonic,poly}
 
 \def\monogreekcaptions{%
    \def\refname{Αναφορές}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-he.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-he.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-he.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-he.ldf}[polyglossia: module for he (Hebrew)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{hebrew}
+\InheritGlossFile{hebrew}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hebrew.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hebrew.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hebrew.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hebrew.ldf}[polyglossia: module for Hebrew]
 
@@ -24,41 +24,48 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{hebrew}{he}
 
-% hebrewcal options
-\define at key{hebrew}{marcheshvan}[true]{\setkeys{hebrewcal}{marcheshvan=#1}}
-\define at key{hebrew}{transliteration}[alt]{\setkeys{hebrewcal}{transliteration=#1}}
-\define at key{hebrew}{fullyear}[true]{\setkeys{hebrewcal}{fullyear=#1}}
-
 \newif\if at calendar@hebrew
-\define at choicekey*+{hebrew}{calendar}[\xpg at val\xpg at nr]{hebrew,gregorian}[gregorian]{%
-   \ifcase\xpg at nr\relax
-      % hebrew:
-      \@calendar at hebrewtrue
-   \or
-      % gregorian:
-      \@calendar at hebrewfalse
-   \fi
-   \xpg at info{Option: Hebrew, calendar=\xpg at val}%
-}{\xpg at warning{Unknown Hebrew calendar `#1'}}
-
 \newif\if at hebrew@numerals
-\define at choicekey*+{hebrew}{numerals}[\xpg at val\xpg at nr]{hebrew,arabic}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % hebrew:
-      \@hebrew at numeralstrue
-      \SetLanguageKeys{hebrew}{bcp47-extension-u=nu-hebr}%
-   \or
-      % arabic:
-      \@hebrew at numeralsfalse
-      \SetLanguageKeys{hebrew}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Hebrew, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Hebrew numerals value `#1'}}
 
-\setkeys{hebrew}{numerals}
+\DeclareKeys[polyglossia/gloss/hebrew]
+  {
+    marcheshvan.code = \setkeys{hebrewcal}{marcheshvan=#1},
+    marcheshvan.default:n = true,
+    transliteration.code = \setkeys{hebrewcal}{transliteration=#1},
+    transliteration.default:n = alt,
+    fullyear.code = \setkeys{hebrewcal}{fullyear=#1},
+    fullyear.default:n = true,
+    calendar.choice:,
+    calendar / hebrew.code =
+      {%
+        \@calendar at hebrewtrue
+      },
+    calendar / gregorian.code =
+      {%
+        \@calendar at hebrewfalse
+      },
+    calendar.default:n = gregorian,
+    calendar/unknown.code = \xpg at warning{Unknown Hebrew calendar `#1'},
+    numerals.choice:,
+    numerals / hebrew.code =
+      {%
+        \@hebrew at numeralstrue
+        \SetLanguageKeys{hebrew}{bcp47-extension-u=nu-hebr}%
+      },
+    numerals / arabic.code =
+      {%
+        \@hebrew at numeralsfalse
+        \SetLanguageKeys{hebrew}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Hebrew numerals value `#1'}
+  }
 
+
+\SetGlossOptions{hebrew}{numerals}
+
 % Register default options
-\xpg at initialize@gloss at options{hebrew}{numerals=arabic,calendar=gregorian,marcheshvan=false,fullyear=false}
+\InitializeGlossOptions{hebrew}{numerals=arabic,calendar=gregorian,marcheshvan=false,fullyear=false}
 
 \def\captionshebrew{%
   \def\prefacename{מבוא}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hi.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hi.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hi.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hi.ldf}[polyglossia: module for hi (Hindi)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{hindi}
+\InheritGlossFile{hindi}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hindi.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hindi.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hindi.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % UTF-8 strings kindly provided by Zdenĕk Wagner, 10-03-2008
 % with corrections and additional contributions by Anshuman Pandey
@@ -25,8 +25,7 @@
 
 \ifx\l at hindi\@undefined%
   \ifx\l at sanskrit\@undefined%
-    \xpg at nopatterns{Hindi}%
-    \adddialect\l at hindi\l at nohyphenation%
+    \XPGNoPatternsFallback{hindi}%
   \else
     \xpg at warning{No hyphenation patterns were loaded for Hindi\MessageBreak
     I will use the patterns for Sanskrit instead}
@@ -35,26 +34,31 @@
 \fi
 
 \def\hindi at language{%
-  \polyglossia at setup@language at patterns{hindi}%
+  \SetupPolyglossiaLangPatterns{hindi}%
 }
 
 \newif\ifhindi at devanagari@numerals
 \hindi at devanagari@numeralstrue
-\define at choicekey*+{hindi}{numerals}[\xpg at val\xpg at nr]{Devanagari,Western}[Devanagari]{%
-   \ifcase\xpg at nr\relax
-      % Devanagari:
-      \hindi at devanagari@numeralstrue%
-      \SetLanguageKeys{hindi}{bcp47-extension-u=nu-deva}%
-   \or
-      % Western:
-      \hindi at devanagari@numeralsfalse%
-      \SetLanguageKeys{hindi}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Hindi, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Hindi numeral `#1'}}
 
+\DeclareKeys[polyglossia/gloss/hindi]
+  {
+    numerals.choice:,
+    numerals / devanagari.code =
+      {%
+        \hindi at devanagari@numeralstrue
+        \SetLanguageKeys{hindi}{bcp47-extension-u=nu-deva}%
+      },
+    numerals / western.code =
+      {%
+          \hindi at devanagari@numeralsfalse
+          \SetLanguageKeys{hindi}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = devanagari,
+    numerals/unknown.code = \xpg at warning{Unknown Hindi numeral `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{hindi}{numerals=devanagari}
+\InitializeGlossOptions{hindi}{numerals=devanagari}
 
 \newcommand{\hindinumerals}[2]{\hindinumber{#2}}
 
@@ -74,6 +78,7 @@
      \def\contentsname{विषय सूची}%
      \def\enclname{}%
      \def\figurename{चित्र}% रेखाचित्र
+     \def\glossaryname{शब्दार्थ सूची}%
      \def\headpagename{पृष्ठ}%
      \def\headtoname{}%
      \def\indexname{सूची}%
@@ -85,6 +90,7 @@
      \def\pagename{पृष्ठ}%
      \def\partname{खण्ड}%
      \def\prefacename{प्रस्तावना}% प्राक्कथन
+     \def\proofname{प्रमाण}%
      \def\refname{हवाले}%
      \def\tablename{तालिका}%
      \def\seename{देखिए}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hr.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hr.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hr.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hr.ldf}[polyglossia: module for hr (Croatian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{croatian}
+\InheritGlossFile{croatian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hsb.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hsb.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hsb.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hsb.ldf}[polyglossia: module for hsb (Higher Sorbian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hu.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hu.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hu.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hu.ldf}[polyglossia: module for hu (Hungarian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{hungarian}
+\InheritGlossFile{hungarian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hungarian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hungarian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hungarian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hungarian.ldf}[polyglossia: module for Hungarian]
 
@@ -25,53 +25,61 @@
 \newif\if at hungarian@swapcaptions
 \newif\if at hungarian@swapheadings
 \newif\if at hungarian@swapheaders
-\define at choicekey*+{hungarian}{swapstrings}[\xpg at val\xpg at nr]{all,captions,headings,headers,hheaders,none}[all]{%
-   \ifcase\xpg at nr\relax
-      % all:
-      \@hungarian at swapcaptionstrue%
-      \@hungarian at swapheadingstrue%
-      \@hungarian at swapheaderstrue%
-   \or
-      % captions:
-      \@hungarian at swapcaptionstrue%
-      \@hungarian at swapheadingsfalse%
-      \@hungarian at swapheadersfalse%
-   \or
-      % headings:
-      \@hungarian at swapcaptionsfalse%
-      \@hungarian at swapheadingstrue%
-      \@hungarian at swapheadersfalse%
-   \or
-      % headers:
-      \@hungarian at swapcaptionsfalse%
-      \@hungarian at swapheadingsfalse%
-      \@hungarian at swapheaderstrue%
-   \or
-      % hheaders:
-      \@hungarian at swapcaptionsfalse%
-      \@hungarian at swapheadingstrue%
-      \@hungarian at swapheaderstrue%
-   \or
-      % none:
-      \@hungarian at swapcaptionsfalse%
-      \@hungarian at swapheadingsfalse%
-      \@hungarian at swapheadersfalse%
-   \fi
-   \xpg at info{Option: Hungarian, swapstrings=\xpg at val}%
-}{\xpg at warning{Unknown Hungarian swapstrings value `#1'}}
 
-% Force punctuation: 1) after section type counters; 2) after @chapapp in the running head
-\define at boolkey{hungarian}[hungarian@]{forceheadingpunctuation}[true]{}
+\DeclareKeys[polyglossia/gloss/hungarian]
+  {
+    forceheadingpunctuation.if = hungarian at forceheadingpunctuation,
+    forceheadingpunctuation.default:n = true,
+    swapstrings.choice:,
+    swapstrings / all.code =
+      {%
+        \@hungarian at swapcaptionstrue
+        \@hungarian at swapheadingstrue
+        \@hungarian at swapheaderstrue
+      },
+    swapstrings / captions.code =
+      {%
+        \@hungarian at swapcaptionstrue
+        \@hungarian at swapheadingsfalse
+        \@hungarian at swapheadersfalse
+      },
+    swapstrings / headings.code = 
+      {%
+        \@hungarian at swapcaptionsfalse
+        \@hungarian at swapheadingstrue
+        \@hungarian at swapheadersfalse
+      },
+    swapstrings / headers.code =
+      {%
+        \@hungarian at swapcaptionsfalse
+        \@hungarian at swapheadingsfalse
+        \@hungarian at swapheaderstrue
+      },
+    swapstrings / hheaders.code =
+      {%
+        \@hungarian at swapcaptionsfalse
+        \@hungarian at swapheadingstrue
+        \@hungarian at swapheaderstrue
+      },
+    swapstrings / none.code = 
+      {%
+        \@hungarian at swapcaptionsfalse
+        \@hungarian at swapheadingsfalse
+        \@hungarian at swapheadersfalse
+      },
+    swapstrings.default:n = all,
+    swapstrings/unknown.code = \xpg at warning{Unknown Hungarian swapstrings value `#1'}
+  }
 
 % Register default options
 % forceheadinpunctuatin is recommended, but the default value is false for compatibility reasons
-\xpg at initialize@gloss at options{hungarian}{swapstrings=all,
+\InitializeGlossOptions{hungarian}{swapstrings=all,
                                          forceheadingpunctuation=false}
 
 
 \def\hungarian at language{%
-   \polyglossia at setup@language at patterns{hungarian}%
-   \xpg at ifdefined{hungarian}{\adddialect\l at magyar\l at hungarian}{}%
+   \SetupPolyglossiaLangPatterns{hungarian}%
+   \IfLanguageDefinedT{hungarian}{\adddialect\l at magyar\l at hungarian}%
 }%
 
 \def\captionshungarian{%
@@ -143,69 +151,13 @@
   % change chapter and part headings
   \if at hungarian@swapheadings
      % With titlesec
-     \ifcsdef{titleformat}{%
-       \ifcsdef{NR at part}{% Hyperref (nameref)
-            \let\xpg at save@part at format\NR at part%
-            \patchcmd{\NR at part}%
-                      {\partname\nobreakspace\thepart}%
-                      {\thepart.\nobreakspace\partname}%
-                      {}%
-                      {\xpg at warning{Failed to patch part for Hungarian}}%
-       }{% not hyperref
-         \ifcsdef{@part}{%
-            \let\xpg at save@part at format\@part%
-            \patchcmd{\@part}%
-                      {\partname\nobreakspace\thepart}%
-                      {\thepart.\nobreakspace\partname}%
-                      {}%
-                      {\xpg at warning{Failed to patch part for Hungarian}}%
-         }{}%
-       }
-       \ifcsdef{chapter}{%
-          \titleformat\chapter[display]%
-             {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
-             {\thechapter.\space\@chapapp}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
-       }{}%
-     }{% (not \ifdefined\titleformat)
+     \@ifundefined{titleformat}{%
        % With KOMA
-       \ifcsdef{sectionformat}{%
-          \ifcsdef{partformat}{%
-            \let\xpg at save@part at format\partformat%
-            \renewcommand{\partformat}{\thepart.~\partname}%
-          }{}%
-          \ifcsdef{chapterformat}{%
-            \let\xpg at save@chap at format\chapterformat%
-            \renewcommand{\chapterformat}{\mbox{\thechapter\autodot%
-                                          \IfUsePrefixLine{\nobreakspace\chapapp}{\enskip}}}%
-          }{}%
-       }{%  (not \ifdefined\sectionformat)
-         % With memoir
-         \ifcsdef{@memptsize}{%
-           \ifcsdef{@makechapterhead}{%
-              \let\xpg at save@chap at format\@makechapterhead%
-              \patchcmd{\@makechapterhead}{\printchaptername \chapternamenum \printchapternum}%
-                       {\printchapternum.\chapternamenum\printchaptername}%
-                       {}%
-                       {\xpg at warning{Failed to patch chapter for Hungarian}}%
-           }{}%
-           \ifcsdef{NR at part}{% Hyperref (nameref)
-                \let\xpg at save@part at format\NR at part%
-                \patchcmd{\NR at part}{\printpartname \partnamenum \printpartnum}%
-                                 {\printpartnum.\partnamenum\printpartname}%
-                                 {}%
-                                 {\xpg at warning{Failed to patch part for Hungarian}}%
-           }{% not hyperref
-             \ifcsdef{@part}{%
-                \let\xpg at save@part at format\@part%
-                \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
-                                 {\printpartnum.\partnamenum\printpartname}%
-                                 {}%
-                                 {\xpg at warning{Failed to patch part for Hungarian}}%
-             }{}%
-           }%
-         }{%  (not \ifdefined\@memptsize)
+       \@ifundefined{sectionformat}{%
+         % Memoir?
+         \@ifundefined{@memptsize}{%
            % With standard classes
-            \ifcsdef{@makechapterhead}{%
+            \@ifundefined{@makechapterhead}{}{%
               \let\xpg at save@chap at format\@makechapterhead%
               \patchcmd{\@makechapterhead}%
                        {\@chapapp\space \thechapter}%
@@ -212,8 +164,17 @@
                        {\thechapter.\space \@chapapp}%
                        {}%
                        {\xpg at warning{Failed to patch chapter for Hungarian}}%
-            }{}%
-            \ifcsdef{NR at part}{% Hyperref (nameref)
+            }%
+            \@ifundefined{NR at part}{% not hyperref
+              \@ifundefined{@part}{}{%
+                \let\xpg at save@part at format\@part%
+                \patchcmd{\@part}%
+                         {\partname\nobreakspace\thepart}%
+                         {\thepart.\nobreakspace\partname}%
+                         {}%
+                         {\@ifundefined{part}{}{\xpg at warning{Failed to patch part for Hungarian}}}%
+              }%  (end \ifdefined\@part)
+            }{% Hyperref (nameref)
               \let\xpg at save@part at format\NR at part%
               \patchcmd{\NR at part}%
                        {\partname\nobreakspace\thepart}%
@@ -220,30 +181,85 @@
                        {\thepart.\nobreakspace\partname}%
                        {}%
                        {\xpg at warning{Failed to patch part for Hungarian}}%
-            }{% not hyperref
-              \ifcsdef{@part}{%
+            }% (end not hyperref)
+          }{% with memoir (\ifdefined\@memptsize)
+           \@ifundefined{@makechapterhead}{}{%
+              \let\xpg at save@chap at format\@makechapterhead%
+              \patchcmd{\@makechapterhead}{\printchaptername \chapternamenum \printchapternum}%
+                       {\printchapternum.\chapternamenum\printchaptername}%
+                       {}%
+                       {\xpg at warning{Failed to patch chapter for Hungarian}}%
+           }%
+           \@ifundefined{NR at part}{% not hyperref
+             \@ifundefined{@part}{}{%
                 \let\xpg at save@part at format\@part%
-                \patchcmd{\@part}%
-                         {\partname\nobreakspace\thepart}%
-                         {\thepart.\nobreakspace\partname}%
-                         {}%
-                         {\ifcsdef{part}{\xpg at warning{Failed to patch part for Hungarian}}{}}%
-              }{}%  (end \ifdefined\@part)
-            }% (end not hyperref)
-          }% (end \ifdefined\@memptsize)
-        }% (end \ifdefined\sectionformat)
+                \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
+                                 {\printpartnum.\partnamenum\printpartname}%
+                                 {}%
+                                 {\xpg at warning{Failed to patch part for Hungarian}}%
+             }%
+           }{% Hyperref (nameref)
+                \let\xpg at save@part at format\NR at part%
+                \patchcmd{\NR at part}{\printpartname \partnamenum \printpartnum}%
+                                 {\printpartnum.\partnamenum\printpartname}%
+                                 {}%
+                                 {\xpg at warning{Failed to patch part for Hungarian}}%
+           }%
+         }% (end \ifdefined\@memptsize)
+        }{% (\ifdefined\sectionformat)
+          \@ifundefined{partformat}{}{%
+            \let\xpg at save@part at format\partformat%
+            \renewcommand{\partformat}{\thepart.~\partname}%
+          }%
+          \@ifundefined{chapterformat}{}{%
+            \let\xpg at save@chap at format\chapterformat%
+            \renewcommand{\chapterformat}{\mbox{\thechapter\autodot%
+                                          \IfUsePrefixLine{\nobreakspace\chapapp}{\enskip}}}%
+          }%
+       }% (end \ifdefined\sectionformat)
+     }{% (\ifdefined\titleformat)
+       \@ifundefined{NR at part}{% not hyperref
+         \@ifundefined{@part}{}{%
+            \let\xpg at save@part at format\@part%
+            \patchcmd{\@part}%
+                      {\partname\nobreakspace\thepart}%
+                      {\thepart.\nobreakspace\partname}%
+                      {}%
+                      {\xpg at warning{Failed to patch part for Hungarian}}%
+         }%
+       }{% Hyperref (nameref)
+            \let\xpg at save@part at format\NR at part%
+            \patchcmd{\NR at part}%
+                      {\partname\nobreakspace\thepart}%
+                      {\thepart.\nobreakspace\partname}%
+                      {}%
+                      {\xpg at warning{Failed to patch part for Hungarian}}%
+       }%
+       \@ifundefined{chapter}{}{%
+          \titleformat\chapter[display]%
+             {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
+             {\thechapter.\space\@chapapp}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
+       }%
      }% (end \ifdefined\titleformat)
   \fi% (end \if at hungarian@swapheadings)
   %
   % Change running headers
   \if at hungarian@swapheaders
-    \ifcsdef{chapterformat}{%
-      % With KOMA
-      \let\xpg at save@chaptermark at format\chaptermarkformat%
-      \renewcommand*\chaptermarkformat{%
-         \thechapter\autodot\ \IfChapterUsesPrefixLine{\chapapp\@hungarian at forced@dot\enskip}{}}
-    }{% (not \ifdefined\chapterformat)
-      \ifcsdef{@memptsize}{%
+    \@ifundefined{chapterformat}{%
+      \@ifundefined{@memptsize}{%
+        % With standard classes
+        \@ifundefined{chaptermark}{}{%
+          \ifpatchable{\chaptermark}%
+               {\@chapapp\ \thechapter.}%
+               {\let\xpg at save@chaptermark at format\chaptermark%
+                \patchcmd{\chaptermark}%
+                    {\@chapapp\ \thechapter.}%
+                    {\thechapter.\ \@chapapp\@hungarian at forced@dot}%
+                    {}%
+                    {\xpg at warning{Failed to patch chaptermark for Hungarian}}}%
+               {}%
+        }% (end \ifdefined\chaptermark)
+      }{% (\ifdefined\@memptsize)
         % With memoir
         \let\xpg at save@chaptermark at format\chaptermark%
         \renewcommand*\chaptermark[1]{%
@@ -254,20 +270,12 @@
               }{}%
             \fi
             ##1}}{}}%
-      }{% (not \ifdefined\@memptsize)
-        % With standard classes
-        \ifcsdef{chaptermark}{%
-          \ifpatchable{\chaptermark}%
-               {\@chapapp\ \thechapter.}%
-               {\let\xpg at save@chaptermark at format\chaptermark%
-                \patchcmd{\chaptermark}%
-                    {\@chapapp\ \thechapter.}%
-                    {\thechapter.\ \@chapapp\@hungarian at forced@dot}%
-                    {}%
-                    {\xpg at warning{Failed to patch chaptermark for Hungarian}}}%
-               {}%
-        }{}% (end \ifdefined\chaptermark)
       }% (end \ifdefined\@memptsize)
+    }{% (\ifdefined\chapterformat)
+      % With KOMA
+      \let\xpg at save@chaptermark at format\chaptermarkformat%
+      \renewcommand*\chaptermarkformat{%
+         \thechapter\autodot\ \IfChapterUsesPrefixLine{\chapapp\@hungarian at forced@dot\enskip}{}}
     }% (end \ifdefined\chapterformat)
   \fi% (end \if at hungarian@swapheaders)
 }
@@ -279,58 +287,58 @@
    \let\fnum at figure\xpg at save@fnum at figure%
    %
    % Reset chapter and part heading
-   \ifcsdef{titleformat}{%
+   \@ifundefined{titleformat}{%
+     \@ifundefined{sectionformat}{%
+        % With memoir and standard classes
+        \@ifundefined{xpg at save@part at format}{}{%
+           \@ifundefined{NR at part}{%
+               \let\@part\xpg at save@part at format%
+           }{%
+               \let\NR at part\xpg at save@part at format%
+           }%
+        }%
+        \@ifundefined{xpg at save@chap at format}{}{%
+          \let\@makechapterhead\xpg at save@chap at format
+        }%
+     }{%
+        % With KOMA
+        \@ifundefined{xpg at save@part at format}{}{%
+           \let\partformat\xpg at save@part at format
+        }%
+        \@ifundefined{xpg at save@chap at format}{}{%
+           \let\chapterformat\xpg at save@chap at format
+        }%
+     }% (end \ifdefined\sectionformat)
+   }{% (\ifdefined\titleformat)
       % With titlesec
-     \ifcsdef{xpg at save@part at format}{%
-        \ifcsdef{NR at part}{%
+     \@ifundefined{xpg at save@part at format}{}{%
+        \@ifundefined{NR at part}{%
+            \let\@part\xpg at save@part at format%
+        }{%
             \let\NR at part\xpg at save@part at format%
-        }{%
-            \let\@part\xpg at save@part at format%
         }%
-     }{}%
-     \ifcsdef{chapter}{%
+     }%
+     \@ifundefined{chapter}{}{%
         \titleformat\chapter[display]%
           {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
           {\@chapapp\space\thechapter}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
-     }{}%
-   }{% (not \ifdefined\titleformat)
-     \ifcsdef{sectionformat}{%
-        % With KOMA
-        \ifcsdef{xpg at save@part at format}{%
-           \let\partformat\xpg at save@part at format
-        }{}%
-        \ifcsdef{xpg at save@chap at format}{%
-           \let\chapterformat\xpg at save@chap at format
-        }{}%
-     }{%
-        % With memoir and standard classes
-        \ifcsdef{xpg at save@part at format}{%
-           \ifcsdef{NR at part}{%
-               \let\NR at part\xpg at save@part at format%
-           }{%
-               \let\@part\xpg at save@part at format%
-           }%
-        }{}%
-        \ifcsdef{xpg at save@chap at format}{%
-          \let\@makechapterhead\xpg at save@chap at format
-        }{}%
-     }% (end \ifdefined\sectionformat)
+     }%
    }% (end \ifdefined\titleformat)
   %
   % Reset headers
-  \ifcsdef{chaptermarkformat}{%
+  \@ifundefined{chaptermarkformat}{%
+     \@ifundefined{chaptermark}{}{%
+       % With memoir and standard classes
+       \@ifundefined{xpg at save@chaptermark at format}{}{%
+         \let\chaptermark\xpg at save@chaptermark at format%
+       }%
+     }% (end \ifdefined\chaptermark)
+  }{%
      % With KOMA
-     \ifcsdef{xpg at save@chaptermark at format}{%
+     \@ifundefined{xpg at save@chaptermark at format}{}{%
        \let\chaptermarkformat\xpg at save@chaptermark at format%
-     }{}%
-  }{%
-     \ifcsdef{chaptermark}{%
-       % With memoir and standard classes
-       \ifcsdef{xpg at save@chaptermark at format}{%
-         \let\chaptermark\xpg at save@chaptermark at format%
-       }{}%
-     }{}% (end \ifdefined\chaptermark)
-  }% (end \ifdefined\chapterformat)
+     }%
+  }% (end \ifdefined\chaptermarkformat)
 }
 % Hungarian needs 1) trailing dots in chapter headings; 2) trailing dot in section, subsection, etc, counters
 \def\@hungarian at forced@dot{}

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hy.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hy.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-hy.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-hy.ldf}[polyglossia: module for hy (Armenian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{armenian}
+\InheritGlossFile{armenian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ia.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ia.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ia.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ia.ldf}[polyglossia: module for ia (Interlingua)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{interlingua}
+\InheritGlossFile{interlingua}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-icelandic.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-icelandic.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-icelandic.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-icelandic.ldf}[polyglossia: module for Icelandic]
 \PolyglossiaSetup{icelandic}{

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-id.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-id.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-id.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-id.ldf}[polyglossia: module for id (Malay)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{malay}
+\InheritGlossFile{malay}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-interlingua.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-interlingua.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-interlingua.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-interlingua.ldf}[polyglossia: module for Interlingua]
 \PolyglossiaSetup{interlingua}{

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-irish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-irish.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-irish.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-irish.ldf}[polyglossia: module for Irish]
 
@@ -5,6 +5,6 @@
 % We only provide this gloss for babel compatibility. Since irish is 
 % a gaelic variety, we use 'gaelic' with variant 'irish' now.
 
-\xpg at load@master at language{gaelic}
+\InheritGlossFile{gaelic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-is.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-is.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-is.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-is.ldf}[polyglossia: module for is (Icelandic)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{icelandic}
+\InheritGlossFile{icelandic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-it.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-it.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-it.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-it.ldf}[polyglossia: module for it (Italian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{italian}
+\InheritGlossFile{italian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-italian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-italian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-italian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,5 +1,5 @@
 % !TEX encoding = UTF-8 Unicode
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-italian.ldf}[polyglossia: module for Italian]
 \PolyglossiaSetup{italian}{
@@ -18,24 +18,22 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{italian}{it}
 
+\DeclareKeys[polyglossia/gloss/italian]
+  {
+    babelshorthands.if = italian at babelshorthands,
+    babelshorthands.default:n = true,
+  }
 
-%%% CHANGES START %%% by Enrico Gregorio
-\define at boolkey{italian}[italian@]{babelshorthands}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{italian}{babelshorthands=false}
+\InitializeGlossOptions{italian}{babelshorthands=false}
 
 \ifsystem at babelshorthands
-  \setkeys{italian}{babelshorthands=true}
+  \SetGlossOptions{italian}{babelshorthands=true}
 \else
-  \setkeys{italian}{babelshorthands=false}
+  \SetGlossOptions{italian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\italian at shorthands{%
   \xpg at activate@shorthands%
@@ -115,7 +113,7 @@
 
 %%% CHANGES START %%% by Enrico Gregorio
 \let\xpgit at savedvalues\empty
-\AtEndPreamble{% the user or the class might define different values
+\AddToHook{begindocument/before}{% the user or the class might define different values
   \edef\xpgit at savedvalues{%
     \clubpenalty=\the\clubpenalty\space
     \@clubpenalty=\the\@clubpenalty\space

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ja.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ja.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ja.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ja.ldf}[polyglossia: module for ja (Japanese)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{japanese}
+\InheritGlossFile{japanese}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-japanese.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-japanese.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-japanese.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-japanese.ldf}[polyglossia: module for Japanese]
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ka.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ka.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ka.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ka.ldf}[polyglossia: module for ka (Georgian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{georgian}
+\InheritGlossFile{georgian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kannada.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kannada.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kannada.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,5 +1,5 @@
 %% gloss-kannada.ldf
-%% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+%% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %%
 %% Copyright 2011 Aravinda VK <hallimanearavind AT gmail.com>,
 %%                Shankar Prasad <prasad.mvs AT gmail.com>,
@@ -53,13 +53,21 @@
 \def\tmp at western{Western}
 \newif\ifkannada at numerals
 \kannada at numeralstrue
+  
+\DeclareKeys[polyglossia/gloss/kannada]
+  {
+    numerals.choice:,
+    numerals / kannada.code =
+      {%
+        \kannada at numeralstrue
+      },
+    numerals / western.code =
+      {%     
+        \kannada at numeralsfalse
+      },
+    numerals.default:n = kannada
+  }
 
-\define at key{kannada}{numerals}[Kannada]{%
-  \def\@tmpa{#1}%
-  \ifx\@tmpa\tmp at western
-    \kannada at numeralsfalse
-  \fi}
-
   
 \def\captionskannada{%
   \def\prefacename{ಮುನ್ನುಡಿ}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-khmer.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-khmer.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-khmer.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-khmer.ldf}[polyglossia: module for Khmer]
 \PolyglossiaSetup{khmer}{
@@ -19,19 +19,25 @@
 
 \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%
-    \SetLanguageKeys{khmer}{bcp47-extension-u=nu-khmr}%
-  \else%
-    \@khmer at numeralsfalse%
-    \SetLanguageKeys{khmer}{bcp47-extension-u=nu-latn}%
-   \fi%
-}
 
-\setkeys{khmer}{numerals}
+\DeclareKeys[polyglossia/gloss/khmer]
+  {
+    numerals.choice:,
+    numerals / khmer.code =
+      {%
+        \@khmer at numeralstrue
+        \SetLanguageKeys{khmer}{bcp47-extension-u=nu-khmr}%
+      },
+    numerals / arabic.code =
+      {%
+        \@khmer at numeralsfalse
+        \SetLanguageKeys{khmer}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = arabic
+  }
 
+\SetGlossOptions{khmer}{numerals}
+
 \def\captionskhmer{%
   \def\prefacename{អារម្ភកថា}%
   \def\refname{ឯកសារយោង}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-km.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-km.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-km.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-km.ldf}[polyglossia: module for km (Khmer)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{khmer}
+\InheritGlossFile{khmer}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr-Arab.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr-Arab.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr-Arab.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-kmr-Arab.ldf}[polyglossia: module for kmr-Arab (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr-Latn.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr-Latn.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr-Latn.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-kmr-Latn.ldf}[polyglossia: module for kmr-Latn (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kmr.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-kmr.ldf}[polyglossia: module for kmr (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kn.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kn.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kn.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-kn.ldf}[polyglossia: module for kn (Kannada)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kannada}
+\InheritGlossFile{kannada}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ko.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ko.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ko.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ko.ldf}[polyglossia: module for ko (Korean)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{korean}
+\InheritGlossFile{korean}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-korean.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-korean.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-korean.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-korean.ldf}[polyglossia: module for Korean]
 
@@ -18,40 +18,48 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{korean}{ko}
 
-% variant : plain (0), classic (1), or modern (2)
-\define at choicekey{korean}{variant}[\xpg at val\xpg at nr]{plain,classic,modern}[plain]{%
-    \let\xpg at korean@variant\xpg at nr
-}
-% captions : hangul (0) or hanja (1)
-\define at choicekey{korean}{captions}[\xpg at val\xpg at nr]{hangul,hanja}[hangul]{%
-    \let\xpg at korean@captions\xpg at nr
-}
-% swapstrings: all (0), headings (1), headers (2), or none (3)
 \newif\if at korean@swapheadings
 \newif\if at korean@swapheaders
-\define at choicekey*+{korean}{swapstrings}[\xpg at val\xpg at nr]{all,headings,headers,none}[all]{%
-   \ifcase\xpg at nr\relax
-      % all:
-      \@korean at swapheadingstrue%
-      \@korean at swapheaderstrue%
-   \or
-      % headings:
-      \@korean at swapheadingstrue%
-      \@korean at swapheadersfalse%
-   \or
-      % headers:
-      \@korean at swapheadingsfalse%
-      \@korean at swapheaderstrue%
-   \or
-      % none:
-      \@korean at swapheadingsfalse%
-      \@korean at swapheadersfalse%
-   \fi
-   \xpg at info{Option: Korean, swapstrings=\xpg at val}%
-}{\xpg at warning{Unknown Korean swapstrings value `#1'}}
 
+\DeclareKeys[polyglossia/gloss/korean]
+  {
+    variant.choices:nn = { plain, classic, modern }
+      {%
+        \edef\xpg at korean@variant{\the\numexpr\UseName{l_keys_choice_int}-1\relax}
+      },
+    variant.default:n = plain,
+    captions.choices:nn = { hangul, hanja }
+      {%
+        \edef\xpg at korean@captions{\the\numexpr\UseName{l_keys_choice_int}-1\relax}
+      },
+    captions.default:n = hangul,
+    swapstrings.choice:,
+    swapstrings / all.code =
+      {%
+        \@korean at swapheadingstrue
+        \@korean at swapheaderstrue
+      },
+    swapstrings / headings.code =
+      {%
+        \@korean at swapheadingstrue
+        \@korean at swapheadersfalse
+      },
+    swapstrings / headers.code =
+      {%
+        \@korean at swapheadingsfalse
+        \@korean at swapheaderstrue
+      },
+    swapstrings / none.code =
+      {%
+        \@korean at swapheadingsfalse
+        \@korean at swapheadersfalse
+      },
+    swapstrings.default:n = all,
+    swapstrings/unknown.code = \xpg at warning{Unknown Korean swapstrings value `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{korean}{variant=plain,swapstrings=all,captions=hangul}
+\InitializeGlossOptions{korean}{variant=plain,swapstrings=all,captions=hangul}
 
 \def\captionskorean{%
     \ifcase\xpg at korean@captions\relax
@@ -113,60 +121,48 @@
   % change chapter and part headings
   \if at korean@swapheadings
     % With titlesec
-    \ifcsdef{titleformat}{%
-      \ifcsdef{NR at part}{% Hyperref (nameref)
-        \let\xpg at save@part at format\NR at part
-        \patchcmd{\NR at part}%
-                 {\partname\nobreakspace\thepart}%
-                 {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
-                 {}%
-                 {\xpg at warning{Failed to patch part for Korean}}%
-      }{% not hyperref
-        \ifcsdef{@part}{%
-            \let\xpg at save@part at format\@part
-            \patchcmd{\@part}%
+    \@ifundefined{titleformat}{%
+      % With KOMA
+      \@ifundefined{sectionformat}{%
+        % With memoir
+        \@ifundefined{@memptsize}{%
+          % With standard classes
+          \@ifundefined{@makechapterhead}{}{%
+            \let\xpg at save@chap at format\@makechapterhead
+            \patchcmd{\@makechapterhead}%
+                     {\@chapapp\space \thechapter}%
+                     {%
+                       \ifx\@chapapp\korean at appendix@chapapp
+                         \appendixname\space \thechapter
+                       \else
+                         \koreanTHEname\space \thechapter\space \@chapapp
+                       \fi
+                     }%
+                     {}%
+                     {\xpg at warning{Failed to patch chapter for Korean}}%
+          }%
+          \@ifundefined{NR at part}{% not hyperref
+            \@ifundefined{@part}{}{%
+              \ifpatchable{\@part}%
+                   {\partname\nobreakspace\thepart}%
+                   {\let\xpg at save@part at format\@part
+                    \patchcmd{\@part}%
+                             {\partname\nobreakspace\thepart}%
+                             {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
+                             {}%
+                             {\@ifundefined{part}{}{\xpg at warning{Failed to patch part for Korean}}}}%
+                   {}%
+            }%  (end \ifdefined\@part)
+          }{% Hyperref (nameref)
+            \let\xpg at save@part at format\NR at part
+            \patchcmd{\NR at part}%
                      {\partname\nobreakspace\thepart}%
                      {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
                      {}%
                      {\xpg at warning{Failed to patch part for Korean}}%
-        }{}%
-      }
-      \ifcsdef{chapter}{%
-        \titleformat\chapter[display]%
-          {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}%
-          {%
-            \ifx\@chapapp\korean at appendix@chapapp
-              \appendixname\space \thechapter
-            \else
-              \koreanTHEname\space \thechapter\space \@chapapp
-            \fi
-          }{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}%
-      }{}%
-    }{% (not \ifdefined\titleformat)
-      % With KOMA
-      \ifcsdef{sectionformat}{%
-        \ifcsdef{partformat}{%
-          \let\xpg at save@part at format\partformat
-          \renewcommand*{\partformat}{\koreanTHEname~\thepart~\partname}%
-        }{}%
-        \ifcsdef{chapterformat}{%
-          \let\xpg at save@chap at format\chapterformat
-          \renewcommand*{\chapterformat}{\mbox{%
-            \IfChapterUsesPrefixLine
-            {%
-              \ifx\@chapapp\korean at appendix@chapapp
-                \chapapp\nobreakspace \thechapter\autodot
-              \else
-                \koreanTHEname\nobreakspace \thechapter\nobreakspace \chapapp\autodot
-              \fi
-            }%
-            {\thechapter\autodot\enskip}%
-          }}%
-        }{}%
-      }{% (not \ifdefined\sectionformat)
-        % With memoir
-        \ifcsdef{@memptsize}{%
-          \ifcsdef{@makechapterhead}{%
+          }% (end not hyperref)
+        }{% (\ifdefined\@memptsize)
+          \@ifundefined{@makechapterhead}{}{%
             \let\xpg at save@chap at format\@makechapterhead
             \patchcmd{\@makechapterhead}%
                      {\printchaptername \chapternamenum \printchapternum}%
@@ -184,19 +180,9 @@
                 \ifpatchable\printchaptername\@chapapp
                   {\chapnamefont\koreanTHEname\chapternamenum}{}}%
             \fi
-          }{}%
-          \ifcsdef{NR at part}{% Hyperref (nameref)
-            \let\xpg at save@part at format\NR at part
-            \patchcmd{\NR at part}%
-                     {\printpartname \partnamenum \printpartnum}%
-                     {\printkoreanpartthe \printpartnum\partnamenum \printpartname}%
-                     {}%
-                     {\xpg at warning{Failed to patch part for Korean}}%
-            \ifdefined\printkoreanpartthe\else
-              \def\printkoreanpartthe{\partnamefont\koreanTHEname\partnamenum}%
-            \fi
-          }{% not hyperref
-            \ifcsdef{@part}{%
+          }%
+          \@ifundefined{NR at part}{% not hyperref
+            \@ifundefined{@part}{}{%
               \let\xpg at save@part at format\@part
               \patchcmd{\@part}%
                        {\printpartname \partnamenum \printpartnum}%
@@ -206,84 +192,77 @@
               \ifdefined\printkoreanpartthe\else
                 \def\printkoreanpartthe{\partnamefont\koreanTHEname\partnamenum}%
               \fi
-            }{}%
-          }%
-        }{% (not \ifdefined\@memptsize)
-          % With standard classes
-          \ifcsdef{@makechapterhead}{%
-            \let\xpg at save@chap at format\@makechapterhead
-            \patchcmd{\@makechapterhead}%
-                     {\@chapapp\space \thechapter}%
-                     {%
-                       \ifx\@chapapp\korean at appendix@chapapp
-                         \appendixname\space \thechapter
-                       \else
-                         \koreanTHEname\space \thechapter\space \@chapapp
-                       \fi
-                     }%
-                     {}%
-                     {\xpg at warning{Failed to patch chapter for Korean}}%
-          }{}%
-          \ifcsdef{NR at part}{% Hyperref (nameref)
+            }%
+          }{% Hyperref (nameref)
             \let\xpg at save@part at format\NR at part
             \patchcmd{\NR at part}%
+                     {\printpartname \partnamenum \printpartnum}%
+                     {\printkoreanpartthe \printpartnum\partnamenum \printpartname}%
+                     {}%
+                     {\xpg at warning{Failed to patch part for Korean}}%
+            \ifdefined\printkoreanpartthe\else
+              \def\printkoreanpartthe{\partnamefont\koreanTHEname\partnamenum}%
+            \fi
+          }%
+        }% (end \ifdefined\@memptsize)
+      }{% (\ifdefined\sectionformat)
+        \@ifundefined{partformat}{}{%
+          \let\xpg at save@part at format\partformat
+          \renewcommand*{\partformat}{\koreanTHEname~\thepart~\partname}%
+        }%
+        \@ifundefined{chapterformat}{}{%
+          \let\xpg at save@chap at format\chapterformat
+          \renewcommand*{\chapterformat}{\mbox{%
+            \IfChapterUsesPrefixLine
+            {%
+              \ifx\@chapapp\korean at appendix@chapapp
+                \chapapp\nobreakspace \thechapter\autodot
+              \else
+                \koreanTHEname\nobreakspace \thechapter\nobreakspace \chapapp\autodot
+              \fi
+            }%
+            {\thechapter\autodot\enskip}%
+          }}%
+        }%
+      }% (end \ifdefined\sectionformat)
+    }{% (\ifdefined\titleformat)
+      \@ifundefined{NR at part}{% not hyperref
+        \@ifundefined{@part}{}{%
+            \let\xpg at save@part at format\@part
+            \patchcmd{\@part}%
                      {\partname\nobreakspace\thepart}%
                      {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
                      {}%
                      {\xpg at warning{Failed to patch part for Korean}}%
-          }{% not hyperref
-            \ifcsdef{@part}{%
-              \ifpatchable{\@part}%
-                   {\partname\nobreakspace\thepart}%
-                   {\let\xpg at save@part at format\@part
-                    \patchcmd{\@part}%
-                             {\partname\nobreakspace\thepart}%
-                             {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
-                             {}%
-                             {\ifcsdef{part}{\xpg at warning{Failed to patch part for Korean}}{}}}%
-                   {}%
-            }{}%  (end \ifdefined\@part)
-          }% (end not hyperref)
-        }% (end \ifdefined\@memptsize)
-      }% (end \ifdefined\sectionformat)
+        }%
+      }{% Hyperref (nameref)
+        \let\xpg at save@part at format\NR at part
+        \patchcmd{\NR at part}%
+                 {\partname\nobreakspace\thepart}%
+                 {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
+                 {}%
+                 {\xpg at warning{Failed to patch part for Korean}}%
+      }%
+      \@ifundefined{chapter}{}{%
+        \titleformat\chapter[display]%
+          {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}%
+          {%
+            \ifx\@chapapp\korean at appendix@chapapp
+              \appendixname\space \thechapter
+            \else
+              \koreanTHEname\space \thechapter\space \@chapapp
+            \fi
+          }{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}%
+      }%
     }% (end \ifdefined\titleformat)
   \fi % (end \if at korean@swapheadings)
   %
   % Change running headers
   \if at korean@swapheaders
-    \ifcsdef{chapterformat}{%
-      % With KOMA
-      \let\xpg at save@chaptermark at format\chaptermarkformat
-      \renewcommand*\chaptermarkformat{%
-        \IfChapterUsesPrefixLine
-        {%
-          \ifx\@chapapp\korean at appendix@chapapp
-            \chapapp\ \thechapter\autodot
-          \else
-            \koreanTHEname\ \thechapter\ \chapapp\autodot
-          \fi
-        }%
-        {\thechapter\autodot}%
-        \enskip
-      }%
-    }{% (not \ifdefined\chapterformat)
-      \ifcsdef{@memptsize}{%
-        % With memoir
-        \let\xpg at save@chaptermark at format\chaptermark
-        \patchcmd{\chaptermark}%
-                 {\@chapapp\ \@nameuse{thechapter}}%
-                 {%
-                   \ifx\@chapapp\korean at appendix@chapapp
-                     \appendixname\ \@nameuse{thechapter}%
-                   \else
-                     \koreanTHEname\ \@nameuse{thechapter}\ \@chapapp
-                   \fi
-                 }%
-                 {}%
-                 {\xpg at warning{Failed to patch chaptermark for Korean}}%
-      }{% (not \ifdefined\@memptsize)
+    \@ifundefined{chapterformat}{%
+      \@ifundefined{@memptsize}{%
         % With standard classes
-        \ifcsdef{chaptermark}{%
+        \@ifundefined{chaptermark}{}{%
           \ifpatchable{\chaptermark}%
                {\@chapapp\ \thechapter}%
                {\let\xpg at save@chaptermark at format\chaptermark
@@ -299,8 +278,37 @@
                          {}%
                          {\xpg at warning{Failed to patch chaptermark for Korean}}}%
                {}%
-        }{}% (end \ifdefined\chaptermark)
+        }% (end \ifdefined\chaptermark)
+      }{% (\ifdefined\@memptsize)
+        % With memoir
+        \let\xpg at save@chaptermark at format\chaptermark
+        \patchcmd{\chaptermark}%
+                 {\@chapapp\ \@nameuse{thechapter}}%
+                 {%
+                   \ifx\@chapapp\korean at appendix@chapapp
+                     \appendixname\ \@nameuse{thechapter}%
+                   \else
+                     \koreanTHEname\ \@nameuse{thechapter}\ \@chapapp
+                   \fi
+                 }%
+                 {}%
+                 {\xpg at warning{Failed to patch chaptermark for Korean}}%
       }% (end \ifdefined\@memptsize)
+    }{% (\ifdefined\chapterformat)
+      % With KOMA
+      \let\xpg at save@chaptermark at format\chaptermarkformat
+      \renewcommand*\chaptermarkformat{%
+        \IfChapterUsesPrefixLine
+        {%
+          \ifx\@chapapp\korean at appendix@chapapp
+            \chapapp\ \thechapter\autodot
+          \else
+            \koreanTHEname\ \thechapter\ \chapapp\autodot
+          \fi
+        }%
+        {\thechapter\autodot}%
+        \enskip
+      }%
     }% (end \ifdefined\chapterformat)
   \fi % (end \if at korean@swapheaders)
 }
@@ -307,57 +315,57 @@
 
 \def\nokorean at headingsformat{%
   % Reset chapter and part heading
-  \ifcsdef{titleformat}{%
+  \@ifundefined{titleformat}{%
+    \@ifundefined{sectionformat}{%
+      % With memoir and standard classes
+      \@ifundefined{xpg at save@part at format}{}{%
+        \@ifundefined{NR at part}{%
+          \let\@part\xpg at save@part at format
+        }{%
+          \let\NR at part\xpg at save@part at format
+        }%
+      }%
+      \@ifundefined{xpg at save@chap at format}{}{%
+        \let\@makechapterhead\xpg at save@chap at format
+      }%
+    }{%
+      % With KOMA
+      \@ifundefined{xpg at save@part at format}{}{%
+        \let\partformat\xpg at save@part at format
+      }%
+      \@ifundefined{xpg at save@chap at format}{}{%
+        \let\chapterformat\xpg at save@chap at format
+      }%
+    }% (end \ifdefined\sectionformat)
+  }{% (\ifdefined\titleformat)
     % With titlesec
-    \ifcsdef{xpg at save@part at format}{%
-      \ifcsdef{NR at part}{%
+    \@ifundefined{xpg at save@part at format}{}{%
+      \@ifundefined{NR at part}{%
+        \let\@part\xpg at save@part at format
+      }{%
         \let\NR at part\xpg at save@part at format
-      }{%
-        \let\@part\xpg at save@part at format
       }%
-    }{}%
-    \ifcsdef{chapter}{%
+    }%
+    \@ifundefined{chapter}{}{%
       \titleformat\chapter[display]%
         {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}%
         {\@chapapp\space\thechapter}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}%
-    }{}%
-  }{% (not \ifdefined\titleformat)
-    \ifcsdef{sectionformat}{%
-      % With KOMA
-      \ifcsdef{xpg at save@part at format}{%
-        \let\partformat\xpg at save@part at format
-      }{}%
-      \ifcsdef{xpg at save@chap at format}{%
-        \let\chapterformat\xpg at save@chap at format
-      }{}%
-    }{%
-      % With memoir and standard classes
-      \ifcsdef{xpg at save@part at format}{%
-        \ifcsdef{NR at part}{%
-          \let\NR at part\xpg at save@part at format
-        }{%
-          \let\@part\xpg at save@part at format
-        }%
-      }{}%
-      \ifcsdef{xpg at save@chap at format}{%
-        \let\@makechapterhead\xpg at save@chap at format
-      }{}%
-    }% (end \ifdefined\sectionformat)
+    }%
   }% (end \ifdefined\titleformat)
   %
   % Reset headers
-  \ifcsdef{chaptermarkformat}{%
+  \@ifundefined{chaptermarkformat}{%
+    \@ifundefined{chaptermark}{}{%
+      % With memoir and standard classes
+      \@ifundefined{xpg at save@chaptermark at format}{}{%
+        \let\chaptermark\xpg at save@chaptermark at format
+      }%
+    }% (end \ifdefined\chaptermark)
+  }{%
     % With KOMA
-    \ifcsdef{xpg at save@chaptermark at format}{%
+    \@ifundefined{xpg at save@chaptermark at format}{}{%
       \let\chaptermarkformat\xpg at save@chaptermark at format
-    }{}%
-  }{%
-    \ifcsdef{chaptermark}{%
-      % With memoir and standard classes
-      \ifcsdef{xpg at save@chaptermark at format}{%
-        \let\chaptermark\xpg at save@chaptermark at format
-      }{}%
-    }{}% (end \ifdefined\chaptermark)
+    }%
   }% (end \ifdefined\chapterformat)
 }
 
@@ -421,13 +429,13 @@
         \XeTeXinterchartokenstate\z@
         \XeTeXlinebreakpenalty\z@
         \XeTeXlinebreakskip\z at skip
-        \XeTeXlinebreaklocale "en"
+        \XeTeXlinebreaklocale ""
         \noextras at korean@common
     }
 \else % luatex
-    \def\inlineextras at korean{\xpg at attr@korean\xpg at korean@variant\relax}
+    \def\inlineextras at korean{\xpg at attr@cjkspacing\xpg at korean@variant\relax}
     \def\noextras at korean{%
-        \unsetattribute\xpg at attr@korean
+        \unsetattribute\xpg at attr@cjkspacing
         \noextras at korean@common
     }
 \fi
@@ -447,7 +455,7 @@
     \let\newattribute\newluatexattribute
     \let\unsetattribute\unsetluatexattribute
 \fi
-\newattribute\xpg at attr@korean
+\newattribute\xpg at attr@cjkspacing
 \newattribute\xpg at attr@autojosa
 % user commands for Josa
 % Josa : particles in Korean grammar that immediately follow a noun or pronoun.
@@ -468,7 +476,7 @@
 \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" }
+\directlua{ require "polyglossia-cjk-spacing" }
 \endinput\fi
 
 % XeTeX

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku-Arab.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku-Arab.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku-Arab.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ku-Arab.ldf}[polyglossia: module for ku-Arab (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku-Latn.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku-Latn.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku-Latn.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ku-Latn.ldf}[polyglossia: module for ku-Latn (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ku.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ku.ldf}[polyglossia: module for ku (Kurdish)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurdish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurdish.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurdish.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Created on September 1, 2019
 % Last updated on May 17, 2020
@@ -41,37 +41,10 @@
 
 \newif\if at kurdish@kurmanji
 \def\kurdish at variant{sorani}
-\define at choicekey*+{kurdish}{variant}[\xpg at val\xpg at nr]{sorani,kurmanji}[sorani]{%
-   \ifcase\xpg at 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=\xpg at val}%
-}{\xpg at warning{Unknown Kurdish variant `#1'}}
 
 \newif\if at kurdish@latin
 \newif\if at kurdish@arabic
-\define at choicekey*+{kurdish}{script}[\xpg at val\xpg at nr]{arabic,latin}{%
-   \ifcase\xpg at 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=\xpg at 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}
@@ -87,7 +60,7 @@
          \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurdish,bcp47=ckb-Arab,bcp47-language=ckb,bcp47-script=Arab,bcp47-casing=ckb-Arab}%
      \fi
      \def\kurdish at script{latin}
-     \xpg at fontsetup@latin{kurdish}%
+     \SetupLatinPolyglossiaFont{kurdish}%
   \else
      \if at kurdish@arabic% arabic explicitly set
         \if at kurdish@kurmanji
@@ -97,16 +70,16 @@
         \else
             \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurdish,bcp47=ckb-Arab,bcp47-language=ckb,bcp47-script=Arab,bcp47-casing=ckb-Arab}%
         \fi
-        \xpg at fontsetup@nonlatin{kurdish}%
+        \SetupNonLatinPolyglossiaFont{kurdish}%
      \else% sorani=arabic, kurmanji=latin
         \if at kurdish@kurmanji
             \@western at numeralstrue%
             \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurmanji,bcp47=kmr-Latn,bcp47-language=kmr,bcp47-script=Latn,bcp47-casing=kmr-Latn}%
-            \xpg at fontsetup@latin{kurdish}%
+            \SetupLatinPolyglossiaFont{kurdish}%
             \def\kurdish at script{latin}
         \else
             \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurdish,bcp47=ckb-Arab,bcp47-language=ckb,bcp47-script=Arab,bcp47-casing=ckb-Arab}%
-            \xpg at fontsetup@nonlatin{kurdish}%
+            \SetupNonLatinPolyglossiaFont{kurdish}%
         \fi
      \fi
   \fi
@@ -113,45 +86,68 @@
 }
 
 \newif\if at western@numerals
-\define at choicekey*+{kurdish}{numerals}[\xpg at val\xpg at nr]{eastern,western}[eastern]{%
-   \ifcase\xpg at nr\relax
-      % eastern:
-      \@western at numeralsfalse%
-   \or
-      % western:
-      \@western at numeralstrue%
-      \@force at western@numeralstrue%
-   \fi
-   \xpg at info{Option: Kurdish, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Kurdish numerals option `#1'}}
 
 \newif\ifkurdish at customsep\kurdish at customsepfalse
 \def\xpg at sepmark{}
-\define at key{kurdish}{sectionsep}[.]{%
-   \kurdish at customseptrue%
-   \gdef\xpg at sepmark{#1}%
-}
 
-%this is needed for \abjad in arabicnumbers.sty
-\define at boolkey{kurdish}[kurdish@]{abjadjimnotail}[true]{%
-  \ifkurdish at abjadjimnotail
-    \abjad at jim@notailtrue%
-  \else
-    \abjad at jim@notailfalse
-  \fi%
-}
+%TODO add option for CALENDAR
 
-% NOT YET USED
-\define at key{kurdish}{locale}[default]{%
-  \def\@kurdish at locale{#1}}
+\DeclareKeys[polyglossia/gloss/kurdish]
+  {
+    variant.choice:,
+    variant / sorani.code =
+      {%
+        \def\kurdish at variant{sorani}%
+        \@kurdish at kurmanjifalse
+        \kurdish at set@variety
+      },
+    variant / kurmanji.code =
+      {%
+        \def\kurdish at variant{kurmanji}%
+        \@kurdish at kurmanjitrue
+        \kurdish at set@variety
+      },
+    variant.default:n = sorani,
+    variant/unknown.code = \xpg at warning{Unknown Kurdish variant `#1'},
+    script.choice:,
+    script / arabic.code =
+      {%
+        \@kurdish at latinfalse
+        \@kurdish at arabictrue
+        \kurdish at set@variety
+      },
+    script / latin.code =
+      {%
+        \@kurdish at latintrue
+        \@kurdish at arabicfalse
+        \kurdish at set@variety
+      },
+    script.default:n = sorani,
+    script/unknown.code = \xpg at warning{Unknown Kurdish script `#1'},
+    numerals.choice:,
+    numerals / eastern.code =
+      {%
+        \@western at numeralsfalse
+      },
+    numerals / western.code =
+      {%
+        \@western at numeralstrue
+        \@force at western@numeralstrue
+      },
+    numerals.default:n = eastern,
+    numerals/unknown.code = \xpg at warning{Unknown Kurdish numerals value `#1'},
+    sectionsep.code = \gdef\xpg at sepmark{#1}\kurdish at customseptrue,
+    sectionsep.default:n = .,
+    abjadjimnotail.if = abjad at jim@notail,
+    abjadjimnotail.default:n = true,
+    locale.store = \@kurdish at locale
+  }
 
-%TODO add option for CALENDAR
-
 % Register default options
-\xpg at initialize@gloss at options{kurdish}{variant=sorani,locale=default,script=arabic,abjadjimnotail=false,numerals=eastern}
+\InitializeGlossOptions{kurdish}{variant=sorani,locale=default,script=arabic,abjadjimnotail=false,numerals=eastern}
 
 \def\kurdish at language{%
-   \polyglossia at setup@language at patterns{\kurdish at pattern}%
+   \SetupPolyglossiaLangPatterns{\kurdish at pattern}%
 }%
 
 \def\kurdishNativemonth#1{\ifcase#1%
@@ -404,9 +400,9 @@
 }
 
 \def\nokurdish at xetex@capsformat{%
-   \ifcsdef{xpg at save@sepmark}{%
+   \ifcsname xpg at save@sepmark\endcsname%
      \SepMark{\xpg at save@sepmark}
-   }{}%
+   \fi%
 }
 
 \def\kurdish at luatex@capsformat{%
@@ -413,7 +409,7 @@
   %
   % change chapter and part headings
   \ifkurdish at customsep
-     \ifcsdef{chapter}{%
+     \ifcsname chapter\endcsname%
         \let\xpg at save@thesection\thesection%
         \renewcommand*\thesection{\thechapter\xpg at sepmark\@arabic\c at section}
         \let\xpg at save@theequation\theequation%
@@ -425,7 +421,7 @@
         \let\xpg at save@thetable\thetable%
 	\renewcommand*\thetable{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at table}
-     }{}
+     \fi%
      \let\xpg at save@thesubsection\thesubsection%
      \renewcommand\thesubsection
 	{\thesection\xpg at sepmark\@arabic\c at subsection}
@@ -440,30 +436,30 @@
 }
 
 \def\nokurdish at luatex@capsformat{%
-   \ifcsdef{xpg at save@thesection}{%
+   \ifcsname xpg at save@thesection\endcsname%
         \let\thesection\xpg at save@thesection%
-   }{}%
-   \ifcsdef{xpg at save@theequation}{%
+   \fi%
+   \ifcsname xpg at save@theequation\endcsname%
         \let\theequation\xpg at save@theequation%
-   }{}%
-   \ifcsdef{xpg at save@thefigure}{%
+   \fi%
+   \ifcsname xpg at save@thefigure\endcsname%
         \let\thefigure\xpg at save@thefigure%
-   }{}%
-   \ifcsdef{xpg at save@thetable}{%
+   \fi%
+   \ifcsname xpg at save@thetable\endcsname%
         \let\thetable\xpg at save@thetable%
-   }{}%
-   \ifcsdef{xpg at save@thesubsection}{%
+   \fi%
+   \ifcsname xpg at save@thesubsection\endcsname%
         \let\thesubsection\xpg at save@thesubsection%
-   \ifcsdef{xpg at save@thesubsubsection}{%
+      \ifcsname xpg at save@thesubsubsection\endcsname%
         \let\thesubsubsection\xpg at save@thesubsubsection%
-   }{}%
-   }{}%
-   \ifcsdef{xpg at save@theparagraph}{%
+      \fi%
+   \fi%
+   \ifcsname xpg at save@theparagraph\endcsname%
         \let\theparagraph\xpg at save@theparagraph%
-   }{}%
-   \ifcsdef{xpg at save@thesubparagraph}{%
+   \fi%
+   \ifcsname xpg at save@thesubparagraph\endcsname%
         \let\thesubparagraph\xpg at save@thesubparagraph%
-   }{}%
+   \fi%
 }
 
 \def\blockextras at kurdish{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurmanji.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurmanji.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-kurmanji.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-kurmanji.ldf}[polyglossia: module for Kurmanji Kurdish]
 
 % We provide this gloss for babel compatibility.
 
-\xpg at load@master at language{kurdish}
+\InheritGlossFile{kurdish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-classic.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-classic.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-classic.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-la-xclassic.ldf}[polyglossia: module for la-xclassic (Latin)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{latin}
+\InheritGlossFile{latin}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-ecclesia.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-ecclesia.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-ecclesia.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-la-xecclesiastic.ldf}[polyglossia: module for la-xecclesiastic (Latin)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{latin}
+\InheritGlossFile{latin}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-medieval.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-medieval.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la-x-medieval.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-la-xmedieval.ldf}[polyglossia: module for la-xmedieval (Latin)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{latin}
+\InheritGlossFile{latin}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-la.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-la.ldf}[polyglossia: module for la (Latin)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{latin}
+\InheritGlossFile{latin}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lao.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lao.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lao.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lao.ldf}[polyglossia: module for Lao]
 
@@ -22,14 +22,23 @@
 
 \newif\if at lao@numerals
 \def\tmp at lao{lao}
-\define at key{lao}{numerals}[arabic]{%
-	\def\@tmpa{#1}%
-	\ifx\@tmpa\tmp at lao\@lao at numeralstrue\else
-	  \@lao at numeralsfalse\fi
-}
 
+\DeclareKeys[polyglossia/gloss/lao]
+  {
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \@lao at numeralsfalse
+      },
+    numerals / lao.code =
+      {%
+        \@lao at numeralstrue
+      },
+    numerals.default:n = arabic
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{lao}{numerals=arabic}
+\InitializeGlossOptions{lao}{numerals=arabic}
 
 % Translations provided by Brian Wilson <bountonw at gmail.com>
 \def\captionslao{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latex.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latex.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latex.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-latex.ldf}[polyglossia: module for default language]
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latin.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latin.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latin.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-latin.ldf}[polyglossia: module for Latin]
 
@@ -33,6 +33,9 @@
 \bool_new:N \l_polyglossia_latin_use_v_bool
 \bool_new:N \l_polyglossia_latin_use_ligatures_bool
 \bool_new:N \l_polyglossia_latin_capitalize_month_bool
+\bool_new:N \l_polyglossia_latin_babelshorthands_bool
+\bool_new:N \l_polyglossia_latin_prosodic_shorthands_bool
+\bool_new:N \l_polyglossia_latin_ecclesiastic_footnotes_bool
 
 \cs_new:Npn \polyglossia_latin_classical_character_codes:
   {
@@ -68,11 +71,11 @@
 
 \cs_new:Npn \polyglossia_latin_use_modern_patterns:
   {
-    \xpg at ifdefined {latin}
+    \IfLanguageDefinedTF {latin}
       {
         \def \latin at language
           {
-            \polyglossia at setup@language at patterns {latin}
+            \SetupPolyglossiaLangPatterns {latin}
             \str_case:Vn \l_polyglossia_latin_variant_str
               {
                 {classic}      { \adddialect \l at classiclatin \l at latin }
@@ -96,11 +99,11 @@
 \cs_new:Npn \polyglossia_latin_set_patterns:n #1
 % #1 may be "classiclatin" or "liturgicallatin"
   {
-    \xpg at ifdefined {#1}
+    \IfLanguageDefinedTF {#1}
       {
         \def \latin at language
           {
-            \polyglossia at setup@language at patterns {#1}
+            \SetupPolyglossiaLangPatterns {#1}
             \str_case:Vn \l_polyglossia_latin_variant_str
               {
                 {classic}      {
@@ -316,7 +319,8 @@
 % Save original footnote definition
 % Do this at the end of the preamble to catch other
 % packages' footnote changes (#391)
-\AtEndPreamble{%
+\hook_gput_code:nnn { begindocument / before } {.}
+{
   \cs_if_exist:NT \@makefntext
     {
       \cs_set_eq:NN \polyglossia_latin_original_footnote:n \@makefntext
@@ -340,40 +344,27 @@
 
 \cs_new:Npn \polyglossia_latin_apply_footnote_option:
   {
-    \str_if_eq:VnTF \xpg at main@language {latin}
+    \IfMainLanguageTF {latin}
       {
         \cs_if_exist:NT \@makefntext
           {
-            \iflatin at ecclesiasticfootnotes
+            \bool_if:NTF \l_polyglossia_latin_ecclesiastic_footnotes_bool
+             {
               \let \@makefntext \polyglossia_latin_variant_footnote:n
-            \else
+             }
+             {
               \let \@makefntext \polyglossia_latin_original_footnote:n
-            \fi
+             }
           }
       }
       {
-        \iflatin at ecclesiasticfootnotes
-          \msg_warning:nn {polyglossia} {latin / ineffective footnote option}
-        \fi
+        \bool_if:NT \l_polyglossia_latin_ecclesiastic_footnotes_bool
+          {
+            \msg_warning:nn {polyglossia} {latin / ineffective footnote option}
+          }
       }
   }
 
-\define at boolkey {latin} [latin@] {ecclesiasticfootnotes} [true]
-  {
-    \token_if_eq_meaning:NNTF \@onlypreamble \@notprerr
-      {
-        % within the document
-        \polyglossia_latin_apply_footnote_option:
-      }
-      {
-        % within the preamble
-        % The application of the option has to be postponed as the main
-        % language may be undefined when the option is called.
-        \AtBeginDocument { \polyglossia_latin_apply_footnote_option: }
-      }
-  }
-
-
 %%%%% Language variants: classic, medieval, modern, and ecclesiastic
 
 \str_new:N \l_polyglossia_latin_variant_str
@@ -436,58 +427,6 @@
     \polyglossia_latin_use_modern_patterns:
   }
 
-\define at key{latin}{variant}
-  {
-    \str_case:nnF {#1}
-      {
-        {classic}
-        {
-          \msg_info:nnn {polyglossia} {latin / language variant} {classic}
-          \polyglossia_latin_classic_settings:
-        }
-        {medieval}
-        {
-          \msg_info:nnn {polyglossia} {latin / language variant} {medieval}
-          \polyglossia_latin_medieval_settings:
-        }
-        {modern}
-        {
-          \msg_info:nnn {polyglossia} {latin / language variant} {modern}
-          \polyglossia_latin_modern_settings:
-        }
-        {ecclesiastic}
-        {
-          \msg_info:nnn {polyglossia} {latin / language variant} {ecclesiastic}
-          \polyglossia_latin_ecclesiastic_settings:
-        }
-      }
-      {
-        \msg_warning:nnn {polyglossia} {latin / illegal language variant} {#1}
-      }
-  }
-
-
-%%%%% Boolean options concerning spelling
-
-\define at boolkey{latin}[latin@]{usej}[true]
-  {
-    \iflatin at usej
-      \bool_set_true:N \l_polyglossia_latin_use_j_bool
-    \else
-      \bool_set_false:N \l_polyglossia_latin_use_j_bool
-    \fi
-  }
-
-\define at boolkey{latin}[latin@]{capitalizemonth}[true]
-  {
-    \iflatin at capitalizemonth
-      \bool_set_true:N \l_polyglossia_latin_capitalize_month_bool
-    \else
-      \bool_set_false:N \l_polyglossia_latin_capitalize_month_bool
-    \fi
-  }
-
-
 %%%%% Hyphenation variants: classic, liturgical, and modern
 
 \msg_new:nnn {polyglossia} {latin / hyphenation variant}
@@ -500,23 +439,6 @@
     The~Latin~hyphenation~variant~"#1"~is~undefined~\msg_line_context:.
   }
 
-\define at key {latin} {hyphenation}
-  {
-    \str_case:nnTF {#1}
-      {
-        {classic}    { \polyglossia_latin_set_patterns:n {classiclatin} }
-        {liturgical} { \polyglossia_latin_set_patterns:n {liturgicallatin} }
-        {modern}     { \polyglossia_latin_use_modern_patterns: }
-      }
-      {
-        \msg_info:nnn {polyglossia} {latin / hyphenation variant} {#1}
-      }
-      {
-        \msg_warning:nnn {polyglossia} {latin / illegal hyphenation variant} {#1}
-      }
-  }
-
-
 %%%%% Latin captions and date
 
 \def \captionslatin
@@ -588,30 +510,89 @@
       }
   }
 
-
-%%%%% Latin shorthands
-
-\define at boolkey{latin}[latin@]{babelshorthands}[true]
+\DeclareKeys[polyglossia/gloss/latin]
   {
+    babelshorthands.bool_set:N = \l_polyglossia_latin_babelshorthands_bool,
+    babelshorthands.default:n = true,
+    prosodicshorthands.bool_set:N = \l_polyglossia_latin_prosodic_shorthands_bool,
+    prosodicshorthands.default:n = true,
+    usej.bool_set:N = \l_polyglossia_latin_use_j_bool,
+    capitalizemonth.bool_set:N = \l_polyglossia_latin_capitalize_month_bool,
+    hyphenation.code = 
+    	\str_case:nnTF {#1}
+      {
+        {classic}    { \polyglossia_latin_set_patterns:n {classiclatin} }
+        {liturgical} { \polyglossia_latin_set_patterns:n {liturgicallatin} }
+        {modern}     { \polyglossia_latin_use_modern_patterns: }
+      }
+      {
+        \msg_info:nnn {polyglossia} {latin / hyphenation variant} {#1}
+      }
+      {
+        \msg_warning:nnn {polyglossia} {latin / illegal hyphenation variant} {#1}
+      },
+    variant.code = 
+    	  \str_case:nnF {#1}
+      {
+        {classic}
+        {
+          \msg_info:nnn {polyglossia} {latin / language variant} {classic}
+          \polyglossia_latin_classic_settings:
+        }
+        {medieval}
+        {
+          \msg_info:nnn {polyglossia} {latin / language variant} {medieval}
+          \polyglossia_latin_medieval_settings:
+        }
+        {modern}
+        {
+          \msg_info:nnn {polyglossia} {latin / language variant} {modern}
+          \polyglossia_latin_modern_settings:
+        }
+        {ecclesiastic}
+        {
+          \msg_info:nnn {polyglossia} {latin / language variant} {ecclesiastic}
+          \polyglossia_latin_ecclesiastic_settings:
+        }
+      }
+      {
+        \msg_warning:nnn {polyglossia} {latin / illegal language variant} {#1}
+      },
+    ecclesiasticfootnotes.choices:nn = { true, false }
+      { 
+        \ifcase\UseName{l_keys_choice_int}\or
+           \bool_set_true:N \l_polyglossia_latin_ecclesiastic_footnotes_bool
+        \else
+          \bool_set_false:N \l_polyglossia_latin_ecclesiastic_footnotes_bool
+        \fi
+        \xpg_if_in_preamble:TF
+          {
+            % within the preamble
+            % The application of the option has to be postponed as the main
+            % language may be undefined when the option is called.
+            \AtBeginDocument { \polyglossia_latin_apply_footnote_option: }
+          }
+          {
+            % within the document
+            \polyglossia_latin_apply_footnote_option:
+          }
+      },
+    ecclesiasticfootnotes.default:n = true
   }
 
-\define at boolkey{latin}[latin@]{prosodicshorthands}[true]
-  {
-  }
-
 % Register default options
-\xpg at initialize@gloss at options{latin}{variant=modern,hyphenation=modern,babelshorthands=false,
+\InitializeGlossOptions{latin}{variant=modern,hyphenation=modern,babelshorthands=false,
                                      prosodicshorthands=false,ecclesiasticfootnotes=false,
                                      usej=false,capitalizemonth=true}
 
 \ifsystem at babelshorthands
-  \setkeys{latin}{babelshorthands=true}
+  \SetGlossOptions{latin}{babelshorthands=true}
 \else
-  \setkeys{latin}{babelshorthands=false}
+  \SetGlossOptions{latin}{babelshorthands=false}
 \fi
 
 \ExplSyntaxOff % babelsh.def does not support expl3 syntax
-\ifcsundef{initiate at active@char}{\input{babelsh.def}}{}
+\@ifundefined{initiate at active@char}{\input{babelsh.def}}{}
 \ExplSyntaxOn
 
 \initiate at active@char {"}
@@ -643,13 +624,13 @@
 
 \AtBeginDocument
   {
-    \str_if_eq:VnTF \xpg at main@language {latin}
+    \IfMainLanguageTF {latin}
       {
-        \iflatin at prosodicshorthands
-        \else
+        \bool_if:NF \l_polyglossia_latin_prosodic_shorthands_bool
+         {
           \shorthandoff {=}
           \shorthandoff* {^}
-        \fi
+         }
       }
       {
         % The following command should not be called if the main language
@@ -1011,7 +992,7 @@
 
 \let \xpgla at savedvalues \empty
 
-\AtEndPreamble
+\hook_gput_code:nnn { begindocument / before } {.}
   {
     \edef \xpgla at savedvalues
       {
@@ -1024,12 +1005,14 @@
 
 \def \noextras at latin
   {
-    \iflatin at babelshorthands
+    \bool_if:NT \l_polyglossia_latin_babelshorthands_bool
+     {
       \polyglossia_latin_no_shorthands:
-    \fi
-    \iflatin at prosodicshorthands
+     }
+    \bool_if:NT \l_polyglossia_latin_prosodic_shorthands_bool
+     {
       \polyglossia_latin_no_prosodic_shorthands:
-    \fi
+     }
     \xpgla at savedvalues
     \polyglossia_latin_no_punctuation_spacing:
     \polyglossia_latin_modern_character_codes:
@@ -1045,16 +1028,20 @@
       {
         \polyglossia_latin_punctuation_spacing:
       }
-    \iflatin at babelshorthands
+    \bool_if:NTF \l_polyglossia_latin_babelshorthands_bool
+     {
       \polyglossia_latin_shorthands:
-    \else
+     }
+     {
       \polyglossia_latin_no_shorthands:
-    \fi
-    \iflatin at prosodicshorthands
+     }
+    \bool_if:NTF \l_polyglossia_latin_prosodic_shorthands_bool
+     {
       \polyglossia_latin_prosodic_shorthands:
-    \else
+     }
+     { 
       \polyglossia_latin_no_prosodic_shorthands:
-    \fi
+     }
   }
 
 \def \blockextras at latin

Deleted: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinclassic.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinclassic.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinclassic.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +0,0 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
-%
-\ProvidesFile{gloss-latinclassic.ldf}[polyglossia: module for classic Latin]
-
-% We provide this as a babel alias
-
-\xpg at load@master at language{latin}
-
-\endinput

Deleted: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinecclesiastic.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinecclesiastic.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinecclesiastic.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +0,0 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
-%
-\ProvidesFile{gloss-latinecclesiastic.ldf}[polyglossia: module for ecclesiastic Latin]
-
-% We provide this as a babel alias
-
-\xpg at load@master at language{latin}
-
-\endinput

Deleted: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinmedieval.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinmedieval.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latinmedieval.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +0,0 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
-%
-\ProvidesFile{gloss-latinmedieval.ldf}[polyglossia: module for medieval Latin]
-
-% We provide this as a babel alias
-
-\xpg at load@master at language{latin}
-
-\endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latvian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latvian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-latvian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-latvian.ldf}[polyglossia: module for Latvian]
 \PolyglossiaSetup{latvian}{
@@ -25,12 +25,12 @@
    \def\contentsname{Saturs}%
    \def\listfigurename{Attēlu saraksts}%
    \def\listtablename{Tabulu saraksts}%
-   \def\indexname{Index}%
+   \def\indexname{Priekšmetu rādītājs}%
    \def\figurename{Att.}%
    \def\tablename{Tabula}%
    \def\partname{Daļa}%
-   \def\enclname{encl}%
-   \def\ccname{cc}%
+   \def\enclname{Pielikumā}%
+   \def\ccname{Kopija(s)}%
    \def\headtoname{To}%
    \def\pagename{lpp.}%
    \def\seename{sk.}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lithuanian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lithuanian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lithuanian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Translated by Paulius Sladkevičius <komsas at gmail.com>
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lo.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lo.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lo.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lo.ldf}[polyglossia: module for lo (Lao)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{lao}
+\InheritGlossFile{lao}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lowersorbian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lowersorbian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lowersorbian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lowersorbian.ldf}[polyglossia: module for Lower Sorbian]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lsorbian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lsorbian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lsorbian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lsorbian.ldf}[polyglossia: module for Lower Sorbian]
 
@@ -5,6 +5,6 @@
 % We only provide this gloss for babel compatibility. Since lsorbian is 
 % a sorbian variety, we use 'sorbian' with variant 'lower' now.
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lt.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lt.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lt.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lt.ldf}[polyglossia: module for lt (Lithuanian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{lithuanian}
+\InheritGlossFile{lithuanian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lv.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lv.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-lv.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-lv.ldf}[polyglossia: module for lv (Latvian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{latvian}
+\InheritGlossFile{latvian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-macedonian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-macedonian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-macedonian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-macedonian.ldf}[polyglossia: module for Macedonian]
 \PolyglossiaSetup{macedonian}{

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-magyar.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-magyar.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-magyar.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-magyar.ldf}[polyglossia: module for Hungarian (Magyar)]
 
 % We only provide this gloss for babel compatibility.
 
-\xpg at load@master at language{hungarian}
+\InheritGlossFile{hungarian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malay.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malay.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malay.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-malay.ldf}[polyglossia: module for Malay]
 
@@ -26,65 +26,44 @@
 % Backwards compat. alias
 \setlanguagealias[variant=malaysian]{malay}{bahasam}
 
-\providebool{malay at melayu}
+\@ifundefined{ifmalay at melayu}%
+  {\newif\ifmalay at melayu}{}
 \malay at melayufalse
 \def\malay at variant{malay}
-\define at choicekey*+{malay}{variant}[\xpg at val\xpg at nr]{indonesian,malaysian}[malaysian]{%
-   \ifcase\xpg at 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,bcp47=zsm,bcp47-language=zsm}%
-      \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,bcp47=id,bcp47-language=id}%
-      \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=\xpg at val}%
-}{\xpg at warning{Unknown malay variant `#1'}}
 
+\DeclareKeys[polyglossia/gloss/malay]
+  {
+    variant.choice:,
+    variant / indonesian.code = 
+      {%
+        \def\malay at variant{indonesian}%
+        \malay at melayufalse
+        \SetLanguageKeys{malay}{language=Indonesian,langtag=IND,babelname=bahasa,bcp47=id,bcp47-language=id}%
+        \SetupLatinPolyglossiaFont{malay}%
+        % Check if \l at indonesian is defined. If not, try to set it to some variety
+        % (specific order as in the csv list), or null language if everything fails
+        \TryPatternWithFallback{indonesian}{indon,bahasai,bahasam,malay,melayu,bahasa}%
+      },
+    variant / malaysian.code =
+      {%
+        \def\malay at variant{malay}%
+        \malay at melayutrue
+        \SetLanguageKeys{malay}{language=Malay,langtag=MLY,babelname=bahasam,bcp47=zsm,bcp47-language=zsm}%
+        \SetupLatinPolyglossiaFont{malay}%
+        % Check if \l at malay is defined. If not, try to set it to some variety
+        % (specific order as in the csv list), or null language if everything fails
+        \TryPatternWithFallback{malay}{melayu,bahasam,bahasai,indonesian,indon,bahasa}%
+      },
+    variant.default:n = malaysian,
+    variant/unknown.code = \xpg at warning{Unknown malay variant `#1'},
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{malay}{variant=malaysian}
+\InitializeGlossOptions{malay}{variant=malaysian}
 
 
 \def\malay at language{%
-   \polyglossia at setup@language at patterns{\malay at variant}%
+   \SetupPolyglossiaLangPatterns{\malay at variant}%
 }%
 
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malayalam.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malayalam.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-malayalam.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-malayalam.ldf}[polyglossia: module for Malayalam]
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-marathi.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-marathi.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-marathi.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Translations provided by Abhijit Navale <abhi_navale at live.in>
 % Ordinals (1-100) added by Niranjan Tambe <niranjanvikastambe at gmail.com> on 14th December, 2019
@@ -28,21 +28,25 @@
 \newif\ifmarathi at devanagari@numerals
 \marathi at devanagari@numeralstrue
 
-\define at choicekey*+{marathi}{numerals}[\xpg at val\xpg at nr]{Western,Devanagari}[Devanagari]{%
-   \ifcase\xpg at nr\relax
-      % Western:
-      \marathi at devanagari@numeralsfalse%
-      \SetLanguageKeys{marathi}{bcp47-extension-u=nu-latn}%
-   \or
-      % Devanagari:
-      \marathi at devanagari@numeralstrue%
-      \SetLanguageKeys{marathi}{bcp47-extension-u=nu-deva}%
-   \fi
-   \xpg at info{Option: Marathi, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Marathi numerals value `#1'}}
+\DeclareKeys[polyglossia/gloss/marathi]
+  {
+    numerals.choice:,
+    numerals / western.code =
+      {%
+        \marathi at devanagari@numeralsfalse
+        \SetLanguageKeys{marathi}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / devanagari.code =
+      {%
+        \marathi at devanagari@numeralstrue
+        \SetLanguageKeys{marathi}{bcp47-extension-u=nu-deva}%
+      },
+    numerals.default:n = devanagari,
+    numerals/unknown.code = \xpg at warning{Unknown Marathi numerals value `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{marathi}{numerals=Devanagari}
+\InitializeGlossOptions{marathi}{numerals=Devanagari}
 
 \newcommand{\marathinumerals}[2]{\marathinumber{#2}}
 

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-medievallatin.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-medievallatin.ldf	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-medievallatin.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -0,0 +1,9 @@
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
+%
+\ProvidesFile{gloss-medievallatin.ldf}[polyglossia: module for medieval Latin]
+
+% We provide this as a babel alias
+
+\InheritGlossFile{latin}
+
+\endinput


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-medievallatin.ldf
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mk.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mk.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mk.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-mk.ldf}[polyglossia: module for mk (Macedonian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{macedonian}
+\InheritGlossFile{macedonian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ml.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ml.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ml.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ml.ldf}[polyglossia: module for ml (Malayalam)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{malayalam}
+\InheritGlossFile{malayalam}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mn.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mn.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mn.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-mn.ldf}[polyglossia: module for mn (Mongolian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{mongolian}
+\InheritGlossFile{mongolian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mongolian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mongolian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mongolian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-mongolian.ldf}[polyglossia: module for Mongolian]
 
@@ -30,43 +30,46 @@
 
 \newif\ifcyrillic at numerals
 \newif\ifcyrillic at asbuk@numerals
-\define at choicekey*+{mongolian}{numerals}[\xpg at val\xpg at nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % arabic:
-      \cyrillic at numeralsfalse%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic-trad:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-   \or
-      % cyrillic-alph:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralstrue%
-   \fi
-   \xpg at info{Option: Mongolian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Mongolian numerals value `#1'}}
 
-\define at boolkey{mongolian}[mongolian@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/mongolian]
+  {
+    babelshorthands.if = mongolian at babelshorthands,
+    babelshorthands.default:n = true,
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \cyrillic at numeralsfalse
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic-trad.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+      },
+    numerals / cyrillic-alph.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralstrue
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Mongolian numerals value `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{mongolian}{babelshorthands=false,numerals=arabic}
+\InitializeGlossOptions{mongolian}{babelshorthands=false,numerals=arabic}
 
 \ifsystem at babelshorthands
-  \setkeys{mongolian}{babelshorthands=true}
+  \SetGlossOptions{mongolian}{babelshorthands=true}
 \else
-  \setkeys{mongolian}{babelshorthands=false}
+  \SetGlossOptions{mongolian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\mongolian at shorthands{%
   \xpg at activate@shorthands%
@@ -119,7 +122,7 @@
    \def\bibname{Номзүй}%
    \def\chaptername{Бүлэг}%
    \def\appendixname{Хавсралт}%
-   \ifcsundef{thechapter}%
+   \@ifundefined{thechapter}%
      {\def\contentsname{Агуулга}}%
      {\def\contentsname{Гарчиг}}%
    \def\listfigurename{Зургийн жагсаалт}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mr.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mr.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-mr.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-mr.ldf}[polyglossia: module for mr (Marathi)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{marathi}
+\InheritGlossFile{marathi}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-naustrian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-naustrian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-naustrian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-naustrian.ldf}[polyglossia: module for Austrian German (current spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nb.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nb.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nb.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-nb.ldf}[polyglossia: module for nb (Norwegian)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{norwegian}
+\InheritGlossFile{norwegian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-newzealand.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-newzealand.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-newzealand.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-newzealand.ldf}[polyglossia: module for Newzealand English]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{english}
+\InheritGlossFile{english}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ngerman.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ngerman.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ngerman.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ngerman.ldf}[polyglossia: module for German (current spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nko.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nko.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nko.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-nko.ldf}[Polyglossia: module for N’Ko]
 \PolyglossiaSetup{nko}{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norsk.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norsk.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norsk.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-norsk.ldf}[polyglossia: module for Norwegian (Bokmal)]
 
@@ -5,7 +5,7 @@
 % We only provide this gloss for babel compatibility. Since norsk is 
 % actually norwegian bokmal, we use 'norwegian' with variant 'bokmal' now.
 
-\xpg at load@master at language{norwegian}
+\InheritGlossFile{norwegian}
 
 \endinput
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norwegian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norwegian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-norwegian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-norwegian.ldf}[polyglossia: module for Norwegian]
 \PolyglossiaSetup{norwegian}{
@@ -20,28 +20,32 @@
 \setlanguagealias[variant=nynorsk]{norwegian}{nynorsk}
 
 \def\norwegian at variant{nynorsk}
-\define at choicekey*+{norwegian}{variant}[\xpg at val\xpg at nr]{nynorsk,bokmal}[nynorsk]{%
-   \ifcase\xpg at nr\relax
-      % nynorsk:
-      \def\norwegian at variant{nynorsk}%
-      \SetLanguageKeys{norwegian}{langtag=NYN,babelname=nynorsk,bcp47=nn,bcp47-language=nn}%
-      \xpg at fontsetup@latin{norwegian}%
-   \or
-      % bokmal:
-      \def\norwegian at variant{norsk}%
-      \SetLanguageKeys{norwegian}{langtag=NOR,babelname=norsk,bcp47=nb,bcp47-language=nb}%
-      \xpg at fontsetup@latin{norwegian}%
-   \fi
-   \xpg at info{Option: norwegian, variant=\xpg at val}%
-}{\xpg at warning{Unknown norwegian variant `#1'}}
 
+\DeclareKeys[polyglossia/gloss/norwegian]
+  {
+    variant.choice:,
+    variant / nynorsk.code =
+      {%
+          \def\norwegian at variant{nynorsk}%
+          \SetLanguageKeys{norwegian}{langtag=NYN,babelname=nynorsk,bcp47=nn,bcp47-language=nn}%
+          \SetupLatinPolyglossiaFont{norwegian}%
+      },
+    variant / bokmal.code =
+      {%
+          \def\norwegian at variant{norsk}%
+          \SetLanguageKeys{norwegian}{langtag=NOR,babelname=norsk,bcp47=nb,bcp47-language=nb}%
+          \SetupLatinPolyglossiaFont{norwegian}%
+      },
+    variant.default:n = nynorsk,
+    variant/unknown.code = \xpg at warning{Unknown norwegian variant `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{norwegian}{variant=nynorsk}
+\InitializeGlossOptions{norwegian}{variant=nynorsk}
 
 
 \def\norwegian at language{%
-   \polyglossia at setup@language at patterns{\norwegian at variant}%
+   \SetupPolyglossiaLangPatterns{\norwegian at variant}%
 }%
 
 \def\captionsnorwegian at nynorsk{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nswissgerman.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nswissgerman.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nswissgerman.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-nswissgerman.ldf}[polyglossia: module for Swiss German (current spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nynorsk.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nynorsk.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-nynorsk.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-nynorsk.ldf}[polyglossia: module for Norwegian (Nynorsk)]
 
@@ -5,7 +5,7 @@
 % We only provide this gloss for babel compatibility. Since nynorsk is 
 % a norwegian variety, we use 'norwegian' with variant 'nynorsk' now.
 
-\xpg at load@master at language{norwegian}
+\InheritGlossFile{norwegian}
 
 \endinput
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-occitan.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-occitan.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-occitan.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 %%
 %% This is file `gloss-occitan.ldf',
@@ -34,19 +34,19 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{occitan}{oc}
 
-\define at boolkey{occitan}[occitan@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/occitan]
+  {
+    babelshorthands.if = occitan at babelshorthands,
+    babelshorthands.default:n = true
+  }
 
 \ifsystem at babelshorthands
-  \setkeys{occitan}{babelshorthands=true}
+  \SetGlossOptions{occitan}{babelshorthands=true}
 \else
-  \setkeys{occitan}{babelshorthands=false}
+  \SetGlossOptions{occitan}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\occitan at shorthands{%
   \xpg at activate@shorthands%
@@ -138,7 +138,7 @@
    \def\today{\occitanday\space \occitanmonth\space de~\number\year}%
 }
 \let\xpgoc at savedvalues\empty
-\AtEndPreamble{% the user or the class might define different values
+\AddToHook{begindocument/before}{% the user or the class might define different values
   \edef\xpgoc at savedvalues{%
     \clubpenalty=\the\clubpenalty\space
     \@clubpenalty=\the\@clubpenalty\space

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-odia.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-odia.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-odia.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % Translations provided by ଅଶୋକ ଦାସ୍ <das at pas.rochester.edu> and ଅଭିଷେକ ଜେନା <avisekjena at gmail.com>
 % TODO implement Odia calendar
@@ -30,32 +30,37 @@
 
 \newif\ifodia at devanagari@numerals
 \newif\ifodia at odia@numerals
-\define at choicekey*+{odia}{numerals}[\xpg at val\xpg at nr]{Devanagari,Odia,Western}[Devanagari]{%
-   \ifcase\xpg at nr\relax
-      % Devanagari:
-      \odia at odia@numeralsfalse%
-      \odia at devanagari@numeralstrue%
-      \SetLanguageKeys{odia}{bcp47=or,bcp47-language=or,bcp47-extension-u=nu-deva}%
-   \or
-      % Odia:
-      \odia at odia@numeralstrue%
-      \odia at devanagari@numeralsfalse%
-   \or
-      % Western:
-      \odia at odia@numeralsfalse%
-      \odia at devanagari@numeralsfalse%
-      \SetLanguageKeys{odia}{bcp47=or,bcp47-language=or,bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Odia, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Odia numeral `#1'}}
-
 \def\extras at odia{}
 \def\noextras at odia{}
 
-\define at boolkey{odia}[odia@]{changecounternumbering}[true]{}
+\DeclareKeys[polyglossia/gloss/odia]
+  {
+    changecounternumbering.if = odia at changecounternumbering,
+    changecounternumbering.default:n = true,
+    numerals.choice:,
+    numerals / devanagari.code =
+      {%
+        \odia at odia@numeralsfalse
+        \odia at devanagari@numeralstrue
+        \SetLanguageKeys{odia}{bcp47=or,bcp47-language=or,bcp47-extension-u=nu-deva}%
+      },
+    numerals / odia.code =
+      {%
+        \odia at odia@numeralstrue
+        \odia at devanagari@numeralsfalse
+      },
+    numerals / western.code =
+      {%
+        \odia at odia@numeralsfalse
+        \odia at devanagari@numeralsfalse
+        \SetLanguageKeys{odia}{bcp47=or,bcp47-language=or,bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = devanagari,
+    numerals/unknown.code = \xpg at warning{Unknown Odia numeral `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{odia}{changecounternumbering=false,numerals=Devanagari}
+\InitializeGlossOptions{odia}{changecounternumbering=false,numerals=Devanagari}
 
 \def\captionsodia{%
   \def\refname{ସନ୍ଦର୍ଭ}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-or.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-or.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-or.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-odia.ldf}[polyglossia: module for or (Odia)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{odia}
+\InheritGlossFile{odia}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-pa.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-pa.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-pa.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-pa.ldf}[polyglossia: module for pa (Punjabi)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{punjabi}
+\InheritGlossFile{punjabi}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-persian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-persian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-persian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-persian.ldf}[polyglossia: module for Persian]
 
@@ -27,42 +27,36 @@
 \setlanguagealias{persian}{farsi}
 
 \newif\if at western@numerals
-\define at choicekey*+{persian}{numerals}[\xpg at val\xpg at nr]{eastern,western}[eastern]{%
-   \ifcase\xpg at nr\relax
-      % eastern:
-      \@western at numeralsfalse%
-      \SetLanguageKeys{persian}{bcp47-extension-u=nu-arab}%
-   \or
-      % western:
-      \@western at numeralstrue%
-      \SetLanguageKeys{persian}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Persian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Persian numerals option `#1'}}
-
 \newif\ifpersian at customsep\persian at customsepfalse
 \def\xpg at sepmark{}
-\define at key{persian}{sectionsep}[.]{%
-   \persian at customseptrue%
-   \gdef\xpg at sepmark{#1}%
-}
 
-%this is needed for \abjad in arabicnumbers.sty
-\define at boolkey{persian}[persian@]{abjadjimnotail}[true]{%
-  \ifpersian at abjadjimnotail
-    \abjad at jim@notailtrue%
-  \else
-    \abjad at jim@notailfalse
-  \fi}
+%TODO add option for CALENDAR
 
-% NOT YET USED
-\define at key{persian}{locale}[default]{%
-  \def\@persian at locale{#1}}
+\DeclareKeys[polyglossia/gloss/persian]
+  {
+    sectionsep.code = \gdef\xpg at sepmark{#1}\persian at customseptrue,
+    sectionsep.default:n = .,
+    abjadjimnotail.if = abjad at jim@notail,
+    abjadjimnotail.default:n = true,
+    locale.store = \@persian at locale,
+    locale.default:n = default,
+    numerals.choice:,
+    numerals / eastern.code =
+      {%
+          \@western at numeralsfalse
+          \SetLanguageKeys{persian}{bcp47-extension-u=nu-arab}%
+      },
+    numerals / western.code =
+      {%
+          \@western at numeralstrue
+          \SetLanguageKeys{persian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = eastern,
+    numerals/unknown.code = \xpg at warning{Unknown Persian numerals option `#1'}
+  }
 
-%TODO add option for CALENDAR
-
 % Register default options
-\xpg at initialize@gloss at options{persian}{locale=default,numerals=eastern,abjadjimnotail=false}
+\InitializeGlossOptions{persian}{locale=default,numerals=eastern,abjadjimnotail=false}
 
 \def\farsigregmonth#1{\ifcase#1%
   \or ژانویه\or فوریه\or مارس\or آوریل\or مه\or ژوئن\or ژوئیه\or اوت\or سپتامبر\or اکتبر\or نوامبر\or دسامبر\fi}
@@ -147,9 +141,9 @@
 }
 
 \def\nopersian at xetex@capsformat{%
-   \ifcsdef{xpg at save@sepmark}{%
+   \ifcsname xpg at save@sepmark\endcsname%
      \SepMark{\xpg at save@sepmark}
-   }{}%
+   \fi%
 }
 
 \def\persian at luatex@capsformat{%
@@ -156,7 +150,7 @@
   %
   % change chapter and part headings
   \ifpersian at customsep
-     \ifcsdef{chapter}{%
+     \ifcsname chapter\endcsname%
         \let\xpg at save@thesection\thesection%
         \renewcommand*\thesection{\thechapter\xpg at sepmark\@arabic\c at section}
         \let\xpg at save@theequation\theequation%
@@ -168,7 +162,7 @@
         \let\xpg at save@thetable\thetable%
 	\renewcommand*\thetable{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at table}
-     }{}
+     \fi%
      \let\xpg at save@thesubsection\thesubsection%
      \renewcommand\thesubsection
 	{\thesection\xpg at sepmark\@arabic\c at subsection}
@@ -183,30 +177,30 @@
 }
 
 \def\nopersian at luatex@capsformat{%
-   \ifcsdef{xpg at save@thesection}{%
+   \ifcsname xpg at save@thesection\endcsname%
         \let\thesection\xpg at save@thesection%
-   }{}%
-   \ifcsdef{xpg at save@theequation}{%
+   \fi%
+   \ifcsname xpg at save@theequation\endcsname%
         \let\theequation\xpg at save@theequation%
-   }{}%
-   \ifcsdef{xpg at save@thefigure}{%
+   \fi%
+   \ifcsname xpg at save@thefigure\endcsname%
         \let\thefigure\xpg at save@thefigure%
-   }{}%
-   \ifcsdef{xpg at save@thetable}{%
+   \fi%
+   \ifcsname xpg at save@thetable\endcsname%
         \let\thetable\xpg at save@thetable%
-   }{}%
-   \ifcsdef{xpg at save@thesubsection}{%
+   \fi%
+   \ifcsname xpg at save@thesubsection\endcsname%
         \let\thesubsection\xpg at save@thesubsection%
-   \ifcsdef{xpg at save@thesubsubsection}{%
+      \ifcsname xpg at save@thesubsubsection\endcsname%
         \let\thesubsubsection\xpg at save@thesubsubsection%
-   }{}%
-   }{}%
-   \ifcsdef{xpg at save@theparagraph}{%
+      \fi%
+   \fi%
+   \ifcsname xpg at save@theparagraph\endcsname%
         \let\theparagraph\xpg at save@theparagraph%
-   }{}%
-   \ifcsdef{xpg at save@thesubparagraph}{%
+   \fi%
+   \ifcsname xpg at save@thesubparagraph\endcsname%
         \let\thesubparagraph\xpg at save@thesubparagraph%
-   }{}%
+   \fi%
 }
 
 \def\blockextras at persian{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-piedmontese.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-piedmontese.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-piedmontese.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,5 +1,5 @@
 % !TEX encoding = UTF-8 Unicode
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-piedmontese.ldf}[2013/02/12 v1.0 polyglossia: module for Piedmontese]
 \makeatletter
@@ -17,19 +17,19 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{piedmontese}{pms}
 
-\define at boolkey{piedmontese}[piedmontese@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/piedmontese]
+  {
+    babelshorthands.if = piedmontese at babelshorthands,
+    babelshorthands.default:n = true
+  }
 
 \ifsystem at babelshorthands
-  \setkeys{piedmontese}{babelshorthands=true}
+  \SetGlossOptions{piedmontese}{babelshorthands=true}
 \else
-  \setkeys{piedmontese}{babelshorthands=false}
+  \SetGlossOptions{piedmontese}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\piedmontese at shorthands{%
   \xpg at activate@shorthands%
@@ -93,7 +93,7 @@
       ëd luj\or d'agost\or dë stèmber\or d'otóber\or ëd novèmber\or dë dzèmber%
       \fi\space dal\space\number\year}}
       
-\AtEndPreamble{% 
+\AddToHook{begindocument/before}{% 
   \edef\xpgpms at savedvalues{%
     \clubpenalty=\the\clubpenalty\space
     \@clubpenalty=\the\@clubpenalty\space

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-polish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-polish.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-polish.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-polish.ldf}[polyglossia: module for Polish]
 
@@ -20,26 +20,26 @@
   \RequirePackage{luavlna}
 \fi
 
-\define at boolkey{polish}[polish@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/polish]
+  {
+    babelshorthands.if = polish at babelshorthands,
+    babelshorthands.default:n = true,
+    splithyphens.if = polish at splithyphens,
+    splithyphens.default:n = true,
+    vlna.if = polish at vlna,
+    vlna.default:n = true,
+  }
 
-\define at boolkey{polish}[polish@]{splithyphens}[true]{}
-
-\define at boolkey{polish}[polish@]{vlna}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{polish}{babelshorthands=false,splithyphens=true,vlna=true}
+\InitializeGlossOptions{polish}{babelshorthands=false,splithyphens=true,vlna=true}
 
 \ifsystem at babelshorthands
-  \setkeys{polish}{babelshorthands=true}
+  \SetGlossOptions{polish}{babelshorthands=true}
 \else
-  \setkeys{polish}{babelshorthands=false}
+  \SetGlossOptions{polish}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \let\xpg at hyphen@char-
 \def\polish@@splhyphen#1{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-polutonikogreek.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-polutonikogreek.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-polutonikogreek.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-polutonikogreek.ldf}[polyglossia: module for polytonic Greek]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{greek}
+\InheritGlossFile{greek}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuges.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuges.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuges.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-portuges.ldf}[polyglossia: module for Portuguese]
 
@@ -7,6 +7,6 @@
 % introduced it in 8.3 filename times). Since polyglossia uses full
 % English language names, we use 'portuguese' now.
 
-\xpg at load@master at language{portuguese}
+\InheritGlossFile{portuguese}
      
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuguese.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuguese.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-portuguese.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-portuguese.ldf}[polyglossia: module for Portuguese]
 
@@ -28,41 +28,42 @@
 \fi
 
 \def\portuguese at variant{portuges}
-\define at choicekey*+{portuguese}{variant}[\xpg at val\xpg at nr]{portuguese,brazilian}[portuguese]{%
-   \ifcase\xpg at nr\relax
-      % portuguese:
-      \def\portuguese at variant{portuges}%
-      \SetLanguageKeys{portuguese}{babelname=portuges,bcp47=pt-PT,bcp47-language=pt,bcp47-region=PT}%
-   \or
-      % brazilian:
-      \def\portuguese at variant{brazil}%
-      \SetLanguageKeys{portuguese}{babelname=brazil,bcp47=pt-BR,bcp47-language=pt,bcp47-region=BR}%
-      % There are no specific brazil patterns
-      \adddialect\l at brazil\l at portuges\relax%
-   \fi
-   \xpg at info{Option: portuguese, variant=\xpg at val}%
-}{\xpg at warning{Unknown portuguese variant `#1'}}
 
-\define at boolkey{portuguese}[portuguese@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/portuguese]
+  {
+    babelshorthands.if = portuguese at babelshorthands,
+    babelshorthands.default:n = true,
+    splithyphens.if = portuguese at splithyphens,
+    splithyphens.default:n = true,
+    variant.choice:,
+    variant / portuguese.code =
+      {%
+        \def\portuguese at variant{portuges}%
+        \SetLanguageKeys{portuguese}{babelname=portuges,bcp47=pt-PT,bcp47-language=pt,bcp47-region=PT}%
+      },
+    variant / brazilian.code =
+      {%
+        \def\portuguese at variant{brazil}%
+        \SetLanguageKeys{portuguese}{babelname=brazil,bcp47=pt-BR,bcp47-language=pt,bcp47-region=BR}%
+        % There are no specific brazil patterns
+        \adddialect\l at brazil\l at portuges\relax
+      },
+    variant.default:n = portuguese,
+    variant/unknown.code = \xpg at warning{Unknown portuguese variant `#1'},
+  }
 
-\define at boolkey{portuguese}[portuguese@]{splithyphens}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{portuguese}{variant=portuguese,
+\InitializeGlossOptions{portuguese}{variant=portuguese,
       babelshorthands=false,
       splithyphens=true}
 
 \ifsystem at babelshorthands
-  \setkeys{portuguese}{babelshorthands=true}
+  \SetGlossOptions{portuguese}{babelshorthands=true}
 \else
-  \setkeys{portuguese}{babelshorthands=false}
+  \SetGlossOptions{portuguese}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \let\xpg at hyphen@char-
 \def\portuguese@@splhyphen#1{%
@@ -131,7 +132,7 @@
 }
 
 \def\portuguese at language{%
-   \polyglossia at setup@language at patterns{\portuguese at variant}%
+   \SetupPolyglossiaLangPatterns{\portuguese at variant}%
 }%
 
 \def\captionsportuguese at portuges{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-punjabi.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-punjabi.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-punjabi.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 % UTF-8 strings kindly provided by 
 % Arvinder Singh Kang, <17-11-2022>
@@ -25,26 +25,31 @@
 
 \def\punjabi at language{%
   % patterns are spelled panjabi
-  \polyglossia at setup@language at patterns{panjabi}%
+  \SetupPolyglossiaLangPatterns{panjabi}%
 }
 
 \newif\ifpunjabi at gurmukhi@numerals
 \punjabi at gurmukhi@numeralstrue
-\define at choicekey*+{punjabi}{numerals}[\xpg at val\xpg at nr]{Gurmukhi,Western}[Gurmukhi]{%
-   \ifcase\xpg at nr\relax
-      % Gurmukhi:
-      \punjabi at gurmukhi@numeralstrue%
-      \SetLanguageKeys{punjabi}{bcp47-extension-u=nu-guru}%
-   \or
-      % Western:
-      \punjabi at gurmukhi@numeralsfalse%
-      \SetLanguageKeys{punjabi}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Punjabi, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Punjabi numeral `#1'}}
 
+\DeclareKeys[polyglossia/gloss/punjabi]
+  {
+    numerals.choice:,
+    numerals / gurmukhi.code =
+      {%
+        \punjabi at gurmukhi@numeralstrue
+        \SetLanguageKeys{punjabi}{bcp47-extension-u=nu-guru}%
+      },
+    numerals / western.code =
+      {%
+        \punjabi at gurmukhi@numeralsfalse
+        \SetLanguageKeys{punjabi}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = gurmukhi,
+    numerals/unknown.code = \xpg at warning{Unknown Punjabi numeral `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{punjabi}{numerals=gurmukhi}
+\InitializeGlossOptions{punjabi}{numerals=gurmukhi}
 
 \newcommand{\punjabinumerals}[2]{\punjabinumber{#2}}
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romanian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romanian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romanian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-romanian.ldf}[polyglossia: module for Romanian]
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romansh.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romansh.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-romansh.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-romansh.ldf}[polyglossia: module for Romansh]
 \makeatletter

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-russian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-russian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-russian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-russian.ldf}[polyglossia: module for Russian]
 
@@ -27,11 +27,6 @@
 \setlanguagealias*[spelling=old]{russian}{ru-petr1708}
 
 \newif\if at russian@modern
-\define at key{russian}{spelling}[modern]{%
-  \ifstrequal{#1}{old}%
-    {\@russian at modernfalse\SetLanguageKeys{russian}{bcp47=ru-petr1708,bcp47-variant=petr1708}}%
-    {\@russian at moderntrue\SetLanguageKeys{russian}{bcp47=ru,bcp47-variant=luna1918}}%
-}
 
 \def\captionsrussian{%
    \if at russian@modern\captionsrussian at modern\else\captionsrussian at old\fi%
@@ -43,49 +38,68 @@
 
 \newif\ifcyrillic at numerals
 \newif\ifcyrillic at asbuk@numerals
-\define at choicekey*+{russian}{numerals}[\xpg at val\xpg at nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % arabic:
-      \cyrillic at numeralsfalse%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{russian}{bcp47-extension-u=nu-latn}%
-   \or
-      % cyrillic:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-trad:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-alph:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralstrue%
-      \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
-   \fi
-   \xpg at info{Option: Russian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Russian numerals value `#1'}}
 
-\define at boolkey{russian}[russian@]{indentfirst}[true]{%
-  \ifrussian at indentfirst
-      \SetLanguageKeys{russian}{indentfirst=true}%
-  \else
-      \SetLanguageKeys{russian}{indentfirst=false}%
-  \fi%
-}
+\DeclareKeys[polyglossia/gloss/russian]
+  {
+    babelshorthands.if = russian at babelshorthands,
+    babelshorthands.default:n = true,
+    forceheadingpunctuation.if = russian at forceheadingpunctuation,
+    forceheadingpunctuation.default:n = true,
+    mathfunctions.if = russian at mathfunctions,
+    mathfunctions.default:n = true,
+    spelling.choice:,
+    spelling / modern.code =
+      {%
+        \@russian at moderntrue
+        \SetLanguageKeys{russian}{bcp47=ru,bcp47-variant=luna1918}%
+      },
+    spelling / old.code =
+      {%
+        \@russian at modernfalse
+        \SetLanguageKeys{russian}{bcp47=ru-petr1708,bcp47-variant=petr1708}%
+      },
+    spelling.default:n = modern,
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \cyrillic at numeralsfalse
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{russian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / cyrillic.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-trad.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-alph.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralstrue
+        \SetLanguageKeys{russian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Russian numerals value `#1'},
+    indentfirst.choice:,
+    indentfirst / true.code =
+      {%
+        \SetLanguageKeys{russian}{indentfirst=true}%
+      },
+    indentfirst / false.code =
+      {%
+        \SetLanguageKeys{russian}{indentfirst=false}%
+      },
+    indentfirst.default:n = true,
+  }
 
-\define at boolkey{russian}[russian@]{babelshorthands}[true]{}
-
-% Force punctuation after heading number
-\define at boolkey{russian}[russian@]{forceheadingpunctuation}[true]{}
-
-% Define some math functions
-\define at boolkey{russian}[russian@]{mathfunctions}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{russian}{babelshorthands=false,
+\InitializeGlossOptions{russian}{babelshorthands=false,
                                        spelling=modern,
                                        numerals=arabic,
                                        indentfirst=true,
@@ -94,16 +108,12 @@
 
 
 \ifsystem at babelshorthands
-  \setkeys{russian}{babelshorthands=true}
+  \SetGlossOptions{russian}{babelshorthands=true}
 \else
-  \setkeys{russian}{babelshorthands=false}
+  \SetGlossOptions{russian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\russian at shorthands{%
   \xpg at activate@shorthands%
@@ -155,7 +165,7 @@
    \def\bibname{Литература}%
    \def\chaptername{Глава}%
    \def\appendixname{Приложение}%
-   \ifcsundef{thechapter}%
+   \@ifundefined{thechapter}%
      {\def\contentsname{Содержание}}%
      {\def\contentsname{Оглавление}}%
    \def\listfigurename{Список иллюстраций}%
@@ -198,7 +208,7 @@
    \def\bibname{Библіографія}%
    \def\chaptername{Глава}%
    \def\appendixname{Приложеніе}%
-   \ifcsundef{thechapter}%
+   \@ifundefined{thechapter}%
      {\def\contentsname{Содержаніе}}%
      {\def\contentsname{Оглавленіе}}%
    \def\listfigurename{Списокъ иллюстрацій}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sami.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sami.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sami.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-sami.ldf}[polyglossia: module for Sami]
 
@@ -28,12 +28,12 @@
 %      % northern:
 %      \def\sami at variant{samin}%
 %      \SetLanguageKeys{sami}{language=Northern Sami,langtag=NSM}%
-%      \xpg at fontsetup@latin{sami}%
+%      \SetupLatinPolyglossiaFont{sami}%
 %   \or
 %      % other:
 %      \def\sami at variant{}%
 %      \SetLanguageKeys{sami}{language= Sami,langtag=}%
-%      \xpg at fontsetup@latin{sami}%
+%      \SetupLatinPolyglossiaFont{sami}%
 %   \fi
 %   \xpg at info{Option: sami, variant=\xpg at val}%
 %}{\xpg at warning{Unknown sami variant `#1'}}
@@ -40,7 +40,7 @@
 
 
 %\def\sami at language{%
-%   \polyglossia at setup@language at patterns{\sami at variant}%
+%   \SetupPolyglossiaLangPatterns{\sami at variant}%
 %}%
 
 \def\captionssami at northern{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-samin.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-samin.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-samin.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-samin.ldf}[polyglossia: module for Northern Sami]
 
@@ -5,6 +5,6 @@
 % We only provide this gloss for babel compatibility. Since samin is 
 % a sami variety, we use 'sami' with variant 'northern' now.
 
-\xpg at load@master at language{sami}
+\InheritGlossFile{sami}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sanskrit.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sanskrit.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sanskrit.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-sanskrit.ldf}[polyglossia: module for Sanskrit]
 
@@ -27,56 +27,55 @@
 \setlanguagealias*[script=gujarati]{sanskrit}{sa-Gujr}
 \setlanguagealias*[script=latin]{sanskrit}{sa-Latn}
 
-\define at key{sanskrit}{Script}[devanagari]{%
-  \ifcsdef{fontsetup at sanskrit@#1}%
-    {\csname fontsetup at sanskrit@#1\endcsname}%
-    {\xpg at error{`#1' is not a valid script for Sanskrit}%
-  }%
-}
-
-\define at key{sanskrit}{script}[devanagari]{\setkeys{sanskrit}{Script=#1}}
-
 \def\fontsetup at sanskrit@devanagari{%
   \SetLanguageKeys{sanskrit}{scripttag=deva,script=Devanagari,bcp47=sa-Deva,bcp47-language=sa,bcp47-script=Deva,bcp47-casing=sa-Deva}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@gujarati{%
   \SetLanguageKeys{sanskrit}{scripttag=gujr,script=Gujarati,bcp47=sa-Gujr,bcp47-language=sa,bcp47-script=Gujr,bcp47-casing=sa-Gujr}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@malayalam{%
   \SetLanguageKeys{sanskrit}{scripttag=mlym,script=Malayalam,bcp47=sa-Mlym,bcp47-language=sa,bcp47-script=Mlym,bcp47-casing=sa-Mlym}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@bengali{%
   \SetLanguageKeys{sanskrit}{scripttag=beng,script=Bengali,bcp47=sa-Beng,bcp47-language=sa,bcp47-script=Beng,bcp47-casing=sa-Beng}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@kannada{%
   \SetLanguageKeys{sanskrit}{scripttag=knda,script=Kannada,bcp47=sa-Knda,bcp47-language=sa,bcp47-script=Knda,bcp47-casing=sa-Knda}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@telugu{%
   \SetLanguageKeys{sanskrit}{scripttag=telu,script=Telugu,bcp47=sa-Relu,bcp47-language=sa,bcp47-script=Relu,bcp47-casing=sa-Relu}
-  \xpg at fontsetup@nonlatin{sanskrit}}
+  \SetupNonLatinPolyglossiaFont{sanskrit}}
 \def\fontsetup at sanskrit@latin{%
   \SetLanguageKeys{sanskrit}{scripttag=latn,script=Latin,bcp47=sa-Latn,bcp47-language=sa,bcp47-script=Latn,bcp47-casing=sa-Latn}
-  \xpg at fontsetup@latin{sanskrit}}
+  \SetupLatinPolyglossiaFont{sanskrit}}
 
 
 \newif\ifsanskrit at devanagari@numerals
 \sanskrit at devanagari@numeralstrue
-\define at choicekey*+{sanskrit}{numerals}[\xpg at val\xpg at nr]{devanagari,western}[devanagari]{%
-   \ifcase\xpg at nr\relax
-      % devanagari:
-      \sanskrit at devanagari@numeralstrue%
-      \SetLanguageKeys{sanskrit}{bcp47-extension-u=nu-deva}%
-   \or
-      % western:
-      \sanskrit at devanagari@numeralsfalse%
-      \SetLanguageKeys{sanskrit}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Sanskrit, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Sanskrit numeral `#1'}}
 
+\DeclareKeys[polyglossia/gloss/sanskrit]
+  {
+    script.code = \@ifundefined{fontsetup at sanskrit@#1}%
+      {\xpg at error{`#1' is not a valid script for Sanskrit}}%
+      {\csname fontsetup at sanskrit@#1\endcsname},
+    script.default:n = devanagari,
+    numerals.choice:,
+    numerals / devanagari.code = 
+      {%
+        \sanskrit at devanagari@numeralstrue
+        \SetLanguageKeys{sanskrit}{bcp47-extension-u=nu-deva}%
+      },
+    numerals / western.code =
+      {%
+        \sanskrit at devanagari@numeralsfalse
+        \SetLanguageKeys{sanskrit}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = devanagari,
+    numerals/unknown.code = \xpg at warning{Unknown Sanskrit numeral `#1'}
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{sanskrit}{script=devanagari,numerals=devanagari}
+\InitializeGlossOptions{sanskrit}{script=devanagari,numerals=devanagari}
 
 % Use \providecommand here as the ldf file might
 % be reloaded via BCP.

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-scottish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-scottish.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-scottish.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-scottish.ldf}[polyglossia: module for Scottish Gaelic]
 
@@ -5,6 +5,6 @@
 % We only provide this gloss for babel compatibility. Since scottish is 
 % a gaelic variety, we use 'gaelic' with variant 'scottish' now.
 
-\xpg at load@master at language{gaelic}
+\InheritGlossFile{gaelic}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-serbian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-serbian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-serbian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-serbian.ldf}[polyglossia: module for Serbian]
 %TODO split into gloss-serbiancyr.ldf and gloss-serbianlat.ldf
@@ -39,68 +39,11 @@
 \fi
 
 \newif\if at serbian@cyr
-\define at choicekey*+{serbian}{Script}[\xpg at val\xpg at nr]{cyrillic,latin}[cyrillic]{%
-   \ifcase\xpg at nr\relax
-      % cyrillic:
-      \@serbian at cyrtrue
-      \xpg at fontsetup@nonlatin{serbian}%
-   \or
-      % 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???
-   \fi
-   \serbian at set@languagekeys%
-   \xpg at info{Option: Serbian, script=\xpg at val}%
-}{\xpg at warning{Unknown Serbian script `#1'}}
-
-\define at key{serbian}{script}[cyrillic]{\setkeys{serbian}{Script=#1}}
-
 \newif\if at serbian@ijekavian
-\define at choicekey*+{serbian}{variant}[\xpg at val\xpg at nr]{ekavian,ijekavian}[ekavian]{%
-   \ifcase\xpg at nr\relax
-      % ekavian:
-      \@serbian at ijekavianfalse%
-   \or
-      % ijekavian:
-      \@serbian at ijekaviantrue%
-   \fi
-   \serbian at set@languagekeys%
-   \xpg at info{Option: Serbian, variant=\xpg at val}%
-}{\xpg at warning{Unknown Serbian variant `#1'}}
 
 \newif\ifcyrillic at numerals
 \newif\ifcyrillic at asbuk@numerals
-\define at choicekey*+{serbian}{numerals}[\xpg at val\xpg at nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % arabic:
-      \cyrillic at numeralsfalse%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{serbian}{bcp47-extension-u=nu-latn}%
-   \or
-      % cyrillic:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-trad:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-alph:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralstrue%
-      \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
-   \fi
-   \xpg at info{Option: Serbian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Serbian numerals value `#1'}}
 
-\define at boolkey{serbian}[serbian@]{splithyphens}[true]{}
-
-\define at boolkey{serbian}[serbian@]{datei}[true]{}
-
 \def\serbian at set@languagekeys{%
    \if at serbian@cyr
      \if at serbian@ijekavian
@@ -117,10 +60,75 @@
    \fi%
 }
 
-\setkeys{serbian}{Script,numerals}
+\DeclareKeys[polyglossia/gloss/serbian]
+  {
+    splithyphens.if = serbian at splithyphens,
+    splithyphens.default:n = true,
+    datei.if = serbian at datei,
+    datei.default:n = true,
+    variant.choice:,
+    variant / ekavian.code =
+      {%
+        \@serbian at ijekavianfalse
+        \serbian at set@languagekeys
+      },
+    variant / ijekavian.code =
+      {%
+        \@serbian at ijekaviantrue
+        \serbian at set@languagekeys
+      },
+    variant.default:n = ekavian,
+    variant/unknown.code = \xpg at warning{Unknown Serbian variant `#1'},
+    script.choice:,
+    script / cyrillic.code =
+      {%
+        \@serbian at cyrtrue
+        \SetupNonLatinPolyglossiaFont{serbian}%
+        \serbian at set@languagekeys
+      },
+    script / latin.code =
+      {%
+        \@serbian at cyrfalse
+        \SetupLatinPolyglossiaFont{serbian}%
+          %TODO \def\serbian at language{\language=\l at serbianlat}%
+          % or should we use Croatian patterns as a fallback for the time being???
+        \serbian at set@languagekeys
+      },
+    script.default:n = cyrillic,
+    script/unknown.code = \xpg at warning{Unknown Serbian script `#1'},
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \cyrillic at numeralsfalse
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{serbian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / cyrillic.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-trad.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-alph.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralstrue
+        \SetLanguageKeys{serbian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Serbian numerals value `#1'}
+  }
 
+\SetGlossOptions{serbian}{script,numerals}
+
 % Register default options
-\xpg at initialize@gloss at options{serbian}{script=cyrillic,numerals=arabic,splithyphens=true}
+\InitializeGlossOptions{serbian}{script=cyrillic,numerals=arabic,splithyphens=true}
 
 \def\captionsserbian{%
    \if at serbian@cyr\captionsserbian at cyr\else\captionsserbian at lat\fi

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-serbianc.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-serbianc.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-serbianc.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-serbianc.ldf}[polyglossia: module for Serbian (cyrillic)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{serbian}
+\InheritGlossFile{serbian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovak.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovak.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovak.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-slovak.ldf}[polyglossia: module for Slovak]
 
@@ -19,26 +19,26 @@
   \RequirePackage{luavlna}
 \fi
 
-\define at boolkey{slovak}[slovak@]{babelshorthands}[true]{}
+\DeclareKeys[polyglossia/gloss/slovak]
+  {
+    babelshorthands.if = slovak at babelshorthands,
+    babelshorthands.default:n = true,
+    splithyphens.if = slovak at splithyphens,
+    splithyphens.default:n = true,
+    vlna.if = slovak at vlna,
+    vlna.default:n = true,
+  }
 
-\define at boolkey{slovak}[slovak@]{splithyphens}[true]{}
-
-\define at boolkey{slovak}[slovak@]{vlna}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{slovak}{babelshorthands=false,splithyphens=true,vlna=true}
+\InitializeGlossOptions{slovak}{babelshorthands=false,splithyphens=true,vlna=true}
 
 \ifsystem at babelshorthands
-  \setkeys{slovak}{babelshorthands=true}
+  \SetGlossOptions{slovak}{babelshorthands=true}
 \else
-  \setkeys{slovak}{babelshorthands=false}
+  \SetGlossOptions{slovak}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \let\xpg at hyphen@char-
 \def\slovak@@splhyphen#1{%
@@ -214,7 +214,7 @@
    \def\contentsname{Obsah}%
    \def\listfigurename{Zoznam obrázkov}%
    \def\listtablename{Zoznam tabuliek}%
-   \def\indexname{Index}%
+   \def\indexname{Register}%
    \def\figurename{Obrázok}%
    \def\tablename{Tabuľka}%
    %\def\thepart{}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovene.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovene.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovene.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-slovene.ldf}[polyglossia: module for Slovenian]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{slovenian}
+\InheritGlossFile{slovenian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovenian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovenian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-slovenian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-slovenian.ldf}[polyglossia: module for Slovenian]
 
@@ -19,10 +19,14 @@
 % Babel aliases
 \setlanguagealias{slovenian}{slovene}
 
-\define at boolkey{slovenian}[slovenian@]{localalph}[true]{}
+\DeclareKeys[polyglossia/gloss/slovenian]
+  {
+    localalph.if = slovenian at localalph,
+    localalph.default:n = true
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{slovenian}{localalph=false}
+\InitializeGlossOptions{slovenian}{localalph=false}
 
 
 \def\captionsslovenian{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sorbian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sorbian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-sorbian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-sorbian.ldf}[polyglossia: module for Sorbian]
 
@@ -26,60 +26,40 @@
 \setlanguagealias[variant=upper]{sorbian}{uppersorbian}
 
 \def\sorbian at variant{usorbian}
-\define at choicekey*+{sorbian}{variant}[\xpg at val\xpg at nr]{upper,lower}[upper]{%
-   \ifcase\xpg at nr\relax
-      % upper:
-      \def\sorbian at variant{usorbian}%
-      \SetLanguageKeys{sorbian}{language=Upper Sorbian,langtag=USB,babelname=uppersorbian,bcp47=hsb,bcp47-language=hsb}%
-      \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,bcp47=dsb,bcp47-language=dsb}%
-      \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=\xpg at val}%
-}{\xpg at warning{Unknown sorbian variant `#1'}}
 
+\DeclareKeys[polyglossia/gloss/sorbian]
+  {
+    olddate.if = sorbian at olddate,
+    olddate.default:n = true,
+    variant.choice:,
+    variant / upper.code = 
+      {%
+        \def\sorbian at variant{usorbian}%
+        \SetLanguageKeys{sorbian}{language=Upper Sorbian,langtag=USB,babelname=uppersorbian,bcp47=hsb,bcp47-language=hsb}%
+        \SetupLatinPolyglossiaFont{sorbian}%
+        % Check if \l at usorbian is defined. If not, try to set it to some variety
+        % (specific order as in the csv list), or null language if everything fails
+        \TryPatternWithFallback{usorbian}{uppersorbian}%
+      },
+    variant / lower.code = 
+      {%
+        \def\sorbian at variant{lsorbian}%
+        \SetLanguageKeys{sorbian}{language=Lower Sorbian,langtag=LSB,babelname=lowersorbian,bcp47=dsb,bcp47-language=dsb}%
+        \SetupLatinPolyglossiaFont{sorbian}%
+        % Check if \l at lsorbian is defined. If not, try to set it to some variety
+        % (specific order as in the csv list), or null language if everything fails
+        \TryPatternWithFallback{lsorbian}{lowersorbian,Lsorbian,usorbian,uppersorbian}%
+      },
+    variant.default:n = upper,
+    variant/unknown.code = \xpg at warning{Unknown sorbian variant `#1'}
+  }
 
-\define at boolkey{sorbian}[sorbian@]{olddate}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{sorbian}{variant=upper,olddate=false}
+\InitializeGlossOptions{sorbian}{variant=upper,olddate=false}
 
 
 \def\sorbian at language{%
-   \polyglossia at setup@language at patterns{\sorbian at variant}%
+   \SetupPolyglossiaLangPatterns{\sorbian at variant}%
 }%
 
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanish.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanish.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-spanish.ldf}[polyglossia: module for Spanish]
 
@@ -27,18 +27,6 @@
 
 \newif\if at spanish@mexico
 \@spanish at mexicofalse
-\define at choicekey*+{spanish}{variant}[\xpg at val\xpg at nr]{spanish,mexican}[spanish]{%
-   \ifcase\xpg at nr\relax
-      % spanish:
-      \@spanish at mexicofalse%
-      \SetLanguageKeys{spanish}{babelname=spanish,bcp47=es-ES,bcp47-region=ES}%
-   \or
-      % mexican:
-      \@spanish at mexicotrue%
-      \SetLanguageKeys{spanish}{babelname=spanishmx,bcp47=es-MX,bcp47-region=MX}%
-   \fi
-   \xpg at info{Option: spanish, variant=\xpg at val}%
-}{\xpg at warning{Unknown spanish variant `#1'}}
 
 % Localized math operators à la babel
 \newif\ifspanish at accentedoperators
@@ -45,34 +33,52 @@
 \newif\ifspanish at spacedoperators
 \newif\ifspanish at locoperators
 
-\define at choicekey*+{spanish}{spanishoperators}[\xpg at val\xpg at nr]{all,accented,spaced,none}[all]{%
-   \ifcase\xpg at nr\relax
-      % all:
-      \spanish at locoperatorstrue%
-      \spanish at accentedoperatorstrue%
-      \spanish at spacedoperatorstrue%
-   \or
-      % accented:
-      \spanish at locoperatorsfalse%
-      \spanish at accentedoperatorstrue%
-      \spanish at spacedoperatorsfalse%
-   \or
-      % spaced:
-      \spanish at locoperatorsfalse%
-      \spanish at accentedoperatorsfalse%
-      \spanish at spacedoperatorstrue%
-   \or
-      % none:
-      \spanish at locoperatorsfalse%
-      \spanish at accentedoperatorsfalse%
-      \spanish at spacedoperatorsfalse%
-   \fi
-   \xpg at info{Option: Spanish, spanishoperators=\xpg at val}%
-}{\xpg at warning{Unknown spanishoperators value `#1'}}
+\DeclareKeys[polyglossia/gloss/spanish]
+  {
+    variant.choice:,
+    variant / spanish.code =
+      {%
+        \@spanish at mexicofalse
+        \SetLanguageKeys{spanish}{babelname=spanish,bcp47=es-ES,bcp47-region=ES}%
+      },
+    variant / mexican.code =
+      {%
+        \@spanish at mexicotrue
+        \SetLanguageKeys{spanish}{babelname=spanishmx,bcp47=es-MX,bcp47-region=MX}%
+      },
+    variant.default:n = spanish,
+    variant/unknown.code = \xpg at warning{Unknown spanish variant `#1'},
+    spanishoperators.choice:,
+    spanishoperators / all.code =
+      {%
+        \spanish at locoperatorstrue
+        \spanish at accentedoperatorstrue
+        \spanish at spacedoperatorstrue
+      },
+    spanishoperators / accented.code =
+      {%
+        \spanish at locoperatorsfalse
+        \spanish at accentedoperatorstrue
+        \spanish at spacedoperatorsfalse
+      },
+    spanishoperators / spaced.code =
+      {%
+        \spanish at locoperatorsfalse
+        \spanish at accentedoperatorsfalse
+        \spanish at spacedoperatorstrue
+      },
+    spanishoperators / none.code =
+      {%
+        \spanish at locoperatorsfalse
+        \spanish at accentedoperatorsfalse
+        \spanish at spacedoperatorsfalse
+      },
+    spanishoperators.default:n = all,
+    spanishoperators/unknown.code = \xpg at warning{Unknown spanishoperators value `#1'}
+  }
 
-
 % Register default options
-\xpg at initialize@gloss at options{spanish}{variant=spanish,spanishoperators=none}
+\InitializeGlossOptions{spanish}{variant=spanish,spanishoperators=none}
 
 \let\xpg at save@lim\lim
 \let\xpg at save@limsup\limsup

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanishmx.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanishmx.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-spanishmx.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-spanishmx.ldf}[polyglossia: module for Mexican Spanish]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{spanish}
+\InheritGlossFile{spanish}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swedish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swedish.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swedish.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-swedish.ldf}[polyglossia: module for Swedish]
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swissgerman.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swissgerman.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-swissgerman.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-swissgerman.ldf}[polyglossia: module for Swiss German (old spelling)]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{german}
+\InheritGlossFile{german}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-syriac.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-syriac.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-syriac.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-syriac.ldf}[polyglossia: module for Syriac]
 
@@ -22,34 +22,37 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{syriac}{syr}
 
-\def\syriacnumber#1{\@syriacnumber{#1}}%
+\def\syriacnumber#1{\@syriacnumber{#1}}
 
 \newif\if at eastern@numerals
-\define at choicekey*+{syriac}{numerals}[\xpg at val\xpg at nr]{eastern,western,abjad}[eastern]{%
-   \ifcase\xpg at nr\relax
-      % eastern:
-      \@eastern at numeralstrue
-      \SetLanguageKeys{syriac}{bcp47-extension-u=nu-syrc}%
-   \or
-      % western:
-      \@eastern at numeralsfalse
-      \SetLanguageKeys{syriac}{bcp47-extension-u=nu-latn}%
-   \or
-      % abjad:
-      \let\syriacnumber\abjadsyriac%
-   \fi
-   \xpg at info{Option: Syriac, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Syriac numerals option `#1'}}
-
 \newif\ifsyriac at customsep\syriac at customsepfalse
 \def\xpg at sepmark{}
-\define at key{syriac}{sectionsep}[.]{%
-   \syriac at customseptrue%
-   \gdef\xpg at sepmark{#1}%
-}
 
+\DeclareKeys[polyglossia/gloss/syriac]
+  {
+    sectionsep.code = \gdef\xpg at sepmark{#1}\syriac at customseptrue,
+    sectionsep.default:n = .,
+    numerals.choice:,
+    numerals / eastern.code =
+      {%
+        \@eastern at numeralstrue
+        \SetLanguageKeys{syriac}{bcp47-extension-u=nu-syrc}%
+      },
+    numerals / western.code =
+      {%
+        \@eastern at numeralsfalse
+        \SetLanguageKeys{syriac}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / abjad.code =
+      {%
+          \let\syriacnumber\abjadsyriac
+      },
+    numerals.default:n = eastern,
+    numerals/unknown.code = \xpg at warning{Unknown Syriac numerals option `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{syriac}{numerals=western}
+\InitializeGlossOptions{syriac}{numerals=western}
 	
 %\define at key{polyglossia}{syriaclocale}[default]{%
 %	\def\@syriac at locale{#1}}
@@ -136,13 +139,13 @@
       \IfCharIsAvailableTF{0661}%
           {\@ensure at LTR{\protect\arabicdigits{\number#1}}}%
           {\@ensure at LTR{\arabicdigits{\number#1}}
-           \ifcsdef{arabicfont}%
+           \@ifundefined{arabicfont}%
+	     {\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}}%
 	     {\@ensure at LTR{\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}}%
           }%
    \else
      %%\RL{\protect\reset at font\number#1}%
@@ -180,9 +183,9 @@
 }
 
 \def\nosyriac at xetex@capsformat{%
-   \ifcsdef{xpg at save@sepmark}{%
+   \ifcsname xpg at save@sepmark\endcsname%
      \SepMark{\xpg at save@sepmark}
-   }{}%
+   \fi%
 }
 
 \def\syriac at luatex@capsformat{%
@@ -189,7 +192,7 @@
   %
   % change chapter and part headings
   \ifsyriac at customsep
-     \ifcsdef{chapter}{%
+     \ifcsname chapter\endcsname%
         \let\xpg at save@thesection\thesection%
         \renewcommand*\thesection{\thechapter\xpg at sepmark\@arabic\c at section}
         \let\xpg at save@theequation\theequation%
@@ -201,7 +204,7 @@
         \let\xpg at save@thetable\thetable%
 	\renewcommand*\thetable{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at table}
-     }{}
+     \fi%
      \let\xpg at save@thesubsection\thesubsection%
      \renewcommand\thesubsection
 	{\thesection\xpg at sepmark\@arabic\c at subsection}
@@ -216,30 +219,30 @@
 }
 
 \def\nosyriac at luatex@capsformat{%
-   \ifcsdef{xpg at save@thesection}{%
+   \ifcsname xpg at save@thesection\endcsname%
         \let\thesection\xpg at save@thesection%
-   }{}%
-   \ifcsdef{xpg at save@theequation}{%
+   \fi%
+   \ifcsname xpg at save@theequation\endcsname%
         \let\theequation\xpg at save@theequation%
-   }{}%
-   \ifcsdef{xpg at save@thefigure}{%
+   \fi%
+   \ifcsname xpg at save@thefigure\endcsname%
         \let\thefigure\xpg at save@thefigure%
-   }{}%
-   \ifcsdef{xpg at save@thetable}{%
+   \fi%
+   \ifcsname xpg at save@thetable\endcsname%
         \let\thetable\xpg at save@thetable%
-   }{}%
-   \ifcsdef{xpg at save@thesubsection}{%
+   \fi%
+   \ifcsname xpg at save@thesubsection\endcsname%
         \let\thesubsection\xpg at save@thesubsection%
-   \ifcsdef{xpg at save@thesubsubsection}{%
+      \ifcsname xpg at save@thesubsubsection\endcsname%
         \let\thesubsubsection\xpg at save@thesubsubsection%
-   }{}%
-   }{}%
-   \ifcsdef{xpg at save@theparagraph}{%
+      \fi%
+   \fi%
+   \ifcsname xpg at save@theparagraph\endcsname%
         \let\theparagraph\xpg at save@theparagraph%
-   }{}%
-   \ifcsdef{xpg at save@thesubparagraph}{%
+   \fi%
+   \ifcsname xpg at save@thesubparagraph\endcsname%
         \let\thesubparagraph\xpg at save@thesubparagraph%
-   }{}%
+   \fi%
 }
 
 \def\blockextras at syriac{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-tamil.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-tamil.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-tamil.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-tamil.ldf}[polyglossia: module for Tamil]
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-telugu.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-telugu.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-telugu.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-telugu.ldf}[polyglossia: module for Telugu]
 

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-thai.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-thai.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-thai.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-thai.ldf}[polyglossia: module for Thai]
 %% This is partly based on thai-latex for Babel:
@@ -29,19 +29,25 @@
 
 \newif\if at thai@numerals
 \def\tmp at thai{thai}
-\define at key{thai}{numerals}[arabic]{%
-	\def\@tmpa{#1}%
-	\ifx\@tmpa\tmp at thai
-	  \@thai at numeralstrue%
-          \SetLanguageKeys{thai}{bcp47-extension-u=nu-thai}%
-	\else
-	  \@thai at numeralsfalse%
-          \SetLanguageKeys{thai}{bcp47-extension-u=nu-latn}%
-	\fi
-}
 
+\DeclareKeys[polyglossia/gloss/thai]
+  {
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \@thai at numeralsfalse
+        \SetLanguageKeys{thai}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / thai.code =
+      {%
+        \@thai at numeralstrue
+        \SetLanguageKeys{thai}{bcp47-extension-u=nu-thai}%
+      },
+    numerals.default:n = arabic,
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{thai}{numerals=arabic}
+\InitializeGlossOptions{thai}{numerals=arabic}
 
 \def\captionsthai{%
    \def\refname{หนังสืออ้างอิง}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-tibetan.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-tibetan.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-tibetan.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-tibetan.ldf}[polyglossia: module for Tibetan]
 %% Copyright 2013 Elie Roux
@@ -24,20 +24,18 @@
 \setlanguagealias*{tibetan}{bo}
 
 \newif\if at tibetan@numerals
-\def\tmp at tibetan{tibetan}
-\define at key{tibetan}{numerals}[tibetan]{%
-	\def\@tmpa{#1}%
-	\ifx\@tmpa\tmp at tibetan
-	   \@tibetan at numeralstrue%
-           \SetLanguageKeys{tibetan}{bcp47-extension-u=nu-tibt}%
-	\else
-	  \@tibetan at numeralsfalse%
-           \SetLanguageKeys{tibetan}{bcp47-extension-u=nu-latn}%
-	\fi%
-}
+\DeclareKeys[polyglossia/gloss/tibetan]
+  {
+    numerals.choice:,
+    numerals/tibetan.code = \@tibetan at numeralstrue
+    	   \SetLanguageKeys{tibetan}{bcp47-extension-u=nu-tibt},
+    numerals/arabic.code = \@tibetan at numeralsfalse
+           \SetLanguageKeys{tibetan}{bcp47-extension-u=nu-latn},
+    numerals.default:n = tibetan
+  }
 
 \ifluatex
-  \newluatexattribute\xpg at tibteol %
+  \newattribute\xpg at tibteol %
   \directlua{polyglossia.load_tibt_eol()}%
 \fi
 
@@ -62,7 +60,7 @@
 }
 
 % Register default options
-\xpg at initialize@gloss at options{tibetan}{numerals=tibetan}
+\InitializeGlossOptions{tibetan}{numerals=tibetan}
 
 % some are known, but very few
 % a few come from "Standardizing Tibetan Terms of Information Technology"

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-turkish.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-turkish.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-turkish.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-turkish.ldf}[polyglossia: module for Turkish]
 \RequirePackage{hijrical}

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-turkmen.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-turkmen.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-turkmen.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-turkmen.ldf}[polyglossia: module for Turkmen]
 %% Translations provided by Nazar Annagurban <nazartm at gmail dot com>

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ug.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ug.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ug.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,8 +1,8 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ug.ldf}[polyglossia: module for ug (Uyghur)]
 % BCP 47 tag for Uyghur
 
-\xpg at load@master at language{uyghur}
+\InheritGlossFile{uyghur}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ukrainian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ukrainian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-ukrainian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-ukrainian.ldf}[polyglossia: module for Ukrainian]
 % Strings taken from Babel
@@ -26,51 +26,52 @@
 
 \newif\ifcyrillic at numerals
 \newif\ifcyrillic at asbuk@numerals
-\define at choicekey*+{ukrainian}{numerals}[\xpg at val\xpg at nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
-   \ifcase\xpg at nr\relax
-      % arabic:
-      \cyrillic at numeralsfalse%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-latn}%
-   \or
-      % cyrillic:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-trad:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralsfalse%
-      \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
-   \or
-      % cyrillic-alph:
-      \cyrillic at numeralstrue%
-      \cyrillic at asbuk@numeralstrue%
-      \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
-   \fi
-   \xpg at info{Option: Ukrainian, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Ukrainian numerals value `#1'}}
 
+\DeclareKeys[polyglossia/gloss/ukrainian]
+  {
+    babelshorthands.if = ukrainian at babelshorthands,
+    babelshorthands.default:n = true,
+    mathfunctions.if = ukrainian at mathfunctions,
+    mathfunctions.default:n = true,
+    numerals.choice:,
+    numerals / arabic.code =
+      {%
+        \cyrillic at numeralsfalse
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-latn}%
+      },
+    numerals / cyrillic.code =
+      {%  
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-trad.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralsfalse
+        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals / cyrillic-alph.code =
+      {%
+        \cyrillic at numeralstrue
+        \cyrillic at asbuk@numeralstrue
+        \SetLanguageKeys{ukrainian}{bcp47-extension-u=nu-cyrl}%
+      },
+    numerals.default:n = arabic,
+    numerals/unknown.code = \xpg at warning{Unknown Ukrainian numerals value `#1'}
+  }
 
-% Define some math functions
-\define at boolkey{ukrainian}[ukrainian@]{mathfunctions}[true]{}
-
 % Register default options
-\xpg at initialize@gloss at options{ukrainian}{numerals=arabic,mathfunctions=true}
+\InitializeGlossOptions{ukrainian}{numerals=arabic,mathfunctions=true}
 
-\define at boolkey{ukrainian}[ukrainian@]{babelshorthands}[true]{}
-
 \ifsystem at babelshorthands
-  \setkeys{ukrainian}{babelshorthands=true}
+  \SetGlossOptions{ukrainian}{babelshorthands=true}
 \else
-  \setkeys{ukrainian}{babelshorthands=false}
+  \SetGlossOptions{ukrainian}{babelshorthands=false}
 \fi
 
-\ifcsundef{initiate at active@char}{%
-  \input{babelsh.def}%
-  \initiate at active@char{"}%
-  \shorthandoff{"}%
-}{}
+\InitializeBabelShorthands
 
 \def\ukrainian at shorthands{%
   \xpg at activate@shorthands%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-uppersorbian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-uppersorbian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-uppersorbian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-uppersorbian.ldf}[polyglossia: module for Upper Sorbian]
 
 % We provide this as a babel alias
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-urdu.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-urdu.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-urdu.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 %%% Adapted from a file contributed by Kamal Abdali
 \ProvidesFile{gloss-urdu.ldf}[polyglossia: module for Urdu]
@@ -25,52 +25,46 @@
 \setlanguagealias*{urdu}{ur}
 
 \newif\if at western@numerals
-\define at choicekey*+{urdu}{numerals}[\xpg at val\xpg at nr]{eastern,western}[eastern]{%
-   \ifcase\xpg at nr\relax
-      % eastern:
-      \@western at numeralsfalse%
-      \SetLanguageKeys{urdu}{bcp47-extension-u=nu-arab}%
-   \or
-      % western:
-      \@western at numeralstrue%
-      \SetLanguageKeys{urdu}{bcp47-extension-u=nu-latn}%
-   \fi
-   \xpg at info{Option: Urdu, numerals=\xpg at val}%
-}{\xpg at warning{Unknown Urdu numerals option `#1'}}
-
 \newif\ifurdu at customsep\urdu at customsepfalse
 \def\xpg at sepmark{}
-\define at key{urdu}{sectionsep}[.]{%
-   \urdu at customseptrue%
-   \gdef\xpg at sepmark{#1}%
-}
-
-%this is needed for \abjad in arabicnumbers.sty
-\define at boolkey{urdu}[urdu@]{abjadjimnotail}[true]{%
-  \ifurdu at abjadjimnotail
-    \abjad at jim@notailtrue%
-  \else
-    \abjad at jim@notailfalse
-  \fi%
-}
-
 \newif\if at hijrical
-\define at choicekey*+{urdu}{calendar}[\xpg at val\xpg at nr]{gregorian,hijri}[gregorian]{%
-   \ifcase\xpg at nr\relax
-      % gregorian:
-      \@hijricalfalse
-   \or
-      % hijri:
-      \@hijricaltrue
-   \fi
-   \xpg at info{Option: Urdu, calendar=\xpg at val}%
-}{\xpg at warning{Unknown Urdu calendar option `#1'}}
 
-\define at key{urdu}{hijricorrection}[0]{%
-  \gdef\urdu at hijri@correction{#1}}%
+\DeclareKeys[polyglossia/gloss/urdu]
+  {
+    abjadjimnotail.if = abjad at jim@notail,
+    abjadjimnotail.default:n = true,
+    sectionsep.code = \gdef\xpg at sepmark{#1}\urdu at customseptrue,
+    sectionsep.default:n = .,
+    hijricorrection.code = \gdef\urdu at hijri@correction{#1},
+    hijricorrection.default:n = 0,
+    calendar.choice:,
+    calendar / gregorian.code =
+      {%
+        \@hijricalfalse
+      },
+    calendar / hijri.code =
+      {%
+        \@hijricaltrue
+      },
+    calendar.default:n = gregorian,
+    calendar/unknown.code = \xpg at warning{Unknown Urdu calendar option `#1'},
+    numerals.choice:,
+    numerals / eastern.code =
+      {%
+        \@western at numeralsfalse
+        \SetLanguageKeys{urdu}{bcp47-extension-u=nu-arab}%
+      },
+    numerals / western.code =
+      {%
+        \@western at numeralstrue
+        \SetLanguageKeys{urdu}{bcp47-extension-u=nu-latn}%
+      },
+    numerals.default:n = eastern,
+    numerals/unknown.code = \xpg at warning{Unknown Urdu numerals option `#1'}
+  }
 
 % This should set the defaults
-\setkeys{urdu}{calendar,numerals,hijricorrection}
+\SetGlossOptions{urdu}{calendar,numerals,hijricorrection}
 
 \def\urdugregmonth#1{\ifcase#1%
   \or جنوری\or فروری\or مارچ\or اپریل\or مئی\or جون\or جولائی\or اگست\or  ستمبر\or اکتوبر\or نومبر\or دسمبر\fi}
@@ -157,9 +151,9 @@
 }
 
 \def\nourdu at xetex@capsformat{%
-   \ifcsdef{xpg at save@sepmark}{%
+   \ifcsname xpg at save@sepmark\endcsname%
      \SepMark{\xpg at save@sepmark}
-   }{}%
+   \fi%
 }
 
 \def\urdu at luatex@capsformat{%
@@ -166,7 +160,7 @@
   %
   % change chapter and part headings
   \ifurdu at customsep
-     \ifcsdef{chapter}{%
+     \ifcsname chapter\endcsname%
         \let\xpg at save@thesection\thesection%
         \renewcommand*\thesection{\thechapter\xpg at sepmark\@arabic\c at section}
         \let\xpg at save@theequation\theequation%
@@ -178,7 +172,7 @@
         \let\xpg at save@thetable\thetable%
 	\renewcommand*\thetable{%
 	    \ifnum\c at chapter>\z@\thechapter\xpg at sepmark\fi\@arabic\c at table}
-     }{}
+     \fi%
      \let\xpg at save@thesubsection\thesubsection%
      \renewcommand\thesubsection
 	{\thesection\xpg at sepmark\@arabic\c at subsection}
@@ -193,30 +187,30 @@
 }
 
 \def\nourdu at luatex@capsformat{%
-   \ifcsdef{xpg at save@thesection}{%
+   \ifcsname xpg at save@thesection\endcsname%
         \let\thesection\xpg at save@thesection%
-   }{}%
-   \ifcsdef{xpg at save@theequation}{%
+   \fi%
+   \ifcsname xpg at save@theequation\endcsname%
         \let\theequation\xpg at save@theequation%
-   }{}%
-   \ifcsdef{xpg at save@thefigure}{%
+   \fi%
+   \ifcsname xpg at save@thefigure\endcsname%
         \let\thefigure\xpg at save@thefigure%
-   }{}%
-   \ifcsdef{xpg at save@thetable}{%
+   \fi%
+   \ifcsname xpg at save@thetable\endcsname%
         \let\thetable\xpg at save@thetable%
-   }{}%
-   \ifcsdef{xpg at save@thesubsection}{%
+   \fi%
+   \ifcsname xpg at save@thesubsection\endcsname%
         \let\thesubsection\xpg at save@thesubsection%
-   \ifcsdef{xpg at save@thesubsubsection}{%
+      \ifcsname xpg at save@thesubsubsection\endcsname%
         \let\thesubsubsection\xpg at save@thesubsubsection%
-   }{}%
-   }{}%
-   \ifcsdef{xpg at save@theparagraph}{%
+      \fi%
+   \fi%
+   \ifcsname xpg at save@theparagraph\endcsname%
         \let\theparagraph\xpg at save@theparagraph%
-   }{}%
-   \ifcsdef{xpg at save@thesubparagraph}{%
+   \fi%
+   \ifcsname xpg at save@thesubparagraph\endcsname%
         \let\thesubparagraph\xpg at save@thesubparagraph%
-   }{}%
+   \fi%
 }
 
 \def\blockextras at urdu{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-usorbian.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-usorbian.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-usorbian.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-usorbian.ldf}[polyglossia: module for Upper Sorbian]
 
@@ -5,6 +5,6 @@
 % We only provide this gloss for babel compatibility. Since usorbian is 
 % a sorbian variety, we use 'sorbian' with variant 'upper' now.
 
-\xpg at load@master at language{sorbian}
+\InheritGlossFile{sorbian}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-uyghur.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-uyghur.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-uyghur.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-uyghur.ldf}[polyglossia: module for Uyghur]
 %% Translations provided by Osman Tursun (Github Account: neouyghur)
@@ -22,62 +22,72 @@
 \newif\if at uyghur@swapcaptions
 \newif\if at uyghur@swapheadings
 \newif\if at uyghur@swapheaders
-\define at choicekey*+{uyghur}{swapstrings}[\xpg at val\xpg at nr]{all,captions,headings,headers,hheaders,none}[all]{%
-   \ifcase\xpg at nr\relax
-      % all:
-      \@uyghur at swapcaptionstrue%
-      \@uyghur at swapheadingstrue%
-      \@uyghur at swapheaderstrue%
-   \or
-      % captions:
-      \@uyghur at swapcaptionstrue%
-      \@uyghur at swapheadingsfalse%
-      \@uyghur at swapheadersfalse%
-   \or
-      % headings:
-      \@uyghur at swapcaptionsfalse%
-      \@uyghur at swapheadingstrue%
-      \@uyghur at swapheadersfalse%
-   \or
-      % headers:
-      \@uyghur at swapcaptionsfalse%
-      \@uyghur at swapheadingsfalse%
-      \@uyghur at swapheaderstrue%
-   \or
-      % hheaders:
-      \@uyghur at swapcaptionsfalse%
-      \@uyghur at swapheadingstrue%
-      \@uyghur at swapheaderstrue%
-   \or
-      % none:
-      \@uyghur at swapcaptionsfalse%
-      \@uyghur at swapheadingsfalse%
-      \@uyghur at swapheadersfalse%
-   \fi
-   \xpg at info{Option: Uyghur, swapstrings=\xpg at val}%
-}{\xpg at warning{Unknown Uyghur swapstrings value `#1'}}
-
 \newif\if at uyghur@ordchapter
 \newif\if at uyghur@romchapter
-\define at choicekey*+{uyghur}{chapterformat}[\xpg at val\xpg at nr]{ordinal,roman,arabic}[ordinal]{%
-   \ifcase\xpg at nr\relax
-      % ordinal:
-      \@uyghur at ordchaptertrue%
-      \@uyghur at romchapterfalse%
-   \or
-      % roman:
-      \@uyghur at ordchapterfalse%
-      \@uyghur at romchaptertrue%
-   \or
-      % arabic:
-      \@uyghur at ordchapterfalse%
-      \@uyghur at romchapterfalse%
-   \fi
-   \xpg at info{Option: Uyghur, chapterformat=\xpg at val}%
-}{\xpg at warning{Unknown Uyghur chapterformat value `#1'}}
 
+\DeclareKeys[polyglossia/gloss/uyghur]
+  {
+    chapterformat.choice:,
+    chapterformat / ordinal.code =
+      {%
+        \@uyghur at ordchaptertrue
+        \@uyghur at romchapterfalse
+      },
+    chapterformat / roman.code =
+      {%
+        \@uyghur at ordchapterfalse
+        \@uyghur at romchaptertrue
+      },
+    chapterformat / arabic.code =
+      {%
+        \@uyghur at ordchapterfalse
+        \@uyghur at romchapterfalse
+      },
+    chapterformat.default:n = ordinal,
+    chapterformat/unknown.code = \xpg at warning{Unknown Uyghur chapterformat value `#1'},
+    swapstrings.choice:,
+    swapstrings / all.code = 
+      {%
+        \@uyghur at swapcaptionstrue
+        \@uyghur at swapheadingstrue
+        \@uyghur at swapheaderstrue
+      },
+    swapstrings / captions.code = 
+      {%
+        \@uyghur at swapcaptionstrue
+        \@uyghur at swapheadingsfalse
+        \@uyghur at swapheadersfalse
+      },
+    swapstrings / headings.code =
+      {%
+        \@uyghur at swapcaptionsfalse
+        \@uyghur at swapheadingstrue
+        \@uyghur at swapheadersfalse
+      },
+    swapstrings / headers.code = 
+      {%
+        \@uyghur at swapcaptionsfalse
+        \@uyghur at swapheadingsfalse
+        \@uyghur at swapheaderstrue
+      },
+    swapstrings / hheaders.code = 
+      {%
+        \@uyghur at swapcaptionsfalse
+        \@uyghur at swapheadingstrue
+        \@uyghur at swapheaderstrue
+      },
+    swapstrings / none.code = 
+      {%
+        \@uyghur at swapcaptionsfalse
+        \@uyghur at swapheadingsfalse
+        \@uyghur at swapheadersfalse
+      },
+    swapstrings.default:n = all,
+    swapstrings/unknown.code = \xpg at warning{Unknown Uyghur swapstrings value `#1'}
+  }
+
 % Register default options
-\xpg at initialize@gloss at options{uyghur}{swapstrings=all,chapterformat=ordinal}
+\InitializeGlossOptions{uyghur}{swapstrings=all,chapterformat=ordinal}
 
 
 \def\captionsuyghur{%
@@ -125,69 +135,13 @@
   % change chapter and part headings
   \if at uyghur@swapheadings
      % With titlesec
-     \ifcsdef{titleformat}{%
-       \ifcsdef{H at old@part}{% Hyperref
-            \let\xpg at save@part at format\H at old@part%
-            \patchcmd{\H at old@part}%
-                      {\partname\nobreakspace\thepart}%
-                      {\the at uyghur@part\nobreakspace\partname}%
-                      {}%
-                      {\xpg at warning{Failed to patch part for Uyghur}}%
-       }{% not hyperref
-         \ifcsdef{@part}{%
-            \let\xpg at save@part at format\@part%
-            \patchcmd{\@part}%
-                      {\partname\nobreakspace\thepart}%
-                      {\the at uyghur@part\nobreakspace\partname}%
-                      {}%
-                      {\xpg at warning{Failed to patch part for Uyghur}}%
-         }{}%
-       }
-       \ifcsdef{chapter}{%
-          \titleformat\chapter[display]%
-             {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
-             {\the at uyghur@chapter\space\@chapapp}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
-       }{}%
-     }{% (not \ifdefined\titleformat)
+     \@ifundefined{titleformat}{%
        % With KOMA
-       \ifcsdef{sectionformat}{%
-          \ifcsdef{partformat}{%
-            \let\xpg at save@part at format\partformat%
-            \renewcommand{\partformat}{\the at uyghur@part~\partname}%
-          }{}%
-          \ifcsdef{chapterformat}{%
-            \let\xpg at save@chap at format\chapterformat%
-            \renewcommand{\chapterformat}{\mbox{\the at uyghur@chapter%
-                                          \IfUsePrefixLine{\nobreakspace\chapapp}{\enskip}}}%
-          }{}%
-       }{%  (not \ifdefined\sectionformat)
+       \@ifundefined{sectionformat}{%
          % With memoir
-         \ifcsdef{@memptsize}{%
-           \ifcsdef{@makechapterhead}{%
-              \let\xpg at save@chap at format\@makechapterhead%
-              \patchcmd{\@makechapterhead}{\printchaptername \chapternamenum \printchapternum}%
-                       {\chapnumfont\the at uyghur@chapter\chapternamenum\printchaptername}%
-                       {}%
-                       {\xpg at warning{Failed to patch chapter for Uyghur}}%
-           }{}%
-           \ifcsdef{H at old@part}{% Hyperref
-                \let\xpg at save@part at format\H at old@part%
-                \patchcmd{\H at old@part}{\printpartname \partnamenum \printpartnum}%
-                                 {\chapnumfont\the at uyghur@part\partnamenum\printpartname}%
-                                 {}%
-                                 {\xpg at warning{Failed to patch part for Uyghur}}%
-           }{% not hyperref
-             \ifcsdef{@part}{%
-                \let\xpg at save@part at format\@part%
-                \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
-                                 {\chapnumfont\the at uyghur@part\partnamenum\printpartname}%
-                                 {}%
-                                 {\xpg at warning{Failed to patch part for Uyghur}}%
-             }{}%
-           }%
-         }{%  (not \ifdefined\@memptsize)
+         \@ifundefined{@memptsize}{%
            % With standard classes
-            \ifcsdef{@makechapterhead}{%
+            \@ifundefined{@makechapterhead}{}{%
               \let\xpg at save@chap at format\@makechapterhead%
               \patchcmd{\@makechapterhead}%
                        {\@chapapp\space \thechapter}%
@@ -194,8 +148,17 @@
                        {\the at uyghur@chapter\space \@chapapp}%
                        {}%
                        {\xpg at warning{Failed to patch chapter for Uyghur}}%
-            }{}%
-            \ifcsdef{H at old@part}{% Hyperref
+            }%
+            \@ifundefined{H at old@part}{% not hyperref
+              \@ifundefined{@part}{}{%
+                \let\xpg at save@part at format\@part%
+                \patchcmd{\@part}%
+                         {\partname\nobreakspace\thepart}%
+                         {\the at uyghur@part\nobreakspace\partname}%
+                         {}%
+                         {\@ifundefined{part}{}{\xpg at warning{Failed to patch part for Uyghur}}}%
+              }%  (end \ifdefined\@part)
+            }{% Hyperref
               \let\xpg at save@part at format\H at old@part%
               \patchcmd{\H at old@part}%
                        {\partname\nobreakspace\thepart}%
@@ -202,30 +165,97 @@
                        {\the at uyghur@part\nobreakspace\partname}%
                        {}%
                        {\xpg at warning{Failed to patch part for Uyghur}}%            
-            }{% not hyperref
-              \ifcsdef{@part}{%
+            }% (end not hyperref)
+          }{%  (\ifdefined\@memptsize)
+           \@ifundefined{@makechapterhead}{}{%
+              \let\xpg at save@chap at format\@makechapterhead%
+              \patchcmd{\@makechapterhead}{\printchaptername \chapternamenum \printchapternum}%
+                       {\chapnumfont\the at uyghur@chapter\chapternamenum\printchaptername}%
+                       {}%
+                       {\xpg at warning{Failed to patch chapter for Uyghur}}%
+           }%
+           \@ifundefined{H at old@part}{% not hyperref
+             \@ifundefined{@part}{}{%
                 \let\xpg at save@part at format\@part%
-                \patchcmd{\@part}%
-                         {\partname\nobreakspace\thepart}%
-                         {\the at uyghur@part\nobreakspace\partname}%
-                         {}%
-                         {\ifcsdef{part}{\xpg at warning{Failed to patch part for Uyghur}}{}}%
-              }{}%  (end \ifdefined\@part)
-            }% (end not hyperref)
-          }% (end \ifdefined\@memptsize)
-        }% (end \ifdefined\sectionformat)
+                \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
+                                 {\chapnumfont\the at uyghur@part\partnamenum\printpartname}%
+                                 {}%
+                                 {\xpg at warning{Failed to patch part for Uyghur}}%
+             }%
+           }{% Hyperref
+                \let\xpg at save@part at format\H at old@part%
+                \patchcmd{\H at old@part}{\printpartname \partnamenum \printpartnum}%
+                                 {\chapnumfont\the at uyghur@part\partnamenum\printpartname}%
+                                 {}%
+                                 {\xpg at warning{Failed to patch part for Uyghur}}%
+           }%
+         }% (end \ifdefined\@memptsize)
+        }{%  (\ifdefined\sectionformat)
+          \@ifundefined{partformat}{}{%
+            \let\xpg at save@part at format\partformat%
+            \renewcommand{\partformat}{\the at uyghur@part~\partname}%
+          }%
+          \@ifundefined{chapterformat}{}{%
+            \let\xpg at save@chap at format\chapterformat%
+            \renewcommand{\chapterformat}{\mbox{\the at uyghur@chapter%
+                                          \IfUsePrefixLine{\nobreakspace\chapapp}{\enskip}}}%
+          }%
+       }% (end \ifdefined\sectionformat)
+     }{% (\ifdefined\titleformat)
+       \@ifundefined{H at old@part}{% not hyperref
+         \@ifundefined{@part}{}{%
+            \let\xpg at save@part at format\@part%
+            \patchcmd{\@part}%
+                      {\partname\nobreakspace\thepart}%
+                      {\the at uyghur@part\nobreakspace\partname}%
+                      {}%
+                      {\xpg at warning{Failed to patch part for Uyghur}}%
+         }%
+       }{% Hyperref
+            \let\xpg at save@part at format\H at old@part%
+            \patchcmd{\H at old@part}%
+                      {\partname\nobreakspace\thepart}%
+                      {\the at uyghur@part\nobreakspace\partname}%
+                      {}%
+                      {\xpg at warning{Failed to patch part for Uyghur}}%
+       }%
+       \@ifundefined{chapter}{}{%
+          \titleformat\chapter[display]%
+             {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
+             {\the at uyghur@chapter\space\@chapapp}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
+       }%
      }% (end \ifdefined\titleformat)
   \fi% (end \if at uyghur@swapheadings)
   %
   % Change running headers
   \if at uyghur@swapheaders
-    \ifcsdef{chapterformat}{%
-      % With KOMA
-      \let\xpg at save@chaptermark at format\chaptermarkformat%
-      \renewcommand*\chaptermarkformat{%
-         \the at uyghur@chapter\ \IfChapterUsesPrefixLine{\chapapp\enskip}{}}
-    }{% (not \ifdefined\chapterformat)
-      \ifcsdef{@memptsize}{%
+    \@ifundefined{chapterformat}{%
+      \@ifundefined{@memptsize}{%
+        % With standard classes
+        \@ifundefined{chaptermark}{}{%
+          \ifpatchable{\chaptermark}%
+               {\@chapapp\ \thechapter.}%
+               {\let\xpg at save@chaptermark at format\chaptermark%
+                \patchcmd{\chaptermark}%
+                    {\@chapapp\ \thechapter.}%
+                    {\the at uyghur@chapter\ \@chapapp}%
+                    {}%
+                    {\xpg at warning{Failed to patch chaptermark for Uyghur}}}%
+               {}%
+        }% (end \ifdefined\sectionmark)
+        \@ifundefined{sectionmark}{}{%
+             \ifpatchable{\sectionmark}%
+                  {\thesection.}%
+                  {\let\xpg at save@sectionmark at format\sectionmark%
+                   \patchcmd{\sectionmark}%
+                      {\thesection.}%
+                      {\thesection}%
+                      {}%
+                      {\xpg at warning{Failed to patch sectionmark for Uyghur}}%
+                  }%
+                  {}%
+       }% (end \ifdefined\chaptermark)
+     }{% (\ifdefined\@memptsize)
         % With memoir
         \let\xpg at save@chaptermark at format\chaptermark%
         \renewcommand*\chaptermark[1]{%
@@ -236,33 +266,14 @@
               }{}%
             \fi
             ##1}}{}}%
-      }{% (not \ifdefined\@memptsize)
-        % With standard classes
-        \ifcsdef{chaptermark}{%
-          \ifpatchable{\chaptermark}%
-               {\@chapapp\ \thechapter.}%
-               {\let\xpg at save@chaptermark at format\chaptermark%
-                \patchcmd{\chaptermark}%
-                    {\@chapapp\ \thechapter.}%
-                    {\the at uyghur@chapter\ \@chapapp}%
-                    {}%
-                    {\xpg at warning{Failed to patch chaptermark for Uyghur}}}%
-               {}%
-        }{}% (end \ifdefined\sectionmark)
-                \ifcsdef{sectionmark}{%
-          \ifpatchable{\sectionmark}%
-               {\thesection.}%
-               {\let\xpg at save@sectionmark at format\sectionmark%
-                \patchcmd{\sectionmark}%
-                    {\thesection.}%
-                    {\thesection}%
-                    {}%
-                    {\xpg at warning{Failed to patch sectionmark for Uyghur}}}%
-               {}%
-        }{}% (end \ifdefined\chaptermark)
       }% (end \ifdefined\@memptsize)
+   }{% (\ifdefined\chapterformat)
+      % With KOMA
+      \let\xpg at save@chaptermark at format\chaptermarkformat%
+      \renewcommand*\chaptermarkformat{%
+         \the at uyghur@chapter\ \IfChapterUsesPrefixLine{\chapapp\enskip}{}}
     }% (end \ifdefined\chapterformat)
-  \fi% (end \if at uyghur@swapheaders)
+ \fi% (end \if at uyghur@swapheaders)
 }
 
 \def\nouyghur at capsformat{%
@@ -272,62 +283,62 @@
    \let\fnum at figure\xpg at save@fnum at figure%
    %
    % Reset chapter and part heading
-   \ifcsdef{titleformat}{%
+   \@ifundefined{titleformat}{%
+     \@ifundefined{sectionformat}{%
+        % With memoir and standard classes
+        \@ifundefined{xpg at save@part at format}{}{%
+           \@ifundefined{H at old@part}{%
+               \let\@part\xpg at save@part at format%
+           }{%
+               \let\H at old@part\xpg at save@part at format%
+           }%
+        }%
+        \@ifundefined{xpg at save@chap at format}{}{%
+          \let\@makechapterhead\xpg at save@chap at format
+        }%
+     }{%
+        % With KOMA
+        \@ifundefined{xpg at save@part at format}{}{%
+           \let\partformat\xpg at save@part at format
+        }%
+        \@ifundefined{xpg at save@chap at format}{}{%
+           \let\chapterformat\xpg at save@chap at format
+        }%
+     }% (end \ifdefined\sectionformat)
+   }{% (\ifdefined\titleformat)
       % With titlesec
-     \ifcsdef{xpg at save@part at format}{%
-        \ifcsdef{H at old@part}{%
+     \@ifundefined{xpg at save@part at format}{}{%
+        \@ifundefined{H at old@part}{%
+            \let\@part\xpg at save@part at format%
+        }{%
             \let\H at old@part\xpg at save@part at format%
-        }{%
-            \let\@part\xpg at save@part at format%
         }%
-     }{}%
-     \ifcsdef{chapter}{%
+     }%
+     \@ifundefined{chapter}{}{%
         \titleformat\chapter[display]%
           {\@ifundefined{ttl at fil}{\raggedright}{\ttl at fil}\ttl at fonts\ttl at sizes6}
           {\@chapapp\space\thechapter}{.8\baselineskip}{\ttl at sizes\z@\ttl at passexplicit}
-     }{}%
-   }{% (not \ifdefined\titleformat)
-     \ifcsdef{sectionformat}{%
-        % With KOMA
-        \ifcsdef{xpg at save@part at format}{%
-           \let\partformat\xpg at save@part at format
-        }{}%
-        \ifcsdef{xpg at save@chap at format}{%
-           \let\chapterformat\xpg at save@chap at format
-        }{}%
-     }{%
-        % With memoir and standard classes
-        \ifcsdef{xpg at save@part at format}{%
-           \ifcsdef{H at old@part}{%
-               \let\H at old@part\xpg at save@part at format%
-           }{%
-               \let\@part\xpg at save@part at format%
-           }%
-        }{}%
-        \ifcsdef{xpg at save@chap at format}{%
-          \let\@makechapterhead\xpg at save@chap at format
-        }{}%
-     }% (end \ifdefined\sectionformat)
+     }%
    }% (end \ifdefined\titleformat)
   %
   % Reset headers
-  \ifcsdef{chaptermarkformat}{%
-     % With KOMA
-     \ifcsdef{xpg at save@chaptermark at format}{%
-       \let\chaptermarkformat\xpg at save@chaptermark at format%
-     }{}%
-  }{%
-     \ifcsdef{chaptermark}{%
+  \@ifundefined{chaptermarkformat}{%
+     \@ifundefined{chaptermark}{}{%
        % With memoir and standard classes
-       \ifcsdef{xpg at save@chaptermark at format}{%
+       \@ifundefined{xpg at save@chaptermark at format}{}{%
          \let\chaptermark\xpg at save@chaptermark at format%
-       }{}%
-     }{}% (end \ifdefined\chaptermark)
-     \ifcsdef{sectionmark}{%
-       \ifcsdef{xpg at save@sectionmark at format}{%
+       }%
+     }% (end \ifdefined\chaptermark)
+     \@ifundefined{sectionmark}{}{%
+       \@ifundefined{xpg at save@sectionmark at format}{}{%
          \let\sectionmark\xpg at save@sectionmark at format%
-       }{}%
-     }{}% (end \ifdefined\sectionmark)
+       }%
+     }% (end \ifdefined\sectionmark)
+  }{%
+     % With KOMA
+     \@ifundefined{xpg at save@chaptermark at format}{}{%
+       \let\chaptermarkformat\xpg at save@chaptermark at format%
+     }%
   }% (end \ifdefined\chapterformat)
 }
 
@@ -363,7 +374,7 @@
 \let\the at uyghur@chapter\thechapter
 
 \def\uyghur at chapterformat{%
-   \ifcsdef{part}{%
+   \@ifundefined{part}{}{%
       \if at uyghur@ordchapter%
         \renewcommand{\the at uyghur@part}{\uyghurord{part}}%
       \fi%
@@ -370,8 +381,8 @@
       \if at uyghur@romchapter%
         \renewcommand{\the at uyghur@part}{\Roman{part}}%
       \fi%
-   }{}%
-   \ifcsdef{chapter}{%
+   }%
+   \@ifundefined{chapter}{}{%
       \if at uyghur@ordchapter%
         \renewcommand{\the at uyghur@chapter}{\uyghurord{chapter}}%
       \fi%
@@ -378,7 +389,7 @@
       \if at uyghur@romchapter%
         \renewcommand{\the at uyghur@chapter}{\Roman{chapter}}%
       \fi%
-   }{}%
+   }%
 }
 
 \def\uyghur at numbers{%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-vietnamese.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-vietnamese.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-vietnamese.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-vietnamese.ldf}[polyglossia: module for Vietnamese]
 %% Strings contributed by Daniel Owens < dhowens . pmbx . net >

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-welsh.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-welsh.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-welsh.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,4 +1,4 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-welsh.ldf}[polyglossia: module for Welsh]
 
@@ -15,21 +15,26 @@
 % BCP-47 compliant aliases
 \setlanguagealias*{welsh}{cy}
 
-\providebool{welsh at formaldate}
+\@ifundefined{ifwelsh at formaldate}%
+  {\newif\ifwelsh at formaldate}{}
 
-\define at choicekey*+{welsh}{date}[\xpg at val\xpg at nr]{long,short}[short]{%
-   \ifcase\xpg at nr\relax
-      % long:
-      \welsh at formaldatetrue
-   \or
-      % accented:
-      \welsh at formaldatefalse
-   \fi
-   \xpg at info{Option: Welsh, date=\xpg at val}%
-}{\xpg at warning{Unknown date value `#1'}}
+\DeclareKeys[polyglossia/gloss/welsh]
+  {
+    date.choice:,
+    date / long.code =
+      {%
+        \welsh at formaldatetrue
+      },
+    date / short.code =
+      {%
+        \welsh at formaldatefalse
+      },
+    date.default:n = short,
+    date/unknown.code = \xpg at warning{Unknown date value `#1'},
+  }
 
 % Register default options
-\xpg at initialize@gloss at options{welsh}{date=short}
+\InitializeGlossOptions{welsh}{date=short}
 
 \def\captionswelsh{%
   \def\refname{Cyfeiriadau}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-zh-CN.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-zh-CN.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-zh-CN.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-zh-CN.ldf}[polyglossia: module for zh-CN (Chinese)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{chinese}
+\InheritGlossFile{chinese}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-zh-TW.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-zh-TW.ldf	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/gloss-zh-TW.ldf	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,9 +1,9 @@
-% Language definition file (part of polyglossia v2.1 -- 2024/03/07)
+% Language definition file (part of polyglossia v2.2 -- 2024/07/15)
 %
 \ProvidesFile{gloss-zh-TW.ldf}[polyglossia: module for zh-TW (Chinese)]
 
 % We provide this as a bcp47-compliant alias
 
-\xpg at load@master at language{chinese}
+\InheritGlossFile{chinese}
 
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/hebrewcal.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/hebrewcal.sty	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/hebrewcal.sty	2024-07-15 21:38:31 UTC (rev 71813)
@@ -73,7 +73,7 @@
        \ifnum#1<5000
          \Hebrewnumeral{#1}%
        \else
-         \ifnum#1<6000 % current millenium, print without thousands
+         \ifnum#1<6000 % current millennium, print without thousands
            \@tempcnta=#1\relax
            \if at xpg@hebrew at fullyear\else\advance\@tempcnta by -5000\fi
            \Hebrewnumeral{\@tempcnta}%

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/hijrical.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/hijrical.sty	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/hijrical.sty	2024-07-15 21:38:31 UTC (rev 71813)
@@ -16,7 +16,7 @@
 \@ifundefined{@Remainder}{\input{cal-util.def}}{}
 
 %% The following functions are straightforward implementation 
-%% of Reingold & Dershowitz, Calendrical Calculations, The Millenium Edition
+%% of Reingold & Dershowitz, Calendrical Calculations, The Millennium Edition
 %%
 
 \def\@FixedFromHijri#1#2#3#4{% year,month,day,counter

Added: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-cjk-spacing.lua
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-cjk-spacing.lua	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-cjk-spacing.lua	2024-07-15 21:38:31 UTC (rev 71813)
@@ -0,0 +1,623 @@
+--
+-- polyglossia-cjk-spacing.lua
+-- part of polyglossia v2.2 -- 2024/07/15
+--
+
+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 whatsit_id = node.id"whatsit"
+local math_id  = node.id"math"
+
+--
+-- attr_cjk: variant = plain: 0, JP/classic: 1, KR/modern: 2, SC: 3, TC: 4
+--
+local attr_cjk = luatexbase.attributes["xpg at attr@cjkspacing"]
+--
+-- attr_josa: ONLY For Korean. DO NOT declare \newattribute for other langs
+--
+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 plus combinings
+--   3: kana small letters
+--   0: dashes (suppress visible spacing after this char)
+--
+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] = 1, -- : 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] = 0, -- ― HORIZONTAL BAR
+    [0x2019] = 1, -- ’ RIGHT SINGLE QUOTATION MARK
+    [0x201D] = 1, -- ” RIGHT DOUBLE QUOTATION MARK
+    [0x2025] = 0, -- ‥ TWO DOT LEADER
+    [0x2026] = 0, -- … 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] = 2, --  COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
+    [0x309A] = 2, --  COMBINING KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
+    [0x309B] = 2, -- ゛ KATAKANA-HIRAGANA VOICED SOUND MARK
+    [0x309C] = 2, -- ゜ 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] = 0, -- ︰ PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
+    [0xFE31] = 0, -- ︱ PRESENTATION FORM FOR VERTICAL EM DASH
+    [0xFE32] = 0, -- ︲ 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] = 2, -- ゙ HALFWIDTH KATAKANA VOICED SOUND MARK
+    [0xFF9F] = 2, -- ゚ 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 2 end -- tone marks
+        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 2 end -- variation selectors
+        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 2 end -- variation selecters
+    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     c >= 0x30000 and c <= 0x323AF
+    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 })
+
+--
+-- get character class
+--      var : variant = plain, JP/classic, KR/modern, SC, TC
+--      c   : codepoint
+--
+local function get_charclass (var, c)
+    if var < 3 then
+        return charclass[c]
+    elseif var == 3 then
+        -- SC : these are left aligned
+        return (c == 0xFF01 or c == 0xFF1F) and 4 -- FULLWIDTH EXCLAMATION/QUESTION MARK
+        or     (c == 0xFF1A or c == 0xFF1B) and 2 -- FULLWIDTH COLON/SEMICOLON
+        or     charclass[c]
+    end
+    -- TC : these are center aligned
+    return (c == 0x3001 or c == 0xFF0C) and 3 -- IDEOGRAPHIC/FULLWIDTH COMMA
+    or     (c == 0x3002 or c == 0xFF0E) and 3 -- IDEOGRAPHIC/FULLWIDTH FULL STOP -- 5 ?
+    or     charclass[c]
+end
+
+--
+-- table for spacing between char classes
+--   1 stands for 0.5*fontsize when variant = JP/classic or SC or TC
+--
+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=KR/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 ~= plain
+--
+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, JP/classic, KR/modern, SC, TC
+--   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, JP/classic, KR/modern, SC, TC
+--   nobr: no linebreak
+--   x:    true between cjk and non-cjk (a little more spacing)
+--
+local function insert_penalty_glue (head, curr, f, var, nobr, x)
+    if nobr then
+        local penalty = get_new_penalty(10000)
+        head, curr = node.insert_after(head, curr, penalty)
+    elseif var == 0 or var == 2 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
+--
+local function cjk_break (head)
+    local curr = head
+    while curr do
+        if attr_cjk and (curr.id == glyph_id or curr.id == math_id and curr.subtype == 1) then
+            local var = node.has_attribute(curr, attr_cjk)
+            if var then
+                local c, f = curr.char or 0, curr.font
+                local cc, cjkc = get_charclass(var, 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 = node.getnext(curr)
+                while next and next.id == whatsit_id do -- skip whatsit nodes
+                    curr, next = next, node.getnext(next)
+                end
+
+                if next and (next.id == glyph_id or next.id == math_id and next.subtype == 0) then
+                    local n = next.char or 0
+                    f = f or next.font or 0 -- in case of curr == math_off
+
+                    -- skip combining. or dash+dash case to suppress stretching
+                    if nobr_before[n] == 2 or (nobr_before[c] == 0 and nobr_before[n] == 0) then
+                        goto skip_combining
+                    end
+
+                    local nc = get_charclass(var, 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)
+
+                    else
+                        local cjkn = is_cjk(n)
+
+                        -- if curr or next is cjk char
+                        if cjkc or cjkn then
+
+                            -- plain variant / cjk+cjk / nobr cjk+noncjk / after dash
+                            --      : insert a 0pt glue
+                            if var == 0 or (cjkc and cjkn) or nobr or nobr_before[c] == 0 then
+                                head, curr = insert_penalty_glue(head, curr, f, var, nobr)
+
+                            -- other cases: insert a small glue
+                            else
+                                head, curr = insert_penalty_glue(head, curr, f, var, nobr, true)
+                            end
+                        end
+                    end
+                end
+            end
+        end
+        ::skip_combining::
+        curr = node.getnext(curr)
+    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_cjk) then
+            local f = font.getfont(curr.font) or font.fonts[curr.font]
+            if f and f.hb then -- harfbuzz do the right thing
+                tone = nil
+            else
+                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
+        end
+        curr = node.getprev(curr)
+    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 = node.getprev(p)
+    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(node.getprev(curr)) or 0x30]
+                end
+                if cc == 0xC774 then
+                    local n = node.getnext(curr)
+                    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 = node.getnext(curr)
+    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.
+--
+luatexbase.add_to_callback( "pre_shaping_filter",
+function(head)
+    if attr_josa then head = auto_josa(head) end
+    head = cjk_break(head)
+    if attr_josa then head = reorder_tm(head) end
+    return head
+end,
+"polyglossia.lang_cjk_spacing")
+
+-- vim:ft=lua:tw=0:sw=4:ts=4:expandtab


Property changes on: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-cjk-spacing.lua
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-french.lua
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-french.lua	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-french.lua	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,6 +1,6 @@
 --
 -- polyglossia-punct.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia-punct')

Deleted: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-korean.lua
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-korean.lua	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-korean.lua	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,609 +0,0 @@
---
--- polyglossia-korean.lua
--- part of polyglossia v2.1 -- 2024/03/07
---
-
-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 f = font.getfont(curr.font) or font.fonts[curr.font]
-            if f and f.hb then -- harfbuzz do the right thing
-                tone = nil
-            else
-                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
-        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

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-latin.lua
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-latin.lua	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-latin.lua	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,6 +1,6 @@
 --
 -- polyglossia-latin.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia-punct')

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-punct.lua
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-punct.lua	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-punct.lua	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,13 +1,12 @@
 --
 -- polyglossia-punct.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia') -- just in case...
 
 local add_to_callback      = luatexbase.add_to_callback
-local remove_from_callback = luatexbase.remove_from_callback
-local priority_in_callback = luatexbase.priority_in_callback
+local declare_callback_rule = luatexbase.declare_callback_rule
 local new_attribute        = luatexbase.new_attribute
 
 local node = node
@@ -331,13 +330,16 @@
     -- important to be able to intermix languages with different spacings
     -- in one paragraph.
     tex.setattribute(punct_attr, id)
-    for _, callback_name in ipairs{ "pre_linebreak_filter", "hpack_filter" } do
-        if not priority_in_callback(callback_name, "polyglossia-punct.process") then
-            add_to_callback(callback_name, process, "polyglossia-punct.process", 1)
-        end
-    end
 end
 
+add_to_callback("pre_linebreak_filter",process,"polyglossia-punct.process")
+add_to_callback("hpack_filter",process,"polyglossia-punct.process")
+declare_callback_rule("pre_linebreak_filter",
+    "polyglossia-punct.process", "before", "luaotfload.node_processor")
+declare_callback_rule("hpack_filter",
+    "polyglossia-punct.process", "before", "luaotfload.node_processor")
+
+
 local function deactivate()
     tex.setattribute(punct_attr, -0x7FFFFFFF) -- this value means "unset"
     -- Though it would make compilation slightly faster, it is not possible to

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-sanskrit.lua
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-sanskrit.lua	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-sanskrit.lua	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,6 +1,6 @@
 --
 -- polyglossia-sanskrit.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia-punct')

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-tibt.lua
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-tibt.lua	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia-tibt.lua	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,6 +1,6 @@
 --
 -- polyglossia-tibt.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 require('polyglossia') -- just in case...
@@ -7,17 +7,15 @@
 
 local add_to_callback = luatexbase.add_to_callback
 local remove_from_callback = luatexbase.remove_from_callback
+local declare_callback_rule = luatexbase.declare_callback_rule
 local priority_in_callback = luatexbase.priority_in_callback
 
 local next, type = next, type
+local node = node
 
-local nodes, fonts, node = nodes, fonts, node
-
-local nodecodes          = nodes.nodecodes --- <= preloaded node.types()
-
 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 copy_node          = node.copy
 local has_attribute      = node.has_attribute
 
@@ -24,7 +22,7 @@
 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 math_code      = node.id('math_char')
   local end_of_math = function (n)
     for n in traverse_nodes(math_code, n.next) do
       return n
@@ -32,10 +30,10 @@
   end
 end
 
--- node types as of April 2013
-local glyph_code         = nodecodes.glyph
-local penalty_code       = nodecodes.penalty
-local kern_code          = nodecodes.kern
+-- node types as of April 2024
+local glyph_code         = node.id('glyph')
+local penalty_code       = node.id('penalty')
+local kern_code          = node.id('kern')
 
 -- we make a new node, so that we can copy it later on
 local penalty_node  = node.new(penalty_code)
@@ -66,7 +64,6 @@
                 end
             end
         elseif id == math_code then
-            -- warning: this is a feature of luatex > 0.76
             start = end_of_math(start) -- weird, can return nil .. no math end?
         end
         if start then
@@ -79,15 +76,13 @@
 local callback_name = "pre_linebreak_filter"
 
 local function activate()
-  if not priority_in_callback (callback_name, "polyglossia-tibt.process") then
-    add_to_callback(callback_name, process, "polyglossia-tibt.process", 1)
-  end
+    add_to_callback(callback_name, process, "polyglossia-tibt.process")
+    declare_callback_rule(callback_name,
+    "polyglossia-tibt.process", "before", "luaotfload.node_processor")
 end
 
 local function desactivate()
-  if priority_in_callback (callback_name, "polyglossia-tibt.process") then
-    remove_from_callback(callback_name, "polyglossia-tibt.process")
-  end
+	remove_from_callback(callback_name, "polyglossia-tibt.process")
 end
 
 polyglossia.activate_tibt_eol    = activate

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.lua
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.lua	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.lua	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,6 +1,6 @@
 --
 -- polyglossia.lua
--- part of polyglossia v2.1 -- 2024/03/07
+-- part of polyglossia v2.2 -- 2024/07/15
 --
 
 local module_name = "polyglossia"
@@ -76,7 +76,7 @@
             end
 
             -- language info will be written into the .log file
-            local s = { "Language data for " .. langentry }
+            local s = { }
             for k, v in pairs(langdata) do
                 if type(v) == 'table' then -- for 'synonyms'
                     s[#s+1] = k .. "\t" .. table.concat(v,',')
@@ -84,7 +84,10 @@
                     s[#s+1] = k .. "\t" .. tostring(v)
                 end
             end
-            log_info(table.concat(s,"\n"))
+            local a = {}
+	    for _,n in pairs(s) do table.insert(a, n) end
+            table.sort(a)
+            log_info("Language data for " .. langentry .. "\n" .. table.concat(a,"\n"))
 
             --
             -- LaTeX's \newlanguage increases language register (count19),
@@ -94,7 +97,7 @@
             -- this possible situation, our newloader() function will
             -- unfortunately overwrite the language \lang at xyz.
             --
-            -- Threfore here we will compare LaTeX's \newlanguage number with
+            -- Therefore 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
@@ -109,7 +112,7 @@
             local newlangid = math.max(langcnt, langid)
             -- set language register for possible \newlanguage
             tex.setcount('global', lang_register, newlangid)
-            -- get new lang object if needeed
+            -- get new lang object if needed
             if langid ~= newlangid then
                 langobject = lang.new(newlangid)
             end

Modified: trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty	2024-07-15 21:37:48 UTC (rev 71812)
+++ trunk/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty	2024-07-15 21:38:31 UTC (rev 71813)
@@ -1,10 +1,11 @@
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesExplPackage
-  {polyglossia} {2024/03/07} {v2.1}
+  {polyglossia} {2024/07/15} {v2.2}
   {Modern multilingual typesetting with XeLaTeX and LuaLaTeX}
 
+% TODO Handle remaining uses in the gloss files (\patchcmd)
+%      and remove package call afterwards
 \RequirePackage{etoolbox}
-\RequirePackage{xkeyval}[2008/08/13]
 % Will raise error if used with anything else than XeTeX or LuaTeX
 \RequirePackage{fontspec}[2010/06/08]% v2.0
 \RequirePackage{iftex}
@@ -11,13 +12,6 @@
 
 \prg_generate_conditional_variant:Nnn \clist_if_in:Nn {Ne} {TF, T, F} % check if needed
 
-% correct a bug in tracklang
-\AddToHook{package/tracklang/after}{%
-  \IfPackageAtLeastTF{tracklang}{2019/08/30}
-      {}
-      {\cs_gset_eq:NN \AddTrackedLangage \AddTrackedLanguage}
-}
-
 %% The following is for compatibility with Babel-aware package:
 % \languageshorthands is provided by babelsh.def, which is
 % only loaded by some glosses, but some classes presuppose
@@ -24,9 +18,10 @@
 % it is there generally. So let's provide a stub:
 \ProvideDocumentCommand \languageshorthands { m } {}
 % These have to be provided at the end of the preamble
-\AddToHook{begindocument/before}{
-  \cs_gset_eq:NN \bbl at set@language \xpg at set@language at aux  % for biblatex
-  \cs_gset_eq:NN \bbl at main@language \xpg at main@language    % for biblatex
+\hook_gput_code:nnn {begindocument/before} {.}
+{
+  \cs_gset_eq:NN \bbl at set@language \xpg_set_language_aux:nn  % for biblatex
+  \cs_gset_eq:NN \bbl at main@language \xpg_main_language_tl    % for biblatex
   \ProvideDocumentCommand \texorpdfstring { m m } { #1 }  % dummy command if hyperref is not loaded
 }
 
@@ -35,16 +30,15 @@
 %% \l at nohyphenation is defined in polyglossia.lua
 \sys_if_engine_luatex:TF
   {
-	\RequirePackage{luatexbase} % already included by fontspec, but needed here
-	\RequireLuaModule{polyglossia}
+	\lua_load_module:n{polyglossia}
   }{
 	\cs_if_free:cT { l at nohyphenation } 
 	   { \chardef\l at nohyphenation=255 }
   }
 
-% Which version of XeTeX do we use? What is the boudary class? 4095 or 255
+% Which version of XeTeX do we use? What is the boundary class? 4095 or 255
 \cs_if_exist:cTF { e at alloc@intercharclass at top }
-  { \let\xpg at boundaryclass=\e at alloc@intercharclass at top }
+  { \cs_gset_eq:NN \xpg at boundaryclass \e at alloc@intercharclass at top }
   { \chardef\xpg at boundaryclass=\@cclv }
 
 % Useful for getting list of loaded languages and variants. Like babel's bbl at loaded
@@ -80,18 +74,18 @@
 \cs_new_nopar:Nn \__xpg_at_begin_document:
 {
   % 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
+  \cs_gset_eq:cc{latin at alph}{@alph}% TODO rename when we have the C locale
+  \cs_gset_eq:cc{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
+  \cs_gset_eq:cc{xpg_Clang_arabic}{@arabic}
   
   \xpg_initial_setup:
   % apply \familydefault changes
-  \xpg at set@familydefault
+  \xpg_set_familydefault:
 }
 
-\AddToHook{begindocument}{
+\hook_gput_code:nnn {begindocument} {.}
+{
   \__xpg_at_begin_document:
 }
 
@@ -99,7 +93,8 @@
 % loaded after \set[main|other]language
 % Track whether the main language has been set
 \bool_new:N \g_xpg_main_lang_set_bool
-\AddToHook{begindocument/end}{
+\hook_gput_code:nnn {begindocument/end} {.}
+{
   % now we have the C locale definition: select the language
   \__xpg_at_begin_document_selectlanguage:
   \bool_gset_true:N \g_xpg_main_lang_set_bool
@@ -107,99 +102,177 @@
   \__xpg_at_begin_document_hyphenation:
 }
 
-%% custom message macros
-\providecommand*{\xpg at error}[1]{
-   \PackageError{polyglossia}{#1}{}
+%
+% MESSAGES
+%
+
+% message templates
+\msg_new:nnn { polyglossia } { general } { #1 }
+
+\msg_new:nnn { polyglossia } { languagenotloaded }
+{
+  The~ language~ #1~ is~ not~ loaded.~ You~ must~ load~ it~ in~ order~ to~ use~ it.
 }
+\msg_redirect_name:nnn { polyglossia } { languagenotloaded } { critical }
 
-\providecommand*{\xpg at warning}[1]{
-   \PackageWarning{polyglossia}{#1}
+\msg_new:nnn { polyglossia } { languagenolongerloaded }
+{
+  The~ language~ #1~ is~ no~ longer~ loaded.~ Please~ rerun~ LaTeX.
 }
+\msg_redirect_name:nnn { polyglossia } { languagenolongerloaded } { warning }
 
-\providecommand*{\xpg at info}[1]{
-   \PackageInfo{polyglossia}
-   {#1\@gobble}
-} %% the \@gobble is to prevent displaying the line nr
+\msg_new:nnn { polyglossia } { unknownlocalnumeral }
+{
+  Unknown~ key~ "#1"~ in~ \string\localnumeral.
+}
 
-%TODO change all instances of \xpg at nopatterns in gloss-*.ldf files
-\providecommand*{\xpg at nopatterns@fallback}[2][nohyphenation]{
-   \xpg at warning{No~ hyphenation~ patterns~ were~ loaded~ for~ `#2'\MessageBreak
-         I~ will~ use~ \string\language=\string\l@ #1\space instead}
-   \expandafter\adddialect\csname l@#2\expandafter\endcsname\csname l@#1\endcsname\relax}
+\msg_new:nnn { polyglossia } { localnumeralemptyvalue }
+{
+  Keys~ of~ \string\localnumeral~ must~ have~ a~ value.
+}
 
-\providecommand*{\xpg at nopatterns}[1]{
-   \xpg at warning{No~ hyphenation~ patterns~ were~ loaded~ for~ `#1'\MessageBreak
-         I~ will~ use~ \string\language=\string\l at nohyphenation\space instead}
-   %%TODO? \expandafter\adddialect\csname l@#1\endcsname\l at nohyphenation\relax
-   }
+\msg_new:nnn { polyglossia } { illvalue }
+{
+  Illegal~ value~ (#1)~ for~ #2!
+}
 
-\def\xpg at ill@value#1#2{
-  \xpg at warning{Illegal~ value~ (#1)~ for~ #2}}
+\msg_new:nnn { polyglossia } { illarg }
+{
+  Invalid~ argument~ (#1)~ for~ #2!
+}
 
-% error out if lang is not loaded
-\cs_new_nopar:Nn \xpg_error_if_lang_not_loaded:n
+\msg_new:nnn { polyglossia } { nopatterns }
 {
-  \seq_if_in:NeF \__xpg_langs_loaded {#1}
-  {
-    \xpg at error{language~ #1~ is~ not~ loaded.~ Please~ load~ it~ before~ using~ it.}
-  }
+  No~ hyphenation~ patterns~ were~ loaded~ for~ `#2' \iow_newline:
+  I~ will~ use~ \string\language=\string\l@ #1\space instead.
 }
 
-\msg_new:nnn { polyglossia } { languagenotloaded }
+\msg_new:nnn { polyglossia } { undefcmd }
 {
-  The~ language~ #1~ is~ not~ loaded.~ You~ should~ load~ it.
+  \tl_to_str:N {#1} ~ is~ not~ defined!
 }
-\msg_redirect_name:nnn { polyglossia } { languagenotloaded } { critical }
 
-\msg_new:nnn { polyglossia } { languagenolongerloaded }
+%% custom message macros
+\cs_new_nopar:Nn \xpg_error_msg:n
 {
-  The~ language~ #1~ is~ no~ longer~ loaded.~ Please~ rerun~ LaTeX.
+   \exp_args:Nnne \msg_error:nnn { polyglossia } { general } { #1 }
 }
-\msg_redirect_name:nnn { polyglossia } { languagenolongerloaded } { warning }
 
-\msg_new:nnn { polyglossia } { unknownlocalnumeral }
+\cs_new_nopar:Nn \xpg_warning_msg:n
 {
-  Unknown~ key~ "#1"~ in~ \string\localnumeral.
+   \exp_args:Nnne \msg_warning:nnn { polyglossia } { general } { #1 }
 }
 
-\msg_new:nnn { polyglossia } { localnumeralemptyvalue }
+\cs_new_nopar:Nn \xpg_info_msg:n
 {
-  Keys~ of~ \string\localnumeral~ must~ have~ value.
+   \exp_args:Nnne \msg_info:nnn { polyglossia } { general } { #1 }
 }
 
+\cs_new_nopar:Nn \xpg_no_patterns_msg:n
+{
+   \msg_warning:nnnn { polyglossia } { nopatterns } { nohyphenation } { #1 }
+}
 
+\cs_new_nopar:Nn \xpg_ill_value_msg:nn
+{
+  \msg_warning:nnnn { polyglossia } { illvalue } { #1 } { #2 }
+}
+
+\cs_new_nopar:Nn \xpg_ill_arg_msg:nn
+{
+  \msg_error:nnnn { polyglossia } { illarg } { #1 } { #2 }
+}
+
+% error out if lang is not loaded
+\cs_new_nopar:Nn \xpg_error_if_lang_not_loaded:n
+{
+  \seq_if_in:NeF \__xpg_langs_loaded {#1}
+  {
+    \msg_error:nnn { polyglossia } { languagenotloaded } { #1 }
+  }
+}
+
 %% use macro if defined, else warn that it is not
 \cs_new_nopar:Nn \__xpg_use_or_warn:N
 {
   \cs_if_exist_use:NF {#1}
   {
-    \xpg at warning {  \tl_to_str:N {#1} ~ is~ not~ defined }
+    \msg_error:nnn { polyglossia } { undefcmd } { #1 }
   }
 }
 \cs_generate_variant:Nn \__xpg_use_or_warn:N {c}
 
+% gloss message interface
+\cs_set_eq:cc { xpg at error }      { xpg_error_msg:n }
+\cs_set_eq:cc { xpg at warning }    { xpg_warning_msg:n }
+\cs_set_eq:cc { xpg at info }       { xpg_info_msg:n }
+\cs_set_eq:cc { xpg at ill@value }  { xpg_ill_value_msg:nn }
 
+
+\NewDocumentCommand \XPGNoPatternsFallback { O{ nohyphenation } m }
+{
+   \msg_warning:nnnn { polyglossia } { nopatterns } { #1 } { #2 }
+   \exp_args:Ncc \adddialect {l@#2} {l@#1}
+}
+
+\NewDocumentCommand \CheckHyphenationPatterns { m }
+{
+   \xpg_if_language_defined:nF {#1}
+    {
+      \XPGNoPatternsFallback{#1}
+    }
+}
+
+%
+% END MESSAGES
+
+
 %% ensure directionality if bidi is loaded, else ignore
-\def\@@ensure at dir#1{\ifcsundef{@ensure at dir}{#1}{\@ensure at dir{#1}}}
-\def\@@ensure at maindir#1{\ifcsundef{@ensure at maindir}{#1}{\@ensure at maindir{#1}}}
+%%% FIXME still used?
+\cs_new_nopar:Npn \@@ensure at dir #1
+{
+  \cs_if_exist_use:c{@ensure at dir}{#1}
+}
 
-%% Used by the language definitions files for right-to-left languages
-\NewDocumentCommand \RequireBidi {}
+\cs_new_nopar:Npn \@@ensure at maindir #1
 {
-    \sys_if_engine_luatex:TF
-      {\ifx\@onlypreamble\@notprerr\else\RequirePackage{luabidi}\fi}
-      {\ifx\@onlypreamble\@notprerr\else\RequirePackage{bidi}\fi}
+  \cs_if_exist_use:c{@ensure at maindir}{#1}
 }
 
-% if #1 is LR run #2 else #3
+% if we are in the document preamble run T else F
+\prg_set_conditional:Nnn \xpg_if_in_preamble: {T, F, TF}
+{
+  \cs_if_eq:NNTF { \@onlypreamble } { \@notprerr }
+  {
+    \prg_return_false:
+  }
+  {
+    \prg_return_true:
+  }
+}
+
+%% Used by the language definitions files for right-to-left languages
+\DeclareDocumentCommand \RequireBidi {}
+  {
+    \xpg_if_in_preamble:T
+      {
+        \sys_if_engine_luatex:TF
+          { \RequirePackage{luabidi} }
+          { \RequirePackage{bidi} }
+      }
+    \DeclareDocumentCommand \RequireBidi {} {}
+  }
+
+% if #1 is LR run T else F
 \prg_set_conditional:Nnn \__xpg_if_LR_str:n {p, T, F, TF}
 {
-  \str_case_e:nnF{#1}{
+  \str_case_e:nnF{#1}
+  {
     {LR}{\prg_return_true:}
     {RL}{\prg_return_false:}
   }
   {
-    \xpg at error{Unknown~ direction~#1}
+    \xpg_error_msg:n {Unknown~ direction~#1}
     \prg_return_false:
   }
 }
@@ -212,7 +285,7 @@
 {
   \__xpg_if_LR_str:nF {#1}
   {
-    \xpg at error{right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}
+    \xpg_error_msg:n {right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}
   }
 }
 \cs_new_nopar:Nn \__xpg_set_text_direction:n
@@ -219,10 +292,11 @@
 {
   \__xpg_if_LR_str:nF {#1}
   {
-    \xpg at error{right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}
+    \xpg_error_msg:n {right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}
   }
 }
-\AddToHook{package/bidi/after}{
+\hook_gput_code:nnn {package/bidi/after} {.}
+{
   \cs_gset_nopar:Nn \__xpg_set_par_direction:n
   {
     \__xpg_if_LR_str:nTF{#1}
@@ -244,7 +318,8 @@
     }
   }
 }
-\AddToHook{package/luabidi/after}{
+\hook_gput_code:nnn {package/luabidi/after} {.}
+{
   \cs_gset_nopar:Nn \__xpg_set_par_direction:n
   {
     \__xpg_if_LR_str:nTF{#1}
@@ -273,13 +348,21 @@
   { \cs_new_nopar:Nn \__xpg_setRTLmain: { \@RTLmaintrue\setnonlatin } }
 
 %% compatibility with babel
-\let\addto\gappto % gappto is defined in etoolbox
+\cs_set:Npn \addto #1 #2
+{
+  \cs_if_exist:NF { #1 }
+     { \cs_new:Npn { #1 } {} }
+  \tl_gput_right:Nn { #1 } { #2 }
+}
 
-%% NEW EXPERIMENTAL SETUP INTERFACE FOR GLOSS FILES
+%% SETUP INTERFACE FOR GLOSS FILES
 %% options currently available:
 %% language : the name of the language (as understood by fontspec)
 %% 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.)
+%%%   TODO: if pattern is prefixed by !, then it should be loaded as a fallback,
+%%%%        with \CheckHyphenationPatterns - 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
 %% scripttag : the OpenType tag for the script
 %% langtag : the OpenType tag for the language
@@ -287,19 +370,20 @@
 %% frenchspacing : boolean
 %% indentfirst : boolean
 %% fontsetup : boolean
-%% TODO: nouppercase : boolean (for scripts like Arabic, Devanagari, etc which have no concept of uppercase/lowercase)
+%% TODO: nouppercase : boolean (for scripts like Arabic, Devanagari, etc which have
+%%       no concept of uppercase/lowercase)
 %% TODO: localalph = {<alph_csname>,<Alph_csname>}
 %% TODO: localnumeral = <csname>
 %%       or even better localdigits = {0123456789} for fully automatic setup
-\newcommand*\PolyglossiaSetup[2]{
+\NewDocumentCommand \PolyglossiaSetup { m m }
+{
   \__xpg_keys_define_lang:n{#1}
   \keys_set:nn { polyglossia / #1 } { #2 }
   \__xpg_setup_hyphen:n {#1}
   %define booleans etoolbox style and set defaults
   %% TODO ? \providetoggle{#1 at setup@done}%
-  % 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?
+  % we initialize this so that we can append below
+  \cs_gset:cpn {init at extras@#1} {}
   % here we do the fontsetup:
   \__xpg_auto_setupfont:n { #1 }
   %% TODO? \toggletrue{#1 at setup@done}
@@ -318,35 +402,41 @@
   \clist_map_inline:nn { #1 } { \keys_set:nn { polyglossia / ##1 } { #2 } }
 }
 
-
+\bool_new:N \l__xpg_have_hyphen_bool
 % setup hyphennames from a str list of hyphen
 \cs_new:Nn \__xpg_setup_hyphen:n
 {
-  \clist_set:Ne{\l_tmpa_clist}{\prop_item:Nn \g_xpg_langsetup_prop {#1 / hyphennames}}
-  \providebool{havehyphen}
-  \boolfalse{havehyphen}
+  \clist_set:Ne{\l_tmpa_clist}{\prop_item:Nn \l_xpg_langsetup_prop {#1 / hyphennames}}
+  \bool_set_false:N \l__xpg_have_hyphen_bool
   % for each hyphen in the set until we find one that works
-  \clist_map_inline:Nn \l_tmpa_clist {
-    \ifbool{havehyphen}{}{
+  \clist_map_inline:Nn \l_tmpa_clist
+  {
+    \bool_if:NF \l__xpg_have_hyphen_bool
+    {
        % check if language hyphenname is defined
-      \__xpg_check_if_exist_l@:nF{#1}{
+      \__xpg_pattern_check_if_exists:nF{#1}
+      {
           % if not, first consider nohyphenation
           \str_if_eq:nnTF{##1}{nohyphenation}
             {
                \cs_gset_eq:cc{l@#1}{l@##1}
-               \global\booltrue{havehyphen}
-            }{
+               \bool_gset_true:N \l__xpg_have_hyphen_bool
+            }
+            {
                % then test if hyphenation is defined
-               \xpg at ifdefined{##1}{
+               \xpg_if_language_defined:nT {##1}
+               {
                   % test if language hyphenation is nohyphenation
-                  \cs_if_eq:cNF{l@#1}{\l at nohyphenation}{\global\booltrue{havehyphen}}{%
+                  \cs_if_eq:cNTF{l@#1}{\l at nohyphenation}
+                    { \bool_gset_true:N \l__xpg_have_hyphen_bool }
+                    {
                       % 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}
-                  }
-                }{}
+                      \xpg_set_hyphenation_patterns:n {##1}
+                      \bool_gset_true:N \l__xpg_have_hyphen_bool
+                    }
+               }
            }
        }
     }
@@ -354,19 +444,17 @@
   % 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{#1}
-      \expandafter\adddialect\csname l@#1\endcsname\l at nohyphenation\relax
-    }
+  \bool_if:NF \l__xpg_have_hyphen_bool
+  {
+    \CheckHyphenationPatterns{#1}
   }
-  \csdef{#1 at language}{
-    \polyglossia at setup@language at patterns{#1}
+  \cs_gset:cpn {#1 at language}
+  {
+    \SetupPolyglossiaLangPatterns{#1}
   }
   % setup hyphenmins
   \clist_set:Ne \l_tmpa_clist
-    { \prop_item:Nn \g_xpg_langsetup_prop {#1 / hyphenmins} }
+    { \prop_item:Nn \l_xpg_langsetup_prop {#1 / hyphenmins} }
   \cs_if_eq:cNF {l@#1} \l at nohyphenation
     {
       \use:x
@@ -378,7 +466,8 @@
     }
 }
 
-\newcommand*\polyglossia at setup@language at patterns[1]{
+\NewDocumentCommand \SetupPolyglossiaLangPatterns { m }
+{
   \bool_if:NTF \g__xpg_hyphenation_disabled_bool
   {
     \tl_gset:Ne \g__xpg_lastlanguage_tl {\the\csname l@#1\endcsname}
@@ -392,32 +481,29 @@
             \language=\l at nohyphenation
           }
           {
-            \xpg at set@hyphenation at patterns{#1}
+            \xpg_set_hyphenation_patterns:n {#1}
           }
       }
       {
         % Since this function is sometimes called from the gloss files
         % directly, we need to check whether the requested hyphenname exists.
-        \xpg at ifdefined{#1}{}
-        {
-          \xpg at nopatterns{#1}
-          \expandafter\adddialect\csname l@#1\endcsname\l at nohyphenation\relax%
-        }
-        \xpg at set@hyphenation at patterns{#1}
+        \CheckHyphenationPatterns{#1}
+        \xpg_set_hyphenation_patterns:n {#1}
       }
   }
 }
 
-\prop_new:N \g_xpg_langsetup_prop
+\prop_new_linked:N \l_xpg_langsetup_prop
 
 \cs_new_protected:Npn \__xpg_keys_define_lang:n #1
 {
-  \keys_define:nn {polyglossia}{
+  \keys_define:nn {polyglossia}
+  {
     % the script font
     #1 / script
        .code:n = {
-          \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/script}{##1}
-          \prop_gput:Nne{\g_xpg_langsetup_prop}{#1/lcscript}
+          \prop_put:Nnn \l_xpg_langsetup_prop {#1/script}{##1}
+          \prop_put:Nne \l_xpg_langsetup_prop {#1/lcscript}
                {\tl_if_empty:nF{##1}{\str_lowercase:n{##1}}}
     },
     #1 / script
@@ -426,7 +512,7 @@
        .initial:n = latin,
     % the opentype script tag
     #1 / scripttag
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/scripttag}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/scripttag}{##1}},
     #1 / scripttag
        .default:n = {},
     #1 / scripttag
@@ -433,7 +519,7 @@
       .initial:n = {},
     % the language full name
     #1 / language
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/language}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/language}{##1}},
     #1 / language
        .value_required:n = true,
     #1 / language
@@ -440,7 +526,7 @@
         .initial:x = {\str_uppercase:n#1},
     % the language tag
     #1 / langtag
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/langtag}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/langtag}{##1}},
     #1 / langtag
        .value_required:n = true,
     #1 / langtag
@@ -447,7 +533,7 @@
        .initial:n = {},
     % the BCP-47 tag
     #1 / bcp47
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47}{##1}},
     #1 / bcp47
        .value_required:n = true,
     #1 / bcp47
@@ -454,7 +540,7 @@
        .initial:n = {},
     % the BCP-47 language tag
     #1 / bcp47-language
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-language}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-language}{##1}},
     #1 / bcp47-language
        .value_required:n = true,
     #1 / bcp47-language
@@ -461,7 +547,7 @@
        .initial:n = {},
     % the BCP-47 region tag
     #1 / bcp47-region
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-region}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-region}{##1}},
     #1 / bcp47-region
        .value_required:n = false,
     #1 / bcp47-region
@@ -468,14 +554,19 @@
        .initial:n = {},
     % the BCP-47 script tag
     #1 / bcp47-script
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-script}{##1}},
+       .code:n =
+         {
+           \prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-script}{##1}
+           \prop_put:Nne \l_xpg_langsetup_prop {#1/lc-bcp47-script}
+               {\tl_if_empty:nF{##1}{\str_lowercase:n{##1}}}
+         },
     #1 / bcp47-script
        .value_required:n = true,
     #1 / bcp47-script
-       .initial:n = {},
+       .initial:n = {Latn},
     % the BCP-47 variant tag
     #1 / bcp47-variant
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-variant}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-variant}{##1}},
     #1 / bcp47-variant
        .value_required:n = false,
     #1 / bcp47-variant
@@ -482,7 +573,7 @@
        .initial:n = {},
     % the BCP-47 extension-t tag
     #1 / bcp47-extension-t
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-extension-t}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-extension-t}{##1}},
     #1 / bcp47-extension-t
        .value_required:n = false,
     #1 / bcp47-extension-t
@@ -489,7 +580,7 @@
        .initial:n = {},
     % the BCP-47 extension-u tag
     #1 / bcp47-extension-u
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-extension-u}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-extension-u}{##1}},
     #1 / bcp47-extension-u
        .value_required:n = false,
     #1 / bcp47-extension-u
@@ -496,7 +587,7 @@
        .initial:n = {},
     % the BCP-47 extension-x tag
     #1 / bcp47-extension-x
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-extension-x}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-extension-x}{##1}},
     #1 / bcp47-extension-x
        .value_required:n = false,
     #1 / bcp47-extension-x
@@ -503,7 +594,7 @@
        .initial:n = {},
     % the BCP-47 casing alias
     #1 / bcp47-casing
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/bcp47-casing}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/bcp47-casing}{##1}},
     #1 / bcp47-casing
        .value_required:n = false,
     #1 / bcp47-casing
@@ -512,7 +603,7 @@
     #1 / hyphennames
     .code:n = {
       \clist_set:Nn{\l_tmpa_clist}{##1}
-      \prop_gput:Nne{\g_xpg_langsetup_prop}{#1/hyphennames}{\clist_use:Nn \l_tmpa_clist {,}}
+      \prop_put:Nne \l_xpg_langsetup_prop {#1/hyphennames}{\clist_use:Nn \l_tmpa_clist {,}}
     },
     #1 / hyphennames
        .value_required:n = true,
@@ -525,8 +616,8 @@
              {LR}{}
              {RL}{\RequireBidi}
            }
-           {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/direction}{##1}}
-           {\xpg at error{Unknown~ direction~ "##1"~ for~ language~ "#1"}}
+           { \prop_put:Nnn \l_xpg_langsetup_prop {#1/direction}{##1} }
+           { \xpg_error_msg:n {Unknown~ direction~ "##1"~ for~ language~ "#1"} }
        },
     #1 / direction
       .value_required:n = true,
@@ -537,9 +628,9 @@
     .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"}}
+        { \xpg_error_msg:n {hypenmins~should~be~a~list~of~two~entries,~got~"##1"} }
       % set prop
-      \prop_gput:Nnn \g_xpg_langsetup_prop {#1/hyphenmins} {##1}
+      \prop_put:Nnn \l_xpg_langsetup_prop {#1/hyphenmins} {##1}
     },
     #1 / hyphenmins
       .value_required:n = true,
@@ -550,9 +641,9 @@
     .code:n = {
       % check syntax
       \int_compare:nNnF { \clist_count:n {##1} } = {1}
-        {\xpg at error{totalhyphenhypenmin~should~be~a~single~entry,~got~"##1"}}
+        { \xpg_error_msg:n {totalhyphenhypenmin~should~be~a~single~entry,~got~"##1"} }
       % set prop
-      \prop_gput:Nnn \g_xpg_langsetup_prop {#1/totalhyphenmin} {##1}
+      \prop_put:Nnn \l_xpg_langsetup_prop {#1/totalhyphenmin} {##1}
     },
     #1 / totalhyphenmin
       .value_required:n = false,
@@ -571,7 +662,7 @@
     % environment name
     #1 / envname
        .code:n = {
-           \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/envname}{##1}
+           \prop_put:Nnn \l_xpg_langsetup_prop {#1/envname}{##1}
        },
     #1/ envname.value_required:n = true,
     #1/ envname.initial:n = {#1},
@@ -578,7 +669,7 @@
     % babel name
     #1 / babelname
        .code:n = {
-           \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/babelname}{##1}
+           \prop_put:Nnn \l_xpg_langsetup_prop {#1/babelname}{##1}
        },
     #1/ babelname.value_required:n = true,
     #1/ babelname.initial:n = {#1},
@@ -585,21 +676,21 @@
     % default numerals
     #1 / localnumeral
          . code:n =  {
-            \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/localnumeral}{##1}
-            \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/Localnumeral}{##1}
+            \prop_put:Nnn \l_xpg_langsetup_prop {#1/localnumeral}{##1}
+            \prop_put:Nnn \l_xpg_langsetup_prop {#1/Localnumeral}{##1}
          },
     #1 / localnumeral.value_required:n = true,
-    #1 / localnumeral.initial:n = {polyglossia at C@localnumeral},
+    #1 / localnumeral.initial:n = {xpg_C_localnumeral:nn},
     % uppercased
     #1 / Localnumeral
          . code:n =  {
-            \prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/Localnumeral}{##1}
+            \prop_put:Nnn \l_xpg_langsetup_prop {#1/Localnumeral}{##1}
          },
     #1 / Localnumeral.value_required:n = true,
-    #1 / Localnumeral.initial:n = {polyglossia at C@localnumeral},
+    #1 / Localnumeral.initial:n = {xpg_C_localnumeral:nn},
     % environment define command (by default create the environment)
     #1 / DefineCommandsCmd
-       .code:n = {\prop_gput:Nnn{\g_xpg_langsetup_prop}{#1/DefineCommandsCmd}{##1}},
+       .code:n = {\prop_put:Nnn \l_xpg_langsetup_prop {#1/DefineCommandsCmd}{##1}},
     #1 / DefineCommandsCmd
        .value_required:n = true,
     #1 / DefineCommandsCmd
@@ -607,9 +698,20 @@
   }
 }
 
+\DeclareExpandableDocumentCommand \babelname { }
+  {
+    \prop_item:Ne  \l_xpg_langsetup_prop { \languagename / babelname }
+  }
+  
+\DeclareExpandableDocumentCommand \mainbabelname { }
+  {
+    \prop_item:Ne  \l_xpg_langsetup_prop { \mainlanguagename / babelname }
+  }
+
 % TODO move to C module
-\newcommand*{\polyglossia at C@localnumeral}[2]{
-   \polyglossia at Clang@@arabic{#2}
+\cs_new:Nn \xpg_C_localnumeral:nn
+{
+   \xpg_Clang_arabic{#2}
 }
 
 \cs_new:Npn \__xpg_localnumeral_parse:nn #1 #2
@@ -633,7 +735,7 @@
 			\__xpg_localnumeral_parse:nn
 	  	  } { #2 }
 	  }
-	{ \use:c { \prop_item:Ne \g_xpg_langsetup_prop
+	{ \use:c { \prop_item:Ne \l_xpg_langsetup_prop
 	{ \languagename / #3 } } { } { #1 } } 
   }
   
@@ -668,18 +770,18 @@
 \cs_new_nopar:Npn \__xpg_indent_first:n #1
   {
 	\bool_if:cTF { g__xpg_#1_if_bool }
-	{ \french at indent } { \nofrench at indent }
+	{ \__xpg_french_indent: } { \__xpg_no_french_indent: }
   }
 
 \cs_new:Nn \__xpg_lang_set_par_direction:n
 {
-  \prop_get:NeNTF \g_xpg_langsetup_prop {#1/direction} \l_tmpa_tl
+  \prop_get:NeNTF \l_xpg_langsetup_prop {#1/direction} \l_tmpa_tl
       {
         \__xpg_set_par_direction:n{\l_tmpa_tl}
       }
       {
-        \xpg at error{Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
-        \prop_show:N{\g_xpg_langsetup_prop}
+        \xpg_error_msg:n {Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
+        \prop_show:N{\l_xpg_langsetup_prop}
       }
 }
 
@@ -686,13 +788,13 @@
 
 \cs_new:Nn \__xpg_lang_set_text_direction:nn
 {
-  \prop_get:NeNTF \g_xpg_langsetup_prop {#1/direction} \l_tmpa_tl
+  \prop_get:NeNTF \l_xpg_langsetup_prop {#1/direction} \l_tmpa_tl
       {
         \__xpg_set_text_direction:n{\l_tmpa_tl}{#2}
       }
       {
-        \xpg at error{Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
-        \prop_show:N{\g_xpg_langsetup_prop}
+        \xpg_error_msg:n {Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
+        \prop_show:N{\l_xpg_langsetup_prop}
       }
 }
 
@@ -723,7 +825,7 @@
   {
     \bool_gset_true:N \g__xpg_hyphenation_disabled_bool
     \tl_gset:Ne \g__xpg_lastlanguage_tl { \the\language }
-    % We do not call \xpg at set@hyphenation at patterns here to avoid a warning message.
+    % We do not call \xpg_set_hyphenation_patterns:n here to avoid a warning message.
     % "nohyphenation" is not listed in language.dat.lua.
     \language=\l at nohyphenation
   }
@@ -735,7 +837,7 @@
   {
     \bool_gset_false:N \g__xpg_hyphenation_disabled_bool
     \language=\tl_use:N{\g__xpg_lastlanguage_tl}
-  }%
+  }
 }
 
 \cs_new:Npn \__xpg_auto_setupfont:n #1
@@ -742,12 +844,12 @@
 {
   \bool_if:cTF { g__xpg_#1_fontsetup_bool }
   {
-    \str_if_eq:eeTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/lcscript}}{latin}
-         {\xpg at fontsetup@latin{#1}}
-         {\xpg at fontsetup@nonlatin{#1}}
+    \str_if_eq:eeTF{\prop_item:Nn{\l_xpg_langsetup_prop}{#1/lcscript}}{latin}
+         {\SetupLatinPolyglossiaFont{#1}}
+         {\SetupNonLatinPolyglossiaFont{#1}}
   }
   {
-    \xpg at info{Skipping~ automatic~ font~ setup~ for~ language~ #1}
+    \xpg_info_msg:n{Skipping~ automatic~ font~ setup~ for~ language~ #1}
   }
 }
 
@@ -759,40 +861,40 @@
   \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~ main~ font~
+    \xpg_warning_msg:n{Asking~ to~ add~ empty~ feature~to~ main~ font~
       (Language="#2"~ to~ langtag~ "#1")}
   }
   {
-    \str_if_eq:nnTF{#2}{Turkish}{
+    \str_if_eq:nnTF{#2}{Turkish}
+    {
       \fontspec_if_language:nTF {TRK}
       {
         \addfontfeature{Language=Turkish}
       }
       {
-        \fontspec_if_language:nTF {TUR}
+        \fontspec_if_language:nT {TUR}
         {
           \addfontfeature{Language=Turkish}
-        }{}
+        }
       }
     }{
-      \fontspec_if_language:nTF{#1}
+      \fontspec_if_language:nT{#1}
       {
         \addfontfeature{Language=#2}
       }
-      {}
     }
   }
 }
-\cs_generate_variant:Nn  \__xpg_add_font_feature_language:nn { on , no, oo , Vn, nV, VV , xn, nx, xx}
+\cs_generate_variant:Nn  \__xpg_add_font_feature_language:nn { ee }
 
-% add fontfeature Script=#2 to scripttag #1
-% do nothing if #1 or #2 is empty
+% add fontfeature Script=#3 to scripttag #2 for family #1
+% do nothing if #2 or #3 is empty
 \cs_new:Nn \__xpg_add_font_feature_script:nnn
 {
   \bool_if:nTF{\tl_if_empty_p:n{#2} || \tl_if_empty_p:n{#3}}
   {
     % maybe an error ?
-    \xpg at warning{Asking~ to~ add~ empty~ feature~to~ main~ font
+    \xpg_warning_msg:n{Asking~ to~ add~ empty~ feature~to~ main~ font
                  (Script="#3"~ to~ scripttag~ "#2")}
   }
   {
@@ -828,119 +930,59 @@
         \regex_replace_once:nnN { \.[^\.]* \Z } { } \xpg_fname_str
         % ... and, finally, quotation marks
         \regex_replace_once:nnN { " } { } \xpg_fname_str
-        \xpg at error{
-          The~ current~ main ~ \xpg_ffamily_tl\space font,~ \xpg_fname_str,~ does~ not~ contain~ the~"#3"~ script!\MessageBreak
-          Please~ define~\csname\tl_if_empty:nF{#3}{\str_lowercase:n{#3}}font\xpg_ffamilysh_tl\endcsname~
-          with~ \string\newfontfamily\space command
+        \xpg_error_msg:n
+          {
+            The~ current~ main ~ \xpg_ffamily_tl\space font,~ \xpg_fname_str,~ does~ not~ contain~ the~"#3"~ script! \iow_newline:
+            Please~ define~\csname\tl_if_empty:nF{#3}{\str_lowercase:n{#3}}font\xpg_ffamilysh_tl\endcsname~
+            with~ \string\newfontfamily\space command
           }
         }
   }
 }
-\cs_generate_variant:Nn  \__xpg_add_font_feature_script:nnn { non , nno, noo , nVn, nnV, nVV , nxn, nnx, nxx}
+\cs_generate_variant:Nn  \__xpg_add_font_feature_script:nnn { nee }
 
-\def\xpg at fontsetup@latin#1{
-  \begingroup
-  \csgdef{#1 at font@rm}{
-    \cs_if_exist_use:cF{#1font}{
-      \rmfamilylatin
-      \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                         {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-    }
-  }
-  \csgdef{#1 at font@sf}{
-    \cs_if_exist_use:cF{#1fontsf}{
-      \sffamilylatin
-      \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                         {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-    }
-  }
-  \csgdef{#1 at font@tt}{
-    \cs_if_exist_use:cF{#1fonttt}{
-      \ttfamilylatin
-      \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                         {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-    }
-  }
-  \endgroup
-}
-
-\def\xpg at fontsetup@nonlatin#1{
-  \begingroup
-  \csgdef{#1 at font@rm}{
-    \cs_if_exist_use:cF{#1font}
+%% TODO: probably can be cleaned a little more
+\cs_new_protected:Npn \__xpg_setup_font:nnnnn #1 #2 #3 #4 #5 % #1 = lang, #2 = family, #3 = family, #4 = gobble, #5 gobble
+  {
+    \cs_set_protected_nopar:cpn { #1 at font@#2 }
       {
-       \providetoggle{#1 at use@script at font}
-       \str_if_eq:nnTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-        {\rmfamilylatin}
-        {\cs_if_exist_use:cTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/lcscript} font}
+        \cs_if_exist_use:cF{ #1font#3 }
           {
-             \toggletrue{#1 at use@script at font}
-           }
-           {
-             \rmfamilylatin
-           }
-       }
-       \iftoggle{#1 at use@script at font}{}{
-           \__xpg_add_font_feature_script:nxx{rm}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/scripttag}}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}
-       }%
-       \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                          {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-      }%
-      \def\familytype{rm}
-  }%
-  \csgdef{#1 at font@sf}{
-    \cs_if_exist_use:cF{#1fontsf}
-      {
-       \providetoggle{#1 at use@script at fontsf}
-       \str_if_eq:nnTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-        {\sffamilylatin}
-        {\cs_if_exist_use:cTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/lcscript} fontsf}
-          {
-             \toggletrue{#1 at use@script at fontsf}
-           }
-           {
-             \sffamilylatin
-           }
-       }
-       \iftoggle{#1 at use@script at fontsf}{}{
-           \__xpg_add_font_feature_script:nxx{sf}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/scripttag}}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}
-       }%
-       \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                          {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-      }%
-      \def\familytype{sf}
-  }%
-  \csgdef{#1 at font@tt}{
-    \cs_if_exist_use:cF{#1fonttt}
-      {
-       \providetoggle{#1 at use@script at fonttt}
-       \str_if_eq:nnTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
-       {\ttfamilylatin}
-       {\cs_if_exist_use:cTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/lcscript} fonttt}
-           {
-             \toggletrue{#1 at use@script at fonttt}
-           }
-           {
-             \ttfamilylatin
-           }
-       }
-       \iftoggle{#1 at use@script at fonttt}{}{
-           \__xpg_add_font_feature_script:nxx{tt}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/scripttag}}
-                                             {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/script}}
-       }
-       \__xpg_add_font_feature_language:xx{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/langtag}}
-                                          {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/language}}
+           \cs_if_exist_use:cF { \prop_item:Nn \l_xpg_langsetup_prop { #1 / lc-bcp47-script } font#3 }
+              {
+                #4 { \prop_item:Nn \l_xpg_langsetup_prop { #1 / lcscript } font#3 }
+                  { 
+                    \use:c { #2familylatin } 
+                    #5
+                      {
+                        \__xpg_add_font_feature_script:nee { #2 }
+                            { \prop_item:Nn \l_xpg_langsetup_prop { #1 / scripttag } }
+                            { \prop_item:Nn \l_xpg_langsetup_prop { #1 / script } }
+                      }
+                  }
+              }
+           \__xpg_add_font_feature_language:ee 
+               { \prop_item:Nn \l_xpg_langsetup_prop { #1 / langtag } }
+               { \prop_item:Nn \l_xpg_langsetup_prop { #1 / language } }
+          }
+        \tl_set:Nn \familytype { #2 }
       }
-      \def\familytype{tt}
   }
-  \endgroup
-}
 
+\NewDocumentCommand \SetupLatinPolyglossiaFont { m }
+  {
+    \__xpg_setup_font:nnnnn { #1 } { rm } { } { \use_ii:nn } { \use_none:n }
+    \__xpg_setup_font:nnnnn { #1 } { sf } { sf } { \use_ii:nn } { \use_none:n }
+    \__xpg_setup_font:nnnnn { #1 } { tt } { tt } { \use_ii:nn } { \use_none:n }
+  }
+
+\NewDocumentCommand \SetupNonLatinPolyglossiaFont { m }
+  {
+    \__xpg_setup_font:nnnnn { #1 } { rm } { } { \cs_if_exist_use:cF } { \use:n }
+    \__xpg_setup_font:nnnnn { #1 } { sf } { sf } { \cs_if_exist_use:cF } { \use:n }
+    \__xpg_setup_font:nnnnn { #1 } { tt } { tt } { \cs_if_exist_use:cF } { \use:n }
+  }
+
 %%% END OF PolyglossiaSetup
 
 %% ensure localization of \markright and \markboth commands
@@ -948,40 +990,53 @@
 \cs_new_nopar:Nn \__xpg_local_marks:n { }
 \cs_new_nopar:Nn \__xpg_enable_local_marks:
 {
-  \xpg at info{Option:~ localmarks}
+  \xpg_info_msg:n{Option:~ localmarks}
   \cs_gset_nopar:Nn \__xpg_local_marks:n
   {
-	 \def\xpg at tmp@lang{##1}
-	 \DeclareRobustCommand\markboth[2]{
-		\begingroup
-		   \let\label\relax \let\index\relax \let\glossary\relax
-		   \unrestored at protected@xdef\@themark
-		   {
-			{\lowercase{\foreignlanguage{\xpg at tmp@lang}}{\protect\@@ensure at maindir{####1}}}
-			{\lowercase{\foreignlanguage{\xpg at tmp@lang}}{\protect\@@ensure at maindir{####2}}}
-		   }
-		   \@temptokena \expandafter{\@themark}
-		   \mark{\the\@temptokena}
-		\endgroup
-		\if at nobreak\ifvmode\nobreak\fi\fi
-	 }
-	 \DeclareRobustCommand\markright[1]{
-		\begingroup
-		   \let\label\relax \let\index\relax \let\glossary\relax
-		   \expandafter\@markright\@themark
-		   {\lowercase{\foreignlanguage{\xpg at tmp@lang}}{\protect\@@ensure at maindir{####1}}}
-		   \@temptokena \expandafter{\@themark}
-		   \mark{\the\@temptokena}
-		\endgroup
-		\if at nobreak\ifvmode\nobreak\fi\fi
-	 }
+	 \DeclareDocumentCommand \markboth { m m }
+	 {
+	     \group_begin:
+                \cs_set_eq:cc { label } { relax }
+                \cs_set_eq:cc { index } { relax }
+                \cs_set_eq:cc { glossary } { relax }
+                \unrestored at protected@xdef\@themark
+		  {
+		     {\foreignlanguage{##1}{\protect\@@ensure at maindir{####1}}}
+		     {\foreignlanguage{##1}{\protect\@@ensure at maindir{####2}}}
+		  }
+                \@temptokena \expandafter{\@themark}
+                \mark_insert:nn{2e-left}{####1}
+                \mark_insert:nn{2e-right}{####2}
+                \tl_if_empty:nF{####2}{ \mark_insert:nn{2e-right-nonempty}{####2} }
+                \mark{\the\@temptokena}
+              \group_end:
+              \if at nobreak\ifvmode\nobreak\fi\fi
+         }
+	 \DeclareDocumentCommand \markright { m }
+	 {
+	     \group_begin:
+               \cs_set_eq:cc { label } { relax }
+               \cs_set_eq:cc { index } { relax }
+               \cs_set_eq:cc { glossary } { relax }
+               \expandafter\@markright\@themark
+		   {\foreignlanguage{##1}{\protect\@@ensure at maindir{####1}}}
+               \@temptokena \expandafter{\@themark}
+               \mark_insert:nn{2e-right}{####1}
+               \tl_if_empty:nF{####1}{ \mark_insert:nn{2e-right-nonempty}{####1} }
+               \mark{\the\@temptokena}
+            \group_end:
+            \if at nobreak\ifvmode\nobreak\fi\fi
+         }
   }
 }
 
 %we call this macro when a gloss file is not found for a given language
-\def\xpg at nogloss#1{
-   \xpg at warning{File~ gloss-#1.ldf~ do~ not~  exists!\MessageBreak
-   I~ will~ nevertheless~ try~ to~ use~ hyphenation~ patterns~ for~ #1.}
+\cs_new_nopar:Nn \__xpg_no_gloss:n
+{
+   \xpg_warning_msg:n
+      {File~ gloss-#1.ldf~ do~ not~  exists! \iow_newline:
+       I~ will~ nevertheless~ try~ to~ use~ hyphenation~ patterns~ for~ #1.}
+
   \PolyglossiaSetup{#1}{hyphenmins={2,3},hyphennames={#1},fontsetup=true}
   % the above amounts to:
   %\ifcsundef{l@#1}%
@@ -990,52 +1045,57 @@
   %\csdef{#1 at language}{\language=\csname l@#1\endcsname}%
 }
 
-\newcommand{\xpg at input}[1]{
+\cs_new_nopar:Nn \xpg_input:n
+{
   % Store catcode of @ before making at letter
-  \chardef\xpg at saved@at at catcode\catcode`\@
-  \makeatletter
-  \input{#1}
+  \cs_set_protected_nopar:Npx \__xpg_restore_at_catcode:
+      { \char_set_catcode:nn { `@ } { \char_value_catcode:n {`\@ } } }
+  \char_set_catcode_letter:N @
+  \file_input:n { #1 }
   % restore former @ catcode
-  \catcode`\@=\xpg at saved@at at catcode
+  \__xpg_restore_at_catcode:
 }
 
 % try to load a language file
-\cs_new:Nn \__xpg_load_lang_definition:nn {
-	\file_if_exist:nTF{gloss-#2.ldf}
+\cs_new:Nn \__xpg_load_lang_definition:nn
+{
+    \file_if_exist:nTF{gloss-#2.ldf}
 	{
-	  % Temporarily force catcode of ~ to 13 since babelsh.def
+	  \tl_set:Nn \xpg__tmp_default_options_tl { #1 }
+	  % Temporarily force catcode of ~ to 13 (active) since babelsh.def
 	  % requires it. This is needed particularly with LaTeX3
 	  % packages which force \ExplSyntaxOn (#425)
-	  \protected\edef\xpg at restore@tilde at catcode{\catcode 126 = \the\catcode 126\relax}
-	  \catcode 126 = 13
-	  \xpg at input{gloss-#2.ldf}
-	  \setkeys{#2}{#1}
+	  \cs_gset_protected:Npx \__xpg_restore_tilde_catcode:
+               { \char_set_catcode:nn { 126 } { \char_value_catcode:n { 126 } } }
+          \char_set_catcode_active:n { 126 }
+	  \xpg_input:n {gloss-#2.ldf}
 	  % restore former ~ catcode
-	  \xpg at restore@tilde at catcode
+	  \__xpg_restore_tilde_catcode:
 	}
 	{
-	  \xpg at nogloss{#2}
+	  \__xpg_no_gloss:n {#2}
 	}
 }
 \cs_generate_variant:Nn \__xpg_load_lang_definition:nn { ee }
 
 % load a master language from an alias file
-\newcommand*\xpg at load@master at language[1] {
-  \xpg at input{gloss-#1.ldf}
+\NewDocumentCommand \InheritGlossFile { m }
+{
   \seq_if_in:NeF \__xpg_langs_loaded {#1}
   {
+    \xpg_input:n {gloss-#1.ldf}
     % define environment and command if not alias
     \str_if_eq:eeT {\prop_item:Ne \__xpg_alias {#1/target}} {#1} {
-      \use:c{\prop_item:Nn{\g_xpg_langsetup_prop}
+      \use:c{\prop_item:Nn{\l_xpg_langsetup_prop}
                           {#1/DefineCommandsCmd}}
                           {#1}
       }
+    \seq_gput_right:Nn \__xpg_langs_loaded {#1}
   }
   \__xpg_register_language:nn{}{#1}
-  \seq_gput_right:Nn \__xpg_langs_loaded {#1}
 }
 
-\prop_new:N \__xpg_alias
+\prop_new_linked:N \__xpg_alias
 
 % define environment and command if not alias
 \cs_new:Nn \xpg_define_language_commands:n {
@@ -1042,7 +1102,7 @@
   \str_if_eq:eeT {\prop_item:Ne \__xpg_alias {#1/target}} {#1}
   {
     \exp_args:Ne
-    \NewDocumentEnvironment {\prop_item:Nn{\g_xpg_langsetup_prop}{#1/envname}} { O{} }
+    \NewDocumentEnvironment {\prop_item:Nn{\l_xpg_langsetup_prop}{#1/envname}} { O{} }
     {
       \otherlanguage [ ##1 ] { #1 }
     }
@@ -1070,7 +1130,7 @@
       % target to self fall back to language table
       \str_if_eq:eeTF { \prop_item:Ne \__xpg_alias {#1/target} } { #1 }
       {
-        \prop_item:Nn{\g_xpg_langsetup_prop} {#1/#2}
+        \prop_item:Nn{\l_xpg_langsetup_prop} {#1/#2}
       }
       % load alias by recursion
       {
@@ -1193,20 +1253,29 @@
   \clist_if_in:NeF \xpg at loaded {#2}{
     \clist_gput_right:Ne \xpg at loaded {#2}
   }
-  % Register the language options
-  \__xpg_set_language_options:nnn {#2} {#1} {@xpg at set@langvariant}
+  \group_begin:
+  % set language options
+  \__xpg_set_language_options:nn {#2} {#1}
   % register babelname
-  \prop_get:NeN \g_xpg_langsetup_prop {#2/babelname} \l_tmpa_tl
+  \prop_get:NeN \l_xpg_langsetup_prop {#2/babelname} \l_tmpa_tl
   \clist_if_in:NeF \xpg at bloaded {\l_tmpa_tl}{
     \clist_gput_right:Ne \xpg at bloaded {\l_tmpa_tl}
   }
   % register BCP-47 ID
-  \prop_get:NeN \g_xpg_langsetup_prop {#2/bcp47} \l_tmpa_tl
+  \prop_get:NeN \l_xpg_langsetup_prop {#2/bcp47} \l_tmpa_tl
   \clist_if_in:NeF \xpg at bcp@loaded {\l_tmpa_tl}{
     \clist_gput_right:Ne \xpg at bcp@loaded {\l_tmpa_tl}
   }
+  % register variant
+  \prop_get:NnNT \l_xpg_curropt_prop {#2/variant} \l_tmpa_tl {
+  \clist_if_in:NeF \xpg at vloaded {\l_tmpa_tl}{
+    \clist_gput_right:Ne \xpg at vloaded {\l_tmpa_tl}
+  }}
+  \group_end:
 }
 
+\prop_new_linked:N \l_xpg_curropt_prop
+
 \DeclareDocumentCommand \setdefaultlanguage { O{} m }
 {
   % latex is an internal language, so do not record
@@ -1221,12 +1290,13 @@
     \__xpg_load_lang_definition:nn{#1}{#2}
     % define environment and command if not alias
     \str_if_eq:eeT {\prop_item:Ne \__xpg_alias {#2/target}} {#2} {
-       \use:c{\prop_item:Ne{\g_xpg_langsetup_prop}
+       \use:c{\prop_item:Ne{\l_xpg_langsetup_prop}
             {#2/DefineCommandsCmd}}
             {#2}
     }
     \seq_gput_right:Ne \__xpg_langs_loaded {#2}
   }
+  \cs_set_nopar:Npe \mainlanguagevariant { \prop_item:Ne \l_xpg_curropt_prop { \xpg_alias_base_lang:n{#2} / variant } }
    \exp_args:Nee \__xpg_set_default_language:nn {\xpg_alias_add_to_option_i:nn{#2}{#1}}
     {\xpg_alias_base_lang:n{#2}}
 }
@@ -1234,70 +1304,22 @@
 
 \cs_new:Nn \__xpg_set_default_language:nn
 {
-  \gdef\xpg at main@language{#2}
-  \tl_if_blank:nTF {#1}
-  {
-    \cs_gset_nopar:Npn \mainlanguagevariant {}
-  }
-  {
-     % Register the language options
-     \__xpg_set_language_options:nnn {#2} {#1} {@xpg at main@langvariant}
-  }
-  \csgdef{#2 at gvar}{\mainlanguagevariant}
+  \tl_gset:Nn \xpg_main_language_tl {#2}
   %% The following settings are for the default language and script
   % this tells bidi.sty or luabidi.sty that the document is RTL
-  \__xpg_if_LR_str:eF{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/direction}}
+  \__xpg_if_LR_str:eF{\prop_item:Nn{\l_xpg_langsetup_prop}{#2/direction}}
   {
     \__xpg_setRTLmain:
   }
   \cs_gset_nopar:Nn \__xpg_at_begin_document_selectlanguage: {
     \selectbackgroundlanguage{#2}
-    \selectlanguage[#1]{#2}%
+    \selectlanguage[#1]{#2}
   }
-  \xpg at info{Default~ language~ is~ #2}
-  \polyglossia at set@language at name[#1]{#2}
+  \str_if_eq:eeF { #2 } { latex }
+      { \xpg_info_msg:n{Default~ language~ is~ #2} }
+  \xpg_set_language_name:n { #2 }
 
   \cs_gset_nopar:Npn \mainlanguagename {#2}
-  % Store babelname of main language (for external packages such as biblatex)
-  \cs_gset_nopar:Npe \mainbabelname { \prop_item:Nn  \g_xpg_langsetup_prop {#2/babelname} }
-  % Store babelname of current language (for external packages such as biblatex)
-  \cs_gset_eq:NN \babelname \mainbabelname
-  \cs_gset_eq:cc{#2 at gbabelname}{babelname}%
-  % Store BCP-47 ID and subtags of main language:
-  % 1. store main.* (sub)tags
-  \cs_gset_nopar:cpe {bcp47.main.tag} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47 } }
-  \cs_gset_nopar:cpe {bcp47.main.language} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-language } }
-  \cs_gset_nopar:cpe {bcp47.main.region} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-region } }
-  \cs_gset_nopar:cpe {bcp47.main.script} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-script } }
-  \cs_gset_nopar:cpe {bcp47.main.variant} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-variant } }
-  \cs_gset_nopar:cpe {bcp47.main.extension.t} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47extension-t } }
-  \cs_gset_nopar:cpe {bcp47.main.extension.u} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-extension-u } }
-  \cs_gset_nopar:cpe {bcp47.main.extension.x} { \prop_item:Nn  \g_xpg_langsetup_prop { #2 / bcp47-extension-x } }
-  % For casing, we fall back to language if bcp47-casing is not explicitly set
-  \cs_set_nopar:cpx {tmpcasing} { \prop_item:Ne \g_xpg_langsetup_prop { #2 / bcp47-casing } }
-  \str_if_empty:NTF \tmpcasing
-           { \cs_gset_nopar:cpe {bcp47.main.casing} { \prop_item:Nn  \g_xpg_langsetup_prop {#2 / bcp47-language} } }
-           { \cs_gset_nopar:cpe {bcp47.main.casing} { \tmpcasing } }
-  % 2. Store lang (sub)tags
-  \cs_gset_eq:cc {bcp47.tag} {bcp47.main.tag}
-  \cs_gset_eq:cc {bcp47.language} {bcp47.main.language}
-  \cs_gset_eq:cc {bcp47.region} {bcp47.main.region}
-  \cs_gset_eq:cc {bcp47.script} {bcp47.main.script}
-  \cs_gset_eq:cc {bcp47.variant} {bcp47.main.variant}
-  \cs_gset_eq:cc {bcp47.extension.t} {bcp47.main.extension.t}
-  \cs_gset_eq:cc {bcp47.extension.u} {bcp47.main.extension.u}
-  \cs_gset_eq:cc {bcp47.extension.x} {bcp47.main.extension.x}
-  \cs_gset_eq:cc {bcp47.casing} {bcp47.main.casing}
-  % 3. Store global language BCP47 settings (with default subtags as set by main language options)
-  \cs_gset_eq:cc{#2 at g.bcp47.tag}{bcp47.tag}
-  \cs_gset_eq:cc{#2 at g.bcp47.language}{bcp47.language}
-  \cs_gset_eq:cc{#2 at g.bcp47.region}{bcp47.region}
-  \cs_gset_eq:cc{#2 at g.bcp47.script}{bcp47.script}
-  \cs_gset_eq:cc{#2 at g.bcp47.variant}{bcp47.variant}
-  \cs_gset_eq:cc{#2 at g.bcp47.extension.t}{bcp47.extension.t}
-  \cs_gset_eq:cc{#2 at g.bcp47.extension.u}{bcp47.extension.u}
-  \cs_gset_eq:cc{#2 at g.bcp47.extension.x}{bcp47.extension.x}
-  \cs_gset_eq:cc{#2 at g.bcp47.casing}{bcp47.casing}
 }
 
 \DeclareCommandCopy \setmainlanguage \setdefaultlanguage
@@ -1308,11 +1330,11 @@
 {
     \str_case:nnF {#1}
       {
-        {bcp-47}    { \csuse{bcp47.tag} }
-        {bcp47}     { \csuse{bcp47.tag} }
+        {bcp-47}    { \use:c{bcp47.tag} }
+        {bcp47}     { \use:c{bcp47.tag} }
       }
       {
-        \xpg at error{Invalid~ \string\languageid\space argument:~ #1}
+        \xpg_ill_arg_msg:nn { #1 } { \languageid }
       }
 }
 
@@ -1322,11 +1344,11 @@
 {
     \str_case:nnF {#1}
       {
-        {bcp-47}    { \csuse{bcp47.main.tag} }
-        {bcp47}     { \csuse{bcp47.main.tag} }
+        {bcp-47}    { \use:c{bcp47.main.tag} }
+        {bcp47}     { \use:c{bcp47.main.tag} }
       }
       {
-        \xpg at error{Invalid~ \string\mainlanguageid\space argument:~ #1}
+        \xpg_ill_arg_msg:nn { #1 } { \mainlanguageid }
       }
 }
 % Kernel command to access to BCP-47 data.
@@ -1346,281 +1368,205 @@
 % and main.* variants thereof
 % See https://github.com/latex3/latex2e/issues/1035
 \DeclareExpandableDocumentCommand \BCPdata {m}
-{
-   \cs_if_exist_use:cF{bcp47.#1}
-        { \xpg at error{Invalid~ \string\BCPdata\space argument:~ #1} }
-}
+  {
+    \cs_if_exist_use:cF{bcp47.#1}
+        { \xpg_ill_arg_msg:nn { #1 } { \BCPdata } }
+  }
 
-% main babel name
-\cs_new_nopar:Npn \mainlanguagename {}
-\cs_new_nopar:Npn \mainbabelname {}
-\cs_new_nopar:cpn {bcp47.main.tag} {}
-\cs_new_nopar:cpn {bcp47.main.language} {}
-\cs_new_nopar:cpn {bcp47.main.region} {}
-\cs_new_nopar:cpn {bcp47.main.script} {}
-\cs_new_nopar:cpn {bcp47.main.variant} {}
-\cs_new_nopar:cpn {bcp47.main.extension.t} {}
-\cs_new_nopar:cpn {bcp47.main.extension.u} {}
-\cs_new_nopar:cpn {bcp47.main.extension.x} {}
-\cs_new_nopar:cpn {bcp47.main.casing} {}
-\cs_new_nopar:Npn \mainlanguagevariant {}%
-% Store main language variant for external packages
-\define at key{xpg at main@langvariant}{variant}{
-  \cs_gset_nopar:Npn \mainlanguagevariant {#1}
-}
+\clist_map_inline:nn 
+  {  
+   language, region, script, variant,
+   extension.t, extension.u, extension.x
+  }{
+     \tl_set:Nn \l_tmpa_tl { #1 }
+     \tl_replace_once:Nnn \l_tmpa_tl { . } { - }
+     \cs_gset_nopar:cpe { bcp47.#1 }
+       {
+         \exp_not:n { \prop_item:Ne  \l_xpg_langsetup_prop } { \exp_not:N \languagename / bcp47-\l_tmpa_tl }
+       }
+     \cs_gset_nopar:cpe { bcp47.main.#1 }
+       {
+         \exp_not:n { \prop_item:Ne  \l_xpg_langsetup_prop } { \exp_not:N \mainlanguagename / bcp47-\l_tmpa_tl } 
+       }
+  }
+\cs_gset_nopar:cpn { bcp47.casing } 
+  {
+    \tl_if_empty:eTF { \prop_item:Ne  \l_xpg_langsetup_prop { \languagename / bcp47-casing } }
+      {
+        \prop_item:Ne  \l_xpg_langsetup_prop { \languagename / bcp47-language }
+      }{
+        \prop_item:Ne  \l_xpg_langsetup_prop { \languagename / bcp47-casing }
+      }
+  }
+\cs_gset_nopar:cpn { bcp47.main.casing } 
+  {
+    \tl_if_empty:eTF { \prop_item:Ne  \l_xpg_langsetup_prop { \mainlanguagename / bcp47-casing } }
+      {
+        \prop_item:Ne  \l_xpg_langsetup_prop { \mainlanguagename / bcp47-language }
+      }{
+        \prop_item:Ne  \l_xpg_langsetup_prop { \mainlanguagename / bcp47-casing }
+      }
+  }
+\cs_gset_nopar:cpn { bcp47.tag } 
+  {
+    \prop_item:Ne  \l_xpg_langsetup_prop { \languagename / bcp47 }
+  }
+\cs_gset_nopar:cpn { bcp47.main.tag } 
+  {
+    \prop_item:Ne  \l_xpg_langsetup_prop { \mainlanguagename / bcp47 }
+  }
 
-\cs_new_nopar:Npn \babelname {}
-\def\languagevariant{}
-% Store current language variant for external packages
-\define at key{xpg at set@langvariant}{variant}{
-  \def\languagevariant{#1}
-}
+\cs_new_nopar:Npn \languagevariant 
+  {
+    \prop_item:Ne  \l_xpg_curropt_prop { \languagename / variant }
+  }
 
-\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}}}
-   }{
-     % Register the language options
-     \__xpg_set_language_options:nnn {#2} {#1} {@xpg at set@langvariant}
-     \cs_set_eq:cc{#2 at var}{languagevariant}
-  }%
+\cs_new:Nn \xpg_set_language_name:n
+{
+  \cs_set:Npn \languagename { #1 }
 }
 
-
-\newcommand*{\resetdefaultlanguage}[2][]{
+\NewDocumentCommand \resetdefaultlanguage { O{} m }
+{
   \__xpg_reset_default_language:nn
     {\xpg_alias_add_to_option_i:nn{#2}{#1}}
     {\xpg_alias_base_lang:n{#2}}
 }
 
-\cs_new:Nn \__xpg_store_bcp_info:nn
-{
-  % Store BCP-47 ID and subtags of current language
-  \tl_if_blank:nTF {#1}{
-    % tag (e.g., en-US)
-    \ifcsundef{#2 at g.bcp47.tag}{
-       \csedef{bcp47.tag}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47 } }
-    }{
-       \csedef{bcp47.tag}{\csuse{#2 at g.bcp47.tag}}
-    }
-    % language (e.g., en)
-    \ifcsundef{#2 at g.bcp47.language}{
-       \csedef{bcp47.language}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-language } }
-    }{
-       \csedef{bcp47.language}{\csuse{#2 at g.bcp47.language}}
-    }
-    % region (e.g., US)
-    \ifcsundef{#2 at g.bcp47.region}{%
-       \csedef{bcp47.region}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-region } }
-    }{
-       \csedef{bcp47.region}{\csuse{#2 at g.bcp47.region}}%
-    }
-    % script (e.g., Latn)
-    \ifcsundef{#2 at g.bcp47.script}{
-       \csedef{bcp47.script}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-script } }
-    }{
-       \csedef{bcp47.script}{\csuse{#2 at g.bcp47.script}}
-    }
-    % variant (e.g., 1996)
-    \ifcsundef{#2 at g.bcp47.variant}{
-       \csedef{bcp47.variant}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-variant } }
-    }{
-       \csedef{bcp47.variant}{\csuse{#2 at g.bcp47.variant}}
-    }
-    % extension.t (tranformation)
-    \ifcsundef{#2 at g.bcp47.extension.t}{%
-       \csedef{bcp47.extension.t}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-t } }
-    }{
-       \csedef{bcp47.extension.t}{\csuse{#2 at g.bcp47.extension.t}}
-    }
-    % extension.u (additional locale information)
-    \ifcsundef{#2 at g.bcp47.extension.u}{%
-       \csedef{bcp47.extension.u}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-u } }
-    }{
-       \csedef{bcp47.extension.u}{\csuse{#2 at g.bcp47.extension.u}}
-    }
-    % extension.x (private use area)
-    \ifcsundef{#2 at g.bcp47.extension.x}{
-       \csedef{bcp47.extension.x}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-x } }
-    }{
-       \csedef{bcp47.extension.x}{\csuse{#2 at g.bcp47.extension.x}}
-    }
-    % casing
-    \ifcsundef{#2 at g.bcp47.casing}{
-       % For casing, we fall back to language if bcp47-casing is not explicitly set
-       \cs_set_nopar:cpx {tmpcasing} { \prop_item:Ne \g_xpg_langsetup_prop { #2 / bcp47-casing } }
-       \str_if_empty:NTF \tmpcasing
-           { \cs_gset_eq:cc {bcp47.casing} {bcp47.language} }
-           { \csedef{bcp47.casing}{ \tmpcasing } }
-    }{
-       \csedef{bcp47.casing}{\csuse{#2 at g.bcp47.casing}}
-    }
-  }{
-    \csedef{bcp47.tag}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47 } }
-    \csedef{bcp47.language}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-language } }
-    \csedef{bcp47.region}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-region } }
-    \csedef{bcp47.script}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-script } }
-    \csedef{bcp47.variant}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-variant } }
-    \csedef{bcp47.extension.t}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-t } }
-    \csedef{bcp47.extension.u}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-u } }
-    \csedef{bcp47.extension.x}{ \prop_item:Nn{ \g_xpg_langsetup_prop}{ #2 / bcp47-extension-x } }
-    % For casing, we fall back to language if bcp47-casing is not explicitly set
-    \cs_set_nopar:cpx {tmpcasing} { \prop_item:Ne \g_xpg_langsetup_prop { #2 / bcp47-casing } }
-    \str_if_empty:NTF \tmpcasing
-         { \cs_gset_eq:cc {bcp47.casing} {bcp47.language} }
-         { \csedef{bcp47.casing}{ \tmpcasing } }
-  }
-}
-
 \cs_new:Nn \__xpg_reset_default_language:nn
 {
   \xpg_error_if_lang_not_loaded:n{#2}
   % disable globalnumbers of previously defined default language
-  \csuse{no\xpg at main@language @globalnumbers}
-  \csuse{noextras@\xpg at main@language}%
+  \use:c{no\xpg_main_language_tl @globalnumbers}
+  \use:c{noextras@\xpg_main_language_tl}
   % 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}%
-  \__xpg_if_LR_str:eF{\prop_item:Ne{\g_xpg_langsetup_prop}{#2/direction}}
+  \cs_if_exist_use:c{noextras at bbl@\mainbabelname}
+  \use:c{init at noextras@\xpg_main_language_tl}
+  \xpg_set_language_name:n { #2 }
+  \__xpg_if_LR_str:eF{\prop_item:Ne{\l_xpg_langsetup_prop}{#2/direction}}
   {
     \@rlmaintrue\@rl at footnotetrue
   }
-  \selectlanguage[#1]{#2}%
-  \selectbackgroundlanguage{#2}%
-  % Store babelname of current language (for external packages such as biblatex)
-  \tl_if_blank:nTF {#1}{%
-    \ifcsundef{#2 at gbabelname}{
-       \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-    }{
-       \edef\babelname{\csuse{#2 at gbabelname}}
-    }
-  }{
-    \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-  }
-  % Store variant
-  \tl_if_blank:nTF {#1}
-  {
-    \cs_gset_nopar:Npn \mainlanguagevariant {}
-  }
-  {
-     % Register the language options
-     \__xpg_set_language_options:nnn {#2} {#1} {@xpg at main@langvariant}
-  }
-  \csgdef{#2 at gvar}{\mainlanguagevariant}
-  % Store BCP-47 id of current language
-  \__xpg_store_bcp_info:nn {#1}{#2}
+  \selectlanguage[#1]{#2}
+  \selectbackgroundlanguage{#2}
+  \cs_set_nopar:Npe \mainlanguagevariant { \prop_item:Ne \l_xpg_curropt_prop { \xpg_alias_base_lang:n{#2} / variant } }
 }
 
 % This saves the normalfont for the latin script since we may change normalfont in other scripts
-\let\normalfontlatin=\normalfont
+\cs_set_eq:cc { normalfontlatin } { normalfont }
 
 % Provide default fonts (as set with \setmainfont, \setsansfont and \setmonofont)
 % for Latin scripts and as a fallback for non-Latin scripts.
-\DeclareRobustCommand\xpg at defaultfont@rm{
+\cs_set_protected:Nn \xpg_defaultfont_rm:
+{
    \tl_if_empty:NF{\g__fontspec_nfss_enc_tl}{\fontencoding{\g__fontspec_nfss_enc_tl}}
    \fontfamily\rmdefault
-   \ifdefined\UseHook\UseHook{rmfamily}\fi
+   \hook_use:n { rmfamily }
    \selectfont
 }
-\DeclareRobustCommand\xpg at defaultfont@sf{
+
+\cs_set_protected:Nn \xpg_defaultfont_sf:
+{
    \tl_if_empty:NF{\g__fontspec_nfss_enc_tl}{\fontencoding{\g__fontspec_nfss_enc_tl}}
    \fontfamily\sfdefault
-   \ifdefined\UseHook\UseHook{sffamily}\fi
+   \hook_use:n { sffamily }
    \selectfont
 }
-\DeclareRobustCommand\xpg at defaultfont@tt{
+
+\cs_set_protected:Nn \xpg_defaultfont_tt:
+{
    \tl_if_empty:NF{\g__fontspec_nfss_enc_tl}{\fontencoding{\g__fontspec_nfss_enc_tl}}
    \fontfamily\ttdefault
-   \ifdefined\UseHook\UseHook{ttfamily}\fi
+   \hook_use:n { ttfamily } 
    \selectfont
 }
 
-\def\xpg at patch@fontfamilies{
+\cs_new:Nn \__xpg_patch_fontfamilies:
+{
   % 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}}
+  \tl_put_right:cn {rmfamily~} {\tl_set:Nn \familytype {rm}}
+  \tl_put_right:cn {sffamily~} {\tl_set:Nn \familytype {sf}}
+  \tl_put_right:cn {ttfamily~} {\tl_set:Nn \familytype {tt}}
 }
 
 % These switches activate the default fonts
 % Note that a simple \let\rmfamilylatin=\rmfamily
 % does not work reliably (see #24)
-\cs_gset_eq:cc{rmfamilylatin}{xpg at defaultfont@rm}
-\cs_gset_eq:cc{sffamilylatin}{xpg at defaultfont@sf}
-\cs_gset_eq:cc{ttfamilylatin}{xpg at defaultfont@tt}
+\cs_set_eq:cc{rmfamilylatin}{xpg_defaultfont_rm:}
+\cs_set_eq:cc{sffamilylatin}{xpg_defaultfont_sf:}
+\cs_set_eq:cc{ttfamilylatin}{xpg_defaultfont_tt:}
 
-\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}}}
-  \xpg at patch@fontfamilies
+\cs_new:Nn \xpg_set_familydefault:
+{
+  \tl_set:Ne \l_tmpa_tl { \familydefault }
+  \tl_set:Ne \l_tmpb_tl { \sfdefault }
+  \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl
+     { \tl_set:Nn \familytype {sf} }
+     { \tl_set_eq:NN \l_tmpb_tl \ttdefault
+       \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl
+           { \tl_set:Nn \familytype {tt} }
+           { \tl_set:Nn \familytype {rm} }
+     }
+  \__xpg_patch_fontfamilies:
   % This (re-)saves the normalfont for the latin script since we may
   % change normalfont in other scripts
-  \let\normalfontlatin=\normalfont
+  \cs_set_eq:cc{ normalfontlatin }{ normalfont }
   % And for all cases, we also reset \<xx>familylatin
-  \cs_gset_eq:cc{rmfamilylatin}{xpg at defaultfont@rm}
-  \cs_gset_eq:cc{sffamilylatin}{xpg at defaultfont@sf}
-  \cs_gset_eq:cc{ttfamilylatin}{xpg at defaultfont@tt}
+  \cs_set_eq:cc{ rmfamilylatin }{ xpg_defaultfont_rm: }
+  \cs_set_eq:cc{ sffamilylatin }{ xpg_defaultfont_sf: }
+  \cs_set_eq:cc{ ttfamilylatin }{ xpg_defaultfont_tt: }
 }
 
-\def\resetfontlatin{
-  \DeclareRobustCommand\rmfamily{\xpg at defaultfont@rm}
-  \DeclareRobustCommand\sffamily{\xpg at defaultfont@sf}
-  \DeclareRobustCommand\ttfamily{\xpg at defaultfont@tt}
-  \xpg at patch@fontfamilies
-  \global\let\normalfont=\normalfontlatin
+\cs_set_nopar:Nn \xpg_select_fontfamily:n
+{
+  \str_if_eq:VnTF \familytype { tt }
+    { \__xpg_use_or_warn:c { #1 at font@tt } }
+    { \str_if_eq:VnTF \familytype { sf }
+        { \__xpg_use_or_warn:c { #1 at font@sf } }
+        { \__xpg_use_or_warn:c { #1 at font@rm } }
+    }
 }
 
-\def\selectfontfamilylatin{
-  \def\tmp at tt{tt}\def\tmp at sf{sf}
-  \ifx\familytype\tmp at tt
-    \ttfamilylatin
-    \else\ifx\familytype\tmp at sf
-      \sffamilylatin
-      \else\rmfamilylatin\fi\fi}
+\cs_set_protected:Npn \xpg_select_default_fontfamily:n #1
+  {
+    \tl_set:Ne \l_tmpa_tl { \familydefault }
+    \tl_set:Ne \l_tmpb_tl { \sfdefault }
+    \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl
+       { \tl_set:Nn \familytype {sf} }
+       { \tl_set_eq:NN \l_tmpb_tl \ttdefault
+         \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl
+             { \tl_set:Nn \familytype {tt} }
+             { \tl_set:Nn \familytype {rm} }
+       }
+     \xpg_select_fontfamily:n{#1}
+  }
 
-\def\xpg at select@fontfamily#1{
-  \def\tmp at tt{tt}\def\tmp at sf{sf}
-  \ifx\familytype\tmp at tt
-    \__xpg_use_or_warn:c{#1 at font@tt}
-  \else\ifx\familytype\tmp at sf
-    \__xpg_use_or_warn:c{#1 at font@sf}
-      \else\__xpg_use_or_warn:c{#1 at font@rm}\fi\fi}
-
-\def\xpg at set@normalfont#1{
-  \letcs{\rmfamily}{#1 at font@rm}
-  \letcs{\sffamily}{#1 at font@sf}
-  \letcs{\ttfamily}{#1 at font@tt}
-  \robustify\rmfamily
-  \robustify\sffamily
-  \robustify\ttfamily
-  \gdef\normalfont{\protect\xpg at select@fontfamily{#1}
-                   \fontseries{\seriesdefault}\selectfont
-                   \fontshape{\shapedefault}
-                   \ifdefined\UseHook\UseHook{normalfont}\fi
-                   \selectfont}
-  \gdef\reset at font{\protect\normalfont}
+\cs_new_nopar:Nn \xpg_set_normalfont:n
+{
+  \cs_set_eq:cc { rmfamily } { #1 at font@rm }
+  \cs_set_eq:cc { sffamily } { #1 at font@sf }
+  \cs_set_eq:cc { ttfamily } { #1 at font@tt }
+  \cs_set_nopar:Npn \normalfont 
+      { \xpg_select_default_fontfamily:n {#1}
+        \fontseries{\seriesdefault}\selectfont
+        \fontshape{\shapedefault}
+        \hook_use:n { normalfont }
+        \selectfont
+      }
+  \cs_set_nopar:Npn \reset at font {\protect\normalfont}
 }
 
-\let\@@fterindentfalse\@afterindentfalse
-\def\french at indent{
-    \let\@afterindentfalse\@afterindenttrue
+\cs_gset_eq:cc { @@fterindentfalse } { @afterindentfalse }
+\cs_new_nopar:Nn \__xpg_french_indent:
+{
+    \cs_set_eq:cc { @afterindentfalse } { @afterindenttrue }
     \@afterindenttrue
 }
-\def\nofrench at indent{
-    \let\@afterindentfalse\@@fterindentfalse
+\cs_new_nopar:Nn \__xpg_no_french_indent:
+{
+    \cs_set_eq:cc { @afterindentfalse } { @@fterindentfalse }
     \@afterindentfalse
 }
 
@@ -1631,10 +1577,10 @@
 
 \cs_new:Nn \__xpg_select_background_language:n
 {
-  \str_if_eq:eeTF{\prop_item:Nn{\g_xpg_langsetup_prop}{#1/lcscript}}{latin}
+  \str_if_eq:eeTF { \prop_item:Nn{\l_xpg_langsetup_prop}{#1/lcscript} } { latin }
                    {}
-                   {\xpg at set@normalfont{#1}}
-  \csuse{#1 at globalnumbers}
+                   { \xpg_set_normalfont:n{#1} }
+  \use:c{#1 at globalnumbers}
 }
 \cs_generate_variant:Nn \__xpg_select_background_language:n {e}
 %  Declare secondary language #2 with language options #1
@@ -1645,7 +1591,7 @@
     \__xpg_load_lang_definition:ee {#1} {#2}
     % define environment and command if not alias
     \str_if_eq:eeT {\prop_item:Ne \__xpg_alias {#2/target}} {#2} {
-       \use:c{\prop_item:Ne{\g_xpg_langsetup_prop}
+       \use:c{\prop_item:Ne{\l_xpg_langsetup_prop}
              {#2/DefineCommandsCmd}}
              {#2}
     }
@@ -1658,28 +1604,13 @@
 \cs_new:Nn \__xpg_set_otherlanguage:nn
 {
   \__xpg_register_language:nn{#1}{#2}
-  % If a variant is set, store it.
-  \gdef\otherlanguagevariant{}
-  % Register the language options
-  \__xpg_set_language_options:nnn {#2} {#1} {@xpg at other@langvariant}
-
-  \csgdef{#2 at gvar}{\otherlanguagevariant}
-  \prop_get:NeNT \g_xpg_langsetup_prop {#2/babelname} \l_tmpa_tl
-    { \xdef\otherlanguagebabelname{\l_tmpa_tl} }
-  \cs_gset_eq:cc{#2 at gbabelname}{otherlanguagebabelname}
 }
 \cs_generate_variant:Nn  \__xpg_set_otherlanguage:nn { ee }
 
-
-% Store main language variant for external packages
-\define at key{xpg at other@langvariant}{variant}{
-  \gdef\otherlanguagevariant{#1}
-}
-
 \NewDocumentCommand \setotherlanguages { m }
-  {
+{
    \clist_map_function:eN { #1 } \setotherlanguage
-  }
+}
 
 \cs_set:Nn \xpg_common_language:
 {% FIXME is this really needed???
@@ -1702,7 +1633,8 @@
 % for specific (esp. tag-based) aliases
 % where \text<alias> would cause clashes
 % (e.g., \textit)
-\newcommand\textlang[3][]{
+\NewDocumentCommand \textlang { O{} m +m }
+{
   \__xpg_textlanguage:een {#1} {#2} {#3}
 }
 
@@ -1711,45 +1643,20 @@
 % inside case changing commands (e.g. \MakeUppercase)
 \tl_put_right:Nn \l_text_case_exclude_arg_tl { \textlang }
 
-% Alias to {<lang>}, but more suitable
-% for specific (esp. tag-based) aliases
-% where {<alias>} would cause clashes
-% (e.g., \fi)
-\DeclareEnvironmentCopy { lang } { otherlanguage }
-
 % wrapper for foreignlanguage and otherlanguage*
-\newcommand*\polyglossia at setforeignlanguage[2][]{
-  \select@@language[#1]{#2}
+\cs_new_nopar:Nn \xpg_set_foreign_language:nn
+{
+  \xpg_select_language:nn { #1 } { #2 }
   \__xpg_register_language:nn{#1}{#2}
-  % Store babelname of current language (for external packages such as biblatex)
-  \tl_if_blank:nTF {#1}{
-    \ifcsundef{#2 at gbabelname}{
-       \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-    }{
-       \edef\babelname{\csuse{#2 at gbabelname}}
-    }
-  }{
-    \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-  }
-  % Store BCP-47 id of current language
-  \__xpg_store_bcp_info:nn {#1}{#2}
 }
 
-% Expandable lowercasing. We use this to assure keyval
-% options are lowercased (also when used in \MakeUppercase
-% contexts e.g. in headings)
-% Macro adapted from tudscr.sty
-\newcommand*\xpg at str@lowercase[2]{
-  \protected at edef#1{
-    \lowercase{\def\noexpand#1{#2}}
-  }#1
-}
-
 % lowercase options before passing to setkeys
-\cs_new:Nn \__xpg_set_keys:nn
+\NewDocumentCommand \SetGlossOptions { m m }
 {
-    \xpg at str@lowercase{\xpg at tmp@opts}{#2}
-    \exp_args:Nne \setkeys{#1}{\xpg at tmp@opts}
+    % \text_lowercase:n fully expands
+    % (as opposed to \str_lowercase:n)
+   \use:c { xpg_#1_default_options_tl }
+   \exp_args:Ne \keys_set:ne{ polyglossia / gloss / #1 }{ \text_lowercase:n {#2} }
 }
 
 % joint code of \foreignlanguage, otherlanguage*
@@ -1759,12 +1666,12 @@
 \cs_new:Nn \xpg_otherlanguage:nn
 {
   \xpg_error_if_lang_not_loaded:n{#2}
-  \__xpg_set_keys:nn{#2}{#1}
-  \polyglossia at setforeignlanguage[#1]{#2}
+  \SetGlossOptions{#2}{#1}
+  \xpg_set_foreign_language:nn { #1 } { #2 }
   % Hook for external packages such as biblatex
   \polyglossia at language@switched
   % buggy restoration heure
-  \csuse{inlineextras@#2}
+  \use:c{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}
@@ -1771,44 +1678,20 @@
 }
 
 \DeclareDocumentCommand { \foreignlanguage } { O{} m +m }
-  {
+{
 	\__xpg_foreignlanguage:eeen {#1} {#2} {\xpg_alias_base_lang:n{#2}} {#3}
-  }
+}
 
 % prevent case changing of language name in \foreignlanguage
 \tl_put_right:Nn \l_text_case_exclude_arg_tl { \foreignlanguage }
 
-% Direct access to polyglossia at setforeignlanguage
+% Direct access to \xpg_set_foreign_language:nn
 % used in captions
-\newcommand{\setforeignlanguage}[2][]
+\NewDocumentCommand \setforeignlanguage { O{} m }
 {
-  \polyglossia at setforeignlanguage[#1]{#2}
+  \xpg_set_foreign_language:nn { #1 } { #2 }
 }
 
-% Stack to store matrix languages
-\seq_new:N \__xpg_current_matrixlang_stack
-
-% Store embedding language when an embedded language is switched to
-\cs_new_nopar:Nn \__xpg_store_matrixlang:
-{
-   \seq_gput_left:Nn \__xpg_current_matrixlang_stack \languagename
-}
-
-% When an embedded language is closed, reset to the embedding language
-% and remove stored matrix language from stack
-\cs_new_nopar:Nn \__xpg_reset_to_matrixlang:
-{
-  % if stack is empty, use main language
-  \seq_gpop_left:NNTF \__xpg_current_matrixlang_stack \l_tmpa_tl
-     { \cs_set_eq:NN \__xpg_current_matrixlang \l_tmpa_tl }
-     { \cs_set_eq:NN \__xpg_current_matrixlang \mainlanguagename }
-  % Reset the language's/script's font families if the embedding script is latin
-  \str_if_eq:eeT{\prop_item:Ne{\g_xpg_langsetup_prop}{\__xpg_current_matrixlang/lcscript}}{latin}
-       {\resetfontlatin}
-  % In case a \<lang>font is defined, re-activate that
-  \exp_args:Ne \xpg at set@normalfont{\__xpg_current_matrixlang}
-}
-
 % internal wrapper for foreign language
 % #1 option
 % #2 alias
@@ -1820,12 +1703,10 @@
   {
     \msg_show:nnn { polyglossia } { languagenotloaded } {#2}
   }{
-    \__xpg_store_matrixlang:
     \group_begin:
       \xpg_otherlanguage:nn{ \xpg_alias_add_to_option_i:nn{#2}{#1} }{ #3 }
       \__xpg_lang_set_text_direction:nn{#3}{#4}
     \group_end:
-    \__xpg_reset_to_matrixlang:
   }
 }
 \cs_generate_variant:Nn \__xpg_foreignlanguage:nnnn {eeen}
@@ -1834,11 +1715,9 @@
 % otherlanguage* is the environment equivalent of \foreignlanguage
 \DeclareDocumentEnvironment { otherlanguage* } { O{} m }
   {
-	\__xpg_store_matrixlang:
 	\__xpg_otherlanguage:eee { #1 } { #2 } { \xpg_alias_base_lang:n { #2 } }
   }{
-	\egroup% \group_end: does not work here!
-	\__xpg_reset_to_matrixlang:
+	\c_group_end_token% \group_end: does not work here!
   }
 
 % internal wrapper
@@ -1853,7 +1732,7 @@
   }{
     \xpg_otherlanguage:nn{ \xpg_alias_add_to_option_i:nn{#2}{#1} }{ #3 }
     \__xpg_lang_set_text_direction:nn{#3}%
-    \bgroup% \group_begin: does not work here!
+    \c_group_begin_token% \group_begin: does not work here!
   }
 }
 \cs_generate_variant:Nn \__xpg_otherlanguage:nnn { eee }
@@ -1869,9 +1748,6 @@
 }
 \cs_generate_variant:Nn \__xpg_textlanguage:nnn {een}
 
-% Track whether we are in an inline lang (\text...) switch
-\bool_new:N \l__xpg_inline_lang_bool
-
 % use by \text<lang> and \textlang. Equivalent to \foreignlanguage,
 % except that dates are localized.
 % #1: option
@@ -1885,29 +1761,27 @@
     \msg_show:nnn { polyglossia } { languagenotloaded } {#2}
   }
   {
-    \__xpg_store_matrixlang:
     \group_begin:
-      \bool_set_true:N \l__xpg_inline_lang_bool
       \xpg_otherlanguage:nn{#1}{#3}
-      \csuse{date#3}
+      \use:c{date#3}
       % 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}
       \__xpg_lang_set_text_direction:nn{#3}{#4}
     \group_end:
-    \__xpg_reset_to_matrixlang:
   }
 }
 \cs_generate_variant:Nn \__xpg_textlanguage:nnnn {nnen}
 
 % Define language-specific hyphenation exceptions
-\newcommand\pghyphenation[3][]{
-  \bgroup
-  \xpg_error_if_lang_not_loaded:n{#2}
-  \setkeys{#2}{#1}
-  \select@@language[#1]{#2}
+\NewDocumentCommand \pghyphenation {O{} m m}
+{
+  \c_group_begin_token
+  \xpg_error_if_lang_not_loaded:n { #2 }
+  \SetGlossOptions{#2}{#1}
+  \xpg_select_language:nn { #1 } { #2 }
   \hyphenation{#3}
-  \egroup
+  \c_group_end_token
 }
 
 
@@ -1914,12 +1788,16 @@
 % Hook that other package authors can use
 % (for instance biblatex):
 % Do not rename!
-\newcommand*{\xpg at hook@setlanguage}{}
+\cs_set_nopar:Npn \xpg at hook@setlanguage {}
 
-\def\xpg at pop@language at i#1#2{
-  \xpg at set@language at aux[#1]{#2}
+\cs_set_nopar:Nn \__xpg_pop_language:nn
+{
+  \xpg_set_language_aux:nn { #1 } { #2 }
   \xpg at hook@setlanguage
-  \let\emp at langname\@undefined}
+% FIXME This seems to be a very old relict. 
+%       The macro is nowhere used. Probably remove.
+%  \let\emp at langname\@undefined
+}
 
 \DeclareDocumentCommand \selectlanguage {s O{} m}
   {
@@ -1938,113 +1816,113 @@
 \cs_new:Nn \__xpg_select_language:nnn
 {
   % Register the language options
-  \__xpg_set_language_options:nnn {#3} {#2} {@xpg at set@langvariant}
+  \__xpg_set_language_options:nn {#3} {#2}
   \IfBooleanTF { #1 }   % The starred variant does not write to the aux
     {
-	  \xpg at set@language at nonaux[#2]{#3}
+	  \xpg_set_language_nonaux:nn { #2 } { #3 }
     }{
-      \cs_set_nopar:Npe \xpg at pop@language { \exp_not:N \xpg at pop@language at i {#2} {#3} }
-      \group_insert_after:N \xpg at pop@language
-	  \xpg at set@language at aux[#2]{#3}
+      \cs_set_nopar:Ne \xpg_pop_language: { \exp_not:N \__xpg_pop_language:nn { #2 } { #3 } }
+      \group_insert_after:N \xpg_pop_language:
+	  \xpg_set_language_aux:nn { #2 } { #3 }
     }
-  \__xpg_register_language:nn{#2}{#3}
+  \__xpg_register_language:nn { #2 } { #3 }
 }
 \cs_generate_variant:Nn \__xpg_select_language:nnn { nee, nne }
 
-
 % set lang option #2 for lang #1
-\cs_new:Nn \__xpg_set_language_options:nnn
+\cs_new:Nn \__xpg_set_language_options:nn
 {
-  \tl_if_blank:nF {#2}
+  \cs_if_exist:cT { xpg_#1_default_options_prop }
   {
-    % 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=#3:#1\relax
-    }%
-    \__xpg_set_keys:nn{#1}{#2}
+  \prop_concat:ccc { l_xpg_curropt_prop } { l_xpg_curropt_prop }
+                   { xpg_#1_default_options_prop }
   }
+  \xpg__keyval_parser:eeN { #2 } { #1 } \l_xpg_curropt_prop 
+  \SetGlossOptions{#1}{#2}
 }
 
 % Initialize default language options, so that
 % \iflanguageoption has the info it needs also
 % for default settings
-\newcommand*\xpg at initialize@gloss at options[2]{
-   \__xpg_set_language_options:nnn {#1} {#2} {@xpg at set@langvariant}
+\NewDocumentCommand \InitializeGlossOptions { m m }
+{
+   \tl_new:c { xpg_#1_default_options_tl }
+   \prop_new:c { xpg_#1_default_options_prop }
+   \keys_precompile:nec { polyglossia / gloss / #1 } 
+                        { \text_lowercase:n { #2, \xpg__tmp_default_options_tl } } 
+                        { xpg_#1_default_options_tl }
+   \xpg__keyval_parser:enc { #2, \xpg__tmp_default_options_tl } { #1 } 
+                           { xpg_#1_default_options_prop }
+   \prop_concat:ccc { l_xpg_curropt_prop } { l_xpg_curropt_prop }
+                    { xpg_#1_default_options_prop }
+   \use:c { xpg_#1_default_options_tl }
+   \__xpg_set_language_options:nn {#1} {#2}
 }
+\tl_new:N \xpg__tmp_default_options_tl
+\cs_generate_variant:Nn \keys_precompile:nnN { nec }
 
 % Record synonymous keyvals such as variant=us and variant=american
-% Syntax: \xpg at set@alias at values{<lang>}{<key>}{<val>}{<alias vals, comma-separated>}
-\newcommand*\xpg at set@alias at values[4]{%
-   \prop_if_exist:cF { xpg at alias@keyvals@#1@#3 }
-      { \prop_new:c {xpg at alias@keyvals@#1@#3} }
-   \prop_put:cnn { xpg at alias@keyvals@#1@#3 }
-      {#2}{#4}
-   \prop_if_exist:cF { xpg at alias@keyvals@#1@#4 }
-      { \prop_new:c {xpg at alias@keyvals@#1@#4} }
-   \prop_put:cnn { xpg at alias@keyvals@#1@#4 }
-      {#2}{#3}
+% Syntax: \SetLanguageAliasValues{<lang>}{<key>}{<alias vals, comma-separated>}
+\int_new:N \l_xpg_alias_keyvals_int
+\int_set:Nn \l_xpg_alias_keyvals_int { 2 }
+\NewDocumentCommand \SetLanguageAliasValues { m m m }
+{
+  \clist_map_inline:nn { #3 }
+    {
+      \int_const:cn { c_xpg_alias_keyvals_#1_#2_##1_int } { \l_xpg_alias_keyvals_int }
+    }
+  \int_incr:N \l_xpg_alias_keyvals_int
 }
 
-% Patch xkeyval to record default values of keys
-\pretocmd{\XKV at define@default}{%
-   \csgdef{xpg at default@opt@\XKV at header #1}{#2}
-}{}{\xpg at warning{Patching xkeyval failed!}}
+\cs_new:Npn \xpg__keyval_parser:nnN #1 #2 #3 % #1 = key-vals, #2 = language, #3 = prop
+  {
+    \keyval_parse:nnn 
+      { \xpg__keyval_parser_default:nnn { #2 } { #3 } }
+      { \xpg__keyval_parser_nondefault:nnnn { #2 } { #3 } }
+      { #1 }
+  }
+\cs_generate_variant:Nn \xpg__keyval_parser:nnN { eeN, enc }
+  
+\cs_new:Npn \xpg__keyval_parser_default:nnn #1 #2 #3 % #1 = lang, #2 = prop, #3 = key
+  {
+    \str_set:Nn \l_tempa_str { #1 / #3 }
+    \str_concat:NNN \l_tempa_str \c__keys_default_root_str \l_tempa_str
+    \prop_put:Nne #2 { #1 / #3 } { \use:c { \l_tempa_str } }
+  }
+  
+\cs_new:Npn \xpg__keyval_parser_nondefault:nnnn #1 #2 #3 #4 % #1 = lang, #2 = prop, #3 = key, #4 = value
+  {
+    \prop_put:Nnn #2 { #1 / #3 } { #4 }
+  }
 
-% Helper to get and register option keyvals
-\def\xpg at parsevariantkeyvalue#1=#2@#3:#4\relax{
-   \def\@tmpa{#1}
-   \def\@tmpb{variant}
-   % variant values are stored in specific macros
-   % (\xpg at main@langvariant, \xpg at other@langvariant
-   % and \xpg at set@langvariant)
-   \ifx\@tmpa\@tmpb\setkeys{#3}{#1=#2}\fi
-   \tl_if_empty:nTF{#2}
+\prg_set_conditional:Npnn \__xpg_check_option_value:NNN #1#2#3 { p , T , F , TF }
+  {
+    \bool_lazy_or:nnTF
       {
-        \ifcsdef{xpg at default@opt at KV@#4@#1}
-           {\xpg at store@opt at keyval#1:\csuse{xpg at default@opt at KV@#4@#1}=:#4\relax}
-           {}%
-      }
-      { \xpg at store@opt at keyval#1:#2:#4\relax }
-}%
+        \str_if_eq_p:ee { \prop_item:Nn \l_xpg_curropt_prop { #1 / #2 } }  { #3 }
+      } {
+        \int_compare_p:nNn
+          {
+            \cs_if_exist_use:cF { c_xpg_alias_keyvals_#1_#2_#3_int } { 0 }
+          } = {
+            \cs_if_exist_use:cF { c_xpg_alias_keyvals_#1_#2_\prop_item:Nn \l_xpg_curropt_prop { #1 / #2 }_int } { 1 }
+          }
+      } { \prg_return_true: } { \prg_return_false: }
+  }
 
-% Store option keys and values
-% This strips trailing '=' from values.
-\def\xpg at store@opt at keyval#1:#2=:#3\relax{
-   \prop_if_exist:cF { xpg at current@options@#3 }
-      { \prop_new:c {xpg at current@options@#3} }
-   \prop_put:cnn { xpg at current@options@#3 }
-      {#1}{#2}
+\prg_set_conditional:Npnn \xpg_if_main_language:n #1 { T, F, TF }
+{
+   \str_if_eq:VnTF \xpg_main_language_tl { #1 }
+        { \prg_return_true: }
+        { \prg_return_false: }
 }
 
+\cs_set_eq:NN \IfMainLanguageTF \xpg_if_main_language:nTF
 
-\prg_set_conditional:Npnn \__xpg_check_option_value:NNN #1#2#3 { p , T , F , TF }
-{
-  \prop_get:cnNTF {xpg at current@options@#1} {#2} \l_tmpa_tl
-     {
-       \str_if_eq:eeTF{\l_tmpa_tl}{#3}
-          {\prg_return_true:}
-          {
-            \prop_get:cnNTF {xpg at alias@keyvals@#1@#3} {#2} \l_tmpb_tl
-               {
-                \clist_set:Ne{\l_tmpa_clist}{\l_tmpb_tl}
-                \providetoggle{xpgvalfound}
-                \togglefalse{xpgvalfound}
-                \clist_map_inline:Nn \l_tmpa_clist {
-                   \str_if_eq:eeT{##1}{\l_tmpa_tl}
-                      { \toggletrue{xpgvalfound} }
-                }
-                \iftoggle{xpgvalfound}{\prg_return_true:}{\prg_return_false:}
-              }
-              {
-                \prg_return_false:
-              }
-         }
-     }
-     {
-       \prg_return_false:
-     }
-}
+\cs_set_eq:NN \IfMainLanguageT \xpg_if_main_language:nT
 
+\cs_set_eq:NN \IfMainLanguageF \xpg_if_main_language:nF
+
 % Test if option value is set
 \DeclareDocumentCommand \iflanguageoption { m m m m m }
 {
@@ -2051,18 +1929,11 @@
   \__xpg_check_option_value:NNNTF{#1}{#2}{#3}{#4}{#5}
 }
 
-
-% Append any variant to csv list of variants
-\define at key{xpg at langvariant}{variant}{
-  \clist_if_in:NeF \xpg at vloaded {#1}{
-    \clist_gput_right:Ne \xpg at vloaded {#1}
-  }
-}
-
 % Test if language is loaded
 \DeclareDocumentCommand \iflanguageloaded { m m m }
 {
-   \AddToHook{begindocument/end}{
+   \hook_gput_code:nnn {begindocument/end} {.}
+   {
      \clist_if_in:NeTF \xpg at loaded{#1}{#2}{#3}
    }
 }
@@ -2070,7 +1941,8 @@
 % Same for babellanguage is loaded
 \DeclareDocumentCommand \ifbabellanguageloaded { m m m }
 {
-  \AddToHook{begindocument/end}{
+  \hook_gput_code:nnn {begindocument/end} {.}
+  {
      \clist_if_in:NeTF \xpg at bloaded{#1}{#2}{#3}
   }
 }
@@ -2078,7 +1950,8 @@
 % Same for languageid
 \DeclareDocumentCommand \iflanguageidloaded { m m m m }
 {
-  \AddToHook{begindocument/end}{
+  \hook_gput_code:nnn {begindocument/end} {.}
+  {
     \str_case:nnTF {#1}
       {
         {bcp-47}    { \clist_if_in:NeTF \xpg at bcp@loaded{#2}{#3}{#4} }
@@ -2086,7 +1959,7 @@
       }
       {}
       {
-        \xpg at error{Invalid~ \string\iflanguageidloaded\space argument:~ #1}
+        \xpg_ill_arg_msg:nn { #1 } { \iflanguageidloaded }
       }
    }%
 }
@@ -2116,30 +1989,21 @@
   }
 
 
-\newcommand*{\xpg at set@language at nonaux}[2][]{
-   \@select at language[#1]{#2}
+\cs_new_nopar:Nn \xpg_set_language_nonaux:nn
+{
+   \__xpg_start_language:nn { #1 } { #2 }
 }
 
 
-\newcommand*{\xpg at set@language at aux}[2][]{
-   % Store babelname of current language (for external packages such as biblatex)
-   \tl_if_blank:nTF {#1}{
-     \ifcsundef{#2 at gbabelname}{
-        \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-     }{
-        \edef\babelname{\csuse{#2 at gbabelname}}
-     }
-   }{
-     \edef\babelname{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/babelname}}
-   }
-   % Store BCP-47 id of current language
-   \__xpg_store_bcp_info:nn {#1}{#2}
-   \@select at language[#1]{#2}
+\cs_new_nopar:Nn \xpg_set_language_aux:nn
+{
+   \__xpg_start_language:nn { #1 } { #2 }
     % Write to the aux
-   \xpg at set@language at only@aux[#1]{#2}
+   \xpg_set_language_only_aux:nn { #1 } { #2 }
 }
 
-\newcommand*{\xpg at set@language at only@aux}[2][]{
+\cs_new_nopar:Nn \xpg_set_language_only_aux:nn
+{
     % Write to the aux (toc files)
    \if at filesw
         \addtocontents{toc}{\selectlanguage*[#1]{#2}}
@@ -2146,16 +2010,18 @@
    \fi
 }
 
-\AtBeginDocument{
+\hook_gput_code:nnn {begindocument} {.}
+{
    \if at filesw
-		\immediate\write\@mainaux
-		{\ProvideDocumentCommand\selectlanguage{sO{}m}{}}
+	\immediate\write\@mainaux
+	{\ProvideDocumentCommand\selectlanguage{sO{}m}{}}
    \fi
 }
 
 % Since captions might float to other language regions,
 % we need to change the language here (#542)
-\AddToHook{cmd/caption/before}{
+\hook_gput_code:nnn {cmd/caption/before} {.}
+{
     \ifhmode\unskip\fi
     \addtocontents{lof}{\protect\setforeignlanguage{\languagename}}
     \addtocontents{lot}{\protect\setforeignlanguage{\languagename}}
@@ -2162,7 +2028,7 @@
 }
 
 % check if language is defined
-\prg_set_conditional:Npnn \__xpg_check_if_exist_l@:n #1 { F, TF }
+\prg_set_conditional:Npnn \__xpg_pattern_check_if_exists:n #1 { F, TF }
   {
 	\bool_lazy_and:nnTF 
 	  { \cs_if_exist_p:c { l@#1 }  }
@@ -2171,34 +2037,75 @@
       { \prg_return_false: }
   }
 
-\def\polyglossia at luatex@load at lang#1{
+\cs_new_nopar:Nn \__xpg_luatex_load_lang:n
+{
   % if \l@#1 is not properly defined, call lua function newloader(#1),
   % and assign the returned number to \l@#1
-  \__xpg_check_if_exist_l@:nF {#1}
+  \__xpg_pattern_check_if_exists:nF {#1}
   {
     \directlua { token.set_char('l@#1', polyglossia.newloader'#1') }
   }
 }
 
-% This check is also used by biblatex, so don't
-% rename silently.
-\newcommand\xpg at ifdefined[3]{
+% check if language is defined
+\prg_set_conditional:Npnn \xpg_if_language_defined:n #1 { T, F, TF }
+{
   % With luatex, we first need to define \l@#1.
   \sys_if_engine_luatex:T
   {
-    \polyglossia at luatex@load at lang{#1}
+    \__xpg_luatex_load_lang:n {#1}
   }
-  \__xpg_check_if_exist_l@:nTF{#1}{#2}{#3}
+  \__xpg_pattern_check_if_exists:nTF{#1}
+        { \prg_return_true: }
+        { \prg_return_false: } 
 }
 
+% Aliases for gloss files
+\cs_gset_eq:cc { IfLanguageDefinedTF } { xpg_if_language_defined:nTF }
+\cs_gset_eq:cc { IfLanguageDefinedT }  { xpg_if_language_defined:nT }
+\cs_gset_eq:cc { IfLanguageDefinedF }  { xpg_if_language_defined:nF }
+
+% Check if patterns for language #1 is defined. If not, try
+% the comma-separated list of fallbacks in #2
+\NewDocumentCommand \TryPatternWithFallback { m m }
+{
+   \xpg_if_language_defined:nF { #1 }
+     {
+        \clist_clear_new:N \l_xpg_lang_patterns
+        \clist_set:Ne \l_xpg_lang_patterns { #2 }
+        \bool_set_false:N \l_tmpa_bool
+        \clist_map_inline:Nn \l_xpg_lang_patterns
+          {
+             \xpg_if_language_defined:nT { ##1 }
+                {
+                   \cs_gset_eq:cc { l@#1 }  { l@##1 }
+                   \bool_set_true:N \l_tmpa_bool
+                   \clist_map_break:
+                }
+          }
+        \bool_if:NF \l_tmpa_bool
+           {
+            \xpg_warning_msg:n
+              {No~ hyphenation~ patterns~ for~ #1~ found \iow_newline:
+               Falling~ back~ to~ the~ default~ patterns~ (=~English)!}
+               \exp_args:Nc \adddialect {l@#1} 0
+           }
+     }
+}
+
+% This old term is used by biblatex, so don't drop!
+\cs_gset_eq:cc { xpg at ifdefined } { xpg_if_language_defined:nTF }
+
 % 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]{
+\cs_new:Nn \xpg_set_bbl_hyphendata:n
+{
   \sys_if_engine_luatex:T
   {
-    \ifcsdef{bbl at hyphendata@#1}{}{
-      \global\@namedef{bbl at hyphendata@\the\language}{}
+    \cs_if_exist:cF {bbl at hyphendata@#1}
+    {
+      \cs_gset:cpn {bbl at hyphendata@\the\language} {}
     }
   }
 }
@@ -2205,48 +2112,50 @@
 
 % 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]{
-  \sys_if_engine_luatex:T { \polyglossia at luatex@load at lang{#1} }
+\cs_new:Nn \xpg_set_hyphenation_patterns:n
+{
+  \sys_if_engine_luatex:T { \__xpg_luatex_load_lang:n {#1} }
   \language=\csname l@#1\endcsname
 }
 
-\newcommand*\@select at language[2][]{
+\cs_new:Nn \__xpg_start_language:nn
+{
    % hook for compatibility with biblatex
-   \select at language{#2}
-   \xpg at set@bbl at hyphendata{\the\language}
+   \select at language { #2 }
+   \xpg_set_bbl_hyphendata:n {\the\language}
    \xpg_initial_setup:
-   \select@@language[#1]{#2}%
+   \xpg_select_language:nn { #1 } { #2 }
    % Hook for external packages such as biblatex
-   \polyglossia at language@switched%
-   \__xpg_lang_set_par_direction:n{#2}
-   \csuse{captions#2}%
-   \csuse{date#2}%
+   \polyglossia at language@switched
+   \__xpg_lang_set_par_direction:n {#2}
+   \use:c {captions#2}
+   \use:c {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}
-   \__xpg_local_marks:n{#2}
-   \csuse{init at extras@#2}%
+   \cs_if_exist_use:c {captions at bbl@\babelname}
+   \cs_if_exist_use:c {date at bbl@\babelname}
+   \__xpg_local_marks:n {#2}
+   \use:c {init at extras@#2}
    \__xpg_indent_first:n { #2 }
-   \csuse{blockextras@#2}%
+   \cs_if_exist_use:c {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}
- }
+   \cs_if_exist_use:c {blockextras at bbl@\babelname}
+}
 
 % hook for compatibility with biblatex
 % (probably no longer used due to the
 %  more general hook that follows, but
 %  we keep it for backwards comp.)
-\def\select at language#1{}
+\cs_set:Npn \select at language #1 {}
 
 % Hook for external packages such as biblatex
 % do not rename!
-\def\polyglossia at language@switched{}
+\cs_new:Npn \polyglossia at language@switched {}
 
-% remove all custumization for language #1
+% remove all customization for language #1
 \cs_new:Npn \noextrascurrent #1
-{%
+{
   \cs_if_exist_use:c{noextras@#1}%
   % This is a hook for external packages which want to access variants
   % via babelname (such as biblatex)
@@ -2254,7 +2163,8 @@
 }
 
 % Common code for `\select at language' and `\foreignlanguage'.
-\newcommand{\select@@language}[2][]{%
+\cs_new:Nn \xpg_select_language:nn
+{
   % disable the extras and number settings of the previous language
   \cs_if_exist:cT{languagename}
   {
@@ -2261,153 +2171,97 @@
     \noextrascurrent{\languagename}
     \cs_if_exist_use:c{no\languagename @numbers}
     \sys_if_engine_xetex:T{
-      \__xpg_if_LR_str:eTF{\prop_item:Ne{\g_xpg_langsetup_prop}{\languagename/direction}}
+      \__xpg_if_LR_str:eTF{\prop_item:Ne{\l_xpg_langsetup_prop}{\languagename/direction}}
       {
-        \__xpg_if_LR_str:eF{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/direction}}
+        \__xpg_if_LR_str:eF{\prop_item:Nn{\l_xpg_langsetup_prop}{#2/direction}}
           {\setnonlatin} % LTR -> RTL
       }
       {
-        \__xpg_if_LR_str:eT{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/direction}}
+        \__xpg_if_LR_str:eT{\prop_item:Nn{\l_xpg_langsetup_prop}{#2/direction}}
           {\setlatin} % RTL -> LTR
       }
     }
   }
-  \polyglossia at set@language at name[#1]{#2}
-  % Set the language's/script's font families
-  \str_if_eq:eeT{\prop_item:Nn{\g_xpg_langsetup_prop}{#2/lcscript}} {latin}
-  {
-    \resetfontlatin
-  }
-  \bool_if:NF \l__xpg_inline_lang_bool
-  { % This for non-inline font switches
-    % in case a \<lang>font is defined
-    \xpg at set@normalfont{#2}
-  }
-  \xpg at select@fontfamily{#2}
+  \xpg_set_language_name:n { #2 }
+  \xpg_set_normalfont:n { #2 }
+  \xpg_select_fontfamily:n { #2 }
   \__xpg_use_or_warn:c{#2 at language}
   \cs_if_exist_use:c{#2 at numbers}
-  \use at localhyphenmins[#1]{#2}
+  \__xpg_use_localhyphenmins:nn { #1 } { #2 }
   \__xpg_french_spacing:n { #2 }
 }
 
 
-\let\xpg at pop@language\relax
+\cs_undefine:N \xpg_pop_language:
 
-%
-% Keep track of the active (nested) languages and options
-%
-\clist_new:N \l_xpg_lang_stack
+\DeclareDocumentEnvironment { otherlanguage } { O{} m }
+  {
+    \selectlanguage[#1]{#2}
+  } { }
 
-\cs_new:Nn \__xpg_stack_language:nn
-{
-  \clist_gpush:Nn \l_xpg_lang_stack {#1:#2}
-}
+% Alias to {<lang>}, but more suitable
+% for specific (esp. tag-based) aliases
+% where {<alias>} would cause clashes
+% (e.g., \fi)
+\DeclareEnvironmentCopy { lang } { otherlanguage }
 
-\cs_generate_variant:Nn \__xpg_stack_language:nn {nx}
-
-\cs_new:Nn \__xpg_unstack_language:n
+\NewDocumentCommand \setlocalhyphenmins { m m m }
 {
-  \clist_gpop:NNTF \l_xpg_lang_stack \l_tmpa_tl {
-     % Stored format = options:language => split:
-     \seq_set_split:Nne \l_tmpa_seq {:} \l_tmpa_tl
-     \seq_get_left:NN \l_tmpa_seq \l_tmpb_tl
-     \seq_get_right:NN \l_tmpa_seq \l_tmpc_tl
-     % Execute passed command with language and maybe options
-     % and re-set stored language's keys
-     \tl_if_empty:NTF \l_tmpb_tl {\cs_if_exist_use:c{#1}{\l_tmpc_tl}}
-                                 {\__xpg_set_keys:nn{\l_tmpc_tl}{\l_tmpb_tl}
-                                  \cs_if_exist_use:c{#1}[\l_tmpb_tl]{\l_tmpc_tl}
-                                 }
-  }
-  {}
-}
-
-\DeclareDocumentEnvironment { otherlanguage } { O{} m }
-  {
-    % Get real current (pre-switch) options (incl. defaults)
-    \clist_clear_new:N \l_xpg_current_options
-    \prop_if_exist:cF { xpg at current@options@\languagename }
-	{ \prop_new:c {xpg at current@options@\languagename} }
-    \prop_map_inline:cn {xpg at current@options@\languagename}
+   \xpg_if_language_defined:nTF{#1}
+   {
+      \cs_if_eq:ccTF { l@#1 } { l at nohyphenation }
       {
-        \clist_put_right:Nn \l_xpg_current_options {##1=##2}
+        \xpg_warning_msg:n {\string\setlocalhyphenmin\space~ useless~ for~ unhyphenated~ language~ #1}
+      }{
+        \providehyphenmins{#1}{#2#3}
       }
-    % Store current (pre-switch) options and language on stack
-    \__xpg_stack_language:nx{\clist_use:Nn \l_xpg_current_options {,}}{\languagename}
-    \selectlanguage[#1]{#2}
-  }
-  {
-    % restore previous language in aux file and remove closed one from stack
-    \__xpg_unstack_language:n{xpg at set@language at only@aux}
-  }
-
-\newcommand{\setlocalhyphenmins}[3]{
-   \xpg at ifdefined{#1}{
-      \expandafter\ifx\csname l@#1\endcsname\l at nohyphenation
-        \xpg at warning{\string\setlocalhyphenmin\space~ useless~ for~ unhyphenated~ language~ #1}
-      \else
-      \providehyphenmins{#1}{#2#3}
-      \fi
    }{
-     \xpg at warning{\string\setlocalhyphenmin\space~ useless~ for~ unknown~ language~ #1}
+     \xpg_warning_msg:n {\string\setlocalhyphenmin\space~ useless~ for~ unknown~ language~ #1}
    }
 }
 
 % \setlanghyphenmins[options]{lang}{l}{r}
-\newcommand*\setlanghyphenmins[4][]{%
+\NewDocumentCommand \setlanghyphenmins { O{} m m m }
+{
   % Check for real language name and options
-  \edef\xpg at tmp@opts{\xpg_alias_add_to_option_i:nn{#2}{#1}}
-  \edef\xpg at tmp@lang{\xpg_alias_base_lang:n{#2}}
-  \bgroup
-  \xpg_error_if_lang_not_loaded:n{\xpg at tmp@lang}
-  \__xpg_set_keys:nn{\xpg at tmp@lang}{\xpg at tmp@opts}
+  \tl_set:Nx \l_tmp_opts_tl { \xpg_alias_add_to_option_i:nn{#2}{#1} }
+  \tl_set:Nx \l_tmp_lang_tl { \xpg_alias_base_lang:n{#2} }
+  \c_group_begin_token
+  \xpg_error_if_lang_not_loaded:n{\l_tmp_lang_tl}
+  \SetGlossOptions{\l_tmp_lang_tl}{ \l_tmp_opts_tl }
   % Store bcp47.tag at hypenmins
-  \tl_if_blank:nTF {\xpg at tmp@opts}{%
-    \ifcsundef{\csname xpg at tmp@lang\endcsname @g.bcp47.tag}{
-       \csedef{tmp at bcp47.tag}{\prop_item:Ne{\g_xpg_langsetup_prop}{ \xpg at tmp@lang / bcp47 }}
-    }{
-       \csedef{tmp at bcp47.tag}{\csuse{#2 at g.bcp47.tag}}
-    }
-  }{
-    \csedef{tmp at bcp47.tag}{\prop_item:Ne{\g_xpg_langsetup_prop}{ \xpg at tmp@lang / bcp47 }}
-  }
-  \csgdef{\csname tmp at bcp47.tag\endcsname @hyphenmins}{{#3}{#4}}
-  \egroup
+  \cs_set_nopar:cpe {tmp at bcp47.tag} { \prop_item:Ne{\l_xpg_langsetup_prop}{ \l_tmp_lang_tl / bcp47 } }
+  \cs_gset:cpn {\csname tmp at bcp47.tag\endcsname @hyphenmins} {{#3}{#4}}
+  \c_group_end_token
 }
 
-% \use at localhypenmins[options]{lang}
-\newcommand*\use at localhyphenmins[2][]{
-  \bgroup
-  \xpg_error_if_lang_not_loaded:n{#2}
-  \__xpg_set_keys:nn{#2}{#1}
+% \__xpg_use_localhyphenmins:nn {options}{lang}
+\cs_new_nopar:Nn \__xpg_use_localhyphenmins:nn
+{
+  \c_group_begin_token
+  \xpg_error_if_lang_not_loaded:n {#2}
+  \SetGlossOptions {#2} {#1}
   % Use bcp47.tag at hypenmins
-  \tl_if_blank:nTF {#1}{
-    \ifcsundef{#2 at g.bcp47.tag}{
-       \csxdef{tmp at bcp47.tag}{\prop_item:Nn{\g_xpg_langsetup_prop}{ #2 / bcp47 }}
-    }{
-       \csxdef{tmp at bcp47.tag}{\csuse{#2 at g.bcp47.tag}}
-    }
-  }{
-    \csxdef{tmp at bcp47.tag}{\prop_item:Nn{\g_xpg_langsetup_prop}{ #2 / bcp47 }}
-  }
-  \egroup
-  \ifcsundef{\csname tmp at bcp47.tag\endcsname @hyphenmins}{
-     \ifcsundef{#2hyphenmins}{}
+  \cs_gset_nopar:cpe {tmp at bcp47.tag} { \prop_item:Nn{\l_xpg_langsetup_prop}{ #2 / bcp47 } }
+  \c_group_end_token
+  \cs_if_exist:cTF {\csname tmp at bcp47.tag\endcsname @hyphenmins}
+   {
+      \tl_set:Ne \l_tmpa_tl { \use:c{\csname tmp at bcp47.tag\endcsname @hyphenmins} }
+      \expandafter \set at hyphenmins \l_tmpa_tl
+   }{
+     \cs_if_exist:cT{#2hyphenmins}
         {
           \expandafter\expandafter\expandafter\set at hyphenmins\csname #2hyphenmins\endcsname\relax
         }
-   }{
-      \edef\tmpa{\csuse{\csname tmp at bcp47.tag\endcsname @hyphenmins}}
-      \expandafter\expandafter\expandafter\set at hyphenmins\tmpa\relax
    }
-   \sys_if_engine_luatex:T{
+   \sys_if_engine_luatex:T
+   {
      % Set \totalhyphenmin if specified
-     \prop_get:NeNTF \g_xpg_langsetup_prop {#2/totalhyphenmin} \l_tmpa_tl
+     \prop_get:NeNT \l_xpg_langsetup_prop {#2/totalhyphenmin} \l_tmpb_tl
      {
-        \xpg at info{totalhyphenmin: '\l_tmpa_tl'}
-        \expandafter\hyphenationmin \l_tmpa_tl
+        \xpg_info_msg:n {totalhyphenmin: '\l_tmpb_tl'}
+        \expandafter\hyphenationmin \l_tmpb_tl
      }
-     {}
    }
 }
 
@@ -2419,23 +2273,26 @@
 \DeclareDocumentEnvironment { hyphenrules } { O{} m }
   {
     % Check for real language name and options
-    \edef\xpg at tmp@opts{\xpg_alias_add_to_option_i:nn{#2}{#1}}
-    \edef\xpg at tmp@lang{\xpg_alias_base_lang:n{#2}}
+    \tl_set:Nx \l_tmp_opts_tl { \xpg_alias_add_to_option_i:nn{#2}{#1} }
+    \tl_set:Nx \l_tmp_lang_tl { \xpg_alias_base_lang:n{#2} }
     % Register the language options
-    \__xpg_set_language_options:nnn {\xpg at tmp@lang} {\xpg at tmp@opts} {@xpg at set@langvariant}
+    \__xpg_set_language_options:nn { \l_tmp_lang_tl } { \l_tmp_opts_tl }
     % Now switch patterns
-    \__xpg_use_or_warn:c{\use:c{xpg at tmp@lang}@language}
+    \__xpg_use_or_warn:c{\use:c{l_tmp_lang_tl}@language}
     % And activate hyphenmins
-    \use at localhyphenmins[\xpg at tmp@opts]{\xpg at tmp@lang}
+    \__xpg_use_localhyphenmins:nn { \l_tmp_opts_tl } { \l_tmp_lang_tl }
   }
   { }
 
-\AddToHook{begindocument/before}{
-   \IfPackageLoadedTF{bidi}{
-      \providecommand*{\aemph}[1]{$\overline{\hboxR{#1}}$}
+\hook_gput_code:nnn {begindocument/before} {.}
+{
+   \IfPackageLoadedTF{bidi}
+   {
+      \ProvideDocumentCommand \aemph { m } { $\overline{\hboxR{#1}}$ }
    }{}
-   \IfPackageLoadedTF{luabidi}{
-      \providecommand*{\aemph}[1]{$\overline{\hbox{\RL{#1}}}$}
+   \IfPackageLoadedTF{luabidi}
+   {
+      \ProvideDocumentCommand \aemph { m } { $\overline{\hbox{\RL{#1}}}$ }
    }{}
 }
 
@@ -2469,7 +2326,8 @@
      .value_required:n = true,
 }
 
-\keys_set:nn { polyglossia } {
+\keys_set:nn { polyglossia }
+{
   localmarks = false,
   verbose = true,
   babelshorthands = false,
@@ -2486,17 +2344,18 @@
 \sys_if_engine_luatex:T{
   \str_if_eq:eeF{\g_xpg_luatex_renderer_str}{none}
   {
-    \xpg at info{Setting~ LuaTeX~ font~ renderer~ to~ \g_xpg_luatex_renderer_str}
+    \xpg_info_msg:n{Setting~ LuaTeX~ font~ renderer~ to~ \g_xpg_luatex_renderer_str}
     \exp_args:Ne \defaultfontfeatures{Renderer=\g_xpg_luatex_renderer_str}
   }
 }
 
-\bool_if:nF \g_xpg_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
+\bool_if:nF \g_xpg_verbose_bool
+{
+   \cs_gset_nopar:Npn \@latex at info #1 { \relax } % no latex info
+   \cs_gset_nopar:Npn \@font at info #1 { \relax } % no latex font info
+   \cs_gset_nopar:Npn \@font at warning #1 { \relax } % no latex font warnings
+   \msg_redirect_module:nnn { fontspec } { info } { none } % no fontspec info
+   \msg_redirect_module:nnn { polyglossia } { info } { none } % no polyglossia info
 }
 
 \bool_if:nT \g_xpg_localmarks_bool {
@@ -2503,6 +2362,17 @@
   \__xpg_enable_local_marks:
 }
 
+% common code to initiate babelshordhands in glosses
+\cs_new:Npn \InitializeBabelShorthands
+{
+  \cs_if_exist:cF {initiate at active@char}
+  {
+    \file_input:n {babelsh.def}
+    \initiate at active@char{"}
+    \shorthandoff{"}
+  }
+}
+
 % Control shorthand (de-)activation
 % This checks that the shorthand char is only deactivated
 % if we have activated it ourselves and hence keeps
@@ -2530,7 +2400,8 @@
 % Inherit shorthands in other languages
 \NewDocumentCommand \inheritbabelshorthands { m m }
 {
-   \AddToHook{begindocument/before}{
+   \hook_gput_code:nnn {begindocument/before} {.}
+   {
        % Load the involved languages if necessary
        % Error if they do not exist
        \tl_set:Nn \l__xpg_tmpa_lang_tl { \xpg_alias_base_lang:n{#1} }
@@ -2537,7 +2408,7 @@
        \clist_if_in:NeF \xpg at loaded {\l__xpg_tmpa_lang_tl}{
            \file_if_exist:nTF{gloss-\l__xpg_tmpa_lang_tl .ldf}
               { \setotherlanguage{#1} }
-              { \xpg at error{ Source~ language~ #1,~ used~ in~
+              { \xpg_error_msg:n { Source~ language~ #1,~ used~ in~
                             \string\inheritbabelshorthands,~ does~ not~ exist } }
        }
        \tl_set:Nn \l__xpg_tmpb_lang_tl { \xpg_alias_base_lang:n{#2} }
@@ -2544,7 +2415,7 @@
        \clist_if_in:NeF \xpg at loaded {\l__xpg_tmpb_lang_tl}{
            \file_if_exist:nTF{gloss-\l__xpg_tmpb_lang_tl .ldf}
               { \setotherlanguage{#2} }
-              { \xpg at error{ Target~ language~ #2,~ used~ in~
+              { \xpg_error_msg:n { Target~ language~ #2,~ used~ in~
                             \string\inheritbabelshorthands,~ does~ not~ exist } }
        }
        % Test whether the requested shorthands exist
@@ -2556,7 +2427,7 @@
                        { \bool_set_true:N \l__xpg_no_shorthands_bool }
        \bool_if:nT { \l__xpg_no_shorthands_bool }
                    {
-                      \xpg at error{ No~ babel~ shorthands~ exist~ for~ language~ #1 }
+                      \xpg_error_msg:n { No~ babel~ shorthands~ exist~ for~ language~ #1 }
                    }
        % If so, apply:
        \bool_if:nF { \l__xpg_no_shorthands_bool }
@@ -2581,7 +2452,7 @@
        \iflanguageloaded{\l__xpg_tmpa_lang_tl}{
            \use:c{\l__xpg_tmpa_lang_tl @shorthands}
        }{
-           \xpg at error{ Language~ #1,~ requested~ in~
+           \xpg_error_msg:n { Language~ #1,~ requested~ in~
                        \string\startbabelshorthands,~ is~ not~ loaded }
        }
     }



More information about the tex-live-commits mailing list.