@f5xc-salesdemos/pi-utils 19.23.0 → 19.24.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@f5xc-salesdemos/pi-utils",
4
- "version": "19.23.0",
4
+ "version": "19.24.0",
5
5
  "description": "Shared utilities for pi packages",
6
6
  "homepage": "https://github.com/f5xc-salesdemos/xcsh",
7
7
  "author": "Can Boluk",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/bun": "^1.3",
41
- "@f5xc-salesdemos/pi-natives": "19.23.0"
41
+ "@f5xc-salesdemos/pi-natives": "19.24.0"
42
42
  },
43
43
  "engines": {
44
44
  "bun": ">=1.3.7"
package/src/i18n.test.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  import { beforeEach, describe, expect, test } from "bun:test";
2
- import { getLocale, initI18n, mapToSupportedLocale, registerLocales, setLocale, t } from "./i18n";
2
+ import {
3
+ getLocale,
4
+ getLocaleDisplayName,
5
+ initI18n,
6
+ LOCALE_DISPLAY_NAMES,
7
+ mapToSupportedLocale,
8
+ registerLocales,
9
+ setLocale,
10
+ t,
11
+ } from "./i18n";
3
12
 
4
13
  const EN = {
5
14
  greeting: "Hello",
@@ -109,6 +118,55 @@ describe("i18n", () => {
109
118
  });
110
119
  });
111
120
 
121
+ describe("LOCALE_DISPLAY_NAMES", () => {
122
+ test("has entries for all 13 supported locales", () => {
123
+ const expected = ["ar", "de", "en", "es", "fr", "hi", "it", "ja", "ko", "pt-br", "th", "zh-cn", "zh-tw"];
124
+ for (const code of expected) {
125
+ expect(LOCALE_DISPLAY_NAMES[code]).toBeDefined();
126
+ expect(typeof LOCALE_DISPLAY_NAMES[code]).toBe("string");
127
+ }
128
+ });
129
+
130
+ test("returns correct names for key locales", () => {
131
+ expect(LOCALE_DISPLAY_NAMES.ko).toBe("Korean");
132
+ expect(LOCALE_DISPLAY_NAMES.ja).toBe("Japanese");
133
+ expect(LOCALE_DISPLAY_NAMES.en).toBe("English");
134
+ expect(LOCALE_DISPLAY_NAMES["zh-cn"]).toBe("Simplified Chinese");
135
+ });
136
+ });
137
+
138
+ describe("getLocaleDisplayName", () => {
139
+ beforeEach(() => {
140
+ registerLocales({ en: EN, ja: JA, "zh-cn": {}, "zh-tw": {}, "pt-br": {}, fr: {}, de: {} });
141
+ setLocale("en");
142
+ });
143
+
144
+ test("returns display name for known locale", () => {
145
+ expect(getLocaleDisplayName("ko")).toBe("Korean");
146
+ expect(getLocaleDisplayName("ja")).toBe("Japanese");
147
+ expect(getLocaleDisplayName("fr")).toBe("French");
148
+ });
149
+
150
+ test("returns display name for regional variant", () => {
151
+ expect(getLocaleDisplayName("pt-br")).toBe("Brazilian Portuguese");
152
+ expect(getLocaleDisplayName("zh-cn")).toBe("Simplified Chinese");
153
+ });
154
+
155
+ test("returns undefined for unknown locale", () => {
156
+ expect(getLocaleDisplayName("xx")).toBeUndefined();
157
+ expect(getLocaleDisplayName("sv")).toBeUndefined();
158
+ });
159
+
160
+ test("returns 'English' for 'en'", () => {
161
+ expect(getLocaleDisplayName("en")).toBe("English");
162
+ });
163
+
164
+ test("normalizes case", () => {
165
+ expect(getLocaleDisplayName("KO")).toBe("Korean");
166
+ expect(getLocaleDisplayName("zh-CN")).toBe("Simplified Chinese");
167
+ });
168
+ });
169
+
112
170
  describe("mapToSupportedLocale", () => {
113
171
  beforeEach(() => {
114
172
  registerLocales({ en: EN, ja: JA, "zh-cn": {}, "zh-tw": {}, "pt-br": {}, fr: {}, de: {} });
package/src/i18n.ts CHANGED
@@ -3,6 +3,27 @@ import { $pickenv } from "./env";
3
3
  type LocaleMap = Record<string, string>;
4
4
  type LocaleBundle = Record<string, LocaleMap>;
5
5
 
6
+ export const LOCALE_DISPLAY_NAMES: Record<string, string> = {
7
+ ar: "Arabic",
8
+ de: "German",
9
+ en: "English",
10
+ es: "Spanish",
11
+ fr: "French",
12
+ hi: "Hindi",
13
+ it: "Italian",
14
+ ja: "Japanese",
15
+ ko: "Korean",
16
+ "pt-br": "Brazilian Portuguese",
17
+ th: "Thai",
18
+ "zh-cn": "Simplified Chinese",
19
+ "zh-tw": "Traditional Chinese",
20
+ };
21
+
22
+ export function getLocaleDisplayName(locale: string): string | undefined {
23
+ const normalized = locale.toLowerCase().replace(/_/g, "-").split(".")[0];
24
+ return LOCALE_DISPLAY_NAMES[normalized];
25
+ }
26
+
6
27
  let currentLocale = "en";
7
28
  let bundles: LocaleBundle = {};
8
29
  let active: LocaleMap = {};
package/src/index.ts CHANGED
@@ -8,7 +8,16 @@ export * from "./frontmatter";
8
8
  export * from "./fs-error";
9
9
  export * from "./glob";
10
10
  export * from "./hook-fetch";
11
- export { getLocale, initI18n, mapToSupportedLocale, registerLocales, setLocale, t } from "./i18n";
11
+ export {
12
+ getLocale,
13
+ getLocaleDisplayName,
14
+ initI18n,
15
+ LOCALE_DISPLAY_NAMES,
16
+ mapToSupportedLocale,
17
+ registerLocales,
18
+ setLocale,
19
+ t,
20
+ } from "./i18n";
12
21
  export * from "./json";
13
22
  export * as logger from "./logger";
14
23
  export * from "./mermaid-ascii";