[latex3-commits] [git/LaTeX3-latex3-babel] master: [Unstable] Autoloading based on BCP47 codes. (7648094)

Javier email at dante.de
Tue Apr 14 18:19:10 CEST 2020


Repository : https://github.com/latex3/babel
On branch  : master
Link       : https://github.com/latex3/babel/commit/7648094c51e599f0b5c5504725e78be5187f1e0a

>---------------------------------------------------------------

commit 7648094c51e599f0b5c5504725e78be5187f1e0a
Author: Javier <email at localhost>
Date:   Tue Apr 14 18:19:10 2020 +0200

    [Unstable] Autoloading based on BCP47 codes.


>---------------------------------------------------------------

7648094c51e599f0b5c5504725e78be5187f1e0a
 .gitignore   |   3 +-
 README.md    |   4 +-
 babel.dtx    | 135 +++++++++++++++++++++++++++++++++++++++++++----------------
 babel.ins    |   2 +-
 babel.pdf    | Bin 767269 -> 769430 bytes
 bbcompat.dtx |   2 +-
 6 files changed, 104 insertions(+), 42 deletions(-)

diff --git a/.gitignore b/.gitignore
index 396f36c..cf845da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,5 @@
 build/*
-
 *.zip
-
 *.pdf
 !*/testfiles/*.pdf
+/xbuild.lua
diff --git a/README.md b/README.md
index c8e6c6b..4c0d513 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-## Babel 3.42.1974
+## Babel 3.42.1977
 
 This package manages culturally-determined typographical (and other)
 rules, and hyphenation patterns for a wide range of languages.  Many
@@ -48,7 +48,7 @@ respective authors.
        - Only a few essential commands are loaded with the format.
        - Improvements in Assamese and Finnish.
        - Fix - Babel reset the \sfcode of » to 1000. It should be 0.
-       -
+       - First steps in the removal of switch.def and plain.def.  
        
 3.42   2020-03-22
        - \getlocaleproperty, to get the value of a field from the loaded
diff --git a/babel.dtx b/babel.dtx
index 2af93e2..d63fca4 100644
--- a/babel.dtx
+++ b/babel.dtx
@@ -31,7 +31,7 @@
 %
 % \iffalse
 %<*filedriver>
-\ProvidesFile{babel.dtx}[2020/04/11 v3.42.1974 The Babel package]
+\ProvidesFile{babel.dtx}[2020/04/14 v3.42.1977 The Babel package]
 \documentclass{ltxdoc}
 \GetFileInfo{babel.dtx}
 \usepackage{fontspec}
@@ -4465,8 +4465,8 @@ help from Bernd Raichle, for which I am grateful.
 % \section{Tools}
 %
 %    \begin{macrocode}
-%<<version=3.42.1974>>
-%<<date=2020/04/11>>
+%<<version=3.42.1977>>
+%<<date=2020/04/14>>
 %    \end{macrocode}
 %
 % \textbf{Do not use the following macros in \texttt{ldf} files. They
@@ -4970,6 +4970,7 @@ help from Bernd Raichle, for which I am grateful.
 \bbl at trace{Defining option 'base'}
 \@ifpackagewith{babel}{base}{%
   \let\bbl at onlyswitch\@empty
+  \let\bbl at provide@locale\relax
   \input babel.def
   \let\bbl at onlyswitch\@undefined
   \ifx\directlua\@undefined
@@ -6554,11 +6555,44 @@ help from Bernd Raichle, for which I am grateful.
       \@empty
     \edef\bbl at tempd{\endgroup\def\noexpand#1{#1}}%
   \bbl at tempd
-  \bbl at usehooks{languagename}{}}
+  \bbl at exp{\\\bbl at usehooks{languagename}{{\languagename}{#1}}}}
 \def\bbl at iflanguage#1{%
   \@ifundefined{l@#1}{\@nolanerr{#1}\@gobble}\@firstofone}
 %    \end{macrocode}
 %
+% After a name has been ‘fixed’, the selectors will try to load the
+% language. If even the fixed name is not defined, will load it on the
+% fly, either based on its name, or if activated, its BCP47 code.
+%
+%    \begin{macrocode}
+\let\bbl at autoload@options\@empty
+\def\bbl at provide@locale{%
+  % Unfinished. To add: search if loaded with \LocaleForEach. Fallbacks
+  % like fr-FR -> fr.
+  \let\bbl at auxname\languagename
+  \ifbbl at bcpallowed
+    \let\bbl at tempa\languagename
+    \edef\languagename{bcp47-\languagename}%
+    \bbl at fixname\languagename
+    \expandafter\ifx\csname date\languagename\endcsname\relax
+      \let\languagename\bbl at tempa
+    \fi
+  \fi
+  \expandafter\ifx\csname date\languagename\endcsname\relax
+    \IfFileExists{babel-\languagename.tex}%
+       {\bbl at exp{\\\babelprovide[\bbl at autoload@options]{\languagename}}}%
+       {\ifbbl at bcpallowed
+          \IfFileExists{babel-\languagename.ini}%
+            {\let\bbl at tempa\languagename
+             \bbl at exp{\lowercase{%
+               \edef\\\languagename{bcp47-\languagename}%
+               \edef\\\localename{bcp47-\localename}}}%
+             \bbl at exp{\\\babelprovide[import=\bbl at tempa]{\languagename}}}%
+            {}%
+        \fi}%
+  \fi}
+%    \end{macrocode}
+%
 %  \begin{macro}{\iflanguage}
 %    Users might want to test (in a private package for instance)
 %    which language is currently active. For this we provide a test
@@ -6676,7 +6710,9 @@ help from Bernd Raichle, for which I am grateful.
 %
 %    \begin{macrocode}
 \def\bbl at push@language{%
-  \xdef\bbl at language@stack{\languagename+\bbl at language@stack}}
+  \ifx\languagename\@undefined\else
+    \xdef\bbl at language@stack{\languagename+\bbl at language@stack}%
+  \fi}
 %    \end{macrocode}
 %
 % Retrieving information from the stack is a little bit less simple, as
@@ -6688,7 +6724,7 @@ help from Bernd Raichle, for which I am grateful.
 %    (delimited by `-') in its third argument.
 %
 %    \begin{macrocode}
-\def\bbl at pop@lang#1+#2-#3{%
+\def\bbl at pop@lang#1+#2&#3{%
   \edef\languagename{#1}\xdef#3{#2}}
 %    \end{macrocode}
 %
@@ -6706,7 +6742,7 @@ help from Bernd Raichle, for which I am grateful.
 %    \begin{macrocode}
 \let\bbl at ifrestoring\@secondoftwo
 \def\bbl at pop@language{%
-  \expandafter\bbl at pop@lang\bbl at language@stack-\bbl at language@stack
+  \expandafter\bbl at pop@lang\bbl at language@stack&\bbl at language@stack
   \let\bbl at ifrestoring\@firstoftwo
   \expandafter\bbl at set@language\expandafter{\languagename}%
   \let\bbl at ifrestoring\@secondoftwo}
@@ -6778,34 +6814,49 @@ help from Bernd Raichle, for which I am grateful.
 %    \begin{macrocode}
 \def\BabelContentsFiles{toc,lof,lot}
 \def\bbl at set@language#1{% from selectlanguage, pop@
+  % The old buggy way. Preserved for compatibility.
   \edef\languagename{%
     \ifnum\escapechar=\expandafter`\string#1\@empty
     \else\string#1\@empty\fi}%
+  \ifcat\relax\noexpand#1%
+    \expandafter\ifx\csname date\languagename\endcsname\relax
+      \edef\languagename{#1}%
+      \let\localename\languagename
+    \else
+      \bbl at warning{Using '\string\language' instead of 'language' is\\%
+                   deprecated. If what you want is to use a macro\\%
+                   containing the actual locale, make sure it does\\%
+                   not match any language. '\string\localename' is\\%
+                   left empty. Reported on }%
+      \def\localename{}% 
+    \fi
+  \else
+    \def\localename{#1}% This one has the correct catcodes
+  \fi
   \select at language{\languagename}%
   % write to auxs
   \expandafter\ifx\csname date\languagename\endcsname\relax\else
     \if at filesw
       \ifx\babel at aux\@gobbletwo\else % Set if single in the first, redundant
-        \protected at write\@auxout{}{\string\babel at aux{\languagename}{}}%
+        \protected at write\@auxout{}{\string\babel at aux{\bbl at auxname}{}}%
       \fi
       \bbl at usehooks{write}{}%
     \fi
   \fi}
+% 
+\newif\ifbbl at bcpallowed
+\bbl at bcpallowedfalse
 \def\select at language#1{% from set@, babel at aux
   % set hymap
   \ifnum\bbl at hymapsel=\@cclv\chardef\bbl at hymapsel4\relax\fi
   % set name
   \edef\languagename{#1}%
   \bbl at fixname\languagename
-  \expandafter\ifx\csname date\languagename\endcsname\relax
-    \IfFileExists{babel-\languagename.tex}%
-      {\babelprovide{\languagename}}%
-      {}%
-  \fi
+  \bbl at provide@locale
   \bbl at iflanguage\languagename{%
      \expandafter\ifx\csname date\languagename\endcsname\relax
       \bbl at error
-        {Unknown language `#1'. Either you have\\%
+        {Unknown language `\languagename'. Either you have\\%
          misspelled its name, it has not been installed,\\%
          or you requested it in a previous run. Fix its name,\\%
          install it or just rerun the file, respectively. In\\%
@@ -7060,11 +7111,7 @@ help from Bernd Raichle, for which I am grateful.
   % set name
   \edef\languagename{#1}%
   \bbl at fixname\languagename
-  \expandafter\ifx\csname date\languagename\endcsname\relax
-    \IfFileExists{babel-\languagename.tex}%
-      {\babelprovide{\languagename}}%
-      {}%
-  \fi
+  \bbl at provide@locale
   \bbl at iflanguage\languagename{%
     \expandafter\ifx\csname date\languagename\endcsname\relax
       \bbl at warning   % TODO - why a warning, not an error?
@@ -7548,7 +7595,7 @@ help from Bernd Raichle, for which I am grateful.
   adddialect=2,patterns=2,defaultcommands=0,encodedcommands=2,write=0,%
   beforeextras=0,afterextras=0,stopcommands=0,stringprocess=0,%
   hyphenation=2,initiateactive=3,afterreset=0,foreign=0,foreign*=0,%
-  beforestart=0,languagename=0}
+  beforestart=0,languagename=2}
 %    \end{macrocode}
 %
 % \begin{macro}{\babelensure}
@@ -9904,13 +9951,13 @@ help from Bernd Raichle, for which I am grateful.
 }
 %    \end{macrocode}
 %
-%    Finally, the default is to use English as the main language.
+%    Finally, make sure the default hyphenrules are defined (even if
+%    empty). 
 %
 %    \begin{macrocode}
 \ifx\l at english\@undefined
   \chardef\l at english\z@
 \fi
-\main at language{english}
 %    \end{macrocode}
 %
 % \subsection{Layout}
@@ -10039,6 +10086,9 @@ help from Bernd Raichle, for which I am grateful.
         \\\foreignlanguage{\languagename}%
         {####1}}}}%
     {}%
+  \bbl at exp{%
+     \\\bbl at toglobal\<bbl at ensure@\languagename>%
+     \\\bbl at toglobal\<bbl at ensure@\languagename\space>}
   % At this point all parameters are defined if 'import'. Now we
   % execute some code depending on them. But what about if nothing was
   % imported? We just load the very basic parameters: ids and a few
@@ -10868,7 +10918,10 @@ help from Bernd Raichle, for which I am grateful.
 %
 %    \begin{macrocode}
 \newcommand\babeladjust[1]{%  TODO. Error handling.
-  \bbl at forkv{#1}{\bbl at cs{ADJ@##1@##2}}}
+  \bbl at forkv{#1}{%
+    \bbl at ifunset{bbl at ADJ@##1@##2}% 
+      {\bbl at cs{ADJ@##1}{##2}}%
+      {\bbl at cs{ADJ@##1@##2}}}}
 %
 \def\bbl at adjust@lua#1#2{%
   \ifvmode
@@ -10922,6 +10975,16 @@ help from Bernd Raichle, for which I am grateful.
   \bbl at adjust@layout{\let\list\bbl at OL@list}}
 \@namedef{bbl at ADJ@hyphenation.extra at on}{%
   \bbl at activateposthyphen}
+%
+\@namedef{bbl at ADJ@autoload.bcp47 at on}{%
+  \bbl at bcpallowedtrue}
+\@namedef{bbl at ADJ@autoload.bcp47 at off}{%
+  \bbl at bcpallowedfalse}
+\@namedef{bbl at ADJ@autoload.options}#1{%
+  \def\bbl at autoload@options{#1}}
+%
+% As the final task, load the code for lua.
+%
 \ifx\directlua\@undefined\else
   \ifx\bbl at luapatterns\@undefined
     \input luababel.def
@@ -20476,16 +20539,17 @@ Babel.cjk_breaks = {
 %    \end{macrocode}
 %
 %    \LaTeX\ needs to be able to switch off writing to its auxiliary
-%    files; plain doesn't have them by default.
+%    files; plain doesn't have them by default. There is a trick to
+%    hide some conditional commands from the outer |\ifx|. The same
+%    trick is applied below.
 %
 %    \begin{macrocode}
-  % Ugly trick to hide the fi to the outer if when false:
-\catcode`\%=9
-  % \ifx\if at filesw\@undefined
-  %   \expandafter\let\csname if at filesw\expandafter\endcsname
-  %     \csname iffalse\endcsname
-  % \fi
-\catcode`\%=14
+\catcode`\&=\z@
+\ifx&if at filesw\@undefined
+  \expandafter\let\csname if at filesw\expandafter\endcsname
+    \csname iffalse\endcsname
+\fi
+\catcode`\&=4
 %    \end{macrocode}
 %
 %    Mimick \LaTeX's commands to define control sequences.
@@ -20552,9 +20616,8 @@ Babel.cjk_breaks = {
       \@x at protect#1%
    \fi
 }
-  % Ugly trick to hide the fi's to the outer if when false:
-\catcode`\%=9 
-  %\def\@x at protect#1\fi#2#3{\fi\protect#1}
+\catcode`\&=\z@  % Trick to hide conditionals
+  \def\@x at protect#1&fi#2#3{&fi\protect#1}
 %    \end{macrocode}
 %
 %    The following little macro |\in@| is taken from \file{latex.ltx};
@@ -20564,8 +20627,8 @@ Babel.cjk_breaks = {
 %    construct with the temporary definition of |\bbl at tempa|.
 %
 %    \begin{macrocode}
-  %\def\bbl at tempa{\csname newif\endcsname\ifin@}
-\catcode`\%=14
+  \def\bbl at tempa{\csname newif\endcsname&ifin@}
+\catcode`\&=4
 \ifx\in@\@undefined
   \def\in@#1#2{%
     \def\in@@##1#1##2##3\in@@{%
diff --git a/babel.ins b/babel.ins
index 6ae2d3d..50dabf1 100644
--- a/babel.ins
+++ b/babel.ins
@@ -26,7 +26,7 @@
 %% and covered by LPPL is defined by the unpacking scripts (with
 %% extension .ins) which are part of the distribution.
 %%
-\def\filedate{2020/04/11}
+\def\filedate{2020/04/14}
 \def\batchfile{babel.ins}
 \input docstrip.tex
 
diff --git a/babel.pdf b/babel.pdf
index 101d012..503cc30 100644
Binary files a/babel.pdf and b/babel.pdf differ
diff --git a/bbcompat.dtx b/bbcompat.dtx
index ed9c0be..5d3526f 100644
--- a/bbcompat.dtx
+++ b/bbcompat.dtx
@@ -30,7 +30,7 @@
 %
 % \iffalse
 %<*dtx>
-\ProvidesFile{bbcompat.dtx}[2020/04/11 v3.42.1974]
+\ProvidesFile{bbcompat.dtx}[2020/04/14 v3.42.1977]
 %</dtx>
 %
 %% File 'bbcompat.dtx'





More information about the latex3-commits mailing list.