From 24132c6fb549bde8369fbd53335c536c88823730 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Thu, 9 May 2024 17:19:06 +0200 Subject: [PATCH] Provide upstream method to try fallback patterns --- tex/gloss-english.ldf | 16 ++-------------- tex/gloss-malay.ldf | 30 ++++-------------------------- tex/gloss-sorbian.ldf | 30 ++++-------------------------- tex/polyglossia.sty | 29 +++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 66 deletions(-) diff --git a/tex/gloss-english.ldf b/tex/gloss-english.ldf index cf19732c..e012f6ae 100644 --- a/tex/gloss-english.ldf +++ b/tex/gloss-english.ldf @@ -142,20 +142,8 @@ \ifxetex % Check if \l@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 - \IfLanguageDefinedF{english}{% - \def\do##1{% - \IfLanguageDefinedTF{#1}% - {\csletcs{l@english}{l@#1}\listbreak}% - {% - \xpg@warning{No hyphenation patterns for English found"\MessageBreak - I will use the 'null' language instead}% - \adddialect\l@english0 - }% - }% - \docsvlist{british, american, usenglishmax, australian, newzealand} - \IfLanguageDefinedTF{english}{}{} - }% + % (specific order as in the csv list), or null language if everything fails + \TryPatternWithFallback{english}{british, american, usenglishmax, australian, newzealand} \fi \def\english@language{% diff --git a/tex/gloss-malay.ldf b/tex/gloss-malay.ldf index 1f3fbe5d..1c287e2d 100644 --- a/tex/gloss-malay.ldf +++ b/tex/gloss-malay.ldf @@ -48,36 +48,14 @@ \SetLanguageKeys{malay}{language=Malay,langtag=MLY,babelname=bahasam,bcp47=zsm,bcp47-language=zsm}% \SetupLatinPolyglossiaFont{malay}% % Check if \l@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 - \IfLanguageDefinedF{malay}{% - \def\do####1{% - \IfLanguageDefinedT{####1}% - {\csletcs{l@malay}{l@####1}\listbreak}% - }% - \docsvlist{melayu,bahasam,bahasai,indonesian,indon,bahasa} - \IfLanguageDefinedF{malay}{% - \xpg@warning{No hyphenation patterns for Malay (Malaysian) found\MessageBreak - I will use the 'null' language instead}% - \adddialect\l@malay0% - }% - }% + % (specific order as in the csv list), or null language if everything fails + \TryPatternWithFallback{malay}{melayu,bahasam,bahasai,indonesian,indon,bahasa}% \else \SetLanguageKeys{malay}{language=Indonesian,langtag=IND,babelname=bahasa,bcp47=id,bcp47-language=id}% \SetupLatinPolyglossiaFont{malay}% % Check if \l@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 - \IfLanguageDefinedF{indonesian}{% - \def\do####1{% - \IfLanguageDefinedT{####1}% - {\csletcs{l@indonesian}{l@####1}\listbreak}% - }% - \docsvlist{indon,bahasai,bahasam,malay,melayu,bahasa} - \IfLanguageDefinedF{indonesian}{% - \xpg@warning{No hyphenation patterns for Malay (Indonesian) found\MessageBreak - I will use the 'null' language instead}% - \adddialect\l@indonesian0 - }% - }% + % (specific order as in the csv list), or null language if everything fails + \TryPatternWithFallback{indonesian}{indon,bahasai,bahasam,malay,melayu,bahasa}% \fi \xpg@info{Option: malay, variant=#1}% }, diff --git a/tex/gloss-sorbian.ldf b/tex/gloss-sorbian.ldf index 4ed3f960..2f8d0075 100644 --- a/tex/gloss-sorbian.ldf +++ b/tex/gloss-sorbian.ldf @@ -39,38 +39,16 @@ \SetLanguageKeys{sorbian}{language=Upper Sorbian,langtag=USB,babelname=uppersorbian,bcp47=hsb,bcp47-language=hsb}% \SetupLatinPolyglossiaFont{sorbian}% % Check if \l@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 - \IfLanguageDefinedF{usorbian}{% - \def\do####1{% - \IfLanguageDefinedT{####1}% - {\csletcs{l@usorbian}{l@####1}\listbreak}% - }% - \docsvlist{uppersorbian} - \IfLanguageDefinedF{usorbian}{% - \xpg@warning{No hyphenation patterns for Upper Sorbian found\MessageBreak - I will use the 'null' language instead}% - \adddialect\l@usorbian0% - } - }% + % (specific order as in the csv list), or null language if everything fails + \TryPatternWithFallback{usorbian}{uppersorbian}% \or % lower: \def\sorbian@variant{lsorbian}% \SetLanguageKeys{sorbian}{language=Lower Sorbian,langtag=LSB,babelname=lowersorbian,bcp47=dsb,bcp47-language=dsb}% \SetupLatinPolyglossiaFont{sorbian}% % Check if \l@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 - \IfLanguageDefinedF{lsorbian}{% - \def\do####1{% - \IfLanguageDefinedT{####1}% - {\csletcs{l@lsorbian}{l@####1}\listbreak}% - }% - \docsvlist{lowersorbian,Lsorbian,usorbian,uppersorbian} - \IfLanguageDefinedF{lsorbian}{% - \xpg@warning{No hyphenation patterns for Lower Sorbian found\MessageBreak - I will use the 'null' language instead}% - \adddialect\l@lsorbian0% - } - }% + % (specific order as in the csv list), or null language if everything fails + \TryPatternWithFallback{lsorbian}{lowersorbian,Lsorbian,usorbian,uppersorbian}% \fi \xpg@info{Option: sorbian, variant=#1}% }, diff --git a/tex/polyglossia.sty b/tex/polyglossia.sty index 9bb3aa9c..1d7d22a6 100644 --- a/tex/polyglossia.sty +++ b/tex/polyglossia.sty @@ -2356,6 +2356,35 @@ \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 } + { + \xpg_info_msg:n{Using~ hyphenation~ pattern~ '##1'~ for~ #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: + I~ will~ use~ the~ 'null'~ language~ instead!} + \exp_args:Nc \adddialect {l@#1} 0 + } + } +} + % This old term is used by biblatex, so don't drop! \cs_gset_eq:cc { xpg@ifdefined } { xpg_if_language_defined:nTF }