intor-translator 1.6.0 → 1.6.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/index.cjs CHANGED
@@ -226,6 +226,28 @@ var resolveLocales = rura.rura.createHook(
226
226
  );
227
227
 
228
228
  // src/shared/utils/find-message-in-locales.ts
229
+ function findMessageByPath(candidate, segments, start = 0) {
230
+ if (start >= segments.length) {
231
+ return candidate;
232
+ }
233
+ if (candidate === null || typeof candidate !== "object") {
234
+ return void 0;
235
+ }
236
+ const objectCandidate = candidate;
237
+ for (let end = segments.length; end > start; end--) {
238
+ const segment = segments.slice(start, end).join(".");
239
+ if (!(segment in objectCandidate)) continue;
240
+ const next = objectCandidate[segment];
241
+ if (end === segments.length) {
242
+ return next;
243
+ }
244
+ const resolved = findMessageByPath(next, segments, end);
245
+ if (resolved !== void 0) {
246
+ return resolved;
247
+ }
248
+ }
249
+ return void 0;
250
+ }
229
251
  var findMessageInLocales = ({
230
252
  messages,
231
253
  candidateLocales,
@@ -234,16 +256,7 @@ var findMessageInLocales = ({
234
256
  for (const locale of candidateLocales) {
235
257
  const messagesForLocale = messages[locale];
236
258
  if (!messagesForLocale) continue;
237
- let candidate = messagesForLocale;
238
- const keys = key.split(".");
239
- for (const key2 of keys) {
240
- if (candidate !== null && typeof candidate === "object" && key2 in candidate) {
241
- candidate = candidate[key2];
242
- } else {
243
- candidate = void 0;
244
- break;
245
- }
246
- }
259
+ const candidate = findMessageByPath(messagesForLocale, key.split("."));
247
260
  if (candidate !== void 0) {
248
261
  return candidate;
249
262
  }
package/dist/index.js CHANGED
@@ -225,6 +225,28 @@ var resolveLocales = rura.createHook(
225
225
  );
226
226
 
227
227
  // src/shared/utils/find-message-in-locales.ts
228
+ function findMessageByPath(candidate, segments, start = 0) {
229
+ if (start >= segments.length) {
230
+ return candidate;
231
+ }
232
+ if (candidate === null || typeof candidate !== "object") {
233
+ return void 0;
234
+ }
235
+ const objectCandidate = candidate;
236
+ for (let end = segments.length; end > start; end--) {
237
+ const segment = segments.slice(start, end).join(".");
238
+ if (!(segment in objectCandidate)) continue;
239
+ const next = objectCandidate[segment];
240
+ if (end === segments.length) {
241
+ return next;
242
+ }
243
+ const resolved = findMessageByPath(next, segments, end);
244
+ if (resolved !== void 0) {
245
+ return resolved;
246
+ }
247
+ }
248
+ return void 0;
249
+ }
228
250
  var findMessageInLocales = ({
229
251
  messages,
230
252
  candidateLocales,
@@ -233,16 +255,7 @@ var findMessageInLocales = ({
233
255
  for (const locale of candidateLocales) {
234
256
  const messagesForLocale = messages[locale];
235
257
  if (!messagesForLocale) continue;
236
- let candidate = messagesForLocale;
237
- const keys = key.split(".");
238
- for (const key2 of keys) {
239
- if (candidate !== null && typeof candidate === "object" && key2 in candidate) {
240
- candidate = candidate[key2];
241
- } else {
242
- candidate = void 0;
243
- break;
244
- }
245
- }
258
+ const candidate = findMessageByPath(messagesForLocale, key.split("."));
246
259
  if (candidate !== void 0) {
247
260
  return candidate;
248
261
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor-translator",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "The Intor translation engine",
5
5
  "author": {
6
6
  "name": "Yiming Liao",
@@ -56,20 +56,18 @@
56
56
  "engines": {
57
57
  "node": ">=20.0.0"
58
58
  },
59
+ "dependencies": {
60
+ "rura": "^1.1.3"
61
+ },
59
62
  "scripts": {
60
63
  "type": "tsc -p tsconfig.json --noEmit",
61
64
  "test": "vitest",
62
65
  "test:types": "tsx scripts/test-types.ts",
63
66
  "clean": "rm -rf dist",
64
67
  "build": "tsup",
65
- "build:release": "pnpm clean && pnpm build && pnpm api:build",
66
68
  "api:check": "api-extractor run -c api-extractor/index.json",
67
69
  "api:build": "api-extractor run -c api-extractor/index.json --local",
68
- "prepublishOnly": "pnpm build:release",
69
70
  "bench:runtime": "tsx bench/runtime/index.ts",
70
71
  "examples:html": "vite --config examples/html/vite.config.ts"
71
- },
72
- "dependencies": {
73
- "rura": "^1.1.3"
74
72
  }
75
- }
73
+ }