Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add JS strings accessible to translations

Marcin Gębalab97a918c0724
diff --git a/.eslintrc.json b/.eslintrc.json
index 7a6a684552..640e184f7c 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -4,6 +4,9 @@
"jquery": true
},
"extends": ["standard", "plugin:react/recommended"],
+ "globals": {
+ "gettext": true
+ },
"plugins": ["react"],
"parser": "babel-eslint",
"rules": {
diff --git a/saleor/static/js/components/categoryPage/CategoryFilter.js b/saleor/static/js/components/categoryPage/CategoryFilter.js
index 645f9e143c..6c0b0737ac 100644
--- a/saleor/static/js/components/categoryPage/CategoryFilter.js
+++ b/saleor/static/js/components/categoryPage/CategoryFilter.js
@@ -15,7 +15,7 @@ export default class CategoryFilter extends Component {
{parent && (
<div className="parents">
<i className="fa fa-arrow-left" aria-hidden="true"></i>
- <a href={parent.url}>See all {parent.name}</a>
+ <a href={parent.url}>{`${gettext('See all')} ${parent.name}`}</a>
</div>
)}
<ul className={category.parent ? ('childs') : ('childs no-parent')}>
diff --git a/saleor/static/js/components/categoryPage/CategoryPage.js b/saleor/static/js/components/categoryPage/CategoryPage.js
index ef4cb01969..1cbeb36a28 100644
--- a/saleor/static/js/components/categoryPage/CategoryPage.js
+++ b/saleor/static/js/components/categoryPage/CategoryPage.js
@@ -96,7 +96,7 @@ class CategoryPage extends Component {
<div className="row">
<div className="col-md-8">
<ul className="category-breadcrumbs">
- <li><a href="/">Home</a></li>
+ <li><a href="/">{gettext('Home')}</a></li>
{category.ancestors && (category.ancestors.map((ancestor) => {
return (
<li key={ancestor.pk}><a href={ancestor.url}>{ancestor.name}</a></li>
@@ -113,11 +113,9 @@ class CategoryPage extends Component {
<div className="row">
<div className="col-md-3">
<div className="product-filters">
- <CategoryFilter
- category={category}
- />
+ <CategoryFilter category={category} />
</div>
- <h2>Filters:</h2>
+ <h2>{gettext('Filters')}</h2>
<div className="product-filters">
<ProductFilters
attributes={attributes}
diff --git a/saleor/static/js/components/categoryPage/NoResults.js b/saleor/static/js/components/categoryPage/NoResults.js
index 4c61ab7af2..c5fe602a05 100644
--- a/saleor/static/js/components/categoryPage/NoResults.js
+++ b/saleor/static/js/components/categoryPage/NoResults.js
@@ -8,8 +8,8 @@ const NoResults = () => {
<div className="no-results">
<div className="col-12">
<InlineSVG src={noResultsImg} />
- <p>Sorry, no matches found for your request.</p>
- <p>Try again or shop new arrivals.</p>
+ <p>{gettext('Sorry, no matches found for your request.')}</p>
+ <p>{gettext('Try again or shop new arrivals.')}</p>
</div>
</div>
);
diff --git a/saleor/static/js/components/categoryPage/PriceFilter.js b/saleor/static/js/components/categoryPage/PriceFilter.js
index 901d2d534b..94d132b5fb 100644
--- a/saleor/static/js/components/categoryPage/PriceFilter.js
+++ b/saleor/static/js/components/categoryPage/PriceFilter.js
@@ -44,7 +44,7 @@ export default class PriceFilter extends Component {
<div className="price-range">
<FilterHeader
onClick={this.changeVisibility}
- title="Price range"
+ title={gettext('Price range')}
visibility={visibility}
/>
{visibility && (
@@ -54,7 +54,7 @@ export default class PriceFilter extends Component {
defaultValue={minPrice}
min="0"
onKeyUp={this.checkKey}
- placeholder="min"
+ placeholder={gettext('from')}
ref={input => (this.minPriceInput = input)}
type="number"
/>
@@ -64,11 +64,11 @@ export default class PriceFilter extends Component {
defaultValue={maxPrice}
min="0"
onKeyUp={this.checkKey}
- placeholder="max"
+ placeholder={gettext('to')}
ref={input => (this.maxPriceInput = input)}
type="number"
/>
- <button className="btn" onClick={this.updateFilter}>Update</button>
+ <button className="btn" onClick={this.updateFilter}>{gettext('Update')}</button>
</div>
)}
</div>
diff --git a/saleor/static/js/components/categoryPage/ProductList.js b/saleor/static/js/components/categoryPage/ProductList.js
index 400a0fa7bd..081ce7335a 100644
--- a/saleor/static/js/components/categoryPage/ProductList.js
+++ b/saleor/static/js/components/categoryPage/ProductList.js
@@ -26,7 +26,7 @@ class ProductList extends Component {
</div>
<div className="load-more">
{hasNextPage && (
- <button className="btn" onClick={this.onLoadMore}>Load more</button>
+ <button className="btn" onClick={this.onLoadMore}>{gettext('Load more')}</button>
)}
</div>
</div>
diff --git a/saleor/static/js/components/categoryPage/ProductPrice.js b/saleor/static/js/components/categoryPage/ProductPrice.js
index dbb744b990..865393e28b 100644
--- a/saleor/static/js/components/categoryPage/ProductPrice.js
+++ b/saleor/static/js/components/categoryPage/ProductPrice.js
@@ -8,7 +8,7 @@ const ProductPrice = ({ availability, price }) => {
return (
<div>
<span itemProp="price">
- {isPriceRange && <span>from </span>}
+ {isPriceRange && <span>{gettext('from')} </span>}
{gross} <span className="currency"> {price.currency}</span>
</span>
{discount && (
diff --git a/saleor/static/js/components/categoryPage/SortBy.js b/saleor/static/js/components/categoryPage/SortBy.js
index 1531888cd1..98a2094596 100644
--- a/saleor/static/js/components/categoryPage/SortBy.js
+++ b/saleor/static/js/components/categoryPage/SortBy.js
@@ -40,30 +40,30 @@ export default class sortBy extends Component {
{sortedValue ? (
sortedValue.search('-') ? (
<div>
- <span>Sort by: <strong>{sortedValue}</strong></span>
+ <span>{gettext('Sort by:')} <strong>{sortedValue}</strong></span>
<div className="sort-order-icon">
<InlineSVG key="arrowUpIcon" src={arrowUpIcon} />
</div>
</div>
) : (
<div>
- <span>Sort by: <strong>{sortedValue.replace('-', '')}</strong></span>
+ <span>{gettext('Sort by:')} <strong>{sortedValue.replace('-', '')}</strong></span>
<div className="sort-order-icon">
<InlineSVG key="arrowDownIcon" src={arrowDownIcon} />
</div>
</div>
)
) : (
- <span>Sort by: <strong>default</strong></span>
+ <span>{gettext('Sort by:')} <strong>{gettext('default')}</strong></span>
)}
</button>
{visibility && (
<ul className="sort-list">
<li className="name">
<div className="row">
- <div className="col-md-6">Sort by <strong>Name</strong></div>
+ <div className="col-md-6">{gettext('Sort by:')} <strong>{gettext('Name')}</strong></div>
<div className="col-md-6">
- <span className="name" onClick={this.setSorting}>ascending</span>
+ <span className="name" onClick={this.setSorting}>{gettext('ascending')}</span>
<div className="float-right sort-order-icon">
<InlineSVG src={arrowUpIcon} />
</div>
@@ -72,7 +72,7 @@ export default class sortBy extends Component {
<div className="row">
<div className="col-md-6"></div>
<div className="col-md-6">
- <span className="-name" onClick={this.setSorting}>descending</span>
+ <span className="-name" onClick={this.setSorting}>{gettext('descending')}</span>
<div className="float-right sort-order-icon">
<InlineSVG src={arrowDownIcon} />
</div>
@@ -81,9 +81,9 @@ export default class sortBy extends Component {
</li>
<li className="price">
<div className="row">
- <div className="col-md-6">Sort by <strong>Price</strong></div>
+ <div className="col-md-6">{gettext('Sort by:')} <strong>{gettext('Price')}</strong></div>
<div className="col-md-6">
- <span className="price" onClick={this.setSorting}>ascending</span>
+ <span className="price" onClick={this.setSorting}>{gettext('ascending')}</span>
<div className="float-right sort-order-icon">
<InlineSVG src={arrowUpIcon} />
</div>
@@ -92,7 +92,7 @@ export default class sortBy extends Component {
<div className="row">
<div className="col-md-6"></div>
<div className="col-md-6">
- <span className="-price" onClick={this.setSorting}>descending</span>
+ <span className="-price" onClick={this.setSorting}>{gettext('descending')}</span>
<div className="float-right sort-order-icon">
<InlineSVG src={arrowDownIcon} />
</div>
diff --git a/saleor/static/js/components/variantPicker/QuantityInput.js b/saleor/static/js/components/variantPicker/QuantityInput.js
index 70ddcb9383..30579cb2e7 100644
--- a/saleor/static/js/components/variantPicker/QuantityInput.js
+++ b/saleor/static/js/components/variantPicker/QuantityInput.js
@@ -18,7 +18,7 @@ export default class QuantityInput extends Component {
});
return (
<div className={formGroupClasses}>
- <label className="control-label product__variant-picker__label" htmlFor="id_quantity">Quantity</label>
+ <label className="control-label product__variant-picker__label" htmlFor="id_quantity">{gettext('Quantity')}</label>
<input
className="form-control"
defaultValue={quantity}
diff --git a/saleor/static/js/components/variantPicker/VariantPicker.js b/saleor/static/js/components/variantPicker/VariantPicker.js
index fe6dcdcf23..506587ebde 100644
--- a/saleor/static/js/components/variantPicker/VariantPicker.js
+++ b/saleor/static/js/components/variantPicker/VariantPicker.js
@@ -109,7 +109,7 @@ export default class VariantPicker extends Component {
className={addToCartBtnClasses}
onClick={this.handleAddToCart}
disabled={disableAddToCart}>
- Add to cart
+ {gettext('Add to cart')}
</button>
</div>
</div>
diff --git a/saleor/urls.py b/saleor/urls.py
index fb1dad36bb..895563d052 100644
--- a/saleor/urls.py
+++ b/saleor/urls.py
@@ -4,6 +4,8 @@ from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.sitemaps.views import sitemap
from django.contrib.staticfiles.views import serve
+from django.views.i18n import javascript_catalog
+
from graphene_django.views import GraphQLView
from .cart.urls import urlpatterns as cart_urls
@@ -28,6 +30,7 @@ urlpatterns = [
url(r'^checkout/', include(checkout_urls, namespace='checkout')),
url(r'^dashboard/', include(dashboard_urls, namespace='dashboard')),
url(r'^graphql', GraphQLView.as_view(graphiql=settings.DEBUG)),
+ url(r'^jsi18n/$', javascript_catalog, name='javascript-catalog'),
url(r'^order/', include(order_urls, namespace='order')),
url(r'^products/', include(product_urls, namespace='product')),
url(r'^profile/', include(userprofile_urls, namespace='profile')),
diff --git a/templates/base.html b/templates/base.html
index 151548e760..8d578b90f7 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -200,6 +200,7 @@
</footer>
{% endblock %}
{% block footer_scripts %}
+ <script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
{% render_bundle 'vendor' 'js' %}
{% render_bundle 'storefront' 'js' %}
{% endblock footer_scripts %}