Skip to content

Commit 8a45cd7

Browse files
committed
Ignore tokens option now accepts RegExp
1 parent 2fefcaa commit 8a45cd7

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function translate(options, contents, copied, filePath) {
205205
throw new Error('No translation dictionaries available to create any files!');
206206
}
207207
var i = contents.indexOf(options.delimiter.prefix);
208-
if (!options.ignoreTokens) {
208+
if (options.ignoreTokens === false && !(options.ignoreTokens instanceof RegExp && options.ignoreTokens.test(filePath))) {
209209
while ((i !== -1)) {
210210
var endMatch, length, token, key;
211211
var tail = contents.substr(i);
@@ -287,7 +287,7 @@ function replace(file, options) {
287287
* @param options
288288
* @returns {Stream}
289289
*/
290-
module.exports = function (options) {
290+
module.exports = function(options) {
291291
if (options) {
292292
if (options.whitelist && !_.isArray(options.whitelist)) {
293293
options.whitelist = [options.whitelist];

readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,12 @@ of the newly generated ones.
166166

167167
### ignoreTokens
168168

169-
Type: boolean
169+
Type: boolean|RegExp
170170
Default: ```false```
171171

172172
When set to true the plugin will ignore all tokens, but still create new files as if they were different for each language. This
173-
differs from a dryRun, which would instead pass on the original file.
173+
differs from a dryRun, which would instead pass on the original file. If the settings is a regular expression then only files
174+
with a matching (original) filename will be ignored.
174175

175176

176177
### includeOriginal

test/index.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,23 @@ describe('gulp-international', () => {
130130
});
131131

132132

133+
it('should only ignore matching files if the ignore tokens option is a regular expression', done => {
134+
var options = {locales: 'test/locales', ignoreTokens: /hello/};
135+
helper(options, files => {
136+
expect(files.length).to.equal(4);
137+
expect(files[0].contents.toString('utf8')).to.equal('<html><body><h1>R.token1</h1></body></html>');
138+
expect(files[0].path).to.equal('test/helloworld-de_DE.html');
139+
expect(files[1].contents.toString('utf8')).to.equal('<html><body><h1>R.token1</h1></body></html>');
140+
expect(files[1].path).to.equal('test/helloworld-en_US.html');
141+
expect(files[2].contents.toString('utf8')).to.equal('<html><body><h1>R.token1</h1></body></html>');
142+
expect(files[2].path).to.equal('test/helloworld-fr_FR.html');
143+
expect(files[3].contents.toString('utf8')).to.equal('<html><body><h1>R.token1</h1></body></html>');
144+
expect(files[3].path).to.equal('test/helloworld-pt-BR.html');
145+
done();
146+
});
147+
});
148+
149+
133150
it ('should include the original file as well as all translations', done => {
134151
var options = { locales: 'test/locales', includeOriginal: true };
135152
helper(options, files => {

0 commit comments

Comments
 (0)