react-intl-po
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -6,2 +6,8 @@ # react-intl-po | ||
## [v1.0.7] | ||
> Sep 13, 2016 | ||
* test(structure): move output .temp file into the temp folder for gitignore. | ||
* feat(po2json): added generation of one output file per input if the specified output is a folder. [@MorrisGallego](https://github.com/MorrisGallego) in [#29] | ||
## [v1.0.6] | ||
@@ -8,0 +14,0 @@ > Aug 19, 2016 |
@@ -10,6 +10,6 @@ #!/usr/bin/env node | ||
_commander2.default.command('json2pot <srcPatterns>').option('-o, --output <path>', 'output path of .pot file').action(require('./extractAndWritePOTFromMessagesSync')); | ||
_commander2.default.command('json2pot <srcPatterns>').option('-o, --output <path>', 'The output pathname of `.pot` file to be translated').action(require('./extractAndWritePOTFromMessagesSync')); | ||
_commander2.default.command('po2json <srcPatterns>').option('-m, --messages-pattern <path>', 'path to extracted message .json files').option('-o, --output <path>', 'output path of pot file').action(require('./filterPOAndWriteTranslateSync')); | ||
_commander2.default.command('po2json <srcPatterns>').option('-m, --messages-pattern <path>', 'The pattern of *json* files extracted from *babel-plugin-react-intl*').option('-o, --output <path>', 'The output pathname of a file / directory').action(require('./filterPOAndWriteTranslateSync')); | ||
_commander2.default.parse(process.argv); |
@@ -33,4 +33,3 @@ 'use strict'; | ||
var result = (0, _flowRight2.default)(_potFormater2.default, // 2. return formated string | ||
_readAllMessageAsObjectSync2.default)( // 1. return messages object | ||
srcPatterns); | ||
_readAllMessageAsObjectSync2.default)(srcPatterns); | ||
@@ -40,5 +39,3 @@ _fs2.default.writeFileSync(output, result); | ||
} /* eslint-disable no-console */ | ||
exports.default = extractAndWritePOTFromMessagesSync; | ||
module.exports = exports['default']; |
@@ -52,2 +52,7 @@ 'use strict'; | ||
var isAJSONFile = function isAJSONFile(string) { | ||
return (/.json/.test(string) | ||
); | ||
}; | ||
function filterPOAndWriteTranslateSync(srcPatterns, _ref) { | ||
@@ -60,4 +65,3 @@ var messagesPattern = _ref.messagesPattern; | ||
_values2.default, // 2. return object values | ||
_readAllMessageAsObjectSync2.default)( // 1. return message object | ||
messagesPattern); | ||
_readAllMessageAsObjectSync2.default)(messagesPattern); | ||
@@ -73,5 +77,15 @@ var locales = Object.keys(translationTable); | ||
(0, _mkdirp2.default)(_path2.default.dirname(output)); // ensure the output folder exists | ||
_fs2.default.writeFileSync(output, JSON.stringify(result, null, 0)); | ||
console.log(_chalk2.default.green('> [react-intl-po] write file -> ' + output + ' ✔️\n')); | ||
if (isAJSONFile(output)) { | ||
_mkdirp2.default.sync(_path2.default.dirname(output)); // ensure the output folder exists | ||
_fs2.default.writeFileSync(output, JSON.stringify(result, null, 0)); | ||
console.log(_chalk2.default.green('> [react-intl-po] write file -> ' + output + ' ✔️\n')); | ||
} else { | ||
_mkdirp2.default.sync(output); // ensure the output folder exists | ||
Object.keys(result).map(function (lang) { | ||
_fs2.default.writeFileSync(_path2.default.join(output, lang + '.json'), JSON.stringify(result[lang], null, 0)); | ||
console.log(_chalk2.default.green('> [react-intl-po] write file -> ' + _path2.default.join(output, lang + '.json') + ' ✔️')); | ||
return null; | ||
}); | ||
} | ||
} | ||
@@ -78,0 +92,0 @@ |
{ | ||
"name": "react-intl-po", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Extract POT from react-intl and convert back to json.", | ||
@@ -5,0 +5,0 @@ "author": "Michael Hsu", |
@@ -51,4 +51,4 @@ # react-intl-po | ||
1. json2pot: Convert `babel-plugin-react-intl`'s output json file to one .pot file. | ||
2. po2json: Convert one translated .po file back to json format. | ||
1. json2pot: Convert the json files extracted from *babel-plugin-react-intl* into one `.pot` file. | ||
2. po2json: Convert translated *.po* files back to `.json` format. | ||
@@ -62,22 +62,32 @@ ### json2pot | ||
| **Arguments** | **Description** | | ||
| ------------- | --------------------------------------------- | | ||
| `srcPatterns` | `babel-plugin-react-intl`'s output json file | | ||
| `output (-o)` | `.pot` file to be translated | | ||
| **Arguments** | **Description** | | ||
| ------------- | ---------------------------------------------------------------------- | | ||
| `srcPatterns` | The pattern of *.json* files extracted from *babel-plugin-react-intl* | | ||
| `output (-o)` | The output pathname of *.pot* file to be translated | | ||
### po2json | ||
#### Case 1: Output one file per locale if a `directory` is set | ||
``` | ||
$ rip po2json './node_modules/mcs-translation/po/mcs-public*.po' \ | ||
-m './_translations/src/**/*.json' \ | ||
-o './translations.json' | ||
-m './_translations/src/**/*.json' \ | ||
-o './translations' | ||
``` | ||
| **Arguments** | **Description** | | ||
| ---------------------- | ----------------------------------------------- | | ||
| `srcPatterns` | translated `.po` files | | ||
| `messagesPattern (-m)` | `babel-plugin-react-intl`'s output json file | | ||
| `output (-o)` | ouput one json formated file to be used in SSR | | ||
#### Case 2: Output one merged file if a `.json file` is set | ||
``` | ||
$ rip po2json './node_modules/mcs-translation/po/mcs-public*.po' \` | ||
-m './_translations/src/**/*.json' \ | ||
-o './translations.json' | ||
``` | ||
| **Arguments** | **Description** | | ||
| ---------------------- | ---------------------------------------------------------------------- | | ||
| `srcPatterns` | The pattern of translated *.po* files | | ||
| `messagesPattern (-m)` | The pattern of *.json* files extracted from *babel-plugin-react-intl* | | ||
| `output (-o)` | The output pathname of a file / directory | | ||
## API | ||
@@ -84,0 +94,0 @@ |
@@ -7,3 +7,3 @@ #!/usr/bin/env node | ||
.command('json2pot <srcPatterns>') | ||
.option('-o, --output <path>', 'output path of .pot file') | ||
.option('-o, --output <path>', 'The output pathname of `.pot` file to be translated') | ||
.action(require('./extractAndWritePOTFromMessagesSync')); | ||
@@ -13,6 +13,9 @@ | ||
.command('po2json <srcPatterns>') | ||
.option('-m, --messages-pattern <path>', 'path to extracted message .json files') | ||
.option('-o, --output <path>', 'output path of pot file') | ||
.option( | ||
'-m, --messages-pattern <path>', | ||
'The pattern of *json* files extracted from *babel-plugin-react-intl*', | ||
) | ||
.option('-o, --output <path>', 'The output pathname of a file / directory') | ||
.action(require('./filterPOAndWriteTranslateSync')); | ||
program.parse(process.argv); |
@@ -13,2 +13,4 @@ /* eslint-disable no-console */ | ||
const isAJSONFile = string => /.json/.test(string); | ||
function filterPOAndWriteTranslateSync(srcPatterns, { messagesPattern, output }) { | ||
@@ -29,7 +31,18 @@ const translationTable = readAllPOAsObjectSync(srcPatterns); | ||
mkdirp(path.dirname(output)); // ensure the output folder exists | ||
fs.writeFileSync(output, JSON.stringify(result, null, 0)); | ||
console.log(chalk.green(`> [react-intl-po] write file -> ${output} ✔️\n`)); | ||
if (isAJSONFile(output)) { | ||
mkdirp.sync(path.dirname(output)); // ensure the output folder exists | ||
fs.writeFileSync(output, JSON.stringify(result, null, 0)); | ||
console.log(chalk.green(`> [react-intl-po] write file -> ${output} ✔️\n`)); | ||
} else { | ||
mkdirp.sync(output); // ensure the output folder exists | ||
Object.keys(result).map(lang => { | ||
fs.writeFileSync(path.join(output, `${lang}.json`), JSON.stringify(result[lang], null, 0)); | ||
console.log(chalk.green( | ||
`> [react-intl-po] write file -> ${path.join(output, `${lang}.json`)} ✔️`)); | ||
return null; | ||
}); | ||
} | ||
} | ||
export default filterPOAndWriteTranslateSync; |
@@ -11,3 +11,3 @@ import fs from 'fs'; | ||
test('should return messages object with default mapper', t => { | ||
const output = './extract.pot.temp'; | ||
const output = './temp/extract.pot'; | ||
@@ -14,0 +14,0 @@ extractAndWritePOTFromMessagesSync('./messages/**/*.json', { output }); |
@@ -10,5 +10,5 @@ import fs from 'fs'; | ||
test('should return messages object with default mapper', t => { | ||
test('should output one merged file if a *json file* is set', t => { | ||
const messagesPattern = './messages/**/*.json'; | ||
const output = './translations.json.temp'; | ||
const output = './temp/translations.json'; | ||
@@ -30,1 +30,23 @@ filterPOAndWriteTranslateSync('./po/mcs-public.*.po', { messagesPattern, output }); | ||
}); | ||
test('should output one file per locale if a *directory* is set', t => { | ||
const messagesPattern = './messages/**/*.json'; | ||
const output = './temp/translations'; | ||
filterPOAndWriteTranslateSync('./po/mcs-public.*.po', { messagesPattern, output }); | ||
t.deepEqual( | ||
JSON.parse(fs.readFileSync(`${output}/zh-CN.json`, 'utf8')), | ||
{ | ||
'App.Creator': '建立者(簡中)', | ||
'NotFound.Creator': '建立者(簡中)', | ||
} | ||
); | ||
t.deepEqual( | ||
JSON.parse(fs.readFileSync(`${output}/zh-TW.json`, 'utf8')), | ||
{ | ||
'App.Creator': '建立者', | ||
'NotFound.Creator': '建立者', | ||
} | ||
); | ||
}); |
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
36439
34
650
118