react-intl-po
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,2 +6,7 @@ # react-intl-po | ||
## [v1.2.0] | ||
> Feb 11, 2017 | ||
* feat(pot): Added support for POT header. ([@Guibod](https://github.com/Guibod) in [#56]) | ||
## [v1.1.0] | ||
@@ -8,0 +13,0 @@ > Oct 26, 2016 |
@@ -30,2 +30,6 @@ 'use strict'; | ||
var _potHeader = require('./potHeader'); | ||
var _potHeader2 = _interopRequireDefault(_potHeader); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -48,7 +52,14 @@ | ||
var messageKey = _ref2.messageKey, | ||
output = _ref2.output; | ||
output = _ref2.output, | ||
headerOptions = _ref2.headerOptions; | ||
var mapper = messageKey ? customKeyMapperFactory(messageKey) : undefined; | ||
var result = (0, _flowRight2.default)(_potFormater2.default, // 2. return formated string | ||
var result = (0, _potHeader2.default)(_extends({ | ||
potCreationDate: new Date(), | ||
charset: 'UTF-8', | ||
encoding: '8bit' | ||
}, headerOptions)); | ||
result += (0, _flowRight2.default)(_potFormater2.default, // 2. return formated string | ||
_readAllMessageAsObjectSync2.default)(srcPatterns, mapper); | ||
@@ -55,0 +66,0 @@ |
@@ -19,2 +19,6 @@ 'use strict'; | ||
var _potHeader = require('./potHeader'); | ||
var _potHeader2 = _interopRequireDefault(_potHeader); | ||
var _readAllMessageAsObjectSync = require('./readAllMessageAsObjectSync'); | ||
@@ -34,2 +38,3 @@ | ||
potFormater: _potFormater2.default, | ||
potHeader: _potHeader2.default, | ||
readAllMessageAsObjectSync: _readAllMessageAsObjectSync2.default, | ||
@@ -36,0 +41,0 @@ readAllPOAsObjectSync: _readAllPOAsObjectSync2.default |
{ | ||
"name": "react-intl-po", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Extract POT from react-intl and convert back to json.", | ||
@@ -52,6 +52,6 @@ "author": "Michael Hsu", | ||
"codecov": "^1.0.1", | ||
"eslint": "^3.8.1", | ||
"lint-config-m": "^2.0.1", | ||
"nyc": "^8.3.2", | ||
"stylelint": "^7.5.0" | ||
"eslint": "^3.13.0", | ||
"lint-config-m": "^3.1.0", | ||
"nyc": "^10.0.0", | ||
"stylelint": "^7.7.1" | ||
}, | ||
@@ -96,7 +96,7 @@ "babel": { | ||
"glob": "^7.1.1", | ||
"lodash": "^4.16.4", | ||
"lodash": "^4.17.4", | ||
"mkdirp": "^0.5.1", | ||
"po2json": "^0.4.5", | ||
"to-object-by": "^1.0.3" | ||
"to-object-by": "^1.1.0" | ||
} | ||
} |
@@ -41,4 +41,4 @@ # react-intl-po | ||
- react-intl | ||
- babel-plugin-react-intl | ||
- [react-intl](https://github.com/yahoo/react-intl) `^2.0.0` | ||
- [babel-plugin-react-intl](https://github.com/yahoo/babel-plugin-react-intl) `^2.0.0` | ||
@@ -45,0 +45,0 @@ ![RIP Workflow](./docs/workflow.png) |
@@ -7,2 +7,3 @@ /* eslint-disable no-console */ | ||
import potFormater from './potFormater'; | ||
import potHeader from './potHeader'; | ||
@@ -16,6 +17,13 @@ const customKeyMapper = (message, messageKey, filename) => ({ | ||
function extractAndWritePOTFromMessagesSync(srcPatterns, { messageKey, output }) { | ||
function extractAndWritePOTFromMessagesSync(srcPatterns, { messageKey, output, headerOptions }) { | ||
const mapper = messageKey ? customKeyMapperFactory(messageKey) : undefined; | ||
const result = flowRight( | ||
let result = potHeader({ | ||
potCreationDate: new Date(), | ||
charset: 'UTF-8', | ||
encoding: '8bit', | ||
...headerOptions, | ||
}); | ||
result += flowRight( | ||
potFormater, // 2. return formated string | ||
@@ -22,0 +30,0 @@ readAllMessageAsObjectSync, // 1. return messages object |
@@ -16,3 +16,3 @@ /* eslint-disable no-console */ | ||
function filterPOAndWriteTranslateSync(srcPatterns, | ||
{ messageKey = 'defaultMessage', messagesPattern, output }) { | ||
{ messageKey = 'defaultMessage', messagesPattern, output }) { | ||
const translationTable = readAllPOAsObjectSync(srcPatterns); | ||
@@ -19,0 +19,0 @@ const messageList = flowRight( |
import extractAndWritePOTFromMessagesSync from './extractAndWritePOTFromMessagesSync'; | ||
import filterPOAndWriteTranslateSync from './filterPOAndWriteTranslateSync'; | ||
import potFormater from './potFormater'; | ||
import potHeader from './potHeader'; | ||
import readAllMessageAsObjectSync from './readAllMessageAsObjectSync'; | ||
@@ -11,4 +12,5 @@ import readAllPOAsObjectSync from './readAllPOAsObjectSync'; | ||
potFormater, | ||
potHeader, | ||
readAllMessageAsObjectSync, | ||
readAllPOAsObjectSync, | ||
}; |
@@ -12,6 +12,17 @@ import fs from 'fs'; | ||
const output = './temp/extract.pot'; | ||
const headerOptions = { potCreationDate: new Date(Date.UTC(2017, 1, 1, 11, 23, 12)) }; | ||
extractAndWritePOTFromMessagesSync('./messages/**/*.json', { output }); | ||
extractAndWritePOTFromMessagesSync('./messages/**/*.json', { output, headerOptions }); | ||
t.is( | ||
fs.readFileSync(output, 'utf8'), | ||
'msgid ""\n' + | ||
'msgstr ""\n' + | ||
'"POT-Creation-Date: 2017-02-01T11:23:12.000Z\\n"\n' + | ||
'"Content-Type: text/plain; charset=UTF-8\\n"\n' + | ||
'"Content-Transfer-Encoding: 8bit\\n"\n' + | ||
'"MIME-Version: 1.0\\n"\n' + | ||
'"X-Generator: react-intl-po\\n"\n' + | ||
'\n' + | ||
'\n' + | ||
'#: ./messages/src/containers/App/App.json\n' + | ||
@@ -37,7 +48,17 @@ '#. [App.Creator] - Creator\n' + | ||
test('should return messages object with custom message key mapper', (t) => { | ||
const output = './temp/extract.pot'; | ||
const output = './temp/extract2.pot'; | ||
const headerOptions = { potCreationDate: new Date(Date.UTC(2017, 1, 1, 11, 23, 12)) }; | ||
extractAndWritePOTFromMessagesSync('./messages/**/*.json', { messageKey: 'id', output }); | ||
extractAndWritePOTFromMessagesSync('./messages/**/*.json', { messageKey: 'id', output, headerOptions }); | ||
t.is( | ||
fs.readFileSync(output, 'utf8'), | ||
'msgid ""\n' + | ||
'msgstr ""\n' + | ||
'"POT-Creation-Date: 2017-02-01T11:23:12.000Z\\n"\n' + | ||
'"Content-Type: text/plain; charset=UTF-8\\n"\n' + | ||
'"Content-Transfer-Encoding: 8bit\\n"\n' + | ||
'"MIME-Version: 1.0\\n"\n' + | ||
'"X-Generator: react-intl-po\\n"\n' + | ||
'\n' + | ||
'\n' + | ||
'#: ./messages/src/containers/App/App.json\n' + | ||
@@ -62,4 +83,4 @@ '#. [App.Creator] - Creator\n' + | ||
'msgid "NotFound.errorButton"\n' + | ||
'msgstr ""\n' | ||
'msgstr ""\n', | ||
); | ||
}); |
@@ -40,3 +40,3 @@ import fs from 'fs'; | ||
'NotFound.Creator': '建立者(簡中)', | ||
} | ||
}, | ||
); | ||
@@ -49,4 +49,4 @@ | ||
'NotFound.Creator': '建立者', | ||
} | ||
}, | ||
); | ||
}); |
@@ -48,3 +48,3 @@ import test from 'ava'; | ||
], | ||
} | ||
}, | ||
); | ||
@@ -57,3 +57,3 @@ }); | ||
'./messages/**/App.json', | ||
(message, filename) => ({ [message.description]: [{ ...message, filename }]}) | ||
(message, filename) => ({ [message.description]: [{ ...message, filename }]}), | ||
), | ||
@@ -85,4 +85,4 @@ { | ||
], | ||
} | ||
}, | ||
); | ||
}); |
import test from 'ava'; | ||
import { | ||
default as readAllPOAsObjectSync, | ||
import readAllPOAsObjectSync, { | ||
DEFAULT_MAPPER as defaultMapper, | ||
@@ -5,0 +4,0 @@ } from '../src/readAllPOAsObjectSync'; |
Sorry, the diff of this file is not supported yet
50229
38
945
Updatedlodash@^4.17.4
Updatedto-object-by@^1.1.0