Bug Tracker

ID:160 🔗
Status:Closed (Not a Bug)
Category:datetime2
Version:v1.5.6
Submitted by:Jonathan Yu <jonathan.i.yu@gmail.com>
Date:2020-05-25 05:01:05
Summary:Trigger language autodetection when setting language after loading datetime2

Report

Hello,

Thanks very much for contributing this excellent work to the CTAN!

I'm trying to use datetime2 in a custom template (document class definition), where the default language is not known until runtime. I would like my title page to receive a datetime2-set date (set using DTMsavedate) and then format it for display in the document locale (ie. including textual month).

However, it seems that datetime2 only scans the tracked languages when the package is loaded, and the subsequent functions cannot trigger a re-scan. I'm not sure if this is a limitation in datetime2 or in the tracklang class, and after perusing the source code of datetime, I still have no clue :-)

I'd be happy to try to fix this issue and submit a patch, but would need a pointer as to where to look in the code.

Best,

Jonathan

MWE

\documentclass{article}

\usepackage{polyglossia}

% If you uncomment this line, the display date will
% appear in unlocalized form (numeric month)
% \usepackage[useregional]{datetime2}

\setdefaultlanguage[variant=american]{english}

\usepackage[useregional]{datetime2}

\begin{document}

% I want this to appear as: March 28, 2014 when
% \setdefaultlanguage is English, or mars 28, 2014
% when \setdefaultlanguage is French
%
% I'm using datetime2 in a document class, but
% definining document languages in the document
% that uses it, so the language is not set until
% after datetime2 is loaded.
%
% I need a method to force datetime2 to re-scan
% the list of tracked languages and check for
% corresponding installed modules.
\DTMdisplaydate{2014}{3}{28}{-1}

\end{document}

\endinput

Evaluation

It's documented that the languages must be setup before datetime2 is loaded, so therefore I have to close this as not a bug. However, it's possible to track additional languages after tracklang has been loaded using commands like \TrackPredefinedDialect or \TrackLanguageTag. You can then use datetime2's \DTMusemodule{dialect}{name} command to load the required language module. (\DTMusemodule automatically uses \TrackPredefinedDialect if the given dialect hasn't already been tracked.)

The actual code used by datetime2 to load all modules is:

\AnyTrackedLanguages
{%
  \ForEachTrackedDialect{\this@dialect}%
  {%
    \@dtm@requiremodule\this@dialect
  }%
}
{}%

This uses \AnyTrackedLanguages to test if any languages have been tracked and then uses \ForEachTrackedDialect to iterate over the list of all tracked dialect labels. The internal command \@dtm@requiremodule performs the actual loading using tracklang's \IfTrackedLanguageFileExists, which tries to determine the basename of the required .ldf language file.

Unfortunately, all of the language packages, such as babel and polyglossia, have their own idiosyncratic way of dealing with languages, so it's hard to provide a general method that easily integrates with all of them. See Localisation with tracklang.tex

Add comment or return to search results.

Watch This Report

If you would like to be notified whenever updates are made to this report, please fill in your email address in the box below and click on "Notify Me of Changes" button. (Please ensure the address is valid.) Your details won't be passed on to third parties in line with this site's Privacy Policy.

If you supply your name, it will be used in the email greeting, which provides a more personal message, otherwise you'll just get a generic greeting. If you have previously supplied your name when signing up for notifications, you don't need to resupply it unless you want to change it.

If you have previously subscribed to notifications for this report, you can unsubscribe by clicking on the "Stop Notification" button.

The "Confirm Bug ID" field helps to protect against spambots. Please enter the bug ID (which you can find at the top of this page).

(Optional.)
E mail:
Confirm E mail:
Confirm Bug ID:

To unsubscribe from all notifications use the notifications page.

Comment

You can append a comment to the report using the form below. Comments are checked first before being added. Any spam or offensive content will be removed first according to this site's Terms of Website Use. Please bear in mind that I develop and maintain free software in my spare time. If you want commerical level support then you can hire a TeX consultant.

The "Confirm Bug ID" field helps to protect against spambots. Please enter the bug ID (which you can find at the top of this page).

(Optional. If provided, it will be shown with the comment.)
Confirm Bug ID:

You can use the following markup:

[pre]Displayed verbatim[/pre]
[tt]monospace text[/tt]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url]

Ordered list:
[ol]
[li]first item[/li]
[li]second item[/li]
[/ol]

Unordered list:
[ul]
[li]first item[/li]
[li]second item[/li]
[/ul]

Click on the Preview button to preview the message.

Return to search results.