Skip to content

Commit

Permalink
Fixed files not being placed in subdirectories with custom filename
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi-nextbit committed Apr 1, 2016
1 parent 018184b commit 3c870f8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function replace(file, options) {
}

var newFile = new gutil.File({
base: path.dirname(filePath) + '/',
base: file.base,
cwd: file.cwd,
path: filePath,
contents: new Buffer(processed[lang], 'utf8')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-international",
"version": "0.0.3",
"version": "0.0.4",
"description": "A gulp plugin that creates multi language versions of your source files",
"license": "Apache-2.0",
"homepage": "http://github.com/mallocator/gulp-international",
Expand Down
22 changes: 16 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ gulp.task('default', function () {

### locales

Type: string (path)
Type: string (path)
Default: ```./locales```

This tells the script where to look for translation file. Currently supported are .json, .js and .ini files. Each format supports
Expand All @@ -54,7 +54,7 @@ You don't have to use this format. Basically any name is valid for the file and

### filename

Type: string
Type: string
Default: ```${path}/${name}-${lang}.${ext}```

This options allows a user to configure the output format as desired. The default will generate all files in the same directory
Expand All @@ -63,7 +63,7 @@ with the language suffix. A configuration to store each version in it's own path

### delimiter

Type: Object
Type: Object
Default:
```
{
Expand Down Expand Up @@ -95,7 +95,7 @@ This configuration would match any tokens formatted like this: ```<div>${title}<

### whitelist

Type: Array(string)
Type: Array(string)
Default: ```undefined```

This option allows to limit the number of translations that can be used. The names that are whitelisted need to match the filename
Expand All @@ -104,15 +104,25 @@ generated. The option is ignored if it is missing.

### blacklist

Type: Array(string)
Type: Array(string)
Default: ```undefined```

The opposite of the whitelist. Any language specified here will be ignored during processing.


### warn

Type: boolean
Type: boolean
Default: ```true```

This enables warning to be printed out if any tokens are missing.


## Feature Ideas for the future

Maybe I'll implement these one day, maybe not.

* Replace links to standard versions with internationalized versions (can probably also just be done with using tokens for imports)
* Extract non code strings from source and list them as still missing translations
* Warn about unused translation strings
* Make translations available as environment variables in jade/js/coffeescript/etc.
25 changes: 20 additions & 5 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ describe('gulp-international', () => {
it('should support a custom filename format', done => {
var options = {
locales: 'test/locales',
filename: '${lang}/${name}.${ext}'
filename: '${path}/${lang}/${name}.${ext}'
};
helper(options, files => {
expect(files[0].path).to.equal('de_DE/helloworld.html');
expect(files[1].path).to.equal('en_US/helloworld.html');
expect(files[2].path).to.equal('fr_FR/helloworld.html');
expect(files[3].path).to.equal('pt-BR/helloworld.html');
expect(files[0].path).to.equal('test/de_DE/helloworld.html');
expect(files[1].path).to.equal('test/en_US/helloworld.html');
expect(files[2].path).to.equal('test/fr_FR/helloworld.html');
expect(files[3].path).to.equal('test/pt-BR/helloworld.html');
done();
});
});
Expand Down Expand Up @@ -224,6 +224,21 @@ describe('gulp-international', () => {
});


it('should work on source files that have no tokens', done => {
var content = '<html><body><h1>notatoken</h1></body></html>';
var options = {
locales: 'test/locales',
whitelist: 'en_US'
};
helper(options, content, files => {
expect(files.length).to.equal(1);
expect(files[0].contents.toString('utf8')).to.equal('<html><body><h1>notatoken</h1></body></html>');
expect(files[0].path).to.equal('test/helloworld-en_US.html');
done();
});
});


it('should be able to process a larger file with multiple replacements', done => {
var content = `
<html>
Expand Down

0 comments on commit 3c870f8

Please sign in to comment.