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

gettext-converter

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gettext-converter - npm Package Compare versions

Comparing version 1.2.3 to 1.2.4

3

cjs/cldrConv.js

@@ -379,4 +379,3 @@ "use strict";

});
var _default = rules;
exports.default = _default;
var _default = exports.default = rules;
module.exports = exports.default;

@@ -7,21 +7,11 @@ "use strict";

exports.default = _default;
var _cldrConv = _interopRequireDefault(require("./cldrConv.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
var FORMS = ['zero', 'one', 'two', 'few', 'many', 'other'];
var regexIndexOf = function regexIndexOf(value, regex, startpos) {

@@ -31,16 +21,13 @@ var indexOf = value.substring(startpos || 0).search(regex);

};
function _default(input) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$keyseparator = _ref.keyseparator,
keyseparator = _ref$keyseparator === void 0 ? '##' : _ref$keyseparator,
_ref$ctxSeparator = _ref.ctxSeparator,
ctxSeparator = _ref$ctxSeparator === void 0 ? '_' : _ref$ctxSeparator,
ignorePlurals = _ref.ignorePlurals,
compatibilityJSON = _ref.compatibilityJSON,
language = _ref.language;
_ref$keyseparator = _ref.keyseparator,
keyseparator = _ref$keyseparator === void 0 ? '##' : _ref$keyseparator,
_ref$ctxSeparator = _ref.ctxSeparator,
ctxSeparator = _ref$ctxSeparator === void 0 ? '_' : _ref$ctxSeparator,
ignorePlurals = _ref.ignorePlurals,
compatibilityJSON = _ref.compatibilityJSON,
language = _ref.language;
var locale = arguments.length > 2 ? arguments[2] : undefined;
var flat = {};
function handleOldFormat(appendTo, obj, parentKey) {

@@ -52,3 +39,2 @@ Object.keys(obj || {}).forEach(function (m) {

var value = obj[m];
if (key.length > 0) {

@@ -59,3 +45,2 @@ key = key + keyseparator + m;

}
var pluralIndex = key.indexOf('_plural');

@@ -66,3 +51,2 @@ if (pluralIndex < 0) pluralIndex = regexIndexOf(key, /_\d+$/);

var number;
if (isPlural && key.indexOf('_plural') < 0) {

@@ -76,8 +60,5 @@ number = parseInt(key.substring(pluralIndex + 1), 10);

}
var ctxKey = key;
if (isPlural) {
ctxKey = ctxKey.substring(0, pluralIndex);
if (ctxKey.indexOf(ctxSeparator) > -1) {

@@ -91,3 +72,2 @@ context = ctxKey.substring(ctxKey.lastIndexOf(ctxSeparator) + ctxSeparator.length, ctxKey.length);

}
if (context === key) context = '';

@@ -97,3 +77,2 @@ if (context !== '') key = key.replace(ctxSeparator + context, '');

if (isPlural) appendKey = "".concat(appendKey, "_").concat(number);
if (typeof value === 'string') {

@@ -123,3 +102,2 @@ kv = {

}
function handleNewFormat(appendTo, obj, parentKey) {

@@ -131,3 +109,2 @@ Object.keys(obj).forEach(function (m) {

var value = obj[m];
if (key.length > 0) {

@@ -138,3 +115,2 @@ key = key + keyseparator + m;

}
var pluralIndex = key.indexOf('_other');

@@ -144,9 +120,6 @@ if (pluralIndex < 0) pluralIndex = regexIndexOf(key, new RegExp("_(".concat(FORMS.join('|'), ")$")));

var code = locale || language;
var cldrRule = _cldrConv.default[code] || _cldrConv.default[code.split(/-|_/)[0]];
if (!cldrRule && locale && language) {
cldrRule = _cldrConv.default[language] || _cldrConv.default[language.split(/-|_/)[0]];
}
if (!cldrRule) isPlural = false;

@@ -156,7 +129,5 @@ if (ignorePlurals) isPlural = false;

var number = 0;
if (isPlural && key.indexOf('_other') < 0) {
form = key.substring(pluralIndex + 1);
var oldSuffix = cldrRule.fromCldr[FORMS.indexOf(form)];
if (!oldSuffix) {

@@ -167,3 +138,2 @@ isPlural = false;

}
if (number === 1) isPlural = false;

@@ -176,8 +146,5 @@ key = key.substring(0, pluralIndex);

}
var ctxKey = key;
if (isPlural) {
ctxKey = ctxKey.substring(0, pluralIndex);
if (ctxKey.indexOf(ctxSeparator) > -1) {

@@ -191,3 +158,2 @@ context = ctxKey.substring(ctxKey.lastIndexOf(ctxSeparator) + ctxSeparator.length, ctxKey.length);

}
if (context === key) context = '';

@@ -197,3 +163,2 @@ if (context !== '') key = key.replace(ctxSeparator + context, '');

if (isPlural) appendKey = "".concat(appendKey, "_").concat(number);
if (typeof value === 'string') {

@@ -223,3 +188,2 @@ kv = {

}
function recurse(appendTo, obj, parentKey) {

@@ -232,7 +196,5 @@ if (compatibilityJSON === 'v4') {

}
recurse(flat, input, '');
Object.keys(flat).forEach(function (m) {
var kv = flat[m];
if (kv.isPlural) {

@@ -245,5 +207,3 @@ if (!flat[kv.key + kv.context]) {

}
var single = flat[kv.key + kv.context];
if (single) {

@@ -257,3 +217,2 @@ single.plurals = [].concat(_toConsumableArray(single.plurals || []), [kv]);

}
module.exports = exports.default;

@@ -7,13 +7,7 @@ "use strict";

exports.default = i18next2js;
var _arrify = _interopRequireDefault(require("arrify"));
var _flatten = _interopRequireDefault(require("./flatten.js"));
var _options = require("./options.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var getGettextPluralPosition = function getGettextPluralPosition(ext, suffix) {

@@ -25,10 +19,7 @@ if (ext) {

}
return -1;
};
var getPluralArray = function getPluralArray(locale, translation, plurals) {
var ext = plurals[locale.toLowerCase()] || plurals[locale.split(/_|-/)[0].toLowerCase()] || plurals.dev;
var pArray = [];
for (var i = 0, len = translation.plurals.length; i < len; i += 1) {

@@ -38,7 +29,5 @@ var plural = translation.plurals[i];

}
pArray.splice(getGettextPluralPosition(ext, translation.pluralNumber - 1), 0, translation.value);
return pArray;
};
var parseGettext = function parseGettext(locale, data) {

@@ -61,3 +50,2 @@ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

out.headers['plural-forms'] = "nplurals=".concat(ext.numbers.length, "; plural=").concat(ext.plurals);
if (!options.noDate) {

@@ -69,3 +57,2 @@ out.headers['pot-creation-date'] = new Date().toISOString();

}
if (options.language) out.headers.language = options.language;else if (setLocaleAsLanguageHeader) out.headers.language = locale;

@@ -75,6 +62,4 @@ var delkeys = [];

var kv = data[m];
if (kv.plurals) {
var pArray = [];
for (var i = 0, len = kv.plurals.length; i < len; i += 1) {

@@ -84,9 +69,6 @@ var plural = kv.plurals[i];

}
if (ext.numbers.length !== 1) {
pArray.splice(getGettextPluralPosition(ext, kv.pluralNumber - 1), 0, kv.value);
}
if (_typeof(trans[kv.context]) !== 'object') trans[kv.context] = {};
if (options.keyasareference) {

@@ -106,3 +88,2 @@ if (_typeof(trans[kv.context][kv.value]) === 'object') {

}
if (kv.key !== kv.value) {

@@ -114,3 +95,2 @@ delkeys.push([kv.context, kv.key]);

var msgid_plural = kv.key;
if (kv.key.indexOf('|#|') > -1) {

@@ -121,3 +101,2 @@ var p = kv.key.split('|#|');

}
trans[kv.context][kv.key] = {

@@ -132,3 +111,2 @@ msgctxt: kv.context,

if (_typeof(trans[kv.context]) !== 'object') trans[kv.context] = {};
if (options.keyasareference) {

@@ -147,3 +125,2 @@ if (_typeof(trans[kv.context][kv.value]) === 'object') {

}
if (kv.key !== kv.value) {

@@ -176,7 +153,5 @@ delkeys.push([kv.context, kv.key]);

};
function i18next2js(locale, body) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var flat = (0, _flatten.default)(typeof body === 'string' ? JSON.parse(body) : body, options, locale);
if (options.base) {

@@ -195,6 +170,4 @@ var bflat = (0, _flatten.default)(JSON.parse(options.base), options);

}
return parseGettext(locale, flat, options);
}
module.exports = exports.default;

@@ -7,9 +7,5 @@ "use strict";

exports.default = i18next2po;
var _i18next2js = _interopRequireDefault(require("./i18next2js.js"));
var _poCompiler = _interopRequireDefault(require("./poCompiler.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function i18next2po(locale, body) {

@@ -20,3 +16,2 @@ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

}
module.exports = exports.default;

@@ -43,18 +43,10 @@ "use strict";

});
var _po2js = _interopRequireDefault(require("./po2js.js"));
var _js2po = _interopRequireDefault(require("./js2po.js"));
var _js2i18next = _interopRequireDefault(require("./js2i18next.js"));
var _po2i18next = _interopRequireDefault(require("./po2i18next.js"));
var _i18next2js = _interopRequireDefault(require("./i18next2js.js"));
var _i18next2po = _interopRequireDefault(require("./i18next2po.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = {
var _default = exports.default = {
po2js: _po2js.default,

@@ -66,3 +58,2 @@ js2po: _js2po.default,

i18next2po: _i18next2po.default
};
exports.default = _default;
};

@@ -7,17 +7,13 @@ "use strict";

exports.default = _default;
var _options = require("./options.js");
var _cldrConv = _interopRequireDefault(require("./cldrConv.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var FORMS = ['zero', 'one', 'two', 'few', 'many', 'other'];
var isFuzzy = function isFuzzy(translation) {
return !!translation.comments && translation.comments.flag === 'fuzzy';
};
var toArrayIfNeeded = function toArrayIfNeeded(value, _ref) {

@@ -27,3 +23,2 @@ var splitNewLine = _ref.splitNewLine;

};
var emptyOrObject = function emptyOrObject(key, value, options) {

@@ -33,6 +28,4 @@ if (options.skipUntranslated && !value) {

}
return _defineProperty({}, key, toArrayIfNeeded(value, options));
};
var getI18nextPluralExtension = function getI18nextPluralExtension(ext, i) {

@@ -42,3 +35,2 @@ if (ext && ext.numbers && ext.numbers.length === 2) return i === 0 ? '' : '_plural';

};
var getGettextValues = function getGettextValues(value, locale, targetKey, options) {

@@ -51,9 +43,6 @@ var values = value.msgstr;

var gettextValues = {};
for (var i = 0; i < values.length; i += 1) {
var pluralSuffix = getI18nextPluralExtension(ext, i);
if (options.compatibilityJSON === 'v4') {
var cldrRule = _cldrConv.default[locale] || _cldrConv.default[locale.split(/-|_/)[0]];
if (cldrRule && cldrRule.toCldr[pluralSuffix] !== undefined && FORMS[cldrRule.toCldr[pluralSuffix]]) {

@@ -63,14 +52,10 @@ pluralSuffix = "_".concat(FORMS[cldrRule.toCldr[pluralSuffix]]);

}
var pkey = targetKey + pluralSuffix;
Object.assign(gettextValues, emptyOrObject(pkey, values[i], options));
}
return gettextValues;
};
function _default(js) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var data = JSON.parse(JSON.stringify(js.translations));
if (options.keyasareference) {

@@ -84,13 +69,9 @@ var keys = [];

data[ctx][id] = x;
if (options.skipUntranslated && (x.msgstr.length === 1 && !x.msgstr[0] || isFuzzy(x))) {
return;
}
if (x.msgstr[0] === '') x.msgstr[0] = x.msgid;
for (var i = 1; i < x.msgstr.length; i += 1) {
if (x.msgstr[i] === '') x.msgstr[i] = x.msgid_plural;
}
x.msgid = id;

@@ -108,3 +89,2 @@ if (id !== key) keys.push([ctx, key]);

}
var json = {};

@@ -119,3 +99,2 @@ var separator = options.keyseparator || '##';

var appendTo = json;
if (key.length === 0) {

@@ -125,3 +104,2 @@ delete context[key];

}
if (options.skipUntranslated && isFuzzy(context[key])) {

@@ -131,9 +109,6 @@ delete context[key];

}
if (key.indexOf(separator) > -1) {
var _keys = key.split(separator);
var x = 0;
while (_keys[x]) {
while (_keys[x] !== undefined && _keys[x] !== null) {
if (x < _keys.length - 1) {

@@ -145,9 +120,6 @@ appendTo[_keys[x]] = appendTo[_keys[x]] || {};

}
x += 1;
}
}
if (m !== '' && !options.ignoreCtx) targetKey = "".concat(targetKey).concat(ctxSeparator).concat(m);
if (options.persistMsgIdPlural) {

@@ -159,3 +131,2 @@ var _context$key = context[key];

}
var newValues = getGettextValues(context[key], locale, targetKey, options);

@@ -167,3 +138,2 @@ Object.assign(appendTo, newValues);

}
module.exports = exports.default;

@@ -7,11 +7,7 @@ "use strict";

exports.default = js2po;
var _poCompiler = _interopRequireDefault(require("./poCompiler.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function js2po(table, options) {
return (0, _poCompiler.default)(table, options);
}
module.exports = exports.default;

@@ -7,17 +7,9 @@ "use strict";

exports.getSetLocaleAsLanguageHeader = exports.getPlurals = void 0;
var _plurals = _interopRequireDefault(require("./plurals.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var getPlurals = function getPlurals(options) {
var getPlurals = exports.getPlurals = function getPlurals(options) {
return options.plurals || _plurals.default;
};
exports.getPlurals = getPlurals;
var getSetLocaleAsLanguageHeader = function getSetLocaleAsLanguageHeader(options) {
var getSetLocaleAsLanguageHeader = exports.getSetLocaleAsLanguageHeader = function getSetLocaleAsLanguageHeader(options) {
return typeof options.setLocaleAsLanguageHeader === 'boolean' ? options.setLocaleAsLanguageHeader : true;
};
exports.getSetLocaleAsLanguageHeader = getSetLocaleAsLanguageHeader;
};

@@ -133,4 +133,3 @@ "use strict";

});
var _default = rules;
exports.default = _default;
var _default = exports.default = rules;
module.exports = exports.default;

@@ -7,9 +7,5 @@ "use strict";

exports.default = po2i18next;
var _po2js = _interopRequireDefault(require("./po2js.js"));
var _js2i18next = _interopRequireDefault(require("./js2i18next.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function po2i18next(fileContents, options) {

@@ -19,3 +15,2 @@ var js = (0, _po2js.default)(fileContents, options);

}
module.exports = exports.default;

@@ -7,11 +7,7 @@ "use strict";

exports.default = po2js;
var _poParser = _interopRequireDefault(require("./poParser.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function po2js(fileContents, options) {
return (0, _poParser.default)(fileContents, options);
}
module.exports = exports.default;

@@ -7,26 +7,16 @@ "use strict";

exports.default = _default;
var _contentType = _interopRequireDefault(require("content-type"));
var _encoding = _interopRequireDefault(require("encoding"));
var _shared = require("./shared.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var handleCharset = function handleCharset(table) {
var ct = _contentType.default.parse(table.headers['Content-Type'] || 'text/plain');
var charset = (0, _shared.formatCharset)(table.charset || ct.parameters.charset || 'utf-8');
if (ct.parameters.charset) {
ct.parameters.charset = (0, _shared.formatCharset)(ct.parameters.charset);
}
table.charset = charset;
table.headers['Content-Type'] = _contentType.default.format(ct);
};
var drawComments = function drawComments(comments) {

@@ -58,3 +48,2 @@ var lines = [];

};
var addPOString = function addPOString() {

@@ -67,14 +56,10 @@ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

var lines = [value];
if (options.foldLength > 0) {
lines = (0, _shared.foldLine)(value, options.foldLength);
}
if (lines.length < 2) {
return "".concat(key, " \"").concat(lines.shift() || '', "\"");
}
return "".concat(key, " \"\"\n\"").concat(lines.join('"\n"'), "\"");
};
var drawBlock = function drawBlock(block) {

@@ -89,13 +74,9 @@ var override = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

var comments = override.comments || block.comments;
if (comments && (comments = drawComments(comments))) {
response.push(comments);
}
if (msgctxt) {
response.push(addPOString('msgctxt', msgctxt, options));
}
response.push(addPOString('msgid', msgid || '', options));
if (msgidPlural) {

@@ -106,3 +87,2 @@ response.push(addPOString('msgid_plural', msgidPlural, options));

});
if (msgstr.length === 0) {

@@ -114,6 +94,4 @@ response.push(addPOString('msgstr[0]', '', options));

}
return response.join('\n');
};
var compile = function compile(table, options) {

@@ -130,3 +108,2 @@ var headerBlock = table.translations[''] && table.translations[''][''] || {};

});
if (options.sort !== false) {

@@ -139,3 +116,2 @@ if (typeof options.sort === 'function') {

}
response = response.map(function (r) {

@@ -147,10 +123,7 @@ return drawBlock(r, {}, options);

}, options));
if (table.charset === 'utf-8' || table.charset === 'ascii') {
return response.join('\n\n');
}
return _encoding.default.convert(response.join('\n\n'), table.charset).toString();
};
function _default() {

@@ -162,6 +135,5 @@ var table = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

var _table$headers = table.headers,
headers = _table$headers === void 0 ? {} : _table$headers;
headers = _table$headers === void 0 ? {} : _table$headers;
headers = Object.keys(headers).reduce(function (result, key) {
var lowerKey = key.toLowerCase();
if (_shared.HEADERS.has(lowerKey)) {

@@ -172,3 +144,2 @@ result[_shared.HEADERS.get(lowerKey)] = headers[key];

}
return result;

@@ -183,3 +154,2 @@ }, {});

}
module.exports = exports.default;

@@ -7,9 +7,5 @@ "use strict";

exports.default = _default;
var _encoding = _interopRequireDefault(require("encoding"));
var _shared = require("./shared.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var states = {

@@ -33,7 +29,5 @@ none: 0x01,

};
var toString = function toString(buf, charset) {
return _encoding.default.convert(buf, 'utf-8', charset).toString('utf-8');
};
var parseHeader = function parseHeader() {

@@ -44,3 +38,2 @@ var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

var key = (parts.shift() || '').trim();
if (key) {

@@ -51,7 +44,5 @@ var value = parts.join(':').trim();

}
return headers;
}, {});
};
var handleCharset = function handleCharset() {

@@ -65,3 +56,2 @@ var buf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

var charset = defaultCharset;
if ((pos = str.search(/^\s*msgid/im)) >= 0) {

@@ -71,7 +61,5 @@ pos = pos + str.substr(pos + 5).search(/^\s*(msgid|msgctxt)/im);

}
if (match = headers.match(/[; ]charset\s*=\s*([\w-]+)(?:[\s;]|\\n)*"\s*$/mi)) {
charset = (0, _shared.formatCharset)(match[1], defaultCharset);
}
if (charset === 'utf-8') {

@@ -83,3 +71,2 @@ return {

}
return {

@@ -90,3 +77,2 @@ fileContents: toString(buf),

};
var lexer = function lexer(chunk) {

@@ -99,7 +85,5 @@ var lex = [];

var chr;
for (var i = 0, len = chunk.length; i < len; i++) {
chr = chunk.charAt(i);
if (chr === '\n') lineNumber += 1;
switch (state) {

@@ -130,5 +114,3 @@ case states.none:

}
break;
case states.comments:

@@ -140,5 +122,3 @@ if (chr === '\n') {

}
break;
case states.string:

@@ -150,15 +130,11 @@ if (escaped) {

break;
case 'n':
node.value += '\n';
break;
case 'r':
node.value += '\r';
break;
default:
node.value += chr;
}
escaped = false;

@@ -174,8 +150,5 @@ } else {

}
escaped = false;
}
break;
case states.key:

@@ -188,3 +161,2 @@ if (!chr.match(symbols.key)) {

}
state = states.none;

@@ -195,14 +167,10 @@ i--;

}
break;
}
}
return lex;
};
var joinStringValues = function joinStringValues(tokens) {
var response = [];
var lastNode;
for (var i = 0, len = tokens.length; i < len; i++) {

@@ -218,6 +186,4 @@ if (lastNode && tokens[i].type === types.string && lastNode.type === types.string) {

}
return response;
};
var parseComments = function parseComments(tokens) {

@@ -227,3 +193,2 @@ tokens.forEach(function (node) {

var lines;
if (node && node.type === types.comments) {

@@ -243,15 +208,11 @@ comment = {

break;
case '.':
comment.extracted.push(line.substr(1).replace(/^\s+/, ''));
break;
case ',':
comment.flag.push(line.substr(1).replace(/^\s+/, ''));
break;
case '|':
comment.previous.push(line.substr(1).replace(/^\s+/, ''));
break;
default:

@@ -270,7 +231,5 @@ comment.translator.push(line.replace(/^\s+/, ''));

};
var handleKeys = function handleKeys(tokens) {
var response = [];
var lastNode;
for (var i = 0, len = tokens.length; i < len; i++) {

@@ -281,7 +240,5 @@ if (tokens[i].type === types.key) {

};
if (i && tokens[i - 1].type === types.comments) {
lastNode.comments = tokens[i - 1].value;
}
lastNode.value = '';

@@ -293,6 +250,4 @@ response.push(lastNode);

}
return response;
};
var handleValues = function handleValues(tokens) {

@@ -303,3 +258,2 @@ var response = [];

var curComments;
for (var i = 0, len = tokens.length; i < len; i++) {

@@ -331,6 +285,4 @@ if (tokens[i].key.toLowerCase() === 'msgctxt') {

}
return response;
};
var normalize = function normalize(tokens, charset) {

@@ -343,17 +295,12 @@ var table = {

var msgctxt;
for (var i = 0, len = tokens.length; i < len; i++) {
msgctxt = tokens[i].msgctxt || '';
if (!table.translations[msgctxt]) table.translations[msgctxt] = {};
if (!table.headers && !msgctxt && !tokens[i].msgid) {
table.headers = parseHeader(tokens[i].msgstr[0]);
}
table.translations[msgctxt][tokens[i].msgid] = tokens[i];
}
return table;
};
var finalize = function finalize(tokens, charset) {

@@ -366,6 +313,4 @@ var data = joinStringValues(tokens);

};
function _default(fileContents) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (typeof options === 'string') {

@@ -376,5 +321,3 @@ options = {

}
options.charset = options.charset || 'iso-8859-1';
if (typeof fileContents === 'string') {

@@ -387,7 +330,5 @@ options.charset = 'utf-8';

}
var lex = lexer(fileContents);
return finalize(lex, options.charset);
}
module.exports = exports.default;

@@ -11,6 +11,4 @@ "use strict";

exports.generateHeader = generateHeader;
var HEADERS = new Map([['project-id-version', 'Project-Id-Version'], ['report-msgid-bugs-to', 'Report-Msgid-Bugs-To'], ['pot-creation-date', 'POT-Creation-Date'], ['po-revision-date', 'PO-Revision-Date'], ['last-translator', 'Last-Translator'], ['language-team', 'Language-Team'], ['language', 'Language'], ['content-type', 'Content-Type'], ['content-transfer-encoding', 'Content-Transfer-Encoding'], ['plural-forms', 'Plural-Forms'], ['mime-version', 'MIME-Version']]);
exports.HEADERS = HEADERS;
var formatCharset = function formatCharset() {
var HEADERS = exports.HEADERS = new Map([['project-id-version', 'Project-Id-Version'], ['report-msgid-bugs-to', 'Report-Msgid-Bugs-To'], ['pot-creation-date', 'POT-Creation-Date'], ['po-revision-date', 'PO-Revision-Date'], ['last-translator', 'Last-Translator'], ['language-team', 'Language-Team'], ['language', 'Language'], ['content-type', 'Content-Type'], ['content-transfer-encoding', 'Content-Transfer-Encoding'], ['plural-forms', 'Plural-Forms'], ['mime-version', 'MIME-Version']]);
var formatCharset = exports.formatCharset = function formatCharset() {
var charset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'iso-8859-1';

@@ -20,5 +18,2 @@ var defaultCharset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'iso-8859-1';

};
exports.formatCharset = formatCharset;
function compareMsgid(_ref, _ref2) {

@@ -31,3 +26,2 @@ var left = _ref.msgid;

}
function foldLine(str) {

@@ -40,10 +34,7 @@ var maxLen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 76;

var match;
while (pos < len) {
curLine = str.substr(pos, maxLen);
while (curLine.substr(-1) === '\\' && pos + curLine.length < len) {
curLine += str.charAt(pos + curLine.length);
}
if (match = /.*?\\n/.exec(curLine)) {

@@ -58,10 +49,7 @@ curLine = match[0];

}
lines.push(curLine);
pos += curLine.length;
}
return lines;
}
function generateHeader() {

@@ -68,0 +56,0 @@ var header = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import cldrConv from './cldrConv.js';
var FORMS = ['zero', 'one', 'two', 'few', 'many', 'other'];
var regexIndexOf = function regexIndexOf(value, regex, startpos) {

@@ -20,16 +13,13 @@ var indexOf = value.substring(startpos || 0).search(regex);

};
export default function (input) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$keyseparator = _ref.keyseparator,
keyseparator = _ref$keyseparator === void 0 ? '##' : _ref$keyseparator,
_ref$ctxSeparator = _ref.ctxSeparator,
ctxSeparator = _ref$ctxSeparator === void 0 ? '_' : _ref$ctxSeparator,
ignorePlurals = _ref.ignorePlurals,
compatibilityJSON = _ref.compatibilityJSON,
language = _ref.language;
_ref$keyseparator = _ref.keyseparator,
keyseparator = _ref$keyseparator === void 0 ? '##' : _ref$keyseparator,
_ref$ctxSeparator = _ref.ctxSeparator,
ctxSeparator = _ref$ctxSeparator === void 0 ? '_' : _ref$ctxSeparator,
ignorePlurals = _ref.ignorePlurals,
compatibilityJSON = _ref.compatibilityJSON,
language = _ref.language;
var locale = arguments.length > 2 ? arguments[2] : undefined;
var flat = {};
function handleOldFormat(appendTo, obj, parentKey) {

@@ -41,3 +31,2 @@ Object.keys(obj || {}).forEach(function (m) {

var value = obj[m];
if (key.length > 0) {

@@ -48,3 +37,2 @@ key = key + keyseparator + m;

}
var pluralIndex = key.indexOf('_plural');

@@ -55,3 +43,2 @@ if (pluralIndex < 0) pluralIndex = regexIndexOf(key, /_\d+$/);

var number;
if (isPlural && key.indexOf('_plural') < 0) {

@@ -65,8 +52,5 @@ number = parseInt(key.substring(pluralIndex + 1), 10);

}
var ctxKey = key;
if (isPlural) {
ctxKey = ctxKey.substring(0, pluralIndex);
if (ctxKey.indexOf(ctxSeparator) > -1) {

@@ -80,3 +64,2 @@ context = ctxKey.substring(ctxKey.lastIndexOf(ctxSeparator) + ctxSeparator.length, ctxKey.length);

}
if (context === key) context = '';

@@ -86,3 +69,2 @@ if (context !== '') key = key.replace(ctxSeparator + context, '');

if (isPlural) appendKey = "".concat(appendKey, "_").concat(number);
if (typeof value === 'string') {

@@ -112,3 +94,2 @@ kv = {

}
function handleNewFormat(appendTo, obj, parentKey) {

@@ -120,3 +101,2 @@ Object.keys(obj).forEach(function (m) {

var value = obj[m];
if (key.length > 0) {

@@ -127,3 +107,2 @@ key = key + keyseparator + m;

}
var pluralIndex = key.indexOf('_other');

@@ -134,7 +113,5 @@ if (pluralIndex < 0) pluralIndex = regexIndexOf(key, new RegExp("_(".concat(FORMS.join('|'), ")$")));

var cldrRule = cldrConv[code] || cldrConv[code.split(/-|_/)[0]];
if (!cldrRule && locale && language) {
cldrRule = cldrConv[language] || cldrConv[language.split(/-|_/)[0]];
}
if (!cldrRule) isPlural = false;

@@ -144,7 +121,5 @@ if (ignorePlurals) isPlural = false;

var number = 0;
if (isPlural && key.indexOf('_other') < 0) {
form = key.substring(pluralIndex + 1);
var oldSuffix = cldrRule.fromCldr[FORMS.indexOf(form)];
if (!oldSuffix) {

@@ -155,3 +130,2 @@ isPlural = false;

}
if (number === 1) isPlural = false;

@@ -164,8 +138,5 @@ key = key.substring(0, pluralIndex);

}
var ctxKey = key;
if (isPlural) {
ctxKey = ctxKey.substring(0, pluralIndex);
if (ctxKey.indexOf(ctxSeparator) > -1) {

@@ -179,3 +150,2 @@ context = ctxKey.substring(ctxKey.lastIndexOf(ctxSeparator) + ctxSeparator.length, ctxKey.length);

}
if (context === key) context = '';

@@ -185,3 +155,2 @@ if (context !== '') key = key.replace(ctxSeparator + context, '');

if (isPlural) appendKey = "".concat(appendKey, "_").concat(number);
if (typeof value === 'string') {

@@ -211,3 +180,2 @@ kv = {

}
function recurse(appendTo, obj, parentKey) {

@@ -220,7 +188,5 @@ if (compatibilityJSON === 'v4') {

}
recurse(flat, input, '');
Object.keys(flat).forEach(function (m) {
var kv = flat[m];
if (kv.isPlural) {

@@ -233,5 +199,3 @@ if (!flat[kv.key + kv.context]) {

}
var single = flat[kv.key + kv.context];
if (single) {

@@ -238,0 +202,0 @@ single.plurals = [].concat(_toConsumableArray(single.plurals || []), [kv]);

@@ -1,7 +0,5 @@

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
import arrify from 'arrify';
import flatten from './flatten.js';
import { getPlurals, getSetLocaleAsLanguageHeader } from './options.js';
var getGettextPluralPosition = function getGettextPluralPosition(ext, suffix) {

@@ -13,10 +11,7 @@ if (ext) {

}
return -1;
};
var getPluralArray = function getPluralArray(locale, translation, plurals) {
var ext = plurals[locale.toLowerCase()] || plurals[locale.split(/_|-/)[0].toLowerCase()] || plurals.dev;
var pArray = [];
for (var i = 0, len = translation.plurals.length; i < len; i += 1) {

@@ -26,7 +21,5 @@ var plural = translation.plurals[i];

}
pArray.splice(getGettextPluralPosition(ext, translation.pluralNumber - 1), 0, translation.value);
return pArray;
};
var parseGettext = function parseGettext(locale, data) {

@@ -49,3 +42,2 @@ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

out.headers['plural-forms'] = "nplurals=".concat(ext.numbers.length, "; plural=").concat(ext.plurals);
if (!options.noDate) {

@@ -57,3 +49,2 @@ out.headers['pot-creation-date'] = new Date().toISOString();

}
if (options.language) out.headers.language = options.language;else if (setLocaleAsLanguageHeader) out.headers.language = locale;

@@ -63,6 +54,4 @@ var delkeys = [];

var kv = data[m];
if (kv.plurals) {
var pArray = [];
for (var i = 0, len = kv.plurals.length; i < len; i += 1) {

@@ -72,9 +61,6 @@ var plural = kv.plurals[i];

}
if (ext.numbers.length !== 1) {
pArray.splice(getGettextPluralPosition(ext, kv.pluralNumber - 1), 0, kv.value);
}
if (_typeof(trans[kv.context]) !== 'object') trans[kv.context] = {};
if (options.keyasareference) {

@@ -94,3 +80,2 @@ if (_typeof(trans[kv.context][kv.value]) === 'object') {

}
if (kv.key !== kv.value) {

@@ -102,3 +87,2 @@ delkeys.push([kv.context, kv.key]);

var msgid_plural = kv.key;
if (kv.key.indexOf('|#|') > -1) {

@@ -109,3 +93,2 @@ var p = kv.key.split('|#|');

}
trans[kv.context][kv.key] = {

@@ -120,3 +103,2 @@ msgctxt: kv.context,

if (_typeof(trans[kv.context]) !== 'object') trans[kv.context] = {};
if (options.keyasareference) {

@@ -135,3 +117,2 @@ if (_typeof(trans[kv.context][kv.value]) === 'object') {

}
if (kv.key !== kv.value) {

@@ -164,7 +145,5 @@ delkeys.push([kv.context, kv.key]);

};
export default function i18next2js(locale, body) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var flat = flatten(typeof body === 'string' ? JSON.parse(body) : body, options, locale);
if (options.base) {

@@ -183,4 +162,3 @@ var bflat = flatten(JSON.parse(options.base), options);

}
return parseGettext(locale, flat, options);
}

@@ -1,11 +0,11 @@

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import { getPlurals } from './options.js';
import cldrConv from './cldrConv.js';
var FORMS = ['zero', 'one', 'two', 'few', 'many', 'other'];
var isFuzzy = function isFuzzy(translation) {
return !!translation.comments && translation.comments.flag === 'fuzzy';
};
var toArrayIfNeeded = function toArrayIfNeeded(value, _ref) {

@@ -15,3 +15,2 @@ var splitNewLine = _ref.splitNewLine;

};
var emptyOrObject = function emptyOrObject(key, value, options) {

@@ -21,6 +20,4 @@ if (options.skipUntranslated && !value) {

}
return _defineProperty({}, key, toArrayIfNeeded(value, options));
};
var getI18nextPluralExtension = function getI18nextPluralExtension(ext, i) {

@@ -30,3 +27,2 @@ if (ext && ext.numbers && ext.numbers.length === 2) return i === 0 ? '' : '_plural';

};
var getGettextValues = function getGettextValues(value, locale, targetKey, options) {

@@ -39,9 +35,6 @@ var values = value.msgstr;

var gettextValues = {};
for (var i = 0; i < values.length; i += 1) {
var pluralSuffix = getI18nextPluralExtension(ext, i);
if (options.compatibilityJSON === 'v4') {
var cldrRule = cldrConv[locale] || cldrConv[locale.split(/-|_/)[0]];
if (cldrRule && cldrRule.toCldr[pluralSuffix] !== undefined && FORMS[cldrRule.toCldr[pluralSuffix]]) {

@@ -51,14 +44,10 @@ pluralSuffix = "_".concat(FORMS[cldrRule.toCldr[pluralSuffix]]);

}
var pkey = targetKey + pluralSuffix;
Object.assign(gettextValues, emptyOrObject(pkey, values[i], options));
}
return gettextValues;
};
export default function (js) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var data = JSON.parse(JSON.stringify(js.translations));
if (options.keyasareference) {

@@ -72,13 +61,9 @@ var keys = [];

data[ctx][id] = x;
if (options.skipUntranslated && (x.msgstr.length === 1 && !x.msgstr[0] || isFuzzy(x))) {
return;
}
if (x.msgstr[0] === '') x.msgstr[0] = x.msgid;
for (var i = 1; i < x.msgstr.length; i += 1) {
if (x.msgstr[i] === '') x.msgstr[i] = x.msgid_plural;
}
x.msgid = id;

@@ -96,3 +81,2 @@ if (id !== key) keys.push([ctx, key]);

}
var json = {};

@@ -107,3 +91,2 @@ var separator = options.keyseparator || '##';

var appendTo = json;
if (key.length === 0) {

@@ -113,3 +96,2 @@ delete context[key];

}
if (options.skipUntranslated && isFuzzy(context[key])) {

@@ -119,9 +101,6 @@ delete context[key];

}
if (key.indexOf(separator) > -1) {
var _keys = key.split(separator);
var x = 0;
while (_keys[x]) {
while (_keys[x] !== undefined && _keys[x] !== null) {
if (x < _keys.length - 1) {

@@ -133,9 +112,6 @@ appendTo[_keys[x]] = appendTo[_keys[x]] || {};

}
x += 1;
}
}
if (m !== '' && !options.ignoreCtx) targetKey = "".concat(targetKey).concat(ctxSeparator).concat(m);
if (options.persistMsgIdPlural) {

@@ -147,3 +123,2 @@ var _context$key = context[key];

}
var newValues = getGettextValues(context[key], locale, targetKey, options);

@@ -150,0 +125,0 @@ Object.assign(appendTo, newValues);

@@ -1,19 +0,14 @@

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
import contentType from 'content-type';
import encoding from 'encoding';
import { HEADERS, formatCharset, compareMsgid, foldLine, generateHeader } from './shared.js';
var handleCharset = function handleCharset(table) {
var ct = contentType.parse(table.headers['Content-Type'] || 'text/plain');
var charset = formatCharset(table.charset || ct.parameters.charset || 'utf-8');
if (ct.parameters.charset) {
ct.parameters.charset = formatCharset(ct.parameters.charset);
}
table.charset = charset;
table.headers['Content-Type'] = contentType.format(ct);
};
var drawComments = function drawComments(comments) {

@@ -45,3 +40,2 @@ var lines = [];

};
var addPOString = function addPOString() {

@@ -54,14 +48,10 @@ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

var lines = [value];
if (options.foldLength > 0) {
lines = foldLine(value, options.foldLength);
}
if (lines.length < 2) {
return "".concat(key, " \"").concat(lines.shift() || '', "\"");
}
return "".concat(key, " \"\"\n\"").concat(lines.join('"\n"'), "\"");
};
var drawBlock = function drawBlock(block) {

@@ -76,13 +66,9 @@ var override = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

var comments = override.comments || block.comments;
if (comments && (comments = drawComments(comments))) {
response.push(comments);
}
if (msgctxt) {
response.push(addPOString('msgctxt', msgctxt, options));
}
response.push(addPOString('msgid', msgid || '', options));
if (msgidPlural) {

@@ -93,3 +79,2 @@ response.push(addPOString('msgid_plural', msgidPlural, options));

});
if (msgstr.length === 0) {

@@ -101,6 +86,4 @@ response.push(addPOString('msgstr[0]', '', options));

}
return response.join('\n');
};
var compile = function compile(table, options) {

@@ -117,3 +100,2 @@ var headerBlock = table.translations[''] && table.translations[''][''] || {};

});
if (options.sort !== false) {

@@ -126,3 +108,2 @@ if (typeof options.sort === 'function') {

}
response = response.map(function (r) {

@@ -134,10 +115,7 @@ return drawBlock(r, {}, options);

}, options));
if (table.charset === 'utf-8' || table.charset === 'ascii') {
return response.join('\n\n');
}
return encoding.convert(response.join('\n\n'), table.charset).toString();
};
export default function () {

@@ -149,6 +127,5 @@ var table = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

var _table$headers = table.headers,
headers = _table$headers === void 0 ? {} : _table$headers;
headers = _table$headers === void 0 ? {} : _table$headers;
headers = Object.keys(headers).reduce(function (result, key) {
var lowerKey = key.toLowerCase();
if (HEADERS.has(lowerKey)) {

@@ -159,3 +136,2 @@ result[HEADERS.get(lowerKey)] = headers[key];

}
return result;

@@ -162,0 +138,0 @@ }, {});

@@ -21,7 +21,5 @@ import encoding from 'encoding';

};
var toString = function toString(buf, charset) {
return encoding.convert(buf, 'utf-8', charset).toString('utf-8');
};
var parseHeader = function parseHeader() {

@@ -32,3 +30,2 @@ var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

var key = (parts.shift() || '').trim();
if (key) {

@@ -39,7 +36,5 @@ var value = parts.join(':').trim();

}
return headers;
}, {});
};
var handleCharset = function handleCharset() {

@@ -53,3 +48,2 @@ var buf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

var charset = defaultCharset;
if ((pos = str.search(/^\s*msgid/im)) >= 0) {

@@ -59,7 +53,5 @@ pos = pos + str.substr(pos + 5).search(/^\s*(msgid|msgctxt)/im);

}
if (match = headers.match(/[; ]charset\s*=\s*([\w-]+)(?:[\s;]|\\n)*"\s*$/mi)) {
charset = formatCharset(match[1], defaultCharset);
}
if (charset === 'utf-8') {

@@ -71,3 +63,2 @@ return {

}
return {

@@ -78,3 +69,2 @@ fileContents: toString(buf),

};
var lexer = function lexer(chunk) {

@@ -87,7 +77,5 @@ var lex = [];

var chr;
for (var i = 0, len = chunk.length; i < len; i++) {
chr = chunk.charAt(i);
if (chr === '\n') lineNumber += 1;
switch (state) {

@@ -118,5 +106,3 @@ case states.none:

}
break;
case states.comments:

@@ -128,5 +114,3 @@ if (chr === '\n') {

}
break;
case states.string:

@@ -138,15 +122,11 @@ if (escaped) {

break;
case 'n':
node.value += '\n';
break;
case 'r':
node.value += '\r';
break;
default:
node.value += chr;
}
escaped = false;

@@ -162,8 +142,5 @@ } else {

}
escaped = false;
}
break;
case states.key:

@@ -176,3 +153,2 @@ if (!chr.match(symbols.key)) {

}
state = states.none;

@@ -183,14 +159,10 @@ i--;

}
break;
}
}
return lex;
};
var joinStringValues = function joinStringValues(tokens) {
var response = [];
var lastNode;
for (var i = 0, len = tokens.length; i < len; i++) {

@@ -206,6 +178,4 @@ if (lastNode && tokens[i].type === types.string && lastNode.type === types.string) {

}
return response;
};
var parseComments = function parseComments(tokens) {

@@ -215,3 +185,2 @@ tokens.forEach(function (node) {

var lines;
if (node && node.type === types.comments) {

@@ -231,15 +200,11 @@ comment = {

break;
case '.':
comment.extracted.push(line.substr(1).replace(/^\s+/, ''));
break;
case ',':
comment.flag.push(line.substr(1).replace(/^\s+/, ''));
break;
case '|':
comment.previous.push(line.substr(1).replace(/^\s+/, ''));
break;
default:

@@ -258,7 +223,5 @@ comment.translator.push(line.replace(/^\s+/, ''));

};
var handleKeys = function handleKeys(tokens) {
var response = [];
var lastNode;
for (var i = 0, len = tokens.length; i < len; i++) {

@@ -269,7 +232,5 @@ if (tokens[i].type === types.key) {

};
if (i && tokens[i - 1].type === types.comments) {
lastNode.comments = tokens[i - 1].value;
}
lastNode.value = '';

@@ -281,6 +242,4 @@ response.push(lastNode);

}
return response;
};
var handleValues = function handleValues(tokens) {

@@ -291,3 +250,2 @@ var response = [];

var curComments;
for (var i = 0, len = tokens.length; i < len; i++) {

@@ -319,6 +277,4 @@ if (tokens[i].key.toLowerCase() === 'msgctxt') {

}
return response;
};
var normalize = function normalize(tokens, charset) {

@@ -331,17 +287,12 @@ var table = {

var msgctxt;
for (var i = 0, len = tokens.length; i < len; i++) {
msgctxt = tokens[i].msgctxt || '';
if (!table.translations[msgctxt]) table.translations[msgctxt] = {};
if (!table.headers && !msgctxt && !tokens[i].msgid) {
table.headers = parseHeader(tokens[i].msgstr[0]);
}
table.translations[msgctxt][tokens[i].msgid] = tokens[i];
}
return table;
};
var finalize = function finalize(tokens, charset) {

@@ -354,6 +305,4 @@ var data = joinStringValues(tokens);

};
export default function (fileContents) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (typeof options === 'string') {

@@ -364,5 +313,3 @@ options = {

}
options.charset = options.charset || 'iso-8859-1';
if (typeof fileContents === 'string') {

@@ -375,5 +322,4 @@ options.charset = 'utf-8';

}
var lex = lexer(fileContents);
return finalize(lex, options.charset);
}

@@ -21,10 +21,7 @@ export var HEADERS = new Map([['project-id-version', 'Project-Id-Version'], ['report-msgid-bugs-to', 'Report-Msgid-Bugs-To'], ['pot-creation-date', 'POT-Creation-Date'], ['po-revision-date', 'PO-Revision-Date'], ['last-translator', 'Last-Translator'], ['language-team', 'Language-Team'], ['language', 'Language'], ['content-type', 'Content-Type'], ['content-transfer-encoding', 'Content-Transfer-Encoding'], ['plural-forms', 'Plural-Forms'], ['mime-version', 'MIME-Version']]);

var match;
while (pos < len) {
curLine = str.substr(pos, maxLen);
while (curLine.substr(-1) === '\\' && pos + curLine.length < len) {
curLine += str.charAt(pos + curLine.length);
}
if (match = /.*?\\n/.exec(curLine)) {

@@ -39,7 +36,5 @@ curLine = match[0];

}
lines.push(curLine);
pos += curLine.length;
}
return lines;

@@ -46,0 +41,0 @@ }

@@ -64,3 +64,3 @@ // inspired by https://github.com/i18next/i18next-gettext-converter/blob/master/src/lib/gettext2json.js

options.skipUntranslated &&
((x.msgstr.length === 1 && !x.msgstr[0]) || isFuzzy(x))
((x.msgstr.length === 1 && !x.msgstr[0]) || isFuzzy(x))
) {

@@ -114,3 +114,3 @@ return

while (keys[x]) {
while (keys[x] !== undefined && keys[x] !== null) {
if (x < keys.length - 1) {

@@ -117,0 +117,0 @@ appendTo[keys[x]] = appendTo[keys[x]] || {}

{
"name": "gettext-converter",
"version": "1.2.3",
"version": "1.2.4",
"description": "po2js and js2po and i18next2po and po2i18next converter gettext resource utils",

@@ -77,21 +77,21 @@ "type": "module",

"arrify": "^2.0.1",
"content-type": "1.0.4",
"content-type": "1.0.5",
"encoding": "0.1.13"
},
"devDependencies": {
"@babel/cli": "7.18.6",
"@babel/core": "7.18.6",
"@babel/preset-env": "7.18.6",
"@babel/cli": "7.23.4",
"@babel/core": "7.23.3",
"@babel/preset-env": "7.23.3",
"babel-plugin-add-module-exports": "1.0.4",
"browserify": "17.0.0",
"eslint": "8.19.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-n": "15.2.4",
"eslint-plugin-promise": "6.0.0",
"eslint": "8.54.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-n": "16.3.1",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-require-path-exists": "1.1.9",
"eslint-plugin-standard": "5.0.0",
"expect.js": "0.3.1",
"mocha": "10.0.0",
"uglify-js": "3.16.2"
"mocha": "10.2.0",
"uglify-js": "3.17.4"
},

@@ -98,0 +98,0 @@ "scripts": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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