Skip to content

Commit 202aaa6

Browse files
anveshmekalabenelan
authored andcommitted
feat: support nn locale (#12079)
**Related Issue:** #11978 ## Summary - Add support for `nn` locale which maps to `no` - removes `t9n` context from locale util since it is handled by lumina controller.
1 parent 6e6b582 commit 202aaa6

File tree

2 files changed

+15
-70
lines changed

2 files changed

+15
-70
lines changed

packages/calcite-components/src/utils/locale.spec.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ describe("getDateTimeFormat()", () => {
187187

188188
describe("getSupportedLocale", () => {
189189
function assertAllContexts(locale: string, expectedLocale: string): void {
190-
expect(getSupportedLocale(locale, "cldr")).toBe(expectedLocale);
191-
expect(getSupportedLocale(locale, "t9n")).toBe(expectedLocale);
190+
expect(getSupportedLocale(locale)).toBe(expectedLocale);
192191
}
193192

194193
it("returns `en` if there is no locale", () => {
@@ -223,13 +222,12 @@ describe("getSupportedLocale", () => {
223222
assertAllContexts("nb", "no");
224223
});
225224

226-
it("maps `zh` to `zh-CN`", () => {
227-
assertAllContexts("zh", "zh-CN");
225+
it("maps `nn` to `no`", () => {
226+
assertAllContexts("nn", "no");
228227
});
229228

230-
it("maps `pt` to `pt-BR` with t9n context", () => {
231-
expect(getSupportedLocale("pt", "t9n")).toBe("pt-BR");
232-
expect(getSupportedLocale("pt", "cldr")).toBe("pt");
229+
it("maps `zh` to `zh-CN`", () => {
230+
assertAllContexts("zh", "zh-CN");
233231
});
234232
});
235233
});

packages/calcite-components/src/utils/locale.ts

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,6 @@ import { BigDecimal, isValidNumber, sanitizeExponentialNumberString } from "./nu
33

44
export const defaultLocale = "en";
55

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-
496
export const locales = [
507
"ar",
518
"bg",
@@ -134,8 +91,7 @@ export const localizedTwentyFourHourMeridiems = new Map(
13491
);
13592

13693
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;
13995

14096
export type NumberingSystem = (typeof numberingSystems)[number];
14197

@@ -160,45 +116,36 @@ export const getSupportedNumberingSystem = (numberingSystem: string): NumberingS
160116
* Gets the locale that best matches the context.
161117
*
162118
* @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)
164119
*/
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 {
168121
if (!locale) {
169122
return defaultLocale;
170123
}
171124

172-
if (contextualLocales.includes(locale)) {
125+
if (supportedLocales.includes(locale)) {
173126
return locale;
174127
}
175128

176129
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-
188130
if (locale.includes("-")) {
189131
locale = locale.replace(/(\w+)-(\w+)/, (_match, language, region) => `${language}-${region.toUpperCase()}`);
190132

191-
if (!contextualLocales.includes(locale)) {
133+
if (!supportedLocales.includes(locale)) {
192134
locale = locale.split("-")[0];
193135
}
194136
}
195137

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+
196143
// we can `zh-CN` as base translation for chinese locales which has no corresponding bundle.
197144
if (locale === "zh") {
198145
return "zh-CN";
199146
}
200147

201-
if (!contextualLocales.includes(locale)) {
148+
if (!supportedLocales.includes(locale)) {
202149
console.warn(
203150
`Translations for the "${locale}" locale are not available and will fall back to the default, English (en).`,
204151
);

0 commit comments

Comments
 (0)