Files
wekan/client/lib/exportLocale.js
T
Lauri Ojansivu 698e980e27 Card PDF and Excel exports say the same thing, in the reader's language,
format and time zone.

#6586 was reopened for what the first fix left, and every point of it was a
symptom of one thing: the PDF export of a card had grown separately from the
Excel export of the same card.

"Assignee, Labels, due,... these titels should be in the user set language" -
the labels were hard-coded English, and not even consistent with each other:
the card export wrote "Due: " while the board export wrote "due" with no
colon. Both exports now build every label from the same i18n keys, in the
language the request carries, through one field() helper that writes every
"Label: value" - so the two cannot drift apart again. Every key carries its
English text as the fallback, so a missing translation shows the word and
never the key.

"I think all those other things we set in a card should be also present" -
both exports now carry title, labels, creator, assignees, members, board,
swimlane, list, card number, requested by, assigned by, the six dates, spent
time, description, custom fields, checklists, subtasks, comments,
attachments, voting and Planning Poker, in that order. Custom fields, voting
and poker are new on BOTH sides; they are appended to ALL_FIELDS rather than
inserted, so a saved ?fields= link still asks for what it always asked for,
and they are checkboxes in the export popup like the rest.

"the time is not in the user set timezone (-2h wrong for Europe/Berlin)" -
it was worse than -2h: the PDF printed UTC and the Excel export printed
whatever zone the server was started in. Dates are stored in UTC and a
profile carries no zone, so the export links now send the browser's IANA
zone and the date format the OPENED CARD is showing - which for a logged-out
reader lives in localStorage, where no server-side lookup reaches it. Both
exports format through formatDateByUserPreference, which gained an optional
zone; without one it still renders in the process zone, which is what every
client-side caller wants. A server-built export given no zone renders UTC
and says UTC. Verified: 12:00Z prints 14:00 for Europe/Berlin, 00:00 on the
15th for Pacific/Auckland, and an unknown zone falls back instead of
failing.

"would it make sense to support markdown formated text in description" - a
description is now cut into runs and drawn in the four base-14 Courier
faces, so **bold**, *italic* and ***both*** are bold, italic and both.
Consecutive Tj operators continue at the current text position, so a font
switch needs no glyph measuring. Strikethrough and inline code keep their
words and lose their markers - a Type1 base-14 font has no strike and there
is no fifth face for code - and an underscore inside a word stays an
underscore.

tests/cardExportParity.test.cjs pins the shared field list, keys, formatter
and request params; tests/pdfExport.test.cjs gains the runs, the wrapping
and the four declared faces. Two of its guards moved rather than being
deleted: they pinned the hard-coded English "Labels: " and "due", which is
the behaviour that deliberately changed, and they now pin that both come
from the same keys.

Thanks to Heart1010 and xet7 !

Fixes #6586,
2026-08-14 00:09:31 +03:00

73 lines
2.9 KiB
JavaScript

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() {
try {
const currentUser = ReactiveCache.getCurrentUser();
if (currentUser) return currentUser.getDateFormat();
return window.localStorage.getItem('dateFormat') || 'YYYY-MM-DD';
} catch (error) {
return 'YYYY-MM-DD';
}
}
export function currentLanguage() {
try {
return TAPi18n.getLanguage() || '';
} 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(),
};
}