Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i18n-po-json

Package Overview
Dependencies
Maintainers
8
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18n-po-json - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

36

dist/src/convert.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc