Visitar URL original
feat(@formatjs/intl-displaynames): add supported locales check to sho… · formatjs/formatjs@4d39f5c · GitHub
Skip to content

Commit 4d39f5c

Browse files
committed
feat(@formatjs/intl-displaynames): add supported locales check to should-polyfill, fix #3066
1 parent 59d297e commit 4d39f5c

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎packages/intl-displaynames/should-polyfill.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ function hasScriptBug() {
2828
return false
2929
}
3030

31-
export function shouldPolyfill() {
32-
return !(Intl as any).DisplayNames || hasMissingICUBug() || hasScriptBug()
31+
function supportedLocalesOf(locale?: string | string[]) {
32+
if (!locale) {
33+
return true
34+
}
35+
const locales = Array.isArray(locale) ? locale : [locale]
36+
return (
37+
(Intl as any).DisplayNames.supportedLocalesOf(locales).length ===
38+
locales.length
39+
)
40+
}
41+
42+
export function shouldPolyfill(locale?: string | string[]) {
43+
return (
44+
!(Intl as any).DisplayNames ||
45+
hasMissingICUBug() ||
46+
hasScriptBug() ||
47+
!supportedLocalesOf(locale)
48+
)
3349
}

0 commit comments

Comments
 (0)