-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
konstantin
committed
Nov 13, 2015
1 parent
fbe279b
commit 00e0e9a
Showing
12 changed files
with
206 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- "iojs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
[![Build Status](https://travis-ci.org/TargetProcess/tau-transifex.svg)](https://travis-ci.org/TargetProcess/tau-transifex) | ||
|
||
Simple API for request to transifex REST API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
projectSlug:'test', | ||
resourceSlug:'test', | ||
login: 'test', | ||
password: 'test' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var config = require('./config'); | ||
var api = require('./index')(config); | ||
api.updateResourceFile({ | ||
"none": {"deep nested message": "deep nested message", "test1": "test1"}, | ||
"custom_js_scope": {"custom js scope": "custom js scope"}, | ||
"remove": {"remove": "remove"} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var _ = require('lodash'); | ||
module.exports = { | ||
mergeStrings: function (newStrings, fromTransifex) { | ||
var flattenStrings = _.defaults.apply(_, [{}].concat(_.values(newStrings))); | ||
var updateStrings = _.merge({}, fromTransifex, flattenStrings); | ||
var obsoleteStrings = _.difference(_.values(fromTransifex), _.values(flattenStrings)); | ||
return { | ||
updateStrings: updateStrings, | ||
obsoleteStrings: obsoleteStrings | ||
}; | ||
}, | ||
generateHash: function (key) { | ||
var crypto = require('crypto'); | ||
var shasum = crypto.createHash('md5'); | ||
var escaped = key.replace(/\\/g, '\\\\').replace(/\./g, '\\.'); | ||
shasum.update(escaped + ":", 'utf8'); | ||
return shasum.digest('hex'); | ||
}, | ||
applyTagsToStrings: function (newStings, stringsWithTags, obsoleteStrings, config) { | ||
var obsoleteTag = config.obsoleteTag; | ||
var strings = _.map(_.compact(stringsWithTags), function (string) { | ||
var token = string.token; | ||
_.each(newStings, function (dictionary, scope) { | ||
var tags = []; | ||
if (dictionary[token]) { | ||
tags = _.chain((string.tags || []).concat(scope)).compact().uniq().value(); | ||
tags = _.without(tags, obsoleteTag); | ||
tags =_.uniq(tags); | ||
string.tags = _.difference(tags, config.skipTags); | ||
} else { | ||
if(_.contains(obsoleteStrings, token)) { | ||
tags = _.chain((string.tags || []).concat(scope)).compact().uniq().value(); | ||
tags.push(obsoleteTag); | ||
tags =_.uniq(tags); | ||
string.tags = _.difference(tags, config.skipTags); | ||
} | ||
} | ||
}); | ||
return string; | ||
}); | ||
return strings; | ||
}, | ||
removeStringsWithCertainTags: function () { | ||
|
||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
"none": {"deep nested message": "deep nested message", "test1": "test1"}, | ||
"custom_js_scope": {"custom js scope": "custom js scope"}, | ||
"remove": {"remove": "remove"} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
test: 'test', | ||
test1: 'test1' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"test": "test", | ||
"test1": "test1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
var utils = require('../lib/utils'); | ||
var test = require('tape'); | ||
var newStings = require('./fextures/newStrings'); | ||
var transifexStrings = require('./fextures/transifexStrings'); | ||
var stringsWithTags = | ||
[ | ||
{ | ||
"comment": "", | ||
"character_limit": null, | ||
"tags": [ | ||
"none" | ||
], | ||
"token": "deep nested message" | ||
}, | ||
{ | ||
"comment": "", | ||
"character_limit": null, | ||
"tags": [ | ||
"none" | ||
], | ||
"token": "test1" | ||
}, | ||
{ | ||
"comment": "", | ||
"character_limit": null, | ||
"tags": null, | ||
"token": "test" | ||
}, | ||
{ | ||
"comment": "", | ||
"character_limit": null, | ||
"tags": [ | ||
"custom_js_scope" | ||
], | ||
"token": "custom js scope" | ||
}, | ||
{ | ||
"comment": "", | ||
"character_limit": null, | ||
"tags": [ | ||
"remove" | ||
], | ||
"token": "remove" | ||
} | ||
|
||
]; | ||
|
||
test('generate hash', function (assert) { | ||
assert.equal( | ||
utils.generateHash('Possible transitions are: {currentStateName} → {nextStateNames}.'), | ||
'43861bf525d30cbbce0c9d0950615645' | ||
); | ||
assert.equal( | ||
utils.generateHash('Possible \\'), | ||
'c3b342eb9097ddcb0f9d2ef0a312be0c' | ||
); | ||
assert.end(); | ||
}); | ||
|
||
test('merge strings', function (assert) { | ||
assert.deepEqual( | ||
utils.mergeStrings(newStings, transifexStrings), | ||
{ | ||
obsoleteStrings: ['test'], | ||
updateStrings: { | ||
'custom js scope': 'custom js scope', | ||
'deep nested message': 'deep nested message', | ||
remove: 'remove', | ||
test: 'test', | ||
test1: 'test1' | ||
} | ||
} | ||
); | ||
assert.end(); | ||
}); | ||
|
||
test('apply tags', function (assert) { | ||
assert.deepEqual( | ||
utils.applyTagsToStrings(newStings, stringsWithTags, ['test'], { | ||
obsoleteTag: 'obsolete', | ||
skipTags: ['remove'] | ||
}), | ||
{ | ||
obsoleteStrings: ['test'], | ||
updateStrings: { | ||
'custom js scope': 'custom js scope', | ||
'deep nested message': 'deep nested message', | ||
remove: 'remove', | ||
test: 'test', | ||
test1: 'test1' | ||
} | ||
} | ||
); | ||
assert.end(); | ||
}); |