PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.17
Yatra – Travel Booking & Tour Operator Software v3.0.17
3.0.17 3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 All 85 releases
← All changes | resources/js/pages/account/utils.ts +69 -15 3.0.4 → 3.0.17 View file →
@@ -2,10 +2,16 @@
2 2 import {
3 3 applyCurrencyPosition,
4 4 formatYatraMoney,
5 5 } from "../../lib/currency-display";
6 +import {
7 + formatDate as formatGlobalDate,
8 + parseDate,
9 +} from "../../lib/dateFormat";
6 10
7 -function toBrowserLocaleTag(locale: string | undefined | null): string | undefined {
11 +function toBrowserLocaleTag(
12 + locale: string | undefined | null,
13 +): string | undefined {
8 14 const raw = String(locale || "").trim();
9 15 if (!raw) return undefined;
10 16 // WP locales are often like "en_US"; Intl expects BCP47 like "en-US".
11 17 return raw.replace(/_/g, "-");
@@ -22,24 +28,17 @@
22 28 if (!value) {
23 29 return __("N/A", "yatra");
24 30 }
25 31
26 - try {
27 - const date = new Date(value);
28 -
29 - // Check if date is valid
30 - if (isNaN(date.getTime())) {
31 - return __("Invalid date", "yatra");
32 - }
33 -
34 - return date.toLocaleDateString(getAccountLocale(), {
35 - year: "numeric",
36 - month: "long",
37 - day: "numeric",
38 - });
39 - } catch (error) {
32 + // Render public account dates in the operator's configured global date
33 + // format (Settings → General) via the shared formatter — not a hardcoded
34 + // browser style. It also parses a date-only value (e.g. a booking's
35 + // travel_date) in LOCAL time, so it no longer rolls back a day in behind-UTC
36 + // timezones (Aug 1 → Jul 31).
37 + if (!parseDate(value)) {
40 38 return __("Invalid date", "yatra");
41 39 }
40 + return formatGlobalDate(value);
42 41 };
43 42
44 43 /** Leading Y-m-d from API datetime strings for stable range comparison. */
45 44 function extractYmd(value: string | undefined | null): string | null {
@@ -68,12 +67,67 @@
68 67 if (!endKey || endKey === startKey) {
69 68 return formatDate(travelDate);
70 69 }
71 70 return sprintf(
71 + // translators: 1: start date, 2: end date. Joined with an en-dash for travel date ranges.
72 72 __("%1$s – %2$s", "yatra"),
73 73 formatDate(travelDate),
74 74 formatDate(endDate),
75 75 );
76 +};
77 +
78 +/**
79 + * Translate a known booking/payment/ticket status to a localized label.
80 + *
81 + * The previous account-page code did `__(booking.status, booking.status)` which
82 + * mis-uses the textdomain argument: WP's i18n runtime treats the second arg as
83 + * the textdomain (defaulting to 'default'), so it never finds the translation
84 + * and silently returns the raw English key like 'confirmed'/'pending'. Worse,
85 + * because the first argument is a runtime variable, the WP-CLI i18n extractor
86 + * skips it — those strings never reach the .pot file and Loco never gets a
87 + * chance to translate them.
88 + *
89 + * Mapping each known status to a static `__('Foo', 'yatra')` call fixes both
90 + * problems at once: extractor sees the literals, translators can localize, and
91 + * unknown values fall back to a title-cased rendition of the raw key.
92 + */
93 +export const getStatusLabel = (status: string | undefined | null): string => {
94 + const raw = typeof status === "string" ? status.toLowerCase().trim() : "";
95 + switch (raw) {
96 + case "pending":
97 + return __("Pending", "yatra");
98 + case "confirmed":
99 + return __("Confirmed", "yatra");
100 + case "processing":
101 + return __("Processing", "yatra");
102 + case "completed":
103 + return __("Completed", "yatra");
104 + case "cancelled":
105 + return __("Cancelled", "yatra");
106 + case "refunded":
107 + return __("Refunded", "yatra");
108 + case "failed":
109 + return __("Failed", "yatra");
110 + case "on_hold":
111 + return __("On hold", "yatra");
112 + case "paid":
113 + return __("Paid", "yatra");
114 + case "partial":
115 + return __("Partial", "yatra");
116 + case "awaiting_response":
117 + return __("Awaiting response", "yatra");
118 + case "resolved":
119 + return __("Resolved", "yatra");
120 + case "closed":
121 + return __("Closed", "yatra");
122 + case "open":
123 + return __("Open", "yatra");
124 + case "":
125 + return __("Pending", "yatra");
126 + default:
127 + // Unknown status — title-case it so admins can see what's coming through.
128 + return raw.charAt(0).toUpperCase() + raw.slice(1).replace(/_/g, " ");
129 + }
76 130 };
77 131
78 132 export const getBadge = (status: string | undefined | null) => {
79 133 const base = "px-2.5 py-0.5 rounded-full text-xs font-medium";