Skip to content
This repository has been archived by the owner on Aug 30, 2018. It is now read-only.

prevent locale caching #619

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions assets/ajax-cart.js.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ var ajaxCart = (function(module, $) {
// Show empty cart
if (cart.item_count === 0) {
$cartContainer
.append('<p>' + {{ 'cart.general.empty' | t | json }} + '</p>');
.append('<p>' + I18n['cart.general.empty'] + '</p>');
cartCallback(cart);
return;
}
Expand Down Expand Up @@ -343,7 +343,7 @@ var ajaxCart = (function(module, $) {
items: items,
note: cart.note,
totalPrice: Shopify.formatMoney(cart.total_price, settings.moneyFormat),
totalCartDiscount: cart.total_discount === 0 ? 0 : {{ 'cart.general.savings_html' | t: price: '[savings]' | json }}.replace('[savings]', Shopify.formatMoney(cart.total_discount, settings.moneyFormat)),
totalCartDiscount: cart.total_discount === 0 ? 0 : I18n['cart.general.savings_html'].replace('[savings]', Shopify.formatMoney(cart.total_discount, settings.moneyFormat)),
totalCartDiscountApplied: cart.total_discount === 0 ? false : true
}

Expand Down
12 changes: 6 additions & 6 deletions assets/timber.js.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ timber.accessibleNav = function () {

timber.drawersInit = function () {
timber.LeftDrawer = new timber.Drawers('NavDrawer', 'left');
{% if settings.ajax_cart_method == "drawer" %}
if (timber.settings.ajax_cart_method == "drawer") {
timber.RightDrawer = new timber.Drawers('CartDrawer', 'right', {
'onDrawerOpen': ajaxCart.load
});
{% endif %}
}
};

timber.mobileNavToggle = function () {
Expand Down Expand Up @@ -226,12 +226,12 @@ timber.productPage = function (options) {
if (variant.available) {
// Available, enable the submit button, change text, show quantity elements
$addToCart.removeClass('disabled').prop('disabled', false);
$addToCartText.html({{ 'products.product.add_to_cart' | t | json }});
$addToCartText.html(I18n['products.product.add_to_cart']);
$quantityElements.show();
} else {
// Sold out, disable the submit button, change text, hide quantity elements
$addToCart.addClass('disabled').prop('disabled', true);
$addToCartText.html({{ 'products.product.sold_out' | t | json }});
$addToCartText.html(I18n['products.product.sold_out']);
$quantityElements.hide();
}

Expand All @@ -241,7 +241,7 @@ timber.productPage = function (options) {
// Also update and show the product's compare price if necessary
if (variant.compare_at_price > variant.price) {
$comparePrice
.html({{ 'products.product.compare_at' | t | json }} + ' ' + Shopify.formatMoney(variant.compare_at_price, moneyFormat))
.html(I18n['products.product.compare_at'] + ' ' + Shopify.formatMoney(variant.compare_at_price, moneyFormat))
.show();
} else {
$comparePrice.hide();
Expand All @@ -253,7 +253,7 @@ timber.productPage = function (options) {
// To only show available variants, implement linked product options:
// - http://docs.shopify.com/manual/configuration/store-customization/advanced-navigation/linked-product-options
$addToCart.addClass('disabled').prop('disabled', true);
$addToCartText.html({{ 'products.product.unavailable' | t | json }});
$addToCartText.html(I18n['products.product.unavailable']);
$quantityElements.hide();
}
};
Expand Down
3 changes: 3 additions & 0 deletions layout/theme.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@
</div>

{{ 'fastclick.min.js' | asset_url | script_tag }}
{% include 'timber-js-locales' %}
<script> window.timber = window.timber || {}; timber.settings = {{ settings | json }};</script>
{{ 'timber.js' | asset_url | script_tag }}

{% comment %}
Expand All @@ -414,6 +416,7 @@
{% if settings.ajax_cart_method == "drawer" %}
{{ 'handlebars.min.js' | asset_url | script_tag }}
{% include 'ajax-cart-template' %}
{% include 'ajax-cart-locales' %}
{{ 'ajax-cart.js' | asset_url | script_tag }}
<script>
jQuery(function($) {
Expand Down
5 changes: 5 additions & 0 deletions snippets/ajax-cart-locales.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
if ((typeof I18n) === 'undefined') { I18n = {}; }
I18n['cart.general.empty'] = {{ 'cart.general.empty' | t | json }};
I18n['cart.general.savings_html'] = {{ 'cart.general.savings_html' | t: price: '[savings]' | json }};
</script>
7 changes: 7 additions & 0 deletions snippets/timber-js-locales.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
if ((typeof I18n) === 'undefined') { I18n = {}; }
I18n['products.product.add_to_cart'] = {{ 'products.product.add_to_cart' | t | json }};
I18n['products.product.unavailable'] = {{ 'products.product.unavailable' | t | json }};
I18n['products.product.sold_out'] = {{ 'products.product.sold_out' | t | json }};
I18n['products.product.compare_at'] = {{ 'products.product.compare_at' | t | json }};
</script>