Skip to content

Commit

Permalink
Provide upstream method to try fallback patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
jspitz committed May 9, 2024
1 parent c835d30 commit 24132c6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 66 deletions.
16 changes: 2 additions & 14 deletions tex/gloss-english.ldf
Original file line number Diff line number Diff line change
Expand Up @@ -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{%
Expand Down
30 changes: 4 additions & 26 deletions tex/gloss-malay.ldf
Original file line number Diff line number Diff line change
Expand Up @@ -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}%
},
Expand Down
30 changes: 4 additions & 26 deletions tex/gloss-sorbian.ldf
Original file line number Diff line number Diff line change
Expand Up @@ -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}%
},
Expand Down
29 changes: 29 additions & 0 deletions tex/polyglossia.sty
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

3 comments on commit 24132c6

@Udi-Fogiel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning and the result dos not mean the same thing, I believe. \language0 are the patterns for english loaded in the format, wht does null langue mean?

@jspitz
Copy link
Collaborator Author

@jspitz jspitz commented on 24132c6 Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be more transparent if we write:
I~ will~ fall~ back~ to~ the~ default~ patterns~ (=English)~ instead!

@jspitz
Copy link
Collaborator Author

@jspitz jspitz commented on 24132c6 Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be more transparent if we write: I~ will~ fall~ back~ to~ the~ default~ patterns~ (=English)~ instead!

done at b3d363d

Please sign in to comment.