-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@formatjs/intl-locale): implement new proposal features for Intl…
….Locale (#3955) Co-authored-by: Long Ho <longlho@users.noreply.github.com>
- Loading branch information
Showing
28 changed files
with
944 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import type {Collation} from './collations.generated' | ||
import {collations} from './collations.generated' | ||
|
||
function isSupported(collation: Collation): boolean { | ||
function isSupported(collation: Collation, locale: string = 'en'): boolean { | ||
try { | ||
return ( | ||
Intl.Collator('en-u-co-' + collation).resolvedOptions().locale === 'en' | ||
Intl.Collator(`${locale}-u-co-${collation}`).resolvedOptions() | ||
.collation === collation | ||
) | ||
} catch (_err) {} | ||
|
||
return false | ||
} | ||
|
||
export function getSupportedCollations(): Collation[] { | ||
return collations.filter(isSupported) | ||
export function getSupportedCollations(locale?: string): Collation[] { | ||
return collations.filter(collation => isSupported(collation, locale)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import type {Timezone} from './timezones.generated' | ||
import {timezones} from './timezones.generated' | ||
|
||
function isSupported(timeZone: Timezone): boolean { | ||
function isSupported(timeZone: Timezone, locale: string = 'en'): boolean { | ||
try { | ||
const formatter = new Intl.DateTimeFormat('en', {timeZone}) | ||
const formatter = new Intl.DateTimeFormat(locale, {timeZone}) | ||
return formatter.resolvedOptions().timeZone === timeZone | ||
} catch (_err) {} | ||
|
||
return false | ||
} | ||
|
||
export function getSupportedTimeZones(): Timezone[] { | ||
return timezones.filter(isSupported) | ||
export function getSupportedTimeZones(locale?: string): Timezone[] { | ||
return timezones.filter(timezone => isSupported(timezone, locale)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import type {Unit} from './units.generated' | ||
import {units} from './units.generated' | ||
|
||
function isSupported(unit: Unit): boolean { | ||
function isSupported(unit: Unit, locale: string = 'en'): boolean { | ||
try { | ||
const formatter = new Intl.NumberFormat('en', {style: 'unit', unit}) | ||
const formatter = new Intl.NumberFormat(locale, {style: 'unit', unit}) | ||
return formatter.resolvedOptions().unit === unit | ||
} catch (_err) {} | ||
|
||
return false | ||
} | ||
|
||
export function getSupportedUnits() { | ||
return units.filter(isSupported) | ||
export function getSupportedUnits(locale?: string) { | ||
return units.filter(unit => isSupported(unit, locale)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* @generated */ | ||
// prettier-ignore | ||
export const calendars = {"001":["gregorian"],"AE":["gregorian","islamic-umalqura","islamic","islamic-civil","islamic-tbla"],"AF":["persian","gregorian","islamic","islamic-civil","islamic-tbla"],"BH":["gregorian","islamic-umalqura","islamic","islamic-civil","islamic-tbla"],"CN":["gregorian","chinese"],"CX":["gregorian","chinese"],"DJ":["gregorian","islamic","islamic-civil","islamic-tbla"],"DZ":["gregorian","islamic","islamic-civil","islamic-tbla"],"EG":["gregorian","coptic","islamic","islamic-civil","islamic-tbla"],"EH":["gregorian","islamic","islamic-civil","islamic-tbla"],"ER":["gregorian","islamic","islamic-civil","islamic-tbla"],"ET":["gregorian","ethiopic"],"HK":["gregorian","chinese"],"IL":["gregorian","hebrew","islamic","islamic-civil","islamic-tbla"],"IN":["gregorian","indian"],"IQ":["gregorian","islamic","islamic-civil","islamic-tbla"],"IR":["persian","gregorian","islamic","islamic-civil","islamic-tbla"],"JO":["gregorian","islamic","islamic-civil","islamic-tbla"],"JP":["gregorian","japanese"],"KM":["gregorian","islamic","islamic-civil","islamic-tbla"],"KR":["gregorian","dangi"],"KW":["gregorian","islamic-umalqura","islamic","islamic-civil","islamic-tbla"],"LB":["gregorian","islamic","islamic-civil","islamic-tbla"],"LY":["gregorian","islamic","islamic-civil","islamic-tbla"],"MA":["gregorian","islamic","islamic-civil","islamic-tbla"],"MO":["gregorian","chinese"],"MR":["gregorian","islamic","islamic-civil","islamic-tbla"],"OM":["gregorian","islamic","islamic-civil","islamic-tbla"],"PS":["gregorian","islamic","islamic-civil","islamic-tbla"],"QA":["gregorian","islamic-umalqura","islamic","islamic-civil","islamic-tbla"],"SA":["islamic-umalqura","gregorian","islamic","islamic-rgsa"],"SD":["gregorian","islamic","islamic-civil","islamic-tbla"],"SG":["gregorian","chinese"],"SY":["gregorian","islamic","islamic-civil","islamic-tbla"],"TD":["gregorian","islamic","islamic-civil","islamic-tbla"],"TH":["buddhist","gregorian"],"TN":["gregorian","islamic","islamic-civil","islamic-tbla"],"TW":["gregorian","roc","chinese"],"YE":["gregorian","islamic","islamic-civil","islamic-tbla"]} as const | ||
export type CalendarsKey = keyof typeof calendars |
Oops, something went wrong.