@f5xc-salesdemos/pi-utils 19.28.2 → 19.29.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 +3 -2
- package/src/i18n.ts +8 -50
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@f5xc-salesdemos/pi-utils",
|
|
4
|
-
"version": "19.
|
|
4
|
+
"version": "19.29.0",
|
|
5
5
|
"description": "Shared utilities for pi packages",
|
|
6
6
|
"homepage": "https://github.com/f5xc-salesdemos/xcsh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"fmt": "biome format --write ."
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@f5xc-salesdemos/i18n-core": "^1.0.0",
|
|
34
35
|
"beautiful-mermaid": "^1.1",
|
|
35
36
|
"handlebars": "^4.7.9",
|
|
36
37
|
"winston": "^3.19",
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@types/bun": "^1.3",
|
|
41
|
-
"@f5xc-salesdemos/pi-natives": "19.
|
|
42
|
+
"@f5xc-salesdemos/pi-natives": "19.29.0"
|
|
42
43
|
},
|
|
43
44
|
"engines": {
|
|
44
45
|
"bun": ">=1.3.7"
|
package/src/i18n.ts
CHANGED
|
@@ -1,29 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getLocaleDisplayName,
|
|
3
|
+
LOCALE_DISPLAY_NAMES,
|
|
4
|
+
mapToSupportedLocale,
|
|
5
|
+
normalizeLocale,
|
|
6
|
+
} from "@f5xc-salesdemos/i18n-core";
|
|
1
7
|
import { $pickenv } from "./env";
|
|
2
8
|
|
|
9
|
+
export { getLocaleDisplayName, LOCALE_DISPLAY_NAMES, mapToSupportedLocale };
|
|
10
|
+
|
|
3
11
|
type LocaleMap = Record<string, string>;
|
|
4
12
|
type LocaleBundle = Record<string, LocaleMap>;
|
|
5
13
|
|
|
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
|
-
|
|
27
14
|
let currentLocale = "en";
|
|
28
15
|
let bundles: LocaleBundle = {};
|
|
29
16
|
let active: LocaleMap = {};
|
|
@@ -88,35 +75,6 @@ export function t(key: string, params?: Record<string, string | number>): string
|
|
|
88
75
|
});
|
|
89
76
|
}
|
|
90
77
|
|
|
91
|
-
/**
|
|
92
|
-
* Map an OS locale code (macOS AppleLanguages, Linux LANG) to a supported xcsh locale.
|
|
93
|
-
* Handles Apple script subtags (zh-Hans, zh-Hant) and regional variants (pt-BR, en-US).
|
|
94
|
-
* Returns undefined if no supported locale matches.
|
|
95
|
-
*/
|
|
96
|
-
export function mapToSupportedLocale(osLocale: string): string | undefined {
|
|
97
|
-
const normalized = normalizeLocale(osLocale);
|
|
98
|
-
|
|
99
|
-
if (bundles[normalized]) return normalized;
|
|
100
|
-
|
|
101
|
-
// Apple uses zh-hans / zh-hant (script subtags) instead of zh-cn / zh-tw
|
|
102
|
-
if (normalized.startsWith("zh-hans")) return bundles["zh-cn"] ? "zh-cn" : undefined;
|
|
103
|
-
if (normalized.startsWith("zh-hant")) return bundles["zh-tw"] ? "zh-tw" : undefined;
|
|
104
|
-
|
|
105
|
-
// Try with region: pt-br, en-us, etc.
|
|
106
|
-
const withRegion = normalized.split("-").slice(0, 2).join("-");
|
|
107
|
-
if (bundles[withRegion]) return withRegion;
|
|
108
|
-
|
|
109
|
-
// Fall back to base language: pt-br → pt, en-us → en
|
|
110
|
-
const base = normalized.split("-")[0];
|
|
111
|
-
if (bundles[base]) return base;
|
|
112
|
-
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function normalizeLocale(raw: string): string {
|
|
117
|
-
return raw.toLowerCase().replace(/_/g, "-").split(".")[0];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
78
|
function parseSystemLocale(raw: string | undefined): string | undefined {
|
|
121
79
|
if (!raw) return undefined;
|
|
122
80
|
const normalized = normalizeLocale(raw);
|