Socket
Socket
Sign inDemoInstall

po2json

Package Overview
Dependencies
7
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0-beta-2 to 1.0.0-beta-3

.idea/jsLibraryMappings.xml

35

lib/parse.js

@@ -8,3 +8,3 @@ /**

*/
var g2m = require('gettext-to-messageformat');
const g2m = require('gettext-to-messageformat');

@@ -15,3 +15,3 @@ module.exports = function (buffer, options) {

options = options || {};
var defaults = {
const defaults = {
pretty: false,

@@ -27,8 +27,9 @@ fuzzy: false,

for (var property in defaults) {
for (const property in defaults) {
options[property] = 'undefined' !== typeof options[property] ? options[property] : defaults[property];
}
var mfTranslations = {};
var mf = {};
const mf = {};
let mfTranslations = {};
let result = {};

@@ -38,3 +39,8 @@ // defer to gettext-to-messageformat for the 'mf' format option

if (options.format === 'mf') {
result = Object.keys(options.mfOptions).length > 0 ? g2m.parsePo(buffer, options.mfOptions) : g2m.parsePo(buffer);
const poString = buffer.toString();
// if the Plural-Forms header is missing, g2m needs a function or will throw an error
const mfOptions = (poString.includes('"Plural-Forms:')) ? options.mfOptions : Object.assign({}, {
pluralFunction: () => 0
}, options.mfOptions);
result = Object.keys(mfOptions).length > 0 ? g2m.parsePo(buffer, mfOptions) : g2m.parsePo(buffer);

@@ -68,14 +74,13 @@ if (options.fullMF) {

// Parse the PO file
var parsed = require('gettext-parser').po.parse(buffer, defaults.charset);
const parsed = require('gettext-parser').po.parse(buffer, defaults.charset);
// Create gettext/Jed compatible JSON from parsed data
var result = {},
contexts = parsed.translations;
const contexts = parsed.translations;
Object.keys(contexts).forEach(function (context) {
var translations = parsed.translations[context];
var pluralForms = parsed.headers ? parsed.headers['plural-forms'] : '';
const translations = parsed.translations[context];
const pluralForms = parsed.headers ? parsed.headers['plural-forms'] : '';
Object.keys(translations).forEach(function (key, i) {
var t = translations[key],
const t = translations[key],
translationKey = context.length ? context + '\u0004' + key : key,

@@ -117,3 +122,3 @@ fuzzy = t.comments && t.comments.flag && t.comments.flag.match(/fuzzy/) !== null;

if (options.format.indexOf('jed') === 0) {
var jed = {
const jed = {
domain: options.domain,

@@ -123,5 +128,5 @@ locale_data: {}

if (options.format === 'jed') {
for (var key in result) {
for (const key in result) {
if (result.hasOwnProperty(key) && key !== '') {
for (var i = 2; i < result[key].length; i++) {
for (let i = 2; i < result[key].length; i++) {
if ('' === result[key][i]) {

@@ -128,0 +133,0 @@ result[key][i] = result[key][0];

{
"name": "po2json",
"description": "Convert PO files to JSON",
"version": "1.0.0-beta-2",
"version": "1.0.0-beta-3",
"homepage": "https://github.com/mikeedwards/po2json",

@@ -55,11 +55,11 @@ "author": {

"engines": {
"node": ">=6.0"
"node": ">=10.0"
},
"scripts": {
"test": "nodeunit test/"
"test": "jest"
},
"devDependencies": {
"jed": "~1.1.1",
"messageformat": "^2.0.4",
"nodeunit": "*"
"jest": "^26.1.0",
"messageformat": "^2.3.0"
},

@@ -73,11 +73,11 @@ "keywords": [

"dependencies": {
"commander": "^2.18.0",
"commander": "^6.0.0",
"gettext-parser": "2.0.0",
"gettext-to-messageformat": "0.3.0"
"gettext-to-messageformat": "0.3.1"
},
"peerDependencies": {
"commander": "^2.18.0",
"commander": "^6.0.0",
"gettext-parser": "2.0.0",
"gettext-to-messageformat": "0.3.0"
"gettext-to-messageformat": "0.3.1"
}
}

@@ -7,4 +7,2 @@ # po2json

[![NPM](https://nodei.co/npm/po2json.png)](https://nodei.co/npm/po2json/)
Convert PO files to Javascript objects or JSON strings. The result is Jed-compatible.

@@ -11,0 +9,0 @@

@@ -6,3 +6,3 @@ {

"A sentence with \"quotation\" marks.": "A sentence with \"quotation\" marks.",
"one product": "{0, plural, p0{one product} p1{{0} products} p2{{0} products}}",
"one product": "{0, plural, p0{one product} p1{{0} products}}",
"string context": {

@@ -9,0 +9,0 @@ "the contextual phrase": "the contextual phrase"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc