Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storefront): BCTHEME-608 Translation mechanism for config.json values should be implemented #2076

Merged
merged 3 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions assets/js/theme/common/utils/translations-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,27 @@ export const createTranslationDictionary = (context) => {
return acc;
}, {});
};

const defaultPageBuilderValues = {
pdp_sale_badge_label: 'On Sale!',
pdp_sold_out_label: 'Sold Out',
'pdp-sale-price-label': 'Now:',
'pdp-non-sale-price-label': 'Was:',
'pdp-retail-price-label': 'MSRP:',
'pdp-custom-fields-tab-label': 'Additional Information',
};

/**
* defines Translation for values from page builder (locally could be found in config.json)
*/
export const translatePageBuilderValues = () => {
$('[data-page-builder-key]').each((_, selector) => {
const $item = $(selector);
const itemText = $item.text().trim();
const itemDefaultTranslation = $item.data('default-translation');

if (itemText === defaultPageBuilderValues[$item.data('page-builder-key')] && itemText !== itemDefaultTranslation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it will be better to change itemDefaultTranslation to JsonTranslation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a taste thing, I prefer to use itemDefaultTranslation

$item.text(itemDefaultTranslation);
}
});
};
16 changes: 15 additions & 1 deletion assets/js/theme/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ import adminBar from './global/adminBar';
import carousel from './common/carousel';
import loadingProgressBar from './global/loading-progress-bar';
import svgInjector from './global/svg-injector';
import { translatePageBuilderValues } from './common/utils/translations-utils';

export default class Global extends PageManager {
onReady() {
const {
channelId, cartId, productId, categoryId, secureBaseUrl, maintenanceModeSettings, adminBarLanguage, showAdminBar,
channelId,
cartId,
productId,
categoryId,
secureBaseUrl,
maintenanceModeSettings,
adminBarLanguage,
showAdminBar,
isProductCardPresented,
isProductListPresented,
} = this.context;
cartPreview(secureBaseUrl, cartId);
quickSearch();
Expand All @@ -35,5 +45,9 @@ export default class Global extends PageManager {
}
loadingProgressBar();
svgInjector();

if (isProductListPresented || isProductCardPresented) {
translatePageBuilderValues();
}
}
}
3 changes: 0 additions & 3 deletions assets/js/theme/product/share.js

This file was deleted.

8 changes: 8 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -960,5 +960,13 @@
"price_max_not_entered": "Max. price is required.",
"price_invalid_value": "Input must be greater than 0.",
"invalid_gift_certificate": "Please enter your valid certificate code."
},
"page_builder": {
"pdp_sale_badge_label": "On Sale!",
"pdp_sold_out_label": "Sold Out",
"pdp-sale-price-label": "Now:",
"pdp-non-sale-price-label": "Was:",
"pdp-retail-price-label": "MSRP:",
"pdp-custom-fields-tab-label": "Additional Information"
}
}
2 changes: 2 additions & 0 deletions templates/components/amp/products/card.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{inject "isProductCardPresented" true}}

