easygettext
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -8,3 +8,3 @@ 'use strict'; | ||
var DEFAULT_DELIM = exports.DEFAULT_DELIM = { | ||
var DEFAULT_DELIMITERS = exports.DEFAULT_DELIMITERS = { | ||
start: '{{', | ||
@@ -11,0 +11,0 @@ end: '}}' |
@@ -37,4 +37,4 @@ #!/usr/bin/env node | ||
var outputFile = argv.output || null; | ||
var startDelim = argv.startDelim === undefined ? constants.DEFAULT_DELIM.start : argv.startDelim; | ||
var endDelim = argv.endDelim === undefined ? constants.DEFAULT_DELIM.end : argv.endDelim; | ||
var startDelimiter = argv.startDelimiter === undefined ? constants.DEFAULT_DELIMITERS.start : argv.startDelimiter; | ||
var endDelimiter = argv.endDelimiter === undefined ? constants.DEFAULT_DELIMITERS.end : argv.endDelimiter; | ||
// Allow to pass extra attributes, e.g. gettext-extract --attribute v-translate --attribute v-i18n | ||
@@ -63,4 +63,4 @@ var extraAttribute = argv.attribute || false; | ||
attributes: attributes, | ||
startDelim: startDelim, | ||
endDelim: endDelim | ||
startDelimiter: startDelimiter, | ||
endDelimiter: endDelimiter | ||
}); | ||
@@ -67,0 +67,0 @@ |
@@ -120,4 +120,4 @@ 'use strict'; | ||
this.options = _extends({ | ||
startDelim: '{{', | ||
endDelim: '}}', | ||
startDelimiter: '{{', | ||
endDelimiter: '}}', | ||
attributes: constants.DEFAULT_ATTRIBUTES, | ||
@@ -140,5 +140,5 @@ lineNumbers: false | ||
var spacesOrPipeChar = '\\s*\\|\\s*'; // matches the pipe string of the filter | ||
var start = _this.options.startDelim.replace(ESCAPE_REGEX, '\\$&'); | ||
var end = _this.options.endDelim.replace(ESCAPE_REGEX, '\\$&'); | ||
return new RegExp(start + '.*' + startOrEndQuotes + '(.*)' + startOrEndQuotes + spacesOrPipeChar + attribute + '.*' + end); | ||
var start = _this.options.startDelimiter.replace(ESCAPE_REGEX, '\\$&'); | ||
var end = _this.options.endDelimiter.replace(ESCAPE_REGEX, '\\$&'); | ||
return new RegExp(start + '[^\'"]*' + startOrEndQuotes + '(.*)' + startOrEndQuotes + spacesOrPipeChar + attribute + '\\s*' + end); | ||
}); | ||
@@ -145,0 +145,0 @@ } |
@@ -130,4 +130,4 @@ 'use strict'; | ||
var extractorWithParams = new _extract.Extractor({ | ||
startDelim: '', | ||
endDelim: '' | ||
startDelimiter: '', | ||
endDelimiter: '' | ||
}); | ||
@@ -137,4 +137,20 @@ var data4 = extractorWithParams._extractTranslationData(fixtures.FILENAME_0, fixtures.HTML3_FILTER4); | ||
(0, _chai.expect)(data4[0].text).to.equal('So long, my dear'); | ||
var data5 = extractor._extractTranslationData(fixtures.FILENAME_0, fixtures.HTML3_FILTER5); | ||
(0, _chai.expect)(data5.length).to.equal(1); | ||
(0, _chai.expect)(data5[0].text).to.equal('Guns\'n roses, my dear'); | ||
var data6 = extractorWithParams._extractTranslationData(fixtures.FILENAME_0, fixtures.HTML3_FILTER6); | ||
(0, _chai.expect)(data6.length).to.equal(1); | ||
(0, _chai.expect)(data6[0].text).to.equal('Guns\'n roses, my dear'); | ||
var extractorWithBindOnce = new _extract.Extractor({ | ||
startDelimiter: '::', | ||
endDelimiter: '' | ||
}); | ||
var data7 = extractorWithBindOnce._extractTranslationData(fixtures.FILENAME_0, fixtures.HTML3_FILTER7); | ||
(0, _chai.expect)(data7.length).to.equal(1); | ||
(0, _chai.expect)(data7[0].text).to.equal('Guns\'n roses, my dear'); | ||
}); | ||
}); | ||
//# sourceMappingURL=extract.spec.js.map |
@@ -24,2 +24,5 @@ 'use strict'; | ||
var HTML3_FILTER4 = exports.HTML3_FILTER4 = "<h2 attr=\""So long, my dear' |i18n\">Martha</h2>"; | ||
var HTML3_FILTER5 = exports.HTML3_FILTER5 = "<h2 attr=\"{{ 'Guns\'n roses, my dear' |i18n }}\">Martha</h2>"; | ||
var HTML3_FILTER6 = exports.HTML3_FILTER6 = "<h2 attr=\"'Guns\'n roses, my dear' |i18n \">Martha</h2>"; | ||
var HTML3_FILTER7 = exports.HTML3_FILTER7 = "<h2 attr=\"::'Guns\'n roses, my dear' |i18n \">Martha</h2>"; | ||
@@ -26,0 +29,0 @@ var HTML4_TAG0 = exports.HTML4_TAG0 = '<translate>Duck</translate>'; |
{ | ||
"name": "easygettext", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Simple tools to extract gettext strings", | ||
@@ -5,0 +5,0 @@ "main": "dist/index", |
@@ -53,3 +53,2 @@ # easygettext | ||
<div placeholder="{{ 'Hello World' | translate }}"></div> | ||
<div placeholder="'Hello World' | translate"></div> | ||
<div placeholder="{{ scopeVariable || ('Hello World' | translate) }}"></div> | ||
@@ -59,2 +58,4 @@ <get-text>Hello World</get-text> | ||
<translate>Hello World</translate> | ||
<!-- The default delimiters '{{' and '}}' must be changed to empty strings to handle this example --> | ||
<div placeholder="'Hello World' | translate"></div> | ||
``` | ||
@@ -72,3 +73,3 @@ | ||
gettext-extract --startDelim '[#' --endDelim '#]' --output dictionary.pot foo.html bar.jade | ||
gettext-extract --startDelimiter '[#' --endDelimiter '#]' --output dictionary.pot foo.html bar.jade | ||
``` | ||
@@ -75,0 +76,0 @@ |
@@ -7,6 +7,6 @@ export const DEFAULT_ATTRIBUTES = [ | ||
export const DEFAULT_DELIM = { | ||
start: '{{', | ||
end: '}}' | ||
} | ||
export const DEFAULT_DELIMITERS = { | ||
start: '{{', | ||
end: '}}', | ||
}; | ||
@@ -13,0 +13,0 @@ export const ATTRIBUTE_COMMENT = 'comment'; |
@@ -20,4 +20,4 @@ #!/usr/bin/env node | ||
const outputFile = argv.output || null; | ||
const startDelim = argv.startDelim === undefined ? constants.DEFAULT_DELIM.start : argv.startDelim; | ||
const endDelim = argv.endDelim === undefined ? constants.DEFAULT_DELIM.end : argv.endDelim; | ||
const startDelimiter = argv.startDelimiter === undefined ? constants.DEFAULT_DELIMITERS.start : argv.startDelimiter; | ||
const endDelimiter = argv.endDelimiter === undefined ? constants.DEFAULT_DELIMITERS.end : argv.endDelimiter; | ||
// Allow to pass extra attributes, e.g. gettext-extract --attribute v-translate --attribute v-i18n | ||
@@ -44,4 +44,4 @@ const extraAttribute = argv.attribute || false; | ||
attributes, | ||
startDelim, | ||
endDelim | ||
startDelimiter, | ||
endDelimiter, | ||
}); | ||
@@ -48,0 +48,0 @@ |
@@ -75,4 +75,4 @@ import cheerio from 'cheerio'; | ||
this.options = Object.assign({ | ||
startDelim: '{{', | ||
endDelim: '}}', | ||
startDelimiter: '{{', | ||
endDelimiter: '}}', | ||
attributes: constants.DEFAULT_ATTRIBUTES, | ||
@@ -93,7 +93,7 @@ lineNumbers: false, | ||
this.filterRegexps = this.options.attributes.map((attribute) => { | ||
const startOrEndQuotes = `(?:\\"|[\\'"])` // matches simple / double / HTML quotes | ||
const spacesOrPipeChar = `\\s*\\|\\s*` // matches the pipe string of the filter | ||
const start = this.options.startDelim.replace(ESCAPE_REGEX, '\\$&'); | ||
const end = this.options.endDelim.replace(ESCAPE_REGEX, '\\$&'); | ||
return new RegExp(`${start}.*${startOrEndQuotes}(.*)${startOrEndQuotes}${spacesOrPipeChar}${attribute}.*${end}`); | ||
const startOrEndQuotes = `(?:\\"|[\\'"])`; // matches simple / double / HTML quotes | ||
const spacesOrPipeChar = `\\s*\\|\\s*`; // matches the pipe string of the filter | ||
const start = this.options.startDelimiter.replace(ESCAPE_REGEX, '\\$&'); | ||
const end = this.options.endDelimiter.replace(ESCAPE_REGEX, '\\$&'); | ||
return new RegExp(`${start}[^'"]*${startOrEndQuotes}(.*)${startOrEndQuotes}${spacesOrPipeChar}${attribute}\\s*${end}`); | ||
}); | ||
@@ -100,0 +100,0 @@ } |
@@ -122,4 +122,4 @@ import {Extractor} from './extract.js'; | ||
const extractorWithParams = new Extractor({ | ||
startDelim: '', | ||
endDelim: '', | ||
startDelimiter: '', | ||
endDelimiter: '', | ||
}); | ||
@@ -129,3 +129,19 @@ const data4 = extractorWithParams._extractTranslationData(fixtures.FILENAME_0, fixtures.HTML3_FILTER4); | ||
expect(data4[0].text).to.equal('So long, my dear'); | ||
const data5 = extractor._extractTranslationData(fixtures.FILENAME_0, fixtures.HTML3_FILTER5); | ||
expect(data5.length).to.equal(1); | ||
expect(data5[0].text).to.equal('Guns\'n roses, my dear'); | ||
const data6 = extractorWithParams._extractTranslationData(fixtures.FILENAME_0, fixtures.HTML3_FILTER6); | ||
expect(data6.length).to.equal(1); | ||
expect(data6[0].text).to.equal('Guns\'n roses, my dear'); | ||
const extractorWithBindOnce = new Extractor({ | ||
startDelimiter: '::', | ||
endDelimiter: '', | ||
}); | ||
const data7 = extractorWithBindOnce._extractTranslationData(fixtures.FILENAME_0, fixtures.HTML3_FILTER7); | ||
expect(data7.length).to.equal(1); | ||
expect(data7[0].text).to.equal('Guns\'n roses, my dear'); | ||
}); | ||
}); |
@@ -22,2 +22,5 @@ export const FILENAME_0 = 'foo.htm'; | ||
export const HTML3_FILTER4 = "<h2 attr=\""So long, my dear' |i18n\">Martha</h2>"; | ||
export const HTML3_FILTER5 = "<h2 attr=\"{{ 'Guns\'n roses, my dear' |i18n }}\">Martha</h2>"; | ||
export const HTML3_FILTER6 = "<h2 attr=\"'Guns\'n roses, my dear' |i18n \">Martha</h2>"; | ||
export const HTML3_FILTER7 = "<h2 attr=\"::'Guns\'n roses, my dear' |i18n \">Martha</h2>"; | ||
@@ -24,0 +27,0 @@ export const HTML4_TAG0 = '<translate>Duck</translate>'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
118521
1461
120
0