@@ -3,49 +3,6 @@ import { BigDecimal, isValidNumber, sanitizeExponentialNumberString } from "./nu
3
3
4
4
export const defaultLocale = "en" ;
5
5
6
- export const t9nLocales = [
7
- "ar" ,
8
- "bg" ,
9
- "bs" ,
10
- "ca" ,
11
- "cs" ,
12
- "da" ,
13
- "de" ,
14
- "el" ,
15
- defaultLocale ,
16
- "es" ,
17
- "et" ,
18
- "fi" ,
19
- "fr" ,
20
- "he" ,
21
- "hr" ,
22
- "hu" ,
23
- "id" ,
24
- "it" ,
25
- "ja" ,
26
- "ko" ,
27
- "lt" ,
28
- "lv" ,
29
- "no" ,
30
- "nl" ,
31
- "pl" ,
32
- "pt-BR" ,
33
- "pt-PT" ,
34
- "ro" ,
35
- "ru" ,
36
- "sk" ,
37
- "sl" ,
38
- "sr" ,
39
- "sv" ,
40
- "th" ,
41
- "tr" ,
42
- "uk" ,
43
- "vi" ,
44
- "zh-CN" ,
45
- "zh-HK" ,
46
- "zh-TW" ,
47
- ] ;
48
-
49
6
export const locales = [
50
7
"ar" ,
51
8
"bg" ,
@@ -134,8 +91,7 @@ export const localizedTwentyFourHourMeridiems = new Map(
134
91
) ;
135
92
136
93
export const numberingSystems = [ "arab" , "arabext" , "latn" ] as const ;
137
-
138
- export const supportedLocales = [ ...new Set ( [ ...t9nLocales , ...locales ] ) ] as const ;
94
+ export const supportedLocales = [ ...locales ] as const ;
139
95
140
96
export type NumberingSystem = ( typeof numberingSystems ) [ number ] ;
141
97
@@ -160,45 +116,36 @@ export const getSupportedNumberingSystem = (numberingSystem: string): NumberingS
160
116
* Gets the locale that best matches the context.
161
117
*
162
118
* @param locale – the BCP 47 locale code
163
- * @param context - specifies whether the locale code should match in the context of CLDR or T9N (translation)
164
119
*/
165
- export function getSupportedLocale ( locale : string , context : "cldr" | "t9n" = "cldr" ) : SupportedLocale {
166
- const contextualLocales = context === "cldr" ? locales : t9nLocales ;
167
-
120
+ export function getSupportedLocale ( locale : string ) : SupportedLocale {
168
121
if ( ! locale ) {
169
122
return defaultLocale ;
170
123
}
171
124
172
- if ( contextualLocales . includes ( locale ) ) {
125
+ if ( supportedLocales . includes ( locale ) ) {
173
126
return locale ;
174
127
}
175
128
176
129
locale = locale . toLowerCase ( ) ;
177
-
178
- // we support both 'nb' and 'no' (BCP 47) for Norwegian but only `no` has corresponding bundle
179
- if ( locale === "nb" ) {
180
- return "no" ;
181
- }
182
-
183
- // we use `pt-BR` as it will have the same translations as `pt`, which has no corresponding bundle
184
- if ( context === "t9n" && locale === "pt" ) {
185
- return "pt-BR" ;
186
- }
187
-
188
130
if ( locale . includes ( "-" ) ) {
189
131
locale = locale . replace ( / ( \w + ) - ( \w + ) / , ( _match , language , region ) => `${ language } -${ region . toUpperCase ( ) } ` ) ;
190
132
191
- if ( ! contextualLocales . includes ( locale ) ) {
133
+ if ( ! supportedLocales . includes ( locale ) ) {
192
134
locale = locale . split ( "-" ) [ 0 ] ;
193
135
}
194
136
}
195
137
138
+ // we support 'nn', 'nb' and 'no' (BCP 47) for Norwegian but only `no` includes corresponding bundle
139
+ if ( locale === "nb" || locale === "nn" ) {
140
+ return "no" ;
141
+ }
142
+
196
143
// we can `zh-CN` as base translation for chinese locales which has no corresponding bundle.
197
144
if ( locale === "zh" ) {
198
145
return "zh-CN" ;
199
146
}
200
147
201
- if ( ! contextualLocales . includes ( locale ) ) {
148
+ if ( ! supportedLocales . includes ( locale ) ) {
202
149
console . warn (
203
150
`Translations for the "${ locale } " locale are not available and will fall back to the default, English (en).` ,
204
151
) ;
0 commit comments