@formatjs/intl-locale 5.1.1 → 5.2.0
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/calendars.generated.d.ts +52 -52
- package/calendars.generated.js +257 -289
- package/character-orders.generated.d.ts +767 -767
- package/character-orders.generated.js +767 -767
- package/get_internal_slots.d.ts +2 -1
- package/get_internal_slots.js +16 -18
- package/hour-cycles.generated.d.ts +276 -276
- package/hour-cycles.generated.js +281 -1045
- package/index.d.ts +98 -96
- package/index.js +561 -549
- package/numbering-systems.generated.d.ts +766 -766
- package/numbering-systems.generated.js +862 -2424
- package/package.json +5 -5
- package/polyfill-force.js +6 -6
- package/polyfill.iife.js +3126 -3056
- package/polyfill.js +8 -8
- package/preference-data.d.ts +2 -2
- package/preference-data.js +34 -38
- package/should-polyfill.js +45 -38
- package/timezones.generated.d.ts +247 -247
- package/timezones.generated.js +505 -964
- package/week-data.generated.d.ts +1295 -1295
- package/week-data.generated.js +1296 -2070
package/polyfill.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Locale } from
|
|
2
|
-
import { shouldPolyfill } from
|
|
1
|
+
import { Locale } from "./index.js";
|
|
2
|
+
import { shouldPolyfill } from "./should-polyfill.js";
|
|
3
3
|
if (shouldPolyfill()) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
Object.defineProperty(Intl, "Locale", {
|
|
5
|
+
value: Locale,
|
|
6
|
+
writable: true,
|
|
7
|
+
enumerable: false,
|
|
8
|
+
configurable: true
|
|
9
|
+
});
|
|
10
10
|
}
|
package/preference-data.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { WeekInfoInternal } from
|
|
2
|
-
export { WeekInfoInternal };
|
|
1
|
+
import type { WeekInfoInternal } from "./week-data.generated.js";
|
|
2
|
+
export { type WeekInfoInternal };
|
|
3
3
|
export declare function getCalendarPreferenceDataForRegion(region?: string): string[];
|
|
4
4
|
export declare function getHourCyclesPreferenceDataForLocaleOrRegion(locale: string, region?: string): string[];
|
|
5
5
|
export declare function getTimeZonePreferenceForRegion(region: string): string[];
|
package/preference-data.js
CHANGED
|
@@ -1,46 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { weekData } from './week-data.generated.js';
|
|
1
|
+
import { timezones } from "./timezones.generated.js";
|
|
2
|
+
import { hourCycles } from "./hour-cycles.generated.js";
|
|
3
|
+
import { calendars } from "./calendars.generated.js";
|
|
4
|
+
import { weekData } from "./week-data.generated.js";
|
|
6
5
|
export function getCalendarPreferenceDataForRegion(region) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
const _region = region ? region.toUpperCase() : null;
|
|
7
|
+
return (calendars[_region || ""] || calendars["001"]).map((c) => {
|
|
8
|
+
// Resolve aliases
|
|
9
|
+
// cldr-json/cldr-code v42.0.0-ALPHA3-2
|
|
10
|
+
// https://github.com/unicode-org/cldr-json/blob/42.0.0-ALPHA3-2/cldr-json/cldr-bcp47/bcp47/calendar.json
|
|
11
|
+
if (c === "gregorian") {
|
|
12
|
+
return "gregory";
|
|
13
|
+
}
|
|
14
|
+
if (c === "islamic-civil") {
|
|
15
|
+
return "islamicc";
|
|
16
|
+
}
|
|
17
|
+
// At the time this has been written this calendar was not listed in
|
|
18
|
+
// the supplemental calendarPreferenceData file
|
|
19
|
+
// https://github.com/unicode-org/cldr-json/blob/42.0.0-ALPHA3-2/cldr-json/cldr-core/supplemental/calendarPreferenceData.json
|
|
20
|
+
// if (c === 'ethiopic-amete-alem') {
|
|
21
|
+
// return 'ethioaa'
|
|
22
|
+
// }
|
|
23
|
+
return c;
|
|
24
|
+
});
|
|
26
25
|
}
|
|
27
26
|
export function getHourCyclesPreferenceDataForLocaleOrRegion(locale, region) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
hourCycles["".concat(_locale, "-001")] ||
|
|
33
|
-
hourCycles['001'];
|
|
34
|
-
return __spreadArray([], hourCyclesPreference, true);
|
|
27
|
+
const _locale = locale.toLowerCase();
|
|
28
|
+
const _region = region ? region.toUpperCase() : "";
|
|
29
|
+
const hourCyclesPreference = hourCycles[_locale] || hourCycles[_region] || hourCycles[`${_locale}-001`] || hourCycles["001"];
|
|
30
|
+
return [...hourCyclesPreference];
|
|
35
31
|
}
|
|
36
32
|
export function getTimeZonePreferenceForRegion(region) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
const territory = region.toLowerCase();
|
|
34
|
+
if (timezones[territory]) {
|
|
35
|
+
return [...timezones[territory]];
|
|
36
|
+
}
|
|
37
|
+
return [];
|
|
42
38
|
}
|
|
43
39
|
export function getWeekDataForRegion(region) {
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
const _region = region ? region.toUpperCase() : "";
|
|
41
|
+
return weekData[_region || "001"] || weekData["001"];
|
|
46
42
|
}
|
package/should-polyfill.js
CHANGED
|
@@ -1,46 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
* https://bugs.chromium.org/p/v8/issues/detail?id=10682
|
|
3
|
+
*/
|
|
4
4
|
function hasIntlGetCanonicalLocalesBug() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
5
|
+
try {
|
|
6
|
+
return new Intl.Locale("und-x-private").toString() === "x-private";
|
|
7
|
+
} catch {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
* Check if Intl.Locale is missing the variants property.
|
|
13
|
+
* This property was added to ECMA-402 via PR #960.
|
|
14
|
+
* https://github.com/tc39/ecma402/pull/960
|
|
15
|
+
* https://github.com/tc39/ecma402/issues/900
|
|
16
|
+
*/
|
|
17
|
+
function hasVariantsProperty() {
|
|
18
|
+
try {
|
|
19
|
+
const locale = new Intl.Locale("en-US-posix");
|
|
20
|
+
// Check if variants property exists
|
|
21
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(locale), "variants");
|
|
22
|
+
return descriptor !== undefined && typeof descriptor.get === "function";
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check if Intl.Locale is missing critical methods from the Intl Locale Info proposal.
|
|
29
|
+
* Firefox has an incomplete implementation that lacks getWeekInfo() and other methods.
|
|
30
|
+
* https://github.com/formatjs/formatjs/issues/5112
|
|
31
|
+
* https://bugzilla.mozilla.org/show_bug.cgi?id=1693576
|
|
32
|
+
*/
|
|
18
33
|
function hasIncompleteLocaleInfo() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
catch (_a) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
34
|
+
try {
|
|
35
|
+
const locale = new Intl.Locale("en-US");
|
|
36
|
+
// Check for getWeekInfo - critical for week calculations (e.g., Luxon's localWeekNumber)
|
|
37
|
+
// This is the most important check as it affects date/time libraries
|
|
38
|
+
if (typeof locale.getWeekInfo !== "function") {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
// Also check for other Intl Locale Info methods
|
|
42
|
+
// These are part of the same proposal and often missing together
|
|
43
|
+
if (typeof locale.getCalendars !== "function" || typeof locale.getCollations !== "function" || typeof locale.getHourCycles !== "function" || typeof locale.getNumberingSystems !== "function" || typeof locale.getTimeZones !== "function" || typeof locale.getTextInfo !== "function") {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
} catch {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
41
50
|
}
|
|
42
51
|
export function shouldPolyfill() {
|
|
43
|
-
|
|
44
|
-
hasIntlGetCanonicalLocalesBug() ||
|
|
45
|
-
hasIncompleteLocaleInfo());
|
|
52
|
+
return !("Locale" in Intl) || hasIntlGetCanonicalLocalesBug() || hasIncompleteLocaleInfo() || !hasVariantsProperty();
|
|
46
53
|
}
|