@underverse-ui/underverse 1.0.51 → 1.0.52

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.js CHANGED
@@ -1444,9 +1444,9 @@ var defaultTranslations = {
1444
1444
  ko: ko_default,
1445
1445
  ja: ja_default
1446
1446
  };
1447
- function resolveTranslationValue(translations, namespace, key) {
1448
- const parts = namespace.split(".");
1449
- let current = translations;
1447
+ function resolveObjectPath(input, path) {
1448
+ const parts = path.split(".");
1449
+ let current = input;
1450
1450
  for (const part of parts) {
1451
1451
  if (current && typeof current === "object" && part in current) {
1452
1452
  current = current[part];
@@ -1454,11 +1454,12 @@ function resolveTranslationValue(translations, namespace, key) {
1454
1454
  return null;
1455
1455
  }
1456
1456
  }
1457
- if (current && typeof current === "object" && key in current) {
1458
- const value = current[key];
1459
- return typeof value === "string" ? value : null;
1460
- }
1461
- return null;
1457
+ return current;
1458
+ }
1459
+ function resolveTranslationValue(translations, namespace, key) {
1460
+ const namespaceValue = resolveObjectPath(translations, namespace);
1461
+ const value = resolveObjectPath(namespaceValue, key);
1462
+ return typeof value === "string" ? value : null;
1462
1463
  }
1463
1464
  function getUnderverseDefaultTranslation(locale, namespace, key) {
1464
1465
  return resolveTranslationValue(defaultTranslations[locale] ?? defaultTranslations.en, namespace, key) ?? resolveTranslationValue(defaultTranslations.en, namespace, key) ?? key;
@@ -22276,6 +22277,23 @@ var defaultTranslations2 = {
22276
22277
  }
22277
22278
  }
22278
22279
  };
22280
+ function resolveObjectPath2(input, path) {
22281
+ const parts = path.split(".");
22282
+ let current = input;
22283
+ for (const part of parts) {
22284
+ if (current && typeof current === "object" && part in current) {
22285
+ current = current[part];
22286
+ } else {
22287
+ return null;
22288
+ }
22289
+ }
22290
+ return current;
22291
+ }
22292
+ function resolveTranslationValue2(translations, namespace, key) {
22293
+ const namespaceValue = resolveObjectPath2(translations, namespace);
22294
+ const value = resolveObjectPath2(namespaceValue, key);
22295
+ return typeof value === "string" ? value : null;
22296
+ }
22279
22297
  var TranslationContext2 = React70.createContext(null);
22280
22298
  var UnderverseProvider = ({ children, locale = "en", translations }) => {
22281
22299
  const t = React70.useCallback(
@@ -22285,20 +22303,7 @@ var UnderverseProvider = ({ children, locale = "en", translations }) => {
22285
22303
  ...defaultTranslations2[locale],
22286
22304
  ...translations
22287
22305
  };
22288
- const parts = namespace.split(".");
22289
- let current = mergedTranslations;
22290
- for (const part of parts) {
22291
- if (current && typeof current === "object" && part in current) {
22292
- current = current[part];
22293
- } else {
22294
- return key;
22295
- }
22296
- }
22297
- if (current && typeof current === "object" && key in current) {
22298
- const value = current[key];
22299
- return typeof value === "string" ? value : key;
22300
- }
22301
- return key;
22306
+ return resolveTranslationValue2(mergedTranslations, namespace, key) ?? key;
22302
22307
  };
22303
22308
  },
22304
22309
  [locale, translations]
@@ -22327,20 +22332,8 @@ function interpolate(template, params) {
22327
22332
  function getInternalTranslation(namespace, locale) {
22328
22333
  return (key, params) => {
22329
22334
  const localeTranslations = defaultTranslations2[locale] || defaultTranslations2.en;
22330
- const parts = namespace.split(".");
22331
- let current = localeTranslations;
22332
- for (const part of parts) {
22333
- if (current && typeof current === "object" && part in current) {
22334
- current = current[part];
22335
- } else {
22336
- return interpolate(key, params);
22337
- }
22338
- }
22339
- if (current && typeof current === "object" && key in current) {
22340
- const value = current[key];
22341
- return typeof value === "string" ? interpolate(value, params) : interpolate(key, params);
22342
- }
22343
- return interpolate(key, params);
22335
+ const value = resolveTranslationValue2(localeTranslations, namespace, key);
22336
+ return typeof value === "string" ? interpolate(value, params) : interpolate(key, params);
22344
22337
  };
22345
22338
  }
22346
22339
  function useTranslations(namespace) {