latex3 / babel

The multilingual framework to localize LaTeX, LuaLaTeX and XeLaTeX
https://latex3.github.io/babel/
LaTeX Project Public License v1.3c
130 stars 35 forks source link

\localeinfo doesn't work as documented #102

Closed u-fischer closed 3 years ago

u-fischer commented 3 years ago
  1. According to the documentation \localefinfo is fully expandable. But actually it issues an error message if the ini has not been loaded and the info is not known. Could it instead call some expandable marker?

  2. The documentation names the fields language.tag.bcp47 and tag.ini but both seems not to work.

  3. Would it be possible to ensure that at least language.tag.bcp47 and tag.bcp47 are always defined, without having to force the loading of the ini file with \BabelEnsureInfo? That would make it easier for a package to add language support without having to worry about such loading details.

\documentclass{article}
\usepackage[british]{babel}
\BabelEnsureInfo %needed
\begin{document}
\localeinfo{tag.bcp47}
\localeinfo{name.english}
\localeinfo{tag.opentype}
\localeinfo{script.name}
\localeinfo{script.tag.bcp47}
\localeinfo{script.tag.opentype}
%\localeinfo{tag.ini} %error
%\localeinfo{language.tag.bcp47} %error
\end{document}
jbezos commented 3 years ago

1-2/ I'll fix it the next release (that's weird - it's like I accidentally deleted them, because I sure wrote it).

3/ “without having to force the loading of the ini file with \BabelEnsureInfo“.

It's something I've had a lot of doubts about. My logic was:

But I can reconsider it. As I said, I'm not clear on this.

u-fischer commented 3 years ago

Regaring 3: I didn't mean that the whole ini should be loaded (and for the same reason you don't want to load them, I don't want to force the loading in hyperref either). But imho it would be useful is at least the tag.bcp47 is always set.

jbezos commented 3 years ago

The point is how 🙂. There must be some source, and the only other possibility I think of is by adding it in every ldf. Or by creating a list in a single file (which, in turn, may require some maintenance, updaters and the like, which I dislike).

u-fischer commented 3 years ago

Imho in the long run, this should be a required setting in the ldf, but I'm not sure how exactly. Actually I don't even know exactly how ldf and ini relate. Who wins if they clash and are both loaded?

jbezos commented 3 years ago

They never clash (so I hope 😉). Once loaded an ldf, its behavior is either extended or modified by an ini file.

u-fischer commented 3 years ago

I think we have different views about "fully expandable". \localeinfo expands fine if the info exists, but for some languages there is no ini and then it errors and this means I can't use it in an edef to test if the info is there. Currently I'm resorting to test an internal babel command but I would prefer a real interface. E.g. an \localeinfoEXP which expands to -no-value-, or a test \iflocaleinfo{tag.bcp47}

\documentclass{article}
\usepackage[portuges]{babel}
\BabelEnsureInfo
\begin{document}
xx 
%\edef\testlocale{\localeinfo{tag.bcp47}} %errors

%that works:
\ifcsname bbl@\csname bbl@info@tag.bcp47\endcsname @\languagename\endcsname
 true\else false \fi

\end{document}
jbezos commented 3 years ago

Every more or less official language name should have a babel-...tex file, but there is none for portuges (a somewhat absurd name coming form the age of 8-letter file names, which very likely should be deprecated).

I think we have different views about "fully expandable".

So it seems 🙂. Returning ?? would be an alternative, but I'm not sure this actually helps.

u-fischer commented 3 years ago

Every more or less official language name should have a babel-...tex file,

A few are missing. Beside portuges I found acadian, magyar, brazil,

Returning ?? would be an alternative, but I'm not sure this actually helps.

Returning ?? would be fine with me. It doesn't explode in an edef and is easily tested. And it doesn't have to be done by \localeinfo if you want to keep it as it is, I'm fine with some other command.

jbezos commented 3 years ago

Doesn't \getlocaleproperty* work for you? It's aimed at cases like this, because the returned value if it doesn't exist is \relax (without the star it raises an error). Not expandable, but I presume you can retrieve the value before.

u-fischer commented 3 years ago

I had excluded it, because I thought I need to know the name, but \getlocaleproperty*\test{\languagename}{identification/tag.bcp47} seems to work. Thanks I will try with it.

u-fischer commented 3 years ago

I tried with \getlocaleproperty. But it is simply not stable enough. E.g this here errors

\documentclass{article}
\usepackage[english]{babel}
\AddBabelHook{test}{afterextras}{\getlocaleproperty*\mytest{\languagename}{identification/tag.bcp47}}

\begin{document}
bbb
\selectlanguage{ngerman}
bbbb
\end{document}

with

! Undefined control sequence.
\bbl@usehooks ...@}\ifx \languagename \@undefined 
jbezos commented 3 years ago

Overlapping elt's. Fixed.