react-intl-po
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -6,2 +6,7 @@ # react-intl-po | ||
## [v2.0.1] | ||
> Feb 12, 2017 | ||
* feat(potFormater): Add defaultMessage to metadata of pot files. ([@Guibod](https://github.com/Guibod) in [#60]) | ||
## [v2.0.0] | ||
@@ -8,0 +13,0 @@ > Feb 11, 2017 |
@@ -7,4 +7,28 @@ 'use strict'; | ||
/** | ||
* Ensure that multi-line strings are properly commented out | ||
* | ||
* For instance: | ||
* This is\nmy multi-line\ncomment | ||
* | ||
* should be escaped as : | ||
* #. This is | ||
* #. my multi-line | ||
* #. comment | ||
* | ||
* @param {String} commentPrefix | ||
* @param {String} rawComment | ||
* @returns {String} | ||
* | ||
* @author Guillaume Boddaert | ||
*/ | ||
var potCommentMultiLineWrapper = function potCommentMultiLineWrapper(commentPrefix, rawComment) { | ||
var comments = rawComment.split('\n'); | ||
return comments.reduce(function (a, b) { | ||
return '' + a + commentPrefix + ' ' + b + '\n'; | ||
}, ''); | ||
}; | ||
/** | ||
* Formatting POT comments | ||
* @param {Object[]} | ||
* @param {Object[]} messageList | ||
* @return {String} | ||
@@ -15,2 +39,3 @@ * | ||
* @author Michael Hsu | ||
* @author Guillaume Boddaert | ||
*/ | ||
@@ -21,4 +46,15 @@ var potCommentsFormater = function potCommentsFormater(messageList) { | ||
id = _ref.id, | ||
description = _ref.description; | ||
return acc + '#: ' + filename + '\n#. [' + id + '] - ' + description + '\n'; | ||
description = _ref.description, | ||
defaultMessage = _ref.defaultMessage; | ||
var out = acc; | ||
out += potCommentMultiLineWrapper('#:', filename); | ||
if (description) { | ||
out += potCommentMultiLineWrapper('#.', '[' + id + '] - ' + description); | ||
} else { | ||
out += potCommentMultiLineWrapper('#.', '[' + id + ']'); | ||
} | ||
out += potCommentMultiLineWrapper('#.', 'defaultMessage is:\n' + defaultMessage); | ||
return out; | ||
}, ''); | ||
@@ -29,3 +65,3 @@ }; | ||
* Formatting POT comments | ||
* @param {Object} | ||
* @param {Object} messageObject | ||
* @return {String} | ||
@@ -32,0 +68,0 @@ * |
{ | ||
"name": "react-intl-po", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Extract POT from react-intl and convert back to json.", | ||
@@ -5,0 +5,0 @@ "author": "Michael Hsu", |
/** | ||
* Ensure that multi-line strings are properly commented out | ||
* | ||
* For instance: | ||
* This is\nmy multi-line\ncomment | ||
* | ||
* should be escaped as : | ||
* #. This is | ||
* #. my multi-line | ||
* #. comment | ||
* | ||
* @param {String} commentPrefix | ||
* @param {String} rawComment | ||
* @returns {String} | ||
* | ||
* @author Guillaume Boddaert | ||
*/ | ||
const potCommentMultiLineWrapper = (commentPrefix, rawComment) => { | ||
const comments = rawComment.split('\n'); | ||
return comments.reduce((a, b) => `${a}${commentPrefix} ${b}\n`, ''); | ||
}; | ||
/** | ||
* Formatting POT comments | ||
* @param {Object[]} | ||
* @param {Object[]} messageList | ||
* @return {String} | ||
@@ -9,11 +32,21 @@ * | ||
* @author Michael Hsu | ||
* @author Guillaume Boddaert | ||
*/ | ||
const potCommentsFormater = messageList => | ||
messageList.reduce((acc, { filename, id, description }) => | ||
`${acc}#: ${filename}\n#. [${id}] - ${description}\n` | ||
, ''); | ||
messageList.reduce((acc, { filename, id, description, defaultMessage }) => { | ||
let out = acc; | ||
out += potCommentMultiLineWrapper('#:', filename); | ||
if (description) { | ||
out += potCommentMultiLineWrapper('#.', `[${id}] - ${description}`); | ||
} else { | ||
out += potCommentMultiLineWrapper('#.', `[${id}]`); | ||
} | ||
out += potCommentMultiLineWrapper('#.', `defaultMessage is:\n${defaultMessage}`); | ||
return out; | ||
}, ''); | ||
/** | ||
* Formatting POT comments | ||
* @param {Object} | ||
* @param {Object} messageObject | ||
* @return {String} | ||
@@ -20,0 +53,0 @@ * |
@@ -27,1 +27,30 @@ import potFormater from '../src/potFormater'; | ||
}); | ||
it('should return pot formatted string, with null or undefined description', () => { | ||
expect( | ||
potFormater({ | ||
'Go to MCS website': [ | ||
{ | ||
id: 'NotFound.errorButton', | ||
defaultMessage: 'Go to MCS website', | ||
filename: './messages/src/containers/NotFound/messages.json', | ||
}, | ||
], | ||
}), | ||
).toMatchSnapshot(); | ||
}); | ||
it('should return pot formatted string, with multi line values', () => { | ||
expect( | ||
potFormater({ | ||
'NotFound.errorButton': [ | ||
{ | ||
id: 'NotFound.errorButton', | ||
description: 'My description\nis\nquite\nlong.', | ||
defaultMessage: 'This is\nmultiline', | ||
filename: './messages/src/containers/NotFound/messages.json', | ||
}, | ||
], | ||
}), | ||
).toMatchSnapshot(); | ||
}); |
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
61553
834