i18n-po-json
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -9,3 +9,3 @@ "use strict"; | ||
var i = src.indexOf(separator); | ||
if (i === -1) { | ||
if (i === -1) { // no separator | ||
return [src, '']; | ||
@@ -21,5 +21,9 @@ } | ||
var header = entries.shift(); | ||
var items = entries.reduce(function (acc, entry) { | ||
var e = parseEntry(entry, opts.withComments, opts.withOccurences); | ||
return e ? acc.concat(e) : acc; | ||
}, []); | ||
return { | ||
meta: parseHeader(header, opts), | ||
items: entries.map(function (entry) { return parseEntry(entry, opts.withComments, opts.withOccurences); }) | ||
meta: header ? parseHeader(header, opts) : undefined, | ||
items: items | ||
}; | ||
@@ -41,3 +45,3 @@ } | ||
} | ||
var headers = result.msgStr.split("\n"); | ||
var headers = result.msgStr ? result.msgStr.split("\n") : []; | ||
if (opts.withMeta === 'plural') { | ||
@@ -56,2 +60,5 @@ var pluralHeader = headers.filter(function (headerItem) { | ||
return headers.reduce(function (acc, header) { | ||
if (header === '') { | ||
return acc; | ||
} | ||
var _a = splitInTwo(header, ':').map(function (v) { return v.trim(); }), name = _a[0], value = _a[1]; | ||
@@ -105,3 +112,4 @@ switch (name) { | ||
default: | ||
if (name) { | ||
// allow X- header | ||
if (!/^X-/.test(name)) { | ||
panic_1.warning('PO header: unknown clause', [name, value]); | ||
@@ -125,9 +133,13 @@ } | ||
var comments = result.comments, occurences = result.occurences, context = result.context, msgid = result.msgid, msgidPlural = result.msgidPlural, msgStr = result.msgStr, msgStrPlural = result.msgStrPlural; | ||
if (!msgid) { | ||
panic_1.panic('Invalid single entry: empty msgid string', entries); | ||
return; | ||
} | ||
if (msgidPlural || msgStrPlural.length > 0) { | ||
if (!msgidPlural || msgStrPlural.length == 0) { | ||
panic_1.panic('Invalid plural entry: absent msgid_plural or msgstr[N] strings', [msgid, msgidPlural]); | ||
panic_1.panic('Invalid plural entry: absent msgid_plural or msgstr[N] strings', [msgid].concat(entries)); | ||
return; | ||
} | ||
if (msgStrPlural.length !== msgStrPlural.filter(function (v) { return !!v; }).length) { | ||
panic_1.warning('Some of plural strings are untranslated', msgStrPlural); | ||
panic_1.warning('Some of plural strings are untranslated', [msgid].concat(msgStrPlural)); | ||
} | ||
@@ -144,6 +156,2 @@ // valid plural form | ||
} | ||
if (!msgid) { | ||
panic_1.panic('Invalid single entry: empty msgid string', [msgid]); | ||
return; | ||
} | ||
if (!msgStr) { | ||
@@ -195,3 +203,4 @@ panic_1.warning('String is untranslated', [msgid]); | ||
if (pluralMatch) { | ||
msgStrPlural[pluralMatch[1]] += JSON.parse(entry); | ||
var idx = parseInt(pluralMatch[1], 10); | ||
msgStrPlural[idx] += JSON.parse(entry); | ||
} | ||
@@ -240,3 +249,4 @@ break; | ||
if (pluralMatch) { | ||
msgStrPlural[pluralMatch[1]] = JSON.parse(body); | ||
var idx = parseInt(pluralMatch[1], 10); | ||
msgStrPlural[idx] = JSON.parse(body); | ||
} | ||
@@ -243,0 +253,0 @@ break; |
{ | ||
"name": "i18n-po-json", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "i18n .po to .json file converter", | ||
@@ -25,25 +25,27 @@ "main": "dist/index.js", | ||
"@types/get-stdin": "^5.0.1", | ||
"@types/mocha": "^5.2.5", | ||
"@types/node": "8.9.4", | ||
"@types/yargs": "^8.0.2", | ||
"array-xor": "^0.1.1", | ||
"browserify": "^14.4.0", | ||
"browserify": "^16.2.2", | ||
"eslint": "3.13.1", | ||
"i18n-proto": "1.0.5", | ||
"karma": "1.7.0", | ||
"karma": "^3.0.0", | ||
"karma-browserify": "^5.1.1", | ||
"karma-firefox-launcher": "^1.0.1", | ||
"karma-mocha": "^1.3.0", | ||
"karma-typescript": "^3.0.4", | ||
"mocha": "^3.4.2", | ||
"ts-node": "^3.3.0", | ||
"tslib": "1.5.0", | ||
"karma-typescript": "^3.0.13", | ||
"mocha": "^5.2.0", | ||
"ts-node": "^7.0.1", | ||
"tslib": "^1.9.3", | ||
"tslint": "4.3.1", | ||
"tslint-eslint-rules": "3.2.3", | ||
"typescript": "^2.4.2", | ||
"uglify-js": "3.0.18", | ||
"typescript": "^2.9.2", | ||
"uglify-js": "^3.4.9", | ||
"watchify": "^3.9.0" | ||
}, | ||
"dependencies": { | ||
"get-stdin": "5.0", | ||
"yargs": "8.0" | ||
"get-stdin": "6.0.0", | ||
"yargs": "8.0.0" | ||
} | ||
} | ||
} |
import { | ||
I18NEntry, | ||
SingleI18NEntry, | ||
PluralI18NEntry, | ||
TranslationJson, | ||
@@ -27,6 +25,10 @@ TranslationMeta | ||
let header = entries.shift(); | ||
let items = entries.reduce((acc, entry) => { | ||
const e = parseEntry(entry, opts.withComments, opts.withOccurences); | ||
return e ? acc.concat(e) : acc; | ||
}, [] as Array<I18NEntry>); | ||
return { | ||
meta: parseHeader(header, opts), | ||
items: entries.map((entry) => parseEntry(entry, opts.withComments, opts.withOccurences)) | ||
meta: header ? parseHeader(header, opts) : undefined, | ||
items | ||
}; | ||
@@ -50,3 +52,3 @@ } | ||
let headers = result.msgStr.split("\n"); | ||
let headers = result.msgStr ? result.msgStr.split("\n") : []; | ||
@@ -71,2 +73,5 @@ if (opts.withMeta === 'plural') { | ||
return headers.reduce<TranslationMeta>((acc, header) => { | ||
if (header === '') { | ||
return acc; | ||
} | ||
let [name, value] = splitInTwo(header, ':').map((v) => v.trim()); | ||
@@ -119,3 +124,4 @@ switch (name) { | ||
default: | ||
if (name) { | ||
// allow X- header | ||
if (!/^X-/.test(name)) { | ||
warning('PO header: unknown clause', [name, value]); | ||
@@ -145,5 +151,10 @@ } | ||
if (!msgid) { | ||
panic('Invalid single entry: empty msgid string', entries); | ||
return; | ||
} | ||
if (msgidPlural || msgStrPlural.length > 0) { | ||
if (!msgidPlural || msgStrPlural.length == 0) { | ||
panic('Invalid plural entry: absent msgid_plural or msgstr[N] strings', [msgid, msgidPlural]); | ||
panic('Invalid plural entry: absent msgid_plural or msgstr[N] strings', [msgid, ...entries]); | ||
return; | ||
@@ -153,3 +164,3 @@ } | ||
if (msgStrPlural.length !== msgStrPlural.filter((v) => !!v).length) { | ||
warning('Some of plural strings are untranslated', msgStrPlural); | ||
warning('Some of plural strings are untranslated', [msgid, ...msgStrPlural]); | ||
} | ||
@@ -168,7 +179,2 @@ | ||
if (!msgid) { | ||
panic('Invalid single entry: empty msgid string', [msgid]); | ||
return; | ||
} | ||
if (!msgStr) { | ||
@@ -233,3 +239,4 @@ warning('String is untranslated', [msgid]); | ||
if (pluralMatch) { | ||
msgStrPlural[pluralMatch[1]] += JSON.parse(entry); | ||
const idx = parseInt(pluralMatch[1], 10); | ||
msgStrPlural[idx] += JSON.parse(entry); | ||
} | ||
@@ -280,3 +287,4 @@ break; | ||
if (pluralMatch) { | ||
msgStrPlural[pluralMatch[1]] = JSON.parse(body); | ||
const idx = parseInt(pluralMatch[1], 10); | ||
msgStrPlural[idx] = JSON.parse(body); | ||
} | ||
@@ -283,0 +291,0 @@ break; |
@@ -6,7 +6,10 @@ import * as assert from 'assert'; | ||
import { splitInTwo, convert, parseEntry, parseHeader, _parse } from '../src/convert'; | ||
const xor = require('array-xor'); | ||
import { splitInTwo, parseEntry, parseHeader, _parse } from '../src/convert'; | ||
let panics = []; | ||
let warnings = []; | ||
interface ErrorMessage { | ||
message: string, | ||
invalid: string[] | ||
} | ||
let panics: Array<ErrorMessage> = []; | ||
let warnings: Array<ErrorMessage> = []; | ||
function preparePanic() { | ||
@@ -482,2 +485,17 @@ panics = []; | ||
}); | ||
it('Allow X- header entry', () => { | ||
let entry = ` | ||
msgid "" | ||
msgstr "" | ||
"X-Entry: value\\n" | ||
"MIME-Version: 1.0\\n" | ||
`; | ||
const opts = { withMeta: 'full' } as PoOptions; | ||
let result = parseHeader(entry, opts); | ||
assert.notEqual(result, undefined); | ||
assert.equal(panics.length, 0); | ||
assert.equal(warnings.length, 0); | ||
}); | ||
}); |
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"tslib": ["./node_modules/tslib/tslib.d.ts"] | ||
}, | ||
"target": "es5", | ||
@@ -16,6 +12,3 @@ "sourceMap": true, | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
], | ||
"compileOnSave": false | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
200567
21
16
1320
+ Addedcamelcase@3.0.0(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedget-stdin@6.0.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedload-json-file@1.1.0(transitive)
+ Addedos-locale@1.4.0(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpath-type@1.1.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedread-pkg@1.1.0(transitive)
+ Addedread-pkg-up@1.0.1(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedwhich-module@1.0.0(transitive)
+ Addedyargs@8.0.0(transitive)
+ Addedyargs-parser@6.0.1(transitive)
- Removedansi-regex@3.0.1(transitive)
- Removedcross-spawn@5.1.0(transitive)
- Removedexeca@0.7.0(transitive)
- Removedfind-up@2.1.0(transitive)
- Removedget-stdin@5.0.1(transitive)
- Removedget-stream@3.0.0(transitive)
- Removedis-fullwidth-code-point@2.0.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedload-json-file@2.0.0(transitive)
- Removedlocate-path@2.0.0(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedmem@1.1.0(transitive)
- Removedmimic-fn@1.2.0(transitive)
- Removednpm-run-path@2.0.2(transitive)
- Removedos-locale@2.1.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-limit@1.3.0(transitive)
- Removedp-locate@2.0.0(transitive)
- Removedp-try@1.0.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedpath-key@2.0.1(transitive)
- Removedpath-type@2.0.0(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedread-pkg@2.0.0(transitive)
- Removedread-pkg-up@2.0.0(transitive)
- Removedshebang-command@1.2.0(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstring-width@2.1.1(transitive)
- Removedstrip-ansi@4.0.0(transitive)
- Removedstrip-bom@3.0.0(transitive)
- Removedstrip-eof@1.0.0(transitive)
- Removedwhich@1.3.1(transitive)
- Removedwhich-module@2.0.1(transitive)
- Removedyallist@2.1.2(transitive)
- Removedyargs@8.0.2(transitive)
- Removedyargs-parser@7.0.0(transitive)
Updatedget-stdin@6.0.0
Updatedyargs@8.0.0