biblatex icon indicating copy to clipboard operation
biblatex copied to clipboard

Detect additional babel/polyglossia language attributes

Open moewew opened this issue 5 years ago • 4 comments

See #937. Related: #939.

babel allows to set and act on language attributes. These attributes can be set either when loading the language via a dot modifier

\usepackage[english, serbian.ijekav]{babel}

or later with \languageattribute

\usepackage[english, serbian]{babel}
\languageattribute{serbian}{ijekav}

polyglossia of course has even more ways to set up language attributes in the gloss files.

Can we somehow query or intercept the active values and act on them as well?

moewew avatar Nov 27 '19 06:11 moewew

babel dot modifiers and language attributes can be queried with

\bbl@ifattributeset{<language>}{<attribute>}
  {<true>}
  {<false>}

See

\documentclass{article}
\usepackage[english, serbian.ijekav]{babel}
\languageattribute{serbian}{datei}

\makeatletter
\begin{document}
\bbl@ifattributeset{serbian}{ijekav}{T}{F}

\bbl@ifattributeset{serbian}{datei}{T}{F}

\bbl@ifattributeset{serbian}{quotes}{T}{F}
\end{document}

\bbl@ifattributeset is documented as internal macro and should be used in \AtBeginDocument after the language files are loaded (I presume the document body is also fine, see the example). Maybe I should ask at https://github.com/latex3/babel/issues if we can have this become an official macro on which we can rely.

moewew avatar Nov 27 '19 07:11 moewew

The upcoming polyglossia (v1.47?) will have \iflanguageoption{<language>}{<option>}{<value>}{<true>}{<false>} to detect active language features: https://github.com/reutenauer/polyglossia/issues/364.

\documentclass{article}
\usepackage{polyglossia}
\usepackage{csquotes}

\setmainlanguage{spanish}
\setotherlanguage{english}

\begin{document}
\iflanguageoption{spanish}{spanishoperators}{false}{T}{F}

\begin{english}
\iflanguageoption{english}{ordinalmonthday}{true}{T}{F}
\iflanguageoption{english}{ordinalmonthday}{false}{T}{F}
\end{english}

\begin{english}[ordinalmonthday=true]
\iflanguageoption{english}{ordinalmonthday}{true}{T}{F}
\iflanguageoption{english}{ordinalmonthday}{false}{T}{F}
\end{english}

\iflanguageoption{english}{ordinalmonthday}{true}{T}{F}
\iflanguageoption{english}{ordinalmonthday}{false}{T}{F}

\begin{english}[ordinalmonthday=false]
\iflanguageoption{english}{ordinalmonthday}{true}{T}{F}
\iflanguageoption{english}{ordinalmonthday}{false}{T}{F}
\end{english}

\iflanguageoption{english}{ordinalmonthday}{true}{T}{F}
\iflanguageoption{english}{ordinalmonthday}{false}{T}{F}
\end{document}

moewew avatar Dec 15 '19 10:12 moewew

It would make sense to have a unified interface for detecting language options in both babel and polyglossia. We could then use that wrapper in localizations.

Alternatively, we could use tracklang for language detection, and I could ask Dr Nicola L. C. Talbot (the author of tracklang) to add support for language options. Tracklang provides a common interface to query the document localisation information, wrapping both babel and polyglossia. Using tracklang would guarantee that we don't unnecessarily duplicate any effort regarding language detection.

randrej avatar Dec 17 '19 13:12 randrej

It would make sense to have a unified interface for detecting language options in both babel and polyglossia. We could then use that wrapper in localizations.

Yes, sure; that was the initial plan. I'm not sure any more how viable that is and how general that wrapper can be if we need to take into account that babel and polyglossia could use different option names and option values for similar features.

For Serbian in particular polyglossia does not seem to support anything equivalent to babel-serbian's ijekav and datei options.

I had a look at tracklang a while back and it seemed to me that we would have to change quite a few things to get it to work with the stuff that biblatex already does. But maybe I should have a look some time. (The problem with adding packages like this is that we are in trouble if they are not maintained any more... Currently the list of biblatex dependencies consists of packages that are so widely used that someone (the LaTeX team) would probably step in to make sure they continue working [except maybe logreq, but we could probably drop that if everything blows up].)

moewew avatar Dec 18 '19 08:12 moewew