Skip to content

Commit

Permalink
fixed placeholders (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
fnhipster authored Nov 7, 2024
1 parent dca8aff commit 59834f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
35 changes: 1 addition & 34 deletions blocks/product-details/product-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,40 +136,7 @@ export default async function decorate(block) {

const langDefinitions = {
default: {
PDP: {
Product: {
Incrementer: { label: placeholders.pdpProductIncrementer },
OutOfStock: { label: placeholders.pdpProductOutofstock },
AddToCart: { label: placeholders.pdpProductAddtocart },
Details: { label: placeholders.pdpProductDetails },
RegularPrice: { label: placeholders.pdpProductRegularprice },
SpecialPrice: { label: placeholders.pdpProductSpecialprice },
PriceRange: {
From: { label: placeholders.pdpProductPricerangeFrom },
To: { label: placeholders.pdpProductPricerangeTo },
},
Image: { label: placeholders.pdpProductImage },
},
Swatches: {
Required: { label: placeholders.pdpSwatchesRequired },
},
Carousel: {
label: placeholders.pdpCarousel,
Next: { label: placeholders.pdpCarouselNext },
Previous: { label: placeholders.pdpCarouselPrevious },
Slide: { label: placeholders.pdpCarouselSlide },
Controls: {
label: placeholders.pdpCarouselControls,
Button: { label: placeholders.pdpCarouselControlsButton },
},
},
Overlay: {
Close: { label: placeholders.pdpOverlayClose },
},
},
Custom: {
AddingToCart: { label: placeholders.pdpCustomAddingtocart },
},
...placeholders,
},
};

Expand Down
16 changes: 11 additions & 5 deletions scripts/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,17 @@ async function fetchPlaceholders(prefix = 'default') {
})
.then((json) => {
const placeholders = {};
json.data
.filter((placeholder) => placeholder.Key)
.forEach((placeholder) => {
placeholders[toCamelCase(placeholder.Key)] = placeholder.Text;
});
json.data.forEach(({ Key, Value }) => {
if (Key) {
const keys = Key.split('.');
const lastKey = keys.pop();
const target = keys.reduce((obj, key) => {
obj[key] = obj[key] || {};
return obj[key];
}, placeholders);
target[lastKey] = Value;
}
});
window.placeholders[prefix] = placeholders;
resolve(window.placeholders[prefix]);
})
Expand Down

0 comments on commit 59834f8

Please sign in to comment.