Skip to content

Commit

Permalink
up - add keep_no_reference, 默认移除不再使用的词条
Browse files Browse the repository at this point in the history
  • Loading branch information
zemzheng committed Jan 11, 2017
1 parent a86d263 commit b1bcce3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ const PLUGIN_NAME = 'gulp-ziey-i18n';
module.exports = function( options ){
// options
// .template
// .options : template 设置
// .po : po 文件内容
// .lang : po 文件的语言标识
// .path : po 文件路径
// .options : template 设置
// .po : po 文件内容
// .lang : po 文件的语言标识
// .path : po 文件路径
// .keep_no_reference : 是否保留不再引用的词条,默认为 false

if( fs.existsSync( options.path ) ){
options.po = fs.readFileSync( options.path, 'utf-8' ) || options.po || '';
}

gettext.handlePoTxt( options.lang, options.po );
gettext.setLang( options.lang );
options.keep_no_reference || gettext.clearCurrentDictEmptyItem();

return through(
function( file ) {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-ziey-i18n",
"version": "1.0.1",
"version": "1.0.2",
"description": "gulp i18n tool by zem",
"main": "index.js",
"scripts": {
Expand All @@ -25,8 +25,8 @@
"dependencies": {
"gulp-util": "~2.2.17",
"through": "~2.3.4",
"ziey-gettext": "^0.6.3",
"ziey-utils": "^0.5.1"
"ziey-gettext": "^0.6.5",
"ziey-utils": "^0.5.3"
},
"repository": {
"type": "git",
Expand All @@ -39,4 +39,4 @@
"readmeFilename": "README",
"_id": "gulp-ziey-i18n@0.0.7",
"_from": "gulp-ziey-i18n@"
}
}
13 changes: 7 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

// options
// .template
// .options : template 设置
// .openTag : '{{', 默认值
// .closeTag : '}}', 默认值
// .po : po 文件内容
// .lang : po 文件的语言标识
// .path : po 文件路径,设置了路径会覆盖 po 的设置
// .options : template 设置
// .openTag : '{{', 默认值
// .closeTag : '}}', 默认值
// .po : po 文件内容
// .lang : po 文件的语言标识
// .path : po 文件路径,设置了路径会覆盖 po 的设置
// .keep_no_reference : 是否保留不再引用的词条,默认为 false
// * 1.先尝试读取 path 的文件内容
// * 2.不存在 path 则使用 po 的文本内容
// * 3 po 为空使用空字符串
Expand Down
21 changes: 20 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var assert = require("should");
var path = require( 'path' );

var Buffer = require('buffer').Buffer;

Expand Down Expand Up @@ -30,12 +31,30 @@ describe( __filename, function(){

// #2 - case
"测试更多" : { str : "Test \"More\"" },
"这是[更多]按钮" : { str : "It's the Button of \"More\"" }
"这是[更多]按钮" : { str : "It's the Button of \"More\"" },

// #3 - 这个词条将被去掉
'empty-item' : { str : '' },

})
},
stream = i18n( opt );

var po_txt;
stream.on( 'data', function( file ){
if( `${ opt.lang }.po` == path.basename( file.path ) ){
po_txt = file.contents.toString();
}
} );
stream.on( 'end', function(){
it( '没有使用的词条将被去掉', function(){
var po_obj = gettext.po2obj( po_txt );
( 'empty-item' in po_obj ).should.equal( false );
( 'a' in po_obj ).should.equal( true );
( '测试更多' in po_obj ).should.equal( true );
} );
} );

check( '单个命中', stream,
'{{= _("a") }}', 'A'
);
Expand Down

0 comments on commit b1bcce3

Please sign in to comment.