intor-translator 1.6.1 → 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,19 +256,7 @@ var findMessageInLocales = ({
234
256
  for (const locale of candidateLocales) {
235
257
  const messagesForLocale = messages[locale];
236
258
  if (!messagesForLocale) continue;
237
- if (key in messagesForLocale) {
238
- return messagesForLocale[key];
239
- }
240
- let candidate = messagesForLocale;
241
- const keys = key.split(".");
242
- for (const key2 of keys) {
243
- if (candidate !== null && typeof candidate === "object" && key2 in candidate) {
244
- candidate = candidate[key2];
245
- } else {
246
- candidate = void 0;
247
- break;
248
- }
249
- }
259
+ const candidate = findMessageByPath(messagesForLocale, key.split("."));
250
260
  if (candidate !== void 0) {
251
261
  return candidate;
252
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,19 +255,7 @@ var findMessageInLocales = ({
233
255
  for (const locale of candidateLocales) {
234
256
  const messagesForLocale = messages[locale];
235
257
  if (!messagesForLocale) continue;
236
- if (key in messagesForLocale) {
237
- return messagesForLocale[key];
238
- }
239
- let candidate = messagesForLocale;
240
- const keys = key.split(".");
241
- for (const key2 of keys) {
242
- if (candidate !== null && typeof candidate === "object" && key2 in candidate) {
243
- candidate = candidate[key2];
244
- } else {
245
- candidate = void 0;
246
- break;
247
- }
248
- }
258
+ const candidate = findMessageByPath(messagesForLocale, key.split("."));
249
259
  if (candidate !== void 0) {
250
260
  return candidate;
251
261
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor-translator",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "The Intor translation engine",
5
5
  "author": {
6
6
  "name": "Yiming Liao",