# Bug Tracker

ID: 160 🔗 Closed (Not a Bug) datetime2 v1.5.6 Jonathan Yu 2020-05-25 05:01:05 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
%
% 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

## Watch This Report

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).

Name: (Optional.)