@bigcommerce/stencil-paper
Advanced tools
Comparing version 1.1.9 to 1.2.0
@@ -7,5 +7,7 @@ 'use strict'; | ||
if (typeof paper.translate === 'function') { | ||
return paper.translate(translationKey, options.hash); | ||
if (paper.translator) { | ||
return paper.translator.translate(translationKey, options.hash); | ||
} | ||
return ''; | ||
}); | ||
@@ -12,0 +14,0 @@ } |
'use strict'; | ||
var _ = require('lodash'); | ||
var localizer = require('./lib/localizer'); | ||
var Translator = require('./lib/translator'); | ||
var Path = require('path'); | ||
@@ -141,4 +141,5 @@ var Fs = require('fs'); | ||
} | ||
// Make translations available to the helpers | ||
self.translate = localizer(acceptLanguage, translations); | ||
self.translator = Translator.create(acceptLanguage, translations); | ||
@@ -240,4 +241,4 @@ callback(); | ||
if (this.translate) { | ||
context.locale_name = this.translate.localeName; | ||
if (this.translator) { | ||
context.locale_name = this.translator.getLocale(); | ||
} | ||
@@ -244,0 +245,0 @@ |
{ | ||
"name": "@bigcommerce/stencil-paper", | ||
"version": "1.1.9", | ||
"version": "1.2.0", | ||
"description": "A stencil plugin to register partials and helpers from handlebars and returns the compiled version for the stencil platform.", | ||
@@ -27,5 +27,5 @@ "main": "index.js", | ||
"handlebars": "^3.0.1", | ||
"hoek": "^2.12.0", | ||
"lodash": "^3.6.0", | ||
"messageformat": "^0.2.2", | ||
"stringz": "^0.1.1", | ||
"tarjan-graph": "^0.3.0" | ||
@@ -32,0 +32,0 @@ }, |
@@ -1,27 +0,40 @@ | ||
var Code = require('code'), | ||
Lab = require('lab'), | ||
Paper = require('../../index'), | ||
lab = exports.lab = Lab.script(), | ||
describe = lab.experiment, | ||
expect = Code.expect, | ||
it = lab.it; | ||
'use strict'; | ||
function c(template, context) { | ||
var theme = new Paper().loadTemplatesSync({template: template}) | ||
const Code = require('code'); | ||
const Lab = require('lab'); | ||
const Paper = require('../../index'); | ||
theme.translate = function (key, params) { | ||
return 'Powered By ' + params.name; | ||
}; | ||
const lab = exports.lab = Lab.script(); | ||
const beforeEach = lab.beforeEach; | ||
const describe = lab.experiment; | ||
const expect = Code.expect; | ||
const it = lab.it; | ||
return theme.render('template', context); | ||
function compile(paper, template, context) { | ||
context = context || {}; | ||
return paper.loadTemplatesSync({ template: template }).render('template', context); | ||
} | ||
describe('lang helper', function() { | ||
var context = { | ||
name: 'BigCommerce' | ||
}; | ||
describe('lang helper', () => { | ||
let context; | ||
let paper; | ||
it('should translate the key with attributes', function(done) { | ||
beforeEach(done => { | ||
context = { | ||
name: 'BigCommerce', | ||
}; | ||
expect(c('{{lang "powered_by" name=name}}', context)) | ||
paper = new Paper(); | ||
paper.translator = { | ||
getLocale: () => 'en', | ||
translate: (key, params) => `Powered By ${params.name}`, | ||
}; | ||
done(); | ||
}); | ||
it('should translate the key with attributes', done => { | ||
expect(compile(paper, '{{lang "powered_by" name=name}}', context)) | ||
.to.be.equal('Powered By BigCommerce'); | ||
@@ -31,2 +44,10 @@ | ||
}); | ||
it('should return an empty string if translator is undefined', done => { | ||
paper.translator = null; | ||
expect(compile(paper, '{{lang "powered_by" name=name}}', context)).to.be.equal(''); | ||
done(); | ||
}); | ||
}); |
@@ -53,6 +53,5 @@ var Code = require('code'), | ||
expect(paper.handlebars.templates['pages/partial']).to.be.a.function(); | ||
expect(paper.translate).to.be.a.function(); | ||
expect(paper.translate('hello', {name: 'Mario'})).to.be.equal('Bonjour Mario'); | ||
expect(paper.translate('hello', {name: 'Already Compiled'})).to.be.equal('Bonjour Already Compiled'); | ||
expect(paper.translate('does_not_exist')).to.be.equal('does_not_exist'); | ||
expect(paper.translator.translate('hello', {name: 'Mario'})).to.be.equal('Bonjour Mario'); | ||
expect(paper.translator.translate('hello', {name: 'Already Compiled'})).to.be.equal('Bonjour Already Compiled'); | ||
expect(paper.translator.translate('does_not_exist')).to.be.equal('does_not_exist'); | ||
@@ -67,3 +66,3 @@ done(); | ||
paper.loadTheme('pages/localeName', 'fr-CA;q=0.8, fr, en', () => { | ||
expect(paper.translate.localeName).to.be.equal('fr'); | ||
expect(paper.translator.getLocale()).to.be.equal('fr'); | ||
@@ -78,3 +77,3 @@ done(); | ||
paper.loadTheme('pages/localeName', 'es-VE, en', () => { | ||
expect(paper.translate.localeName).to.be.equal('en'); | ||
expect(paper.translator.getLocale()).to.be.equal('en'); | ||
@@ -81,0 +80,0 @@ done(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114608
75
2982
+ Addedstringz@^0.1.1
+ Addedstringz@0.1.2(transitive)
- Removedhoek@^2.12.0
- Removedhoek@2.16.3(transitive)