@objectstack/core 3.2.5 → 3.2.6
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs +67 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +65 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/fallbacks/fallbacks.test.ts +125 -2
- package/src/fallbacks/index.ts +3 -0
- package/src/fallbacks/memory-i18n.ts +112 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @objectstack/core@3.2.
|
|
2
|
+
> @objectstack/core@3.2.6 build /home/runner/work/spec/spec/packages/core
|
|
3
3
|
> tsup --config ../../tsup.config.ts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
[34mCLI[39m Cleaning output folder
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[34mCJS[39m Build start
|
|
13
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
14
|
-
[32mESM[39m [1mdist/index.js.map [22m[
|
|
15
|
-
[32mESM[39m ⚡️ Build success in
|
|
16
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
17
|
-
[32mCJS[39m [1mdist/index.cjs.map [22m[
|
|
18
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
+
[32mESM[39m [1mdist/index.js [22m[32m150.14 KB[39m
|
|
14
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m318.23 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 120ms
|
|
16
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m153.26 KB[39m
|
|
17
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m319.87 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 120ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 4487ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m63.12 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m63.12 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -55,6 +55,7 @@ __export(index_exports, {
|
|
|
55
55
|
createApiRegistryPlugin: () => createApiRegistryPlugin,
|
|
56
56
|
createLogger: () => createLogger,
|
|
57
57
|
createMemoryCache: () => createMemoryCache,
|
|
58
|
+
createMemoryI18n: () => createMemoryI18n,
|
|
58
59
|
createMemoryJob: () => createMemoryJob,
|
|
59
60
|
createMemoryQueue: () => createMemoryQueue,
|
|
60
61
|
createPluginConfigValidator: () => createPluginConfigValidator,
|
|
@@ -62,6 +63,7 @@ __export(index_exports, {
|
|
|
62
63
|
getEnv: () => getEnv,
|
|
63
64
|
getMemoryUsage: () => getMemoryUsage,
|
|
64
65
|
isNode: () => isNode,
|
|
66
|
+
resolveLocale: () => resolveLocale,
|
|
65
67
|
safeExit: () => safeExit
|
|
66
68
|
});
|
|
67
69
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1093,11 +1095,73 @@ function createMemoryJob() {
|
|
|
1093
1095
|
};
|
|
1094
1096
|
}
|
|
1095
1097
|
|
|
1098
|
+
// src/fallbacks/memory-i18n.ts
|
|
1099
|
+
function resolveLocale(requestedLocale, availableLocales) {
|
|
1100
|
+
if (availableLocales.length === 0) return void 0;
|
|
1101
|
+
if (availableLocales.includes(requestedLocale)) return requestedLocale;
|
|
1102
|
+
const lower = requestedLocale.toLowerCase();
|
|
1103
|
+
const caseMatch = availableLocales.find((l) => l.toLowerCase() === lower);
|
|
1104
|
+
if (caseMatch) return caseMatch;
|
|
1105
|
+
const baseLang = requestedLocale.split("-")[0].toLowerCase();
|
|
1106
|
+
const baseMatch = availableLocales.find((l) => l.toLowerCase() === baseLang);
|
|
1107
|
+
if (baseMatch) return baseMatch;
|
|
1108
|
+
const variantMatch = availableLocales.find((l) => l.split("-")[0].toLowerCase() === baseLang);
|
|
1109
|
+
if (variantMatch) return variantMatch;
|
|
1110
|
+
return void 0;
|
|
1111
|
+
}
|
|
1112
|
+
function createMemoryI18n() {
|
|
1113
|
+
const translations = /* @__PURE__ */ new Map();
|
|
1114
|
+
let defaultLocale = "en";
|
|
1115
|
+
function resolveKey(data, key) {
|
|
1116
|
+
const parts = key.split(".");
|
|
1117
|
+
let current = data;
|
|
1118
|
+
for (const part of parts) {
|
|
1119
|
+
if (current == null || typeof current !== "object") return void 0;
|
|
1120
|
+
current = current[part];
|
|
1121
|
+
}
|
|
1122
|
+
return typeof current === "string" ? current : void 0;
|
|
1123
|
+
}
|
|
1124
|
+
function resolveTranslations(locale) {
|
|
1125
|
+
if (translations.has(locale)) return translations.get(locale);
|
|
1126
|
+
const resolved = resolveLocale(locale, [...translations.keys()]);
|
|
1127
|
+
if (resolved) return translations.get(resolved);
|
|
1128
|
+
return void 0;
|
|
1129
|
+
}
|
|
1130
|
+
return {
|
|
1131
|
+
_fallback: true,
|
|
1132
|
+
_serviceName: "i18n",
|
|
1133
|
+
t(key, locale, params) {
|
|
1134
|
+
const data = resolveTranslations(locale) ?? translations.get(defaultLocale);
|
|
1135
|
+
const value = data ? resolveKey(data, key) : void 0;
|
|
1136
|
+
if (value == null) return key;
|
|
1137
|
+
if (!params) return value;
|
|
1138
|
+
return value.replace(/\{\{(\w+)\}\}/g, (_, name) => String(params[name] ?? `{{${name}}}`));
|
|
1139
|
+
},
|
|
1140
|
+
getTranslations(locale) {
|
|
1141
|
+
return resolveTranslations(locale) ?? {};
|
|
1142
|
+
},
|
|
1143
|
+
loadTranslations(locale, data) {
|
|
1144
|
+
const existing = translations.get(locale) ?? {};
|
|
1145
|
+
translations.set(locale, { ...existing, ...data });
|
|
1146
|
+
},
|
|
1147
|
+
getLocales() {
|
|
1148
|
+
return [...translations.keys()];
|
|
1149
|
+
},
|
|
1150
|
+
getDefaultLocale() {
|
|
1151
|
+
return defaultLocale;
|
|
1152
|
+
},
|
|
1153
|
+
setDefaultLocale(locale) {
|
|
1154
|
+
defaultLocale = locale;
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1096
1159
|
// src/fallbacks/index.ts
|
|
1097
1160
|
var CORE_FALLBACK_FACTORIES = {
|
|
1098
1161
|
cache: createMemoryCache,
|
|
1099
1162
|
queue: createMemoryQueue,
|
|
1100
|
-
job: createMemoryJob
|
|
1163
|
+
job: createMemoryJob,
|
|
1164
|
+
i18n: createMemoryI18n
|
|
1101
1165
|
};
|
|
1102
1166
|
|
|
1103
1167
|
// src/kernel.ts
|
|
@@ -4920,6 +4984,7 @@ var PackageManager = class {
|
|
|
4920
4984
|
createApiRegistryPlugin,
|
|
4921
4985
|
createLogger,
|
|
4922
4986
|
createMemoryCache,
|
|
4987
|
+
createMemoryI18n,
|
|
4923
4988
|
createMemoryJob,
|
|
4924
4989
|
createMemoryQueue,
|
|
4925
4990
|
createPluginConfigValidator,
|
|
@@ -4927,6 +4992,7 @@ var PackageManager = class {
|
|
|
4927
4992
|
getEnv,
|
|
4928
4993
|
getMemoryUsage,
|
|
4929
4994
|
isNode,
|
|
4995
|
+
resolveLocale,
|
|
4930
4996
|
safeExit
|
|
4931
4997
|
});
|
|
4932
4998
|
//# sourceMappingURL=index.cjs.map
|