poly-lexis 0.5.3 → 0.6.0

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.
@@ -532,6 +532,21 @@ var init_language_fallback = __esm({
532
532
  // src/translations/utils/utils.ts
533
533
  import * as fs from "fs";
534
534
  import * as path2 from "path";
535
+ function flattenObject(obj, prefix = "") {
536
+ const result = {};
537
+ for (const [key, value] of Object.entries(obj)) {
538
+ const newKey = prefix ? `${prefix}.${key}` : key;
539
+ if (typeof value === "string") {
540
+ result[newKey] = value;
541
+ } else if (typeof value === "object" && value !== null) {
542
+ Object.assign(result, flattenObject(value, newKey));
543
+ }
544
+ }
545
+ return result;
546
+ }
547
+ function isNestedObject(obj) {
548
+ return Object.values(obj).some((value) => typeof value === "object" && value !== null);
549
+ }
535
550
  function readTranslations(translationsPath, language) {
536
551
  const langPath = path2.join(translationsPath, language);
537
552
  if (!fs.existsSync(langPath)) {
@@ -543,7 +558,12 @@ function readTranslations(translationsPath, language) {
543
558
  const namespace = path2.basename(file, ".json");
544
559
  const filePath = path2.join(langPath, file);
545
560
  const content = fs.readFileSync(filePath, "utf-8");
546
- translations[namespace] = JSON.parse(content);
561
+ const parsed = JSON.parse(content);
562
+ if (isNestedObject(parsed)) {
563
+ translations[namespace] = flattenObject(parsed);
564
+ } else {
565
+ translations[namespace] = parsed;
566
+ }
547
567
  }
548
568
  return translations;
549
569
  }