@usequeek/theme-kit 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -33
- package/apps/apps.css +4 -0
- package/components/blog/post-meta.tsx +7 -20
- package/components/metafield-date.tsx +17 -0
- package/components/product-metafields.tsx +2 -2
- package/package.json +1 -1
- package/provider.tsx +27 -2
- package/shared-blocks/product-qa.tsx +9 -7
- package/shared-blocks/reviews.tsx +10 -7
- package/strings/theme-strings.ts +18 -16
- package/types/vendor.ts +4 -0
- package/utils/format.ts +43 -26
- package/utils/locale.ts +119 -26
package/README.md
CHANGED
|
@@ -357,47 +357,58 @@ English. See also [Translating your theme](https://docs.usequeek.com/docs/themes
|
|
|
357
357
|
|
|
358
358
|
## Locale-aware dates, numbers and relative time
|
|
359
359
|
|
|
360
|
-
Dates, counts, money and relative time follow the SHOPPER's
|
|
361
|
-
|
|
362
|
-
`
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
360
|
+
Dates, counts, money and relative time follow the SHOPPER's language, and
|
|
361
|
+
English reads the way the STORE's country writes it: a US store prints
|
|
362
|
+
`Oct 2, 2026` and `$11.50`, a Nigerian store `2 Oct 2026` and `₦5,000`, a
|
|
363
|
+
British one `2 Oct 2026` and `£8`. No country is ever assumed: with nothing to
|
|
364
|
+
go on the kit prints neutral English (`en`) in UTC.
|
|
365
|
+
|
|
366
|
+
- **One mapping.** `resolveIntlLocale(locale, region?)` (`utils/locale.ts`,
|
|
367
|
+
pure: no `next/*`, no React) is the single canonical storefront-code →
|
|
368
|
+
Intl-locale mapping every formatter goes through. English takes the region
|
|
369
|
+
its code names (`en-GB` stays `en-GB`), else `region`, else neutral `en`;
|
|
370
|
+
missing/invalid codes are English; everything else passes through (`fr`,
|
|
371
|
+
`ar`, `pt-BR`, `zh-CN`, `yo`, `ha`, `sw`, …). A region English is not
|
|
372
|
+
formatted in natively on both the server (Node 22) and the browser reads as
|
|
373
|
+
`en` too, so the two never print differently (hydration).
|
|
374
|
+
`resolveSupportedLocale` falls back to English in the same region when the
|
|
375
|
+
runtime's ICU lacks a locale — formatting never throws.
|
|
376
|
+
- **Where the region comes from.** Dates: `storeRegion(store)`, the store's
|
|
377
|
+
`country_code`, else its currency's home. Money: the currency's home
|
|
378
|
+
(`currencyRegion`: USD → US, NGN → NG; none for EUR and the X-codes), so a
|
|
379
|
+
store's own currency prints its bare local sign; an `en-GB` reader still
|
|
380
|
+
sees `US$5`. So pass money formatters the storefront locale
|
|
381
|
+
(`useStorefrontLocale()`), never the store's display tag: `en-US` there would
|
|
382
|
+
print a naira market price as `NGN 5,000`. Zone: `storeTimeZone(store)`, the
|
|
383
|
+
store's `timezone`, else UTC.
|
|
384
|
+
- **What themes call.** In a client component, `useStoreDisplayFormat()`
|
|
385
|
+
(`provider`) returns `{ locale, timeZone }` for this store; pass them to
|
|
386
|
+
`formatShopperDate(value, locale, options?, timeZone)`, or to
|
|
387
|
+
`formatThemeDate(value, locale, { ...options, timeZone })`. On the server,
|
|
388
|
+
`storeDisplayFormat(requestLocale, profile)` gives the same answer from the
|
|
389
|
+
same profile, so the server render and the browser agree. Siblings:
|
|
390
|
+
`formatThemeNumber`, `formatThemeMoney`, and
|
|
378
391
|
`formatThemeRelativeTime(-1, 'day', locale)` (`hier`, `أمس`, `ontem`, …,
|
|
379
392
|
`numeric: 'auto'`). `formatThemeMoney` uses the currency's default
|
|
380
393
|
decimals (`₦5,000.00`); `formatMoney` drops them from a whole amount
|
|
381
|
-
(`₦5,000`) and otherwise prints all of them (`₦0.28`,
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
minimal-ICU runtimes render English rather than throwing.
|
|
394
|
+
(`₦5,000`) and otherwise prints all of them (`₦0.28`, `$11.50`).
|
|
395
|
+
`formatCount`/`formatMoney` take an optional locale. `PostMeta`, the
|
|
396
|
+
reviews and Q&A blocks and date metafields read the store's format.
|
|
397
|
+
- **Fallbacks.** Unknown locale → English in the store's region; no region →
|
|
398
|
+
neutral `en`; no zone → UTC; invalid date → `''`; minimal-ICU runtimes
|
|
399
|
+
render English rather than throwing.
|
|
388
400
|
- **Plural selection stays separate.** `canonicalThemeLocale`
|
|
389
401
|
(`strings/theme-strings.ts`) is for `t()` plural selection ONLY: it returns
|
|
390
|
-
a bare `'en'` tag
|
|
391
|
-
|
|
392
|
-
`resolveIntlLocale` (en* → `en-NG`) instead.
|
|
402
|
+
a bare `'en'` tag with no region. Never pass it to a date, number, money or
|
|
403
|
+
relative-time formatter — formatters use `resolveIntlLocale` instead.
|
|
393
404
|
|
|
394
405
|
```tsx
|
|
395
|
-
import {
|
|
396
|
-
import {
|
|
406
|
+
import { useStoreDisplayFormat } from '@usequeek/theme-kit/provider';
|
|
407
|
+
import { formatShopperDate } from '@usequeek/theme-kit/utils/format';
|
|
397
408
|
|
|
398
|
-
const locale =
|
|
399
|
-
|
|
400
|
-
//
|
|
409
|
+
const { locale, timeZone } = useStoreDisplayFormat();
|
|
410
|
+
formatShopperDate(post.published_at, locale, { year: 'numeric', month: 'long', day: 'numeric' }, timeZone);
|
|
411
|
+
// US store → "October 2, 2026" · Nigerian store → "2 October 2026" · fr → "2 octobre 2026"
|
|
401
412
|
```
|
|
402
413
|
|
|
403
414
|
## Consumers
|
package/apps/apps.css
CHANGED
|
@@ -586,6 +586,10 @@
|
|
|
586
586
|
flex-direction: column;
|
|
587
587
|
align-items: stretch;
|
|
588
588
|
}
|
|
589
|
+
/* Stacked, `flex: 1 1 20rem` would set a 320px HEIGHT on the text: size it to its lines instead. */
|
|
590
|
+
.core-consent-banner__text {
|
|
591
|
+
flex: 0 1 auto;
|
|
592
|
+
}
|
|
589
593
|
.core-consent-banner__actions {
|
|
590
594
|
justify-content: flex-end;
|
|
591
595
|
}
|
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useStorefront, useThemeStrings } from '../../provider';
|
|
3
|
+
import { useStoreDisplayFormat, useStorefront, useThemeStrings } from '../../provider';
|
|
4
4
|
import type { JSX } from 'react';
|
|
5
5
|
import type { Post } from '../../types/page';
|
|
6
6
|
import { Image } from '../image';
|
|
7
|
-
import {
|
|
8
|
-
import { resolveIntlLocale } from '../../utils/locale';
|
|
9
|
-
|
|
10
|
-
function formatDate(value: string, locale: string | null): string {
|
|
11
|
-
const date = new Date(value);
|
|
12
|
-
if (Number.isNaN(date.getTime())) {
|
|
13
|
-
return '';
|
|
14
|
-
}
|
|
15
|
-
// Shopper's locale through the canonical mapping (English stays the
|
|
16
|
-
// British/Nigerian order, "15 February 2026"); the fixed zone keeps a post
|
|
17
|
-
// published near midnight UTC on the same day on the server and in the browser.
|
|
18
|
-
return formatDisplayDate(
|
|
19
|
-
date,
|
|
20
|
-
{ year: 'numeric', month: 'long', day: 'numeric' },
|
|
21
|
-
resolveIntlLocale(locale),
|
|
22
|
-
);
|
|
23
|
-
}
|
|
7
|
+
import { formatShopperDate } from '../../utils/format';
|
|
24
8
|
|
|
25
9
|
/**
|
|
26
10
|
* Shared post byline: author (avatar + name, falling back to the vendor),
|
|
@@ -28,12 +12,15 @@ function formatDate(value: string, locale: string | null): string {
|
|
|
28
12
|
* style via `.core-post-meta*` selectors (colours inherit brand vars).
|
|
29
13
|
*/
|
|
30
14
|
export function PostMeta({ post, className }: { post: Post; className?: string }): JSX.Element {
|
|
31
|
-
const { vendor
|
|
15
|
+
const { vendor } = useStorefront();
|
|
16
|
+
const display = useStoreDisplayFormat();
|
|
32
17
|
const t = useThemeStrings();
|
|
33
18
|
|
|
34
19
|
const authorName = post.author?.name ?? vendor.name ?? null;
|
|
35
20
|
const authorAvatar = post.author?.avatar_url ?? vendor.logo ?? null;
|
|
36
|
-
const published = post.published_at
|
|
21
|
+
const published = post.published_at
|
|
22
|
+
? formatShopperDate(post.published_at, display.locale, { year: 'numeric', month: 'long', day: 'numeric' }, display.timeZone)
|
|
23
|
+
: '';
|
|
37
24
|
const readingTime = post.reading_time && post.reading_time > 0 ? t('blog.meta.reading', { count: post.reading_time }) : '';
|
|
38
25
|
|
|
39
26
|
return (
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useContext, type JSX } from 'react';
|
|
4
|
+
import { StorefrontContext } from '../provider';
|
|
5
|
+
import { formatShopperDate } from '../utils/format';
|
|
6
|
+
import { storeDisplayFormat } from '../utils/locale';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A date metafield is a calendar day: the store's English (or the shopper's language), read in UTC so the day never
|
|
10
|
+
* moves with a zone. A client component (it reads the store from context), so the metafield renderers that place it
|
|
11
|
+
* stay usable from a server component; outside a provider it prints neutral English.
|
|
12
|
+
*/
|
|
13
|
+
export function MetafieldDate({ time }: { time: number }): JSX.Element {
|
|
14
|
+
const context = useContext(StorefrontContext);
|
|
15
|
+
const locale = context ? (context.display ?? storeDisplayFormat(context.locale, context.vendor)).locale : null;
|
|
16
|
+
return <>{formatShopperDate(time, locale, {}, 'UTC')}</>;
|
|
17
|
+
}
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
Product,
|
|
8
8
|
ProductVariant,
|
|
9
9
|
} from '../types/product';
|
|
10
|
-
import {
|
|
10
|
+
import { MetafieldDate } from './metafield-date';
|
|
11
11
|
|
|
12
12
|
/** Merchant-set labels and types for custom fields, keyed by field key. Passed as `metafieldDefinitions` on the product page. */
|
|
13
13
|
export interface ProductMetafieldDefinitionLabels {
|
|
@@ -125,7 +125,7 @@ function renderScalar(value: MetafieldScalar, key: string, label: string, type:
|
|
|
125
125
|
const time = new Date(text).getTime();
|
|
126
126
|
return (
|
|
127
127
|
<p className="core-metafields__text">
|
|
128
|
-
{Number.isNaN(time) ? text :
|
|
128
|
+
{Number.isNaN(time) ? text : <MetafieldDate time={time} />}
|
|
129
129
|
</p>
|
|
130
130
|
);
|
|
131
131
|
}
|
package/package.json
CHANGED
package/provider.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import type { Post } from './types/page';
|
|
|
8
8
|
import type { Product } from './types/product';
|
|
9
9
|
import type { StorefrontConfig, VendorProfile } from './types/vendor';
|
|
10
10
|
import { getBrandCssVariables } from './utils/brand';
|
|
11
|
-
import { parseLocaleCode } from './utils/locale';
|
|
11
|
+
import { parseLocaleCode, storeDisplayFormat, type StoreDisplayFormat } from './utils/locale';
|
|
12
12
|
import { normalizeStoreLocales, type StoreLocale, type StoreLocaleInput } from './utils/locale-switch';
|
|
13
13
|
import { normalizeStoreMarkets, parseMarketId, setBrowserMarketId, type StoreMarket } from './utils/market';
|
|
14
14
|
import { reconcileMarketChoice } from './utils/market-choice';
|
|
@@ -65,6 +65,8 @@ interface StorefrontContextValue {
|
|
|
65
65
|
markets?: StoreMarket[];
|
|
66
66
|
/** The market the shopper chose, only when it is one of `markets`; null = the store's own currency. */
|
|
67
67
|
activeMarketId?: number | null;
|
|
68
|
+
/** This store's date format (`storeDisplayFormat(locale, vendor)`), built once per provider. Optional so hand-built context values keep compiling; `useStoreDisplayFormat()` builds it when absent. */
|
|
69
|
+
display?: StoreDisplayFormat;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
/** The context behind {@link StorefrontProvider}. Read it through the hooks; use it directly only to test for a provider without throwing. */
|
|
@@ -169,8 +171,10 @@ export function StorefrontProvider({
|
|
|
169
171
|
// A cookie naming a market the store no longer publishes: drop it (and the lines priced under it) once.
|
|
170
172
|
reconcileMarketChoice(vendorSlug, vendorId, marketsKnown ? resolvedMarkets : null);
|
|
171
173
|
}, [vendorSlug, vendorId, resolvedMarkets, marketsKnown]);
|
|
174
|
+
const display = useMemo(() => storeDisplayFormat(resolvedLocale, vendor), [resolvedLocale, vendor]);
|
|
172
175
|
const value = useMemo(
|
|
173
176
|
() => ({
|
|
177
|
+
display,
|
|
174
178
|
vendor,
|
|
175
179
|
config,
|
|
176
180
|
menus,
|
|
@@ -183,7 +187,7 @@ export function StorefrontProvider({
|
|
|
183
187
|
markets: resolvedMarkets,
|
|
184
188
|
activeMarketId,
|
|
185
189
|
}),
|
|
186
|
-
[config, menus, previewData, vendor, resolvedBasePath, pagesChrome, resolvedLocale, resolvedStrings, resolvedLocales, resolvedMarkets, activeMarketId],
|
|
190
|
+
[display, config, menus, previewData, vendor, resolvedBasePath, pagesChrome, resolvedLocale, resolvedStrings, resolvedLocales, resolvedMarkets, activeMarketId],
|
|
187
191
|
);
|
|
188
192
|
const brandRootRef = useRef<HTMLDivElement>(null);
|
|
189
193
|
|
|
@@ -239,6 +243,27 @@ export function useStorefrontLocale(): string | null {
|
|
|
239
243
|
return context.locale ?? null;
|
|
240
244
|
}
|
|
241
245
|
|
|
246
|
+
/**
|
|
247
|
+
* How this store's dates read, for `formatShopperDate` / `formatDisplayDate` /
|
|
248
|
+
* `formatThemeDate`: `locale` is the shopper's language in the store's region
|
|
249
|
+
* (a US store's English is `en-US`, a Nigerian one's `en-NG`), `timeZone` the
|
|
250
|
+
* store's zone (UTC when it sent none). Built from the store profile, so the
|
|
251
|
+
* server render and the browser agree.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* const { locale, timeZone } = useStoreDisplayFormat();
|
|
255
|
+
* formatShopperDate(order.created_at, locale, undefined, timeZone);
|
|
256
|
+
*/
|
|
257
|
+
export function useStoreDisplayFormat(): StoreDisplayFormat {
|
|
258
|
+
const context = useContext(StorefrontContext);
|
|
259
|
+
|
|
260
|
+
if (!context) {
|
|
261
|
+
throw new Error('useStoreDisplayFormat() was called outside <StorefrontProvider>. Render the component inside StorefrontProvider.');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return context.display ?? storeDisplayFormat(context.locale, context.vendor);
|
|
265
|
+
}
|
|
266
|
+
|
|
242
267
|
/**
|
|
243
268
|
* The client theme-string surface: the bound `t` for the active locale.
|
|
244
269
|
* Chain order: merchant/host override dictionaries (`strings` prop), then
|
|
@@ -6,9 +6,10 @@ import type { ProductQaBlockData, ProductQuestionItem } from '../types/block';
|
|
|
6
6
|
import { Image } from '../components/image';
|
|
7
7
|
import { useProductQuestions } from '../hooks/use-product-questions';
|
|
8
8
|
import { useAuth } from '../hooks/use-auth';
|
|
9
|
-
import { useIsThemePreview, useStorefront, useThemeStrings } from '../provider';
|
|
9
|
+
import { useIsThemePreview, useStoreDisplayFormat, useStorefront, useThemeStrings } from '../provider';
|
|
10
10
|
import { getQueekClient } from '../sdk/queek-client';
|
|
11
|
-
import {
|
|
11
|
+
import { formatShopperDate } from '../utils/format';
|
|
12
|
+
import type { StoreDisplayFormat } from '../utils/locale';
|
|
12
13
|
|
|
13
14
|
const MAX_QUESTION_LENGTH = 1000;
|
|
14
15
|
|
|
@@ -152,6 +153,7 @@ function AskQuestionPanel({ productSlug }: { productSlug: string }): JSX.Element
|
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
function QuestionCard({ question }: { question: ProductQuestionItem }): JSX.Element {
|
|
156
|
+
const display = useStoreDisplayFormat();
|
|
155
157
|
return (
|
|
156
158
|
<article className="core-block-product-qa__card">
|
|
157
159
|
<header className="core-block-product-qa__card-head">
|
|
@@ -170,7 +172,7 @@ function QuestionCard({ question }: { question: ProductQuestionItem }): JSX.Elem
|
|
|
170
172
|
</div>
|
|
171
173
|
<div className="core-block-product-qa__card-meta">
|
|
172
174
|
<p className="core-block-product-qa__author">{question.user.name}</p>
|
|
173
|
-
<p className="core-block-product-qa__date">{formatDate(question.created_at)}</p>
|
|
175
|
+
<p className="core-block-product-qa__date">{formatDate(question.created_at, display)}</p>
|
|
174
176
|
</div>
|
|
175
177
|
</header>
|
|
176
178
|
|
|
@@ -179,7 +181,7 @@ function QuestionCard({ question }: { question: ProductQuestionItem }): JSX.Elem
|
|
|
179
181
|
{question.answer ? (
|
|
180
182
|
<div className="core-block-product-qa__answer">
|
|
181
183
|
<p className="core-block-product-qa__answer-label">
|
|
182
|
-
Answered{question.answered_at ? ` · ${formatDate(question.answered_at)}` : ''}
|
|
184
|
+
Answered{question.answered_at ? ` · ${formatDate(question.answered_at, display)}` : ''}
|
|
183
185
|
</p>
|
|
184
186
|
<p className="core-block-product-qa__answer-body">{question.answer}</p>
|
|
185
187
|
</div>
|
|
@@ -198,7 +200,7 @@ function initialsFor(name: string): string {
|
|
|
198
200
|
.toUpperCase();
|
|
199
201
|
}
|
|
200
202
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return
|
|
203
|
+
/** In the store's format (explicit locale + zone: this block renders on the server too). */
|
|
204
|
+
function formatDate(iso: string, display: StoreDisplayFormat): string {
|
|
205
|
+
return formatShopperDate(iso, display.locale, undefined, display.timeZone);
|
|
204
206
|
}
|
|
@@ -5,8 +5,9 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
5
5
|
import type { ReviewItem, ReviewsBlockData, ReviewsSummary } from '../types/block';
|
|
6
6
|
import { Image } from '../components/image';
|
|
7
7
|
import { useReviews } from '../hooks/use-reviews';
|
|
8
|
-
import { useStorefront } from '../provider';
|
|
9
|
-
import {
|
|
8
|
+
import { useStoreDisplayFormat, useStorefront } from '../provider';
|
|
9
|
+
import { formatShopperDate } from '../utils/format';
|
|
10
|
+
import type { StoreDisplayFormat } from '../utils/locale';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Framework-owned reviews block. Renders verified, platform-generated reviews
|
|
@@ -241,6 +242,7 @@ function SpotlightReviews({ reviews }: { reviews: ReviewItem[] }): JSX.Element {
|
|
|
241
242
|
* quiet-luxury) where card backgrounds/shadows would read as noise.
|
|
242
243
|
*/
|
|
243
244
|
function MinimalList({ reviews }: { reviews: ReviewItem[] }): JSX.Element {
|
|
245
|
+
const display = useStoreDisplayFormat();
|
|
244
246
|
return (
|
|
245
247
|
<ul className="core-block-reviews__minimal">
|
|
246
248
|
{reviews.map((review) => (
|
|
@@ -248,7 +250,7 @@ function MinimalList({ reviews }: { reviews: ReviewItem[] }): JSX.Element {
|
|
|
248
250
|
<div className="core-block-reviews__minimal-head">
|
|
249
251
|
<Stars rating={review.rating} small />
|
|
250
252
|
<p className="core-block-reviews__author">{review.user.name}</p>
|
|
251
|
-
<p className="core-block-reviews__date">{formatDate(review.created_at)}</p>
|
|
253
|
+
<p className="core-block-reviews__date">{formatDate(review.created_at, display)}</p>
|
|
252
254
|
{review.is_verified_purchase ? (
|
|
253
255
|
<span className="core-block-reviews__pill core-block-reviews__pill--verified">Verified buyer</span>
|
|
254
256
|
) : null}
|
|
@@ -264,6 +266,7 @@ function MinimalList({ reviews }: { reviews: ReviewItem[] }): JSX.Element {
|
|
|
264
266
|
}
|
|
265
267
|
|
|
266
268
|
function ReviewCard({ review }: { review: ReviewItem }): JSX.Element {
|
|
269
|
+
const display = useStoreDisplayFormat();
|
|
267
270
|
return (
|
|
268
271
|
<article className="core-block-reviews__card">
|
|
269
272
|
<header className="core-block-reviews__card-head">
|
|
@@ -278,7 +281,7 @@ function ReviewCard({ review }: { review: ReviewItem }): JSX.Element {
|
|
|
278
281
|
</div>
|
|
279
282
|
<div className="core-block-reviews__card-meta">
|
|
280
283
|
<p className="core-block-reviews__author">{review.user.name}</p>
|
|
281
|
-
<p className="core-block-reviews__date">{formatDate(review.created_at)}</p>
|
|
284
|
+
<p className="core-block-reviews__date">{formatDate(review.created_at, display)}</p>
|
|
282
285
|
</div>
|
|
283
286
|
<Stars rating={review.rating} />
|
|
284
287
|
</header>
|
|
@@ -425,7 +428,7 @@ function initialsFor(name: string): string {
|
|
|
425
428
|
.toUpperCase();
|
|
426
429
|
}
|
|
427
430
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
return
|
|
431
|
+
/** In the store's format (explicit locale + zone: this block renders on the server too). */
|
|
432
|
+
function formatDate(iso: string, display: StoreDisplayFormat): string {
|
|
433
|
+
return formatShopperDate(iso, display.locale, undefined, display.timeZone);
|
|
431
434
|
}
|
package/strings/theme-strings.ts
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
import {
|
|
32
32
|
ENGLISH_DISPLAY_LOCALE,
|
|
33
|
+
currencyRegion,
|
|
33
34
|
parseLocaleCode,
|
|
34
35
|
resolveIntlLocale,
|
|
35
36
|
resolveSupportedLocale,
|
|
@@ -82,12 +83,11 @@ const PLURAL_FORMS = ['one', 'two', 'few', 'many', 'other'] as const;
|
|
|
82
83
|
/**
|
|
83
84
|
* Canonical locale for PLURAL SELECTION ONLY (used by `t()`).
|
|
84
85
|
*
|
|
85
|
-
* This returns a bare `'en'` tag for unknown codes,
|
|
86
|
-
*
|
|
87
|
-
* `Intl.
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* Formatters must route through `resolveIntlLocale` (en* → en-NG) instead.
|
|
86
|
+
* This returns a bare `'en'` tag for unknown codes, with no region. NEVER
|
|
87
|
+
* pass its result to `Intl.DateTimeFormat` / `Intl.NumberFormat` /
|
|
88
|
+
* `Intl.RelativeTimeFormat`, `toLocale*`, or any date/number/money/relative-time
|
|
89
|
+
* formatter: formatters route through `resolveIntlLocale` with the store's
|
|
90
|
+
* region (`storeDisplayFormat`) so a store prints its own country's order.
|
|
91
91
|
*
|
|
92
92
|
* Unknown/unparseable codes become English, mirroring `parseLocaleCode` (and
|
|
93
93
|
* the API's unknown-locale rule). A well-formed code the runtime's ICU
|
|
@@ -333,15 +333,16 @@ export async function createThemeStrings(options?: {
|
|
|
333
333
|
|
|
334
334
|
/**
|
|
335
335
|
* Pick the Intl tag for one theme formatting call: the storefront locale
|
|
336
|
-
* through the single canonical mapping (`resolveIntlLocale
|
|
337
|
-
*
|
|
338
|
-
*
|
|
336
|
+
* through the single canonical mapping (`resolveIntlLocale`, with `region`
|
|
337
|
+
* for an English reader whose code names none), or English when the
|
|
338
|
+
* runtime's ICU lacks the locale. Never throws.
|
|
339
339
|
*/
|
|
340
340
|
function themeFormatTag(
|
|
341
341
|
locale: string | null | undefined,
|
|
342
342
|
supportedLocalesOf: (locales: string[]) => readonly string[],
|
|
343
|
+
region?: string | null,
|
|
343
344
|
): string {
|
|
344
|
-
return resolveSupportedLocale(resolveIntlLocale(locale), supportedLocalesOf);
|
|
345
|
+
return resolveSupportedLocale(resolveIntlLocale(locale, region), supportedLocalesOf, resolveIntlLocale(null, region));
|
|
345
346
|
}
|
|
346
347
|
|
|
347
348
|
/** Locale-aware number formatting keyed by the active locale (unknown → English). Never throws. */
|
|
@@ -367,11 +368,12 @@ export function formatThemeNumber(
|
|
|
367
368
|
* English). `''` if unparseable. Never throws.
|
|
368
369
|
*
|
|
369
370
|
* THE helper themes call instead of hardcoding 'en-GB' in their own date
|
|
370
|
-
* formatting: pass the
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
371
|
+
* formatting: pass the store's display locale (client: `useStoreDisplayFormat().locale`;
|
|
372
|
+
* server: `storeDisplayFormat(requestLocale, profile).locale`) and the same Intl
|
|
373
|
+
* options, with `timeZone` set to the store's zone — English shoppers see the
|
|
374
|
+
* store's own country's order ("2 October 2026" in Britain or Nigeria,
|
|
375
|
+
* "October 2, 2026" in the US), other shoppers see their own locale. A Node
|
|
376
|
+
* whose ICU lacks the locale falls back to English, never an exception.
|
|
375
377
|
*/
|
|
376
378
|
export function formatThemeDate(
|
|
377
379
|
value: string | number | Date,
|
|
@@ -472,7 +474,7 @@ export function formatThemeMoney(
|
|
|
472
474
|
options?: Omit<Intl.NumberFormatOptions, 'style' | 'currency'>,
|
|
473
475
|
): string {
|
|
474
476
|
const code = normalizeMoneyCurrency(currency);
|
|
475
|
-
const tag = themeFormatTag(locale, (l) => Intl.NumberFormat.supportedLocalesOf(l));
|
|
477
|
+
const tag = themeFormatTag(locale, (l) => Intl.NumberFormat.supportedLocalesOf(l), currencyRegion(code));
|
|
476
478
|
try {
|
|
477
479
|
return new Intl.NumberFormat(tag, {
|
|
478
480
|
...options,
|
package/types/vendor.ts
CHANGED
|
@@ -144,6 +144,10 @@ export interface VendorProfile {
|
|
|
144
144
|
address?: string | null;
|
|
145
145
|
delivery_time?: string | null;
|
|
146
146
|
currency?: string | null;
|
|
147
|
+
/** The store's country (ISO 3166-1 alpha-2), when the API sends it: the region its English dates read in. */
|
|
148
|
+
country_code?: string | null;
|
|
149
|
+
/** The store's IANA time zone (`timezone` on the store payload): the calendar its dates read on. */
|
|
150
|
+
timezone?: string | null;
|
|
147
151
|
rating_value?: number;
|
|
148
152
|
rating_count?: number;
|
|
149
153
|
rating_label?: string | null;
|
package/utils/format.ts
CHANGED
|
@@ -10,24 +10,24 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import {
|
|
12
12
|
ENGLISH_DISPLAY_LOCALE,
|
|
13
|
+
currencyRegion,
|
|
13
14
|
resolveIntlLocale,
|
|
14
15
|
resolveSupportedLocale,
|
|
15
16
|
} from './locale';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
|
-
* The locale and zone
|
|
19
|
-
*
|
|
20
|
-
* default prints differently there
|
|
21
|
-
* browser
|
|
22
|
-
*
|
|
23
|
-
*
|
|
19
|
+
* The neutral locale and zone a date/number falls back to when the caller
|
|
20
|
+
* passes none. Always explicit, never the runtime's: storefront pages render
|
|
21
|
+
* on the server first, and a runtime default prints differently there than in
|
|
22
|
+
* the shopper's browser, which fails hydration. A store's own region and zone
|
|
23
|
+
* come from the store (`storeDisplayFormat` / `useStoreDisplayFormat()`), never
|
|
24
|
+
* from a fixed country.
|
|
24
25
|
*
|
|
25
26
|
* Aliases `ENGLISH_DISPLAY_LOCALE` (`utils/locale.ts`) — the value lives in
|
|
26
|
-
* exactly one place.
|
|
27
|
-
* here, so English output is byte-identical with or without a locale.
|
|
27
|
+
* exactly one place.
|
|
28
28
|
*/
|
|
29
29
|
export const DISPLAY_LOCALE: string = ENGLISH_DISPLAY_LOCALE;
|
|
30
|
-
export const DISPLAY_TIME_ZONE = '
|
|
30
|
+
export const DISPLAY_TIME_ZONE = 'UTC';
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Pick the Intl tag for one formatting call: the storefront locale through
|
|
@@ -37,45 +37,52 @@ export const DISPLAY_TIME_ZONE = 'Africa/Lagos';
|
|
|
37
37
|
function displayTagFor(
|
|
38
38
|
locale: string | null | undefined,
|
|
39
39
|
supportedLocalesOf: (locales: string[]) => readonly string[],
|
|
40
|
+
region?: string | null,
|
|
40
41
|
): string {
|
|
41
|
-
return resolveSupportedLocale(resolveIntlLocale(locale), supportedLocalesOf);
|
|
42
|
+
return resolveSupportedLocale(resolveIntlLocale(locale, region), supportedLocalesOf, resolveIntlLocale(null, region));
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
|
-
* A date for display
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* A date for display, identical on server and browser. '' if unparseable.
|
|
47
|
+
* Pass the store's format (`useStoreDisplayFormat()`): a US store prints
|
|
48
|
+
* "Feb 14, 2026", a Nigerian or British one "14 Feb 2026", each in the store's
|
|
49
|
+
* zone (or `options.timeZone`). With neither, neutral English in UTC. The locale is routed through
|
|
50
|
+
* `resolveIntlLocale`, so a storefront code and a resolved tag both work.
|
|
49
51
|
*/
|
|
50
52
|
export function formatDisplayDate(
|
|
51
53
|
value: string | number | Date,
|
|
52
54
|
options: Intl.DateTimeFormatOptions = { day: 'numeric', month: 'short', year: 'numeric' },
|
|
53
55
|
locale: string = DISPLAY_LOCALE,
|
|
56
|
+
timeZone: string = options.timeZone ?? DISPLAY_TIME_ZONE,
|
|
54
57
|
): string {
|
|
55
58
|
const date = value instanceof Date ? value : new Date(value);
|
|
56
59
|
if (Number.isNaN(date.getTime())) return '';
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
timeZone
|
|
60
|
-
}
|
|
60
|
+
const tag = resolveIntlLocale(locale);
|
|
61
|
+
try {
|
|
62
|
+
return date.toLocaleDateString(tag, { ...options, timeZone });
|
|
63
|
+
} catch {
|
|
64
|
+
return date.toLocaleDateString(tag, { ...options, timeZone: DISPLAY_TIME_ZONE });
|
|
65
|
+
}
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
/**
|
|
64
69
|
* A date for display in the SHOPPER's locale: `formatDisplayDate` with the
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
70
|
+
* locale checked against this runtime's ICU (a missing locale prints English).
|
|
71
|
+
* Pass `useStoreDisplayFormat()`'s `locale` and `timeZone` for the store's own
|
|
72
|
+
* order and calendar; `fr` renders "14 févr. 2026", and so on. Invalid-date
|
|
73
|
+
* handling is `formatDisplayDate`'s. Never throws.
|
|
69
74
|
*/
|
|
70
75
|
export function formatShopperDate(
|
|
71
76
|
value: string | number | Date,
|
|
72
77
|
locale: string | null | undefined,
|
|
73
78
|
options: Intl.DateTimeFormatOptions = { day: 'numeric', month: 'short', year: 'numeric' },
|
|
79
|
+
timeZone: string = options.timeZone ?? DISPLAY_TIME_ZONE,
|
|
74
80
|
): string {
|
|
75
81
|
return formatDisplayDate(
|
|
76
82
|
value,
|
|
77
83
|
options,
|
|
78
84
|
displayTagFor(locale, (l) => Intl.DateTimeFormat.supportedLocalesOf(l)),
|
|
85
|
+
timeZone,
|
|
79
86
|
);
|
|
80
87
|
}
|
|
81
88
|
|
|
@@ -175,6 +182,16 @@ function moneyFormatters(tag: string, code: string): MoneyFormatters {
|
|
|
175
182
|
return formatters;
|
|
176
183
|
}
|
|
177
184
|
|
|
185
|
+
/**
|
|
186
|
+
* The Intl tag one amount prints in: the shopper's language, and for English
|
|
187
|
+
* the currency's home region ("$11.50" for USD, "₦5,000" for NGN, "£8" for
|
|
188
|
+
* GBP) unless the shopper's own code names a region (an `en-GB` reader sees
|
|
189
|
+
* "US$11.50").
|
|
190
|
+
*/
|
|
191
|
+
function moneyTagFor(locale: string | null | undefined, currency: string): string {
|
|
192
|
+
return displayTagFor(locale, (l) => Intl.NumberFormat.supportedLocalesOf(l), currencyRegion(currency));
|
|
193
|
+
}
|
|
194
|
+
|
|
178
195
|
/**
|
|
179
196
|
* The money display rule (see the top of this file). "Whole" is decided by
|
|
180
197
|
* Intl itself AFTER rounding to the currency's digits, so $11.999 prints "$12"
|
|
@@ -199,7 +216,7 @@ function formatAtMinorUnits(amount: number | string, code: string, tag: string):
|
|
|
199
216
|
*
|
|
200
217
|
* @example
|
|
201
218
|
* formatMoney(5000, 'NGN'); // "₦5,000"
|
|
202
|
-
* formatMoney(11.5, 'USD'); // "
|
|
219
|
+
* formatMoney(11.5, 'USD'); // "$11.50"
|
|
203
220
|
*/
|
|
204
221
|
export function formatMoney(
|
|
205
222
|
amount: number,
|
|
@@ -207,7 +224,7 @@ export function formatMoney(
|
|
|
207
224
|
locale?: string | null,
|
|
208
225
|
): string {
|
|
209
226
|
const code = normalizeCurrencyCode(currency);
|
|
210
|
-
const tag =
|
|
227
|
+
const tag = moneyTagFor(locale, code);
|
|
211
228
|
try {
|
|
212
229
|
return formatAtMinorUnits(amount, code, tag);
|
|
213
230
|
} catch {
|
|
@@ -224,7 +241,7 @@ export function formatMoney(
|
|
|
224
241
|
*
|
|
225
242
|
* @example
|
|
226
243
|
* formatWireMoney('4500.00', 'NGN'); // "₦4,500"
|
|
227
|
-
* formatWireMoney('11.50', 'USD'); // "
|
|
244
|
+
* formatWireMoney('11.50', 'USD'); // "$11.50"
|
|
228
245
|
*/
|
|
229
246
|
export function formatWireMoney(
|
|
230
247
|
amount: string,
|
|
@@ -236,7 +253,7 @@ export function formatWireMoney(
|
|
|
236
253
|
}
|
|
237
254
|
|
|
238
255
|
const code = normalizeCurrencyCode(currency);
|
|
239
|
-
const tag =
|
|
256
|
+
const tag = moneyTagFor(locale, code);
|
|
240
257
|
try {
|
|
241
258
|
return formatAtMinorUnits(amount, code, tag);
|
|
242
259
|
} catch {
|
package/utils/locale.ts
CHANGED
|
@@ -19,57 +19,150 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* English display locale
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* the value lives in exactly one place.
|
|
22
|
+
* English display locale with no region: the neutral last resort when neither
|
|
23
|
+
* the shopper's locale nor the store says where the reader is. Never a fixed
|
|
24
|
+
* country: a store's region comes from the store itself (`storeRegion`), and
|
|
25
|
+
* money from its currency's home (`currencyRegion`). `DISPLAY_LOCALE` in
|
|
26
|
+
* `utils/format.ts` aliases this, so the value lives in exactly one place.
|
|
28
27
|
*/
|
|
29
|
-
export const ENGLISH_DISPLAY_LOCALE = 'en
|
|
28
|
+
export const ENGLISH_DISPLAY_LOCALE = 'en';
|
|
29
|
+
|
|
30
|
+
const REGION_PATTERN = /^[A-Z]{2}$/;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The regions English is formatted in natively by BOTH the server (Node 22, full ICU) and current browsers (checked on
|
|
34
|
+
* Chrome 152, which ships a superset). A regional tag outside this list resolves differently on the two sides (Chrome
|
|
35
|
+
* formats `en-FR` as "14 Feb 2026", Node falls back to `en` and prints "Feb 14, 2026"), which fails hydration, so it
|
|
36
|
+
* reads as neutral `en` instead. Extend only with a region both runtimes format natively.
|
|
37
|
+
*/
|
|
38
|
+
export const ENGLISH_REGIONS: ReadonlySet<string> = new Set(
|
|
39
|
+
'AE,AG,AI,AS,AT,AU,BB,BE,BI,BM,BS,BW,BZ,CA,CC,CH,CK,CM,CX,CY,DE,DG,DK,DM,ER,FI,FJ,FK,FM,GB,GD,GG,GH,GI,GM,GU,GY,HK,ID,IE,IL,IM,IN,IO,JE,JM,KE,KI,KN,KY,LC,LR,LS,MG,MH,MO,MP,MS,MT,MU,MV,MW,MY,NA,NF,NG,NL,NR,NU,NZ,PG,PH,PK,PN,PR,PW,RW,SB,SC,SD,SE,SG,SH,SI,SL,SS,SX,SZ,TC,TK,TO,TT,TV,TZ,UG,UM,US,VC,VG,VI,VU,WS,ZA,ZM,ZW'.split(','),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
function regionCode(value: unknown): string | null {
|
|
43
|
+
const code = typeof value === 'string' ? value.trim().toUpperCase() : '';
|
|
44
|
+
return REGION_PATTERN.test(code) ? code : null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The country a currency belongs to: the first two letters of its ISO 4217
|
|
49
|
+
* code (USD → US, GBP → GB, NGN → NG). Null for a currency with no single home
|
|
50
|
+
* (EUR, and the X-codes such as XOF/XAF) or anything that is not a 3-letter code.
|
|
51
|
+
* English money is written the way its home country writes it, so a store's own
|
|
52
|
+
* currency prints the bare local symbol ("$11.50" for USD, "₦5,000" for NGN).
|
|
53
|
+
*/
|
|
54
|
+
export function currencyRegion(currency: unknown): string | null {
|
|
55
|
+
const code = typeof currency === 'string' ? currency.trim().toUpperCase() : '';
|
|
56
|
+
if (!/^[A-Z]{3}$/.test(code) || code.startsWith('X') || code === 'EUR') return null;
|
|
57
|
+
return code.slice(0, 2);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Where a store is, for the English dates it prints: its country (`country_code`,
|
|
62
|
+
* ISO 3166-1 alpha-2), else its currency's home (`currencyRegion`), else null
|
|
63
|
+
* (neutral English). Pure: the server render and the browser give the same answer
|
|
64
|
+
* from the same store profile.
|
|
65
|
+
*/
|
|
66
|
+
export function storeRegion(store: { country_code?: unknown; currency?: unknown } | null | undefined): string | null {
|
|
67
|
+
if (!store || typeof store !== 'object') return null;
|
|
68
|
+
return regionCode(store.country_code) ?? currencyRegion(store.currency);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The region subtag a locale code carries itself (`en-GB` → GB, `en-Latn-US` → US), or null. */
|
|
72
|
+
function ownRegion(code: string): string | null {
|
|
73
|
+
try {
|
|
74
|
+
return regionCode(new Intl.Locale(code).region);
|
|
75
|
+
} catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
30
79
|
|
|
31
80
|
/**
|
|
32
81
|
* THE single canonical mapping from a storefront locale code to the Intl
|
|
33
|
-
* locale dates/numbers/relative time are formatted in
|
|
34
|
-
* with English in the British/Nigerian style ("2 October 2026", never US
|
|
35
|
-
* "October 2, 2026").
|
|
82
|
+
* locale dates/numbers/relative time are formatted in.
|
|
36
83
|
*
|
|
37
|
-
* -
|
|
38
|
-
* `en-GB
|
|
39
|
-
*
|
|
40
|
-
*
|
|
84
|
+
* - English: the reader's own region when the code carries one (`en-GB`
|
|
85
|
+
* stays `en-GB`), else `region` (the store's, or a currency's home), else
|
|
86
|
+
* neutral `en`; a region outside `ENGLISH_REGIONS` (not native on both the
|
|
87
|
+
* server and the browser) is neutral `en` too. So a US store reads "Feb 14, 2026" and "$11.50", a
|
|
88
|
+
* Nigerian one "14 Feb 2026" and "₦5,000".
|
|
89
|
+
* - Missing/invalid codes are English.
|
|
41
90
|
* - Every other well-formed code passes through unchanged (`fr`, `ar`,
|
|
42
91
|
* `pt-BR`, `zh-CN`, `yo`, `ha`, `sw`, …).
|
|
43
92
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
93
|
+
* Idempotent for a regional tag: `en-US` maps to itself whatever `region`
|
|
94
|
+
* says, so a resolved tag can be passed wherever a storefront locale is
|
|
95
|
+
* expected. Pure (no `next/*`, no
|
|
96
|
+
* React) like the rest of this module. Never throws. Pair with
|
|
97
|
+
* `resolveSupportedLocale` when the runtime's ICU may lack the locale — this
|
|
98
|
+
* function maps, it does not probe.
|
|
47
99
|
*/
|
|
48
|
-
export function resolveIntlLocale(locale: string | null | undefined): string {
|
|
100
|
+
export function resolveIntlLocale(locale: string | null | undefined, region?: string | null): string {
|
|
49
101
|
const code = parseLocaleCode(locale);
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
return
|
|
102
|
+
if (code && (code.split('-')[0] ?? '').toLowerCase() !== 'en') return code;
|
|
103
|
+
const chosen = [code ? ownRegion(code) : null, regionCode(region)].find((r) => r !== null && ENGLISH_REGIONS.has(r));
|
|
104
|
+
return chosen ? `en-${chosen}` : ENGLISH_DISPLAY_LOCALE;
|
|
53
105
|
}
|
|
54
106
|
|
|
55
107
|
/**
|
|
56
108
|
* Graceful ICU fallback for one formatting call: the candidate when this
|
|
57
|
-
* Node's ICU formats it natively, `
|
|
58
|
-
*
|
|
59
|
-
*
|
|
109
|
+
* Node's ICU formats it natively, `fallback` otherwise (a minimal-ICU build
|
|
110
|
+
* with no French data still renders English, never an exception). Pass the
|
|
111
|
+
* English tag for the same region as the fallback (`resolveIntlLocale(null,
|
|
112
|
+
* region)`) so a language the runtime lacks still prints the store's own
|
|
113
|
+
* symbol and order. Never throws — pass any Intl constructor's
|
|
60
114
|
* `supportedLocalesOf`, e.g. `(l) => Intl.DateTimeFormat.supportedLocalesOf(l)`.
|
|
61
115
|
*/
|
|
62
116
|
export function resolveSupportedLocale(
|
|
63
117
|
candidate: string,
|
|
64
118
|
supportedLocalesOf: (locales: string[]) => readonly string[],
|
|
119
|
+
fallback: string = ENGLISH_DISPLAY_LOCALE,
|
|
65
120
|
): string {
|
|
66
121
|
try {
|
|
67
|
-
return supportedLocalesOf([candidate]).length > 0 ? candidate :
|
|
122
|
+
return supportedLocalesOf([candidate]).length > 0 ? candidate : fallback;
|
|
123
|
+
} catch {
|
|
124
|
+
return fallback;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The store's IANA time zone (`timezone` on the store profile), or `UTC` when it sent none or one this runtime does not know. */
|
|
129
|
+
export function storeTimeZone(store: unknown): string {
|
|
130
|
+
const zone = typeof store === 'object' && store !== null ? (store as { timezone?: unknown }).timezone : null;
|
|
131
|
+
if (typeof zone !== 'string' || zone.trim() === '') return 'UTC';
|
|
132
|
+
try {
|
|
133
|
+
return new Intl.DateTimeFormat(ENGLISH_DISPLAY_LOCALE, { timeZone: zone.trim() }).resolvedOptions().timeZone;
|
|
68
134
|
} catch {
|
|
69
|
-
return
|
|
135
|
+
return 'UTC';
|
|
70
136
|
}
|
|
71
137
|
}
|
|
72
138
|
|
|
139
|
+
/** How one store's dates read: the Intl tag for the shopper's language in the store's region, and the store's time zone. */
|
|
140
|
+
export interface StoreDisplayFormat {
|
|
141
|
+
locale: string;
|
|
142
|
+
timeZone: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The display format for a store: `locale` through `resolveIntlLocale` with the
|
|
147
|
+
* store's region (checked against this runtime's ICU), `timeZone` from
|
|
148
|
+
* `storeTimeZone`. Pure; server pages call it with the profile they hold,
|
|
149
|
+
* client components read it through `useStoreDisplayFormat()`.
|
|
150
|
+
*/
|
|
151
|
+
export function storeDisplayFormat(
|
|
152
|
+
locale: string | null | undefined,
|
|
153
|
+
store: { country_code?: unknown; currency?: unknown; timezone?: unknown } | null | undefined,
|
|
154
|
+
): StoreDisplayFormat {
|
|
155
|
+
const region = storeRegion(store);
|
|
156
|
+
return {
|
|
157
|
+
locale: resolveSupportedLocale(
|
|
158
|
+
resolveIntlLocale(locale, region),
|
|
159
|
+
(l) => Intl.DateTimeFormat.supportedLocalesOf(l),
|
|
160
|
+
resolveIntlLocale(null, region),
|
|
161
|
+
),
|
|
162
|
+
timeZone: storeTimeZone(store),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
73
166
|
/** Request header the proxy sets for published non-primary locales. */
|
|
74
167
|
export const LOCALE_CODE_HEADER = 'x-queek-locale';
|
|
75
168
|
|