<article class="card {{#if alternate}}card--alternate{{/if}}">
<figure class="card-figure">
{{#or price.sale_price_with_tax.value price.sale_price_without_tax.value}}
Expand Down
2 changes: 2 additions & 0 deletions templates/components/amp/products/list.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{inject "isProductListPresented" true}}

<ul class="productList">
{{#each products}}
<li class="product">
Expand Down
11 changes: 10 additions & 1 deletion templates/components/products/card.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{inject "isProductCardPresented" true}}
Copy link
Contributor

@yurytut1993 yurytut1993 Jun 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add the same flag to list-item component since there is a possibility it can be used as a card component (without list) in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it used only in scope of list I prefer to leave as it is


<article
class="card
{{#if alternate}} card--alternate{{/if}}"
Expand Down Expand Up @@ -29,13 +31,17 @@
badge-type='sold-out'
badge_view=theme_settings.product_sold_out_badges
badge_label=theme_settings.pdp_sold_out_label
page_builder_key="pdp_sold_out_label"
default_translation=(lang "page_builder.pdp_sold_out_label")
}}
{{else}}
{{#or price.sale_price_with_tax.value price.sale_price_without_tax.value}}
{{> components/products/product-badge
badge-type='sale'
badge_view=theme_settings.product_sale_badges
badge_label=theme_settings.pdp_sale_badge_label
page_builder_key="pdp_sale_badge_label"
default_translation=(lang "page_builder.pdp_sale_badge_label")
}}
{{/or}}
{{/if}}
Expand Down Expand Up @@ -105,7 +111,10 @@
<h3 class="card-title">
<a aria-label="{{name}},{{> components/products/product-aria-label}}"
href="{{url}}"
{{#if settings.data_tag_enabled}} data-event-type="product-click" {{/if}}>{{name}}</a>
{{#if settings.data_tag_enabled}}data-event-type="product-click"{{/if}}
>
{{name}}
</a>
</h3>

<div class="card-text" data-test-info-type="price">
Expand Down
8 changes: 7 additions & 1 deletion templates/components/products/description-tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
{{/if}}
{{#all product.custom_fields theme_settings.show_custom_fields_tabs}}
<li class="tab">
<a class="tab-title" href="#tab-{{dashcase (lowercase (sanitize theme_settings.pdp-custom-fields-tab-label))}}">{{sanitize theme_settings.pdp-custom-fields-tab-label}}</a>
<a class="tab-title"
href="#tab-{{dashcase (lowercase (sanitize theme_settings.pdp-custom-fields-tab-label))}}"
data-page-builder-key="pdp-custom-fields-tab-label"
data-default-translation="{{lang "page_builder.pdp-custom-fields-tab-label"}}"
>
{{sanitize theme_settings.pdp-custom-fields-tab-label}}
</a>
</li>
{{/all}}
{{#all settings.show_product_reviews theme_settings.show_product_reviews product.reviews.total}}
Expand Down
20 changes: 15 additions & 5 deletions templates/components/products/list-item.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{{#if settings.data_tag_enabled}}
<article class="listItem" data-event-type="{{event}}" data-entity-id="{{id}}" data-position="{{position}}" data-name="{{name}}" data-product-category="{{#each category}}{{#if @last}}{{this}}{{else}}{{this}}, {{/if}}{{/each}}" data-product-brand="{{brand.name}}" data-product-price="{{#if price.with_tax}}{{price.with_tax.value}}{{else}}{{price.without_tax.value}}{{/if}}">
<article class="listItem"
data-event-type="{{event}}"
data-entity-id="{{id}}"
data-position="{{position}}"
data-name="{{name}}"
data-product-category="{{#each category}}{{#if @last}}{{this}}{{else}}{{this}}, {{/if}}{{/each}}"
data-product-brand="{{brand.name}}"
data-product-price="{{#if price.with_tax}}{{price.with_tax.value}}{{else}}{{price.without_tax.value}}{{/if}}"
>
{{else}}
<article class="listItem">
{{/if}}
Expand All @@ -16,13 +24,17 @@
badge-type='sold-out'
badge_view=theme_settings.product_sold_out_badges
badge_label=theme_settings.pdp_sold_out_label
page_builder_key="pdp_sold_out_label"
default_translation=(lang "page_builder.pdp_sold_out_label")
}}
{{else}}
{{#or price.sale_price_with_tax.value price.sale_price_without_tax.value}}
{{> components/products/product-badge
badge-type='sale'
badge_view=theme_settings.product_sale_badges
badge_label=theme_settings.pdp_sale_badge_label
page_builder_key="pdp_sale_badge_label"
default_translation=(lang "page_builder.pdp_sale_badge_label")
}}
{{/or}}
{{/if}}
Expand Down Expand Up @@ -53,10 +65,8 @@
{{/if}}
<h4 class="listItem-title">
<a href="{{url}}"
aria-label="{{name}},{{> components/products/product-aria-label}}"
{{#if settings.data_tag_enabled}}
data-event-type="product-click"
{{/if}}
aria-label="{{name}},{{> components/products/product-aria-label}}"
{{#if settings.data_tag_enabled}}data-event-type="product-click"{{/if}}
>
{{name}}
</a>
Expand Down
2 changes: 2 additions & 0 deletions templates/components/products/list.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{inject "isProductListPresented" true}}

<ul class="productList">
{{#each products}}
<li class="product">
Expand Down
40 changes: 32 additions & 8 deletions templates/components/products/price-range.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{{#and price.retail_price_range.min.with_tax price.retail_price_range.max.with_tax}}
<div class="price-section price-section--withTax rrp-price--withTax">
{{theme_settings.pdp-retail-price-label}}
<span data-page-builder-key="pdp-retail-price-label" data-default-translation="{{lang "page_builder.pdp-retail-price-label"}}">
{{theme_settings.pdp-retail-price-label}}
</span>
<span data-product-rrp-price-with-tax class="price price--rrp">{{price.retail_price_range.min.with_tax.formatted}} - {{price.retail_price_range.max.with_tax.formatted}}</span>
</div>
{{else}}
{{#if price.with_tax}}
<div class="price-section price-section--withTax rrp-price--withTax" style="display: none;">
{{theme_settings.pdp-retail-price-label}}
<span data-page-builder-key="pdp-retail-price-label" data-default-translation="{{lang "page_builder.pdp-retail-price-label"}}">
{{theme_settings.pdp-retail-price-label}}
</span>
<span data-product-rrp-with-tax class="price price--rrp">
{{price.rrp_with_tax.formatted}}
</span>
Expand All @@ -16,14 +20,22 @@
{{#and price.price_range.min.with_tax price.price_range.max.with_tax}}
{{!-- Never display the "non-sales price" if there is a price range to be shown, but we do want the element on the page --}}
<div class="price-section price-section--withTax non-sale-price--withTax" style="display: none;">
{{theme_settings.pdp-non-sale-price-label}}
<span data-page-builder-key="pdp-non-sale-price-label" data-default-translation="{{lang "page_builder.pdp-non-sale-price-label"}}">
{{theme_settings.pdp-non-sale-price-label}}
</span>
<span data-product-non-sale-price-with-tax class="price price--non-sale">
{{price.non_sale_price_with_tax.formatted}}
</span>
</div>
<div class="price-section price-section--withTax" {{#if schema_org}}itemprop="offers" itemscope itemtype="https://schema.org/Offer"{{/if}}>
<span class="price-label">{{theme_settings.pdp-price-label}}</span>
<span class="price-now-label" style="display: none;">{{theme_settings.pdp-sale-price-label}}</span>
<span class="price-now-label"
style="display: none;"
data-page-builder-key="pdp-sale-price-label"
data-default-translation="{{lang "page_builder.pdp-sale-price-label"}}"
>
{{theme_settings.pdp-sale-price-label}}
</span>
<span data-product-price-with-tax class="price price--withTax">{{price.price_range.min.with_tax.formatted}} - {{price.price_range.max.with_tax.formatted}}</span>
{{#and price.price_range.min.without_tax price.price_range.max.without_tax}}
<abbr title="{{lang 'products.including_tax'}}">{{lang 'products.price_with_tax' tax_label=price.price_range.min.tax_label}}</abbr>
Expand All @@ -46,13 +58,17 @@
{{/and}}
{{#and price.retail_price_range.min.without_tax price.retail_price_range.max.without_tax}}
<div class="price-section price-section--withoutTax rrp-price--withoutTax{{#if price.with_tax}} price-section--minor{{/if}}">
{{theme_settings.pdp-retail-price-label}}
<span data-page-builder-key="pdp-retail-price-label" data-default-translation="{{lang "page_builder.pdp-retail-price-label"}}">
{{theme_settings.pdp-retail-price-label}}
</span>
<span data-product-rrp-price-without-tax class="price price--rrp">{{price.retail_price_range.min.without_tax.formatted}} - {{price.retail_price_range.max.without_tax.formatted}}</span>
</div>
{{else}}
{{#if price.without_tax}}
<div class="price-section price-section--withoutTax rrp-price--withoutTax{{#if price.with_tax}} price-section--minor{{/if}}" style="display: none;">
{{theme_settings.pdp-retail-price-label}}
<span data-page-builder-key="pdp-retail-price-label" data-default-translation="{{lang "page_builder.pdp-retail-price-label"}}">
{{theme_settings.pdp-retail-price-label}}
</span>
<span data-product-rrp-price-without-tax class="price price--rrp">
{{price.rrp_without_tax.formatted}}
</span>
Expand All @@ -62,14 +78,22 @@
{{#and price.price_range.min.without_tax price.price_range.max.without_tax}}
{{!-- Never display the "non-sales price" if there is a price range to be shown, but we do want the element on the page --}}
<div class="price-section price-section--withoutTax non-sale-price--withoutTax{{#if price.with_tax}} price-section--minor{{/if}}" style="display: none;">
{{theme_settings.pdp-non-sale-price-label}}
<span data-page-builder-key="pdp-non-sale-price-label" data-default-translation="{{lang "page_builder.pdp-non-sale-price-label"}}">
{{theme_settings.pdp-non-sale-price-label}}
</span>
<span data-product-non-sale-price-without-tax class="price price--non-sale">
{{price.non_sale_price_without_tax.formatted}}
</span>
</div>
<div class="price-section price-section--withoutTax{{#and price_range.min.with_tax price_range.max.with_tax}} price-section--minor{{/and}}" {{#if schema_org}}itemprop="offers" itemscope itemtype="https://schema.org/Offer"{{/if}}>
<span class="price-label">{{theme_settings.pdp-price-label}}</span>
<span class="price-now-label" style="display: none;">{{theme_settings.pdp-sale-price-label}}</span>
<span class="price-now-label"
style="display: none;"
data-page-builder-key="pdp-sale-price-label"
data-default-translation="{{lang "page_builder.pdp-sale-price-label"}}"
>
{{theme_settings.pdp-sale-price-label}}
</span>
<span data-product-price-without-tax class="price price--withoutTax">{{price.price_range.min.without_tax.formatted}} - {{price.price_range.max.without_tax.formatted}}</span>
{{#and price.price_range.min.with_tax price.price_range.max.with_tax}}
<abbr title="{{lang 'products.excluding_tax'}}">{{lang 'products.price_without_tax' tax_label=price.price_range.min.tax_label}}</abbr>
Expand Down
34 changes: 25 additions & 9 deletions templates/components/products/price.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{!-- There are 2 code paths for generating the PDP pricing HTML determined by the following #and condition.
{{!-- There are 2 code paths for generating the PDP pricing HTML determined by the following #and condition.
If a 'price_range' exists then we generate all HTML in price-range.html, otherwise it is defined here. Both code
paths generate the same HTML structure with some differences in whether that element is displayed by default (css styling).

Expand All @@ -9,13 +9,17 @@
{{else}}
{{#if price.with_tax}}
<div class="price-section price-section--withTax rrp-price--withTax" {{#unless price.rrp_with_tax}}style="display: none;"{{/unless}}>
{{theme_settings.pdp-retail-price-label}}
<span data-page-builder-key="pdp-retail-price-label" data-default-translation="{{lang "page_builder.pdp-retail-price-label"}}">
{{theme_settings.pdp-retail-price-label}}
</span>
<span data-product-rrp-with-tax class="price price--rrp">
{{price.rrp_with_tax.formatted}}
</span>
</div>
<div class="price-section price-section--withTax non-sale-price--withTax" {{#unless price.non_sale_price_with_tax}}style="display: none;"{{/unless}}>
{{theme_settings.pdp-non-sale-price-label}}
<span data-page-builder-key="pdp-non-sale-price-label" data-default-translation="{{lang "page_builder.pdp-non-sale-price-label"}}">
{{theme_settings.pdp-non-sale-price-label}}
</span>
<span data-product-non-sale-price-with-tax class="price price--non-sale">
{{price.non_sale_price_with_tax.formatted}}
</span>
Expand All @@ -24,12 +28,16 @@
<span class="price-label" {{#if price.non_sale_price_with_tax}}style="display: none;"{{/if}}>
{{theme_settings.pdp-price-label}}
</span>
<span class="price-now-label" {{#unless price.non_sale_price_with_tax}}style="display: none;"{{/unless}}>
<span class="price-now-label"
{{#unless price.non_sale_price_with_tax}}style="display: none;"{{/unless}}
data-page-builder-key="pdp-sale-price-label"
data-default-translation="{{lang "page_builder.pdp-sale-price-label"}}"
>
{{theme_settings.pdp-sale-price-label}}
</span>
<span data-product-price-with-tax class="price price--withTax">{{price.with_tax.formatted}}</span>
{{#if schema_org}}
<meta itemprop="availability" itemtype="https://schema.org/ItemAvailability"
<meta itemprop="availability" itemtype="https://schema.org/ItemAvailability"
content="https://schema.org/{{#if product.pre_order}}PreOrder{{else if product.out_of_stock}}OutOfStock{{else if product.can_purchase '===' false}}OutOfStock{{else}}InStock{{/if}}">
<meta itemprop="itemCondition" itemtype="https://schema.org/OfferItemCondition" content="https://schema.org/{{product.condition}}Condition">
<meta itemprop="priceCurrency" content="{{currency_selector.active_currency_code}}">
Expand All @@ -47,13 +55,17 @@
{{/if}}
{{#if price.without_tax}}
<div class="price-section price-section--withoutTax rrp-price--withoutTax{{#if price.with_tax}} price-section--minor{{/if}}" {{#unless price.rrp_without_tax}}style="display: none;"{{/unless}}>
{{theme_settings.pdp-retail-price-label}}
<span data-product-rrp-price-without-tax class="price price--rrp">
<span data-page-builder-key="pdp-retail-price-label" data-default-translation="{{lang "page_builder.pdp-retail-price-label"}}">
{{theme_settings.pdp-retail-price-label}}
</span>
<span data-product-rrp-price-without-tax class="price price--rrp">
{{price.rrp_without_tax.formatted}}
</span>
</div>
<div class="price-section price-section--withoutTax non-sale-price--withoutTax{{#if price.with_tax}} price-section--minor{{/if}}" {{#unless price.non_sale_price_without_tax}}style="display: none;"{{/unless}}>
{{theme_settings.pdp-non-sale-price-label}}
<span data-page-builder-key="pdp-non-sale-price-label" data-default-translation="{{lang "page_builder.pdp-non-sale-price-label"}}">
{{theme_settings.pdp-non-sale-price-label}}
</span>
<span data-product-non-sale-price-without-tax class="price price--non-sale">
{{price.non_sale_price_without_tax.formatted}}
</span>
Expand All @@ -62,7 +74,11 @@
<span class="price-label" {{#if price.non_sale_price_without_tax}}style="display: none;"{{/if}}>
{{theme_settings.pdp-price-label}}
</span>
<span class="price-now-label" {{#unless price.non_sale_price_without_tax}}style="display: none;"{{/unless}}>
<span class="price-now-label"
{{#unless price.non_sale_price_without_tax}}style="display: none;"{{/unless}}
data-page-builder-key="pdp-sale-price-label"
data-default-translation="{{lang "page_builder.pdp-sale-price-label"}}"
>
{{theme_settings.pdp-sale-price-label}}
</span>
<span data-product-price-without-tax class="price price--withoutTax{{#if price.with_tax}} price-section--minor{{/if}}">{{price.without_tax.formatted}}</span>
Expand Down
Loading