@intlayer/core 5.4.1 → 5.4.2
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/dist/cjs/localization/getLocaleName.cjs +12 -14
- package/dist/cjs/localization/getLocaleName.cjs.map +1 -1
- package/dist/esm/localization/getLocaleName.mjs +12 -14
- package/dist/esm/localization/getLocaleName.mjs.map +1 -1
- package/dist/types/localization/getLocaleName.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -21,24 +21,22 @@ __export(getLocaleName_exports, {
|
|
|
21
21
|
getLocaleName: () => getLocaleName
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(getLocaleName_exports);
|
|
24
|
+
const dnCache = /* @__PURE__ */ new Map();
|
|
24
25
|
const getLocaleName = (displayLocale, targetLocale = displayLocale) => {
|
|
25
|
-
if (typeof Intl?.DisplayNames
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return displayNames.of(displayLocale) ?? "Unknown locale";
|
|
31
|
-
} catch {
|
|
32
|
-
return displayLocale;
|
|
26
|
+
if (typeof Intl?.DisplayNames !== "function") {
|
|
27
|
+
if (process.env.NODE_ENV === "development") {
|
|
28
|
+
console.warn(
|
|
29
|
+
`Intl.DisplayNames is not supported; falling back to raw locale (${displayLocale}). Consider adding a polyfill as https://formatjs.github.io/docs/polyfills/intl-displaynames/`
|
|
30
|
+
);
|
|
33
31
|
}
|
|
32
|
+
return displayLocale;
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
34
|
+
let dn = dnCache.get(targetLocale);
|
|
35
|
+
if (!dn) {
|
|
36
|
+
dn = new Intl.DisplayNames([targetLocale], { type: "language" });
|
|
37
|
+
dnCache.set(targetLocale, dn);
|
|
40
38
|
}
|
|
41
|
-
return displayLocale;
|
|
39
|
+
return dn.of(displayLocale) ?? "Unknown locale";
|
|
42
40
|
};
|
|
43
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
42
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/getLocaleName.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\n\nexport const getLocaleName = (\n displayLocale: LocalesValues,\n targetLocale: LocalesValues = displayLocale\n): string => {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/localization/getLocaleName.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\n\nconst dnCache = new Map<LocalesValues, Intl.DisplayNames>();\n\nexport const getLocaleName = (\n displayLocale: LocalesValues,\n targetLocale: LocalesValues = displayLocale\n): string => {\n if (typeof Intl?.DisplayNames !== 'function') {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `Intl.DisplayNames is not supported; falling back to raw locale (${displayLocale}). Consider adding a polyfill as https://formatjs.github.io/docs/polyfills/intl-displaynames/`\n );\n }\n return displayLocale;\n }\n\n // new Intl.DisplayNames() is fairly heavy: under the hood every call parses CLDR data and builds a resolver table. In your LocaleSwitcher it’s invoked:\n let dn = dnCache.get(targetLocale);\n if (!dn) {\n dn = new Intl.DisplayNames([targetLocale], { type: 'language' });\n dnCache.set(targetLocale, dn);\n }\n\n return dn.of(displayLocale) ?? 'Unknown locale';\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,MAAM,UAAU,oBAAI,IAAsC;AAEnD,MAAM,gBAAgB,CAC3B,eACA,eAA8B,kBACnB;AACX,MAAI,OAAO,MAAM,iBAAiB,YAAY;AAC5C,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ;AAAA,QACN,mEAAmE,aAAa;AAAA,MAClF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,QAAQ,IAAI,YAAY;AACjC,MAAI,CAAC,IAAI;AACP,SAAK,IAAI,KAAK,aAAa,CAAC,YAAY,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/D,YAAQ,IAAI,cAAc,EAAE;AAAA,EAC9B;AAEA,SAAO,GAAG,GAAG,aAAa,KAAK;AACjC;","names":[]}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
+
const dnCache = /* @__PURE__ */ new Map();
|
|
1
2
|
const getLocaleName = (displayLocale, targetLocale = displayLocale) => {
|
|
2
|
-
if (typeof Intl?.DisplayNames
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return displayNames.of(displayLocale) ?? "Unknown locale";
|
|
8
|
-
} catch {
|
|
9
|
-
return displayLocale;
|
|
3
|
+
if (typeof Intl?.DisplayNames !== "function") {
|
|
4
|
+
if (process.env.NODE_ENV === "development") {
|
|
5
|
+
console.warn(
|
|
6
|
+
`Intl.DisplayNames is not supported; falling back to raw locale (${displayLocale}). Consider adding a polyfill as https://formatjs.github.io/docs/polyfills/intl-displaynames/`
|
|
7
|
+
);
|
|
10
8
|
}
|
|
9
|
+
return displayLocale;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
);
|
|
11
|
+
let dn = dnCache.get(targetLocale);
|
|
12
|
+
if (!dn) {
|
|
13
|
+
dn = new Intl.DisplayNames([targetLocale], { type: "language" });
|
|
14
|
+
dnCache.set(targetLocale, dn);
|
|
17
15
|
}
|
|
18
|
-
return displayLocale;
|
|
16
|
+
return dn.of(displayLocale) ?? "Unknown locale";
|
|
19
17
|
};
|
|
20
18
|
export {
|
|
21
19
|
getLocaleName
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/getLocaleName.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\n\nexport const getLocaleName = (\n displayLocale: LocalesValues,\n targetLocale: LocalesValues = displayLocale\n): string => {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/localization/getLocaleName.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\n\nconst dnCache = new Map<LocalesValues, Intl.DisplayNames>();\n\nexport const getLocaleName = (\n displayLocale: LocalesValues,\n targetLocale: LocalesValues = displayLocale\n): string => {\n if (typeof Intl?.DisplayNames !== 'function') {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `Intl.DisplayNames is not supported; falling back to raw locale (${displayLocale}). Consider adding a polyfill as https://formatjs.github.io/docs/polyfills/intl-displaynames/`\n );\n }\n return displayLocale;\n }\n\n // new Intl.DisplayNames() is fairly heavy: under the hood every call parses CLDR data and builds a resolver table. In your LocaleSwitcher it’s invoked:\n let dn = dnCache.get(targetLocale);\n if (!dn) {\n dn = new Intl.DisplayNames([targetLocale], { type: 'language' });\n dnCache.set(targetLocale, dn);\n }\n\n return dn.of(displayLocale) ?? 'Unknown locale';\n};\n"],"mappings":"AAEA,MAAM,UAAU,oBAAI,IAAsC;AAEnD,MAAM,gBAAgB,CAC3B,eACA,eAA8B,kBACnB;AACX,MAAI,OAAO,MAAM,iBAAiB,YAAY;AAC5C,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ;AAAA,QACN,mEAAmE,aAAa;AAAA,MAClF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,QAAQ,IAAI,YAAY;AACjC,MAAI,CAAC,IAAI;AACP,SAAK,IAAI,KAAK,aAAa,CAAC,YAAY,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/D,YAAQ,IAAI,cAAc,EAAE;AAAA,EAC9B;AAEA,SAAO,GAAG,GAAG,aAAa,KAAK;AACjC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleName.d.ts","sourceRoot":"","sources":["../../../src/localization/getLocaleName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"getLocaleName.d.ts","sourceRoot":"","sources":["../../../src/localization/getLocaleName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAI7D,eAAO,MAAM,aAAa,GACxB,eAAe,aAAa,EAC5B,eAAc,aAA6B,KAC1C,MAkBF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
|
|
6
6
|
"keywords": [
|
|
@@ -75,9 +75,9 @@
|
|
|
75
75
|
],
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"negotiator": "^1.0.0",
|
|
78
|
-
"@intlayer/
|
|
79
|
-
"@intlayer/
|
|
80
|
-
"@intlayer/dictionaries-entry": "5.4.
|
|
78
|
+
"@intlayer/api": "5.4.2",
|
|
79
|
+
"@intlayer/config": "5.4.2",
|
|
80
|
+
"@intlayer/dictionaries-entry": "5.4.2"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@types/negotiator": "^0.6.3",
|
|
@@ -91,15 +91,15 @@
|
|
|
91
91
|
"tsup": "^8.4.0",
|
|
92
92
|
"typescript": "^5.8.2",
|
|
93
93
|
"@utils/eslint-config": "1.0.4",
|
|
94
|
-
"@utils/ts-config": "1.0.4",
|
|
95
94
|
"@utils/ts-config-types": "1.0.4",
|
|
95
|
+
"@utils/ts-config": "1.0.4",
|
|
96
96
|
"@utils/tsup-config": "1.0.4"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
|
-
"@intlayer/api": "5.4.
|
|
100
|
-
"@intlayer/
|
|
101
|
-
"
|
|
102
|
-
"intlayer": "5.4.
|
|
99
|
+
"@intlayer/api": "5.4.2",
|
|
100
|
+
"@intlayer/dictionaries-entry": "5.4.2",
|
|
101
|
+
"intlayer": "5.4.2",
|
|
102
|
+
"@intlayer/config": "5.4.2"
|
|
103
103
|
},
|
|
104
104
|
"engines": {
|
|
105
105
|
"node": ">=14.18"
|