@revenexx/cover 0.2.33 → 0.2.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.2.33",
3
+ "version": "0.2.34",
4
4
  "description": "Cover \u2014 revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -40,6 +40,11 @@ export interface LiveProductDoc {
40
40
  categories?: string[];
41
41
  category_labels?: string[];
42
42
  attrs?: Record<string, unknown>;
43
+ /**
44
+ * The same attributes in the document's own locale (`attribute:locale.*`),
45
+ * carrying only the keys a tenant actually translated.
46
+ */
47
+ attrs_locale?: Record<string, unknown>;
43
48
  locale: string;
44
49
  updated_at?: number;
45
50
  }
@@ -292,7 +297,7 @@ export async function mapLiveDocToDetail(doc: LiveProductDoc, locale: Locale = "
292
297
  // attribute definitions so the storefront shows the localized LABEL
293
298
  // (never the technical code), select values as their option label, a
294
299
  // unit suffix where declared, and hides internal/media keys (e.g. image).
295
- attributes: await buildSpecRows(doc.attrs ?? {}, locale),
300
+ attributes: await buildSpecRows(doc.attrs ?? {}, doc.attrs_locale ?? {}, locale),
296
301
  prices: [],
297
302
  };
298
303
  }
@@ -737,7 +742,37 @@ export function renderLiveAttributeValue(
737
742
  * localized label, option/unit-aware value, internal keys hidden. Degrades to
738
743
  * prettified keys if the attribute metadata can't be loaded.
739
744
  */
740
- async function buildSpecRows(attrs: Record<string, unknown>, locale: Locale): Promise<{ id: number; name: string; value: string }[]> {
745
+ /**
746
+ * The two attribute buckets, merged for display: a translated value wins where
747
+ * one exists, the common value carries the rest.
748
+ *
749
+ * Tenants translate SOME attributes, not all — `attrs_locale` holds only the
750
+ * keys with a value in this locale, so a key missing there is the normal case
751
+ * and not a gap. An empty string counts as missing too: a half-filled
752
+ * translation should fall back to the value that IS there rather than blank
753
+ * the row out, which is the difference between a German word on an English
754
+ * page and no answer at all.
755
+ */
756
+ function mergeLocalizedAttrs(
757
+ common: Record<string, unknown>,
758
+ localized: Record<string, unknown>,
759
+ ): Record<string, unknown> {
760
+ const merged = { ...common };
761
+ for (const [key, value] of Object.entries(localized)) {
762
+ if (value === null || value === undefined || value === "") {
763
+ continue;
764
+ }
765
+ merged[key] = value;
766
+ }
767
+ return merged;
768
+ }
769
+
770
+ async function buildSpecRows(
771
+ common: Record<string, unknown>,
772
+ localized: Record<string, unknown>,
773
+ locale: Locale,
774
+ ): Promise<{ id: number; name: string; value: string }[]> {
775
+ const attrs = mergeLocalizedAttrs(common, localized);
741
776
  let meta: Record<string, LiveAttributeMeta> = {};
742
777
  try {
743
778
  meta = await loadLiveAttributeMeta();