Files
wekan/client/lib/exportLocale.js
T
Lauri Ojansivu 46607d4299 Add an admin date format override for everyone
Place the global date format checkbox and selector between Board member
list and Wait Spinner in Visibility settings. While enabled, use the
selected format for members and guests, call the card section Date and
hide its personal format selector. Preserve personal preferences so they
return when the override is disabled.

Apply the same policy to date displays, filter parsing and browser export
requests. Validate supported formats and retain admin-only settings writes.
Add positive, negative and browser regression coverage and document the
setting. Translate the new label without changing existing translations.

Lower-confidence new translations include Acehnese, Aymara, Cherokee,
Inuktitut, Kashmiri, Nahuatl, Veps, Volapuk and Wolaytta; native-speaker
review would improve these labels.

Thanks to Mathia2 and xet7 !

Fixes #6703,
2026-09-17 18:13:20 +03:00

78 lines
3.1 KiB
JavaScript

const { resolveDateFormat } = require('/models/lib/dateFormatPolicy');
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
// What a server-rendered export needs to know about the reader, and cannot work
// out on its own (#6586).
//
// A PDF export is built on the SERVER: it reads the card out of the database and
// writes the file. That is the right place for it, and it costs the two things
// the browser knows and the server does not.
//
// The TIME ZONE is the reported bug - "the time is not in the user set timezone
// (-2h wrong for Europe/Berlin)". Dates are stored in UTC, and a profile carries
// no timezone in WeKan, so the only place the reader's zone exists is the
// browser. `Intl.DateTimeFormat().resolvedOptions().timeZone` is the IANA name
// ("Europe/Berlin"), which is exactly what the server's own Intl wants back.
//
// The LANGUAGE is on the profile of a logged-in user, and the server prefers that
// - but a PUBLIC board's export has no logged-in user to read it off, and the
// language the reader is looking at WeKan in is the one the export should be in.
// The Excel card export already takes a `lang` query param for this reason; the
// PDF exports now do the same.
//
// The DATE FORMAT is the third, and the reason is the same shape: the opened
// card renders its dates with the reader's `dateFormat` preference, and for a
// reader who is not logged in that preference lives in localStorage - a place
// the server has no access to. An export that printed 2026-08-14 for a card
// showing 14-08-2026 would be the same card in two formats.
//
// All three are best-effort: an old runtime with no Intl, a language that is not
// set yet, or no preference at all must not stop a download. The server falls
// back to UTC, English and YYYY-MM-DD.
export function browserTimezone() {
try {
return Intl.DateTimeFormat().resolvedOptions().timeZone || '';
} catch (error) {
return '';
}
}
// The date format the OPENED CARD is showing, worked out exactly as
// client/components/cards/cardDate.js works it out - the profile's setting, and
// for a reader who is not logged in the localStorage value the card view falls
// back to, which the server cannot see at all. An export of a card should print
// its dates the way the card prints them.
export function cardDateFormat() {
const setting = ReactiveCache.getCurrentSetting();
try {
const currentUser = ReactiveCache.getCurrentUser();
if (currentUser) return resolveDateFormat(currentUser.getDateFormat(), setting);
return resolveDateFormat(window.localStorage.getItem('dateFormat'), setting);
} catch (error) {
return resolveDateFormat(null, setting);
}
}
export function currentLanguage() {
try {
return TAPi18n.getLanguage()
|| (navigator.languages && navigator.languages[0])
|| navigator.language
|| '';
} catch (error) {
return '';
}
}
// The query params every server-rendered export link carries, so a second export
// cannot quietly grow a third spelling of them.
export function exportLocaleParams() {
return {
tz: browserTimezone(),
lang: currentLanguage(),
dateFormat: cardDateFormat(),
};
}