Comparing version 6.0.3 to 6.1.0
@@ -22,3 +22,5 @@ "use strict"; | ||
options = options || {}; | ||
options = options || { | ||
captureSpacesBetweenElements: false | ||
}; | ||
@@ -35,3 +37,3 @@ if (typeof str !== 'string') { | ||
try { | ||
xmlObj = _xmlJs.default.xml2js(str, {}); | ||
xmlObj = _xmlJs.default.xml2js(str, options); | ||
} catch (err) { | ||
@@ -47,10 +49,15 @@ if (cb) return cb(err); | ||
if (xliffRoot.elements && xliffRoot.elements.length) { | ||
var srcLang = xliffRoot.elements[0].attributes['source-language']; | ||
var trgLang = xliffRoot.elements[0].attributes['target-language']; | ||
var elements = xliffRoot.elements.filter(function (e) { | ||
return e.type === 'element'; | ||
}); | ||
var srcLang = elements[0].attributes['source-language'] || xliffRoot.attributes.srcLang; | ||
var trgLang = elements[0].attributes['target-language'] || xliffRoot.attributes.trgLang; | ||
result.sourceLanguage = srcLang; | ||
result.targetLanguage = trgLang; | ||
if (!result.targetLanguage) delete result.targetLanguage; | ||
result.resources = xliffRoot.elements.reduce(function (resources, file) { | ||
result.resources = elements.reduce(function (resources, file) { | ||
var namespace = options.namespace || file.attributes.original; | ||
var body = file.elements.find(function (e) { | ||
var body = file.elements.filter(function (e) { | ||
return e.type === 'element'; | ||
}).find(function (e) { | ||
return e.name === 'body'; | ||
@@ -60,3 +67,3 @@ }); | ||
var bodyChildren = body.elements.filter(function (child) { | ||
return child.type !== 'comment'; | ||
return child.type !== 'comment' && child.type === 'element'; | ||
}); | ||
@@ -63,0 +70,0 @@ resources[namespace] = createUnits(bodyChildren); |
@@ -11,3 +11,5 @@ import convert from 'xml-js'; | ||
options = options || {}; | ||
options = options || { | ||
captureSpacesBetweenElements: false | ||
}; | ||
@@ -24,3 +26,3 @@ if (typeof str !== 'string') { | ||
try { | ||
xmlObj = convert.xml2js(str, {}); | ||
xmlObj = convert.xml2js(str, options); | ||
} catch (err) { | ||
@@ -36,10 +38,15 @@ if (cb) return cb(err); | ||
if (xliffRoot.elements && xliffRoot.elements.length) { | ||
var srcLang = xliffRoot.elements[0].attributes['source-language']; | ||
var trgLang = xliffRoot.elements[0].attributes['target-language']; | ||
var elements = xliffRoot.elements.filter(function (e) { | ||
return e.type === 'element'; | ||
}); | ||
var srcLang = elements[0].attributes['source-language'] || xliffRoot.attributes.srcLang; | ||
var trgLang = elements[0].attributes['target-language'] || xliffRoot.attributes.trgLang; | ||
result.sourceLanguage = srcLang; | ||
result.targetLanguage = trgLang; | ||
if (!result.targetLanguage) delete result.targetLanguage; | ||
result.resources = xliffRoot.elements.reduce(function (resources, file) { | ||
result.resources = elements.reduce(function (resources, file) { | ||
var namespace = options.namespace || file.attributes.original; | ||
var body = file.elements.find(function (e) { | ||
var body = file.elements.filter(function (e) { | ||
return e.type === 'element'; | ||
}).find(function (e) { | ||
return e.name === 'body'; | ||
@@ -49,3 +56,3 @@ }); | ||
var bodyChildren = body.elements.filter(function (child) { | ||
return child.type !== 'comment'; | ||
return child.type !== 'comment' && child.type === 'element'; | ||
}); | ||
@@ -52,0 +59,0 @@ resources[namespace] = createUnits(bodyChildren); |
@@ -10,3 +10,3 @@ import convert from 'xml-js' | ||
} | ||
options = options || {} | ||
options = options || { captureSpacesBetweenElements: false } | ||
if (typeof str !== 'string') { | ||
@@ -22,3 +22,3 @@ const err = new Error('The first parameter was not a string') | ||
try { | ||
xmlObj = convert.xml2js(str, {}) | ||
xmlObj = convert.xml2js(str, options) | ||
} catch (err) { | ||
@@ -32,4 +32,5 @@ if (cb) return cb(err) | ||
if (xliffRoot.elements && xliffRoot.elements.length) { | ||
const srcLang = xliffRoot.elements[0].attributes['source-language'] | ||
const trgLang = xliffRoot.elements[0].attributes['target-language'] | ||
const elements = xliffRoot.elements.filter((e) => e.type === 'element') | ||
const srcLang = elements[0].attributes['source-language'] || xliffRoot.attributes.srcLang | ||
const trgLang = elements[0].attributes['target-language'] || xliffRoot.attributes.trgLang | ||
@@ -40,9 +41,9 @@ result.sourceLanguage = srcLang | ||
result.resources = xliffRoot.elements.reduce((resources, file) => { | ||
result.resources = elements.reduce((resources, file) => { | ||
const namespace = options.namespace || file.attributes.original | ||
const body = file.elements.find((e) => e.name === 'body') | ||
const body = file.elements.filter((e) => e.type === 'element').find((e) => e.name === 'body') | ||
body.elements = body.elements || [] | ||
const bodyChildren = body.elements.filter( | ||
(child) => child.type !== 'comment' | ||
(child) => child.type !== 'comment' && child.type === 'element' | ||
) | ||
@@ -49,0 +50,0 @@ |
{ | ||
"name": "xliff", | ||
"version": "6.0.3", | ||
"version": "6.1.0", | ||
"description": "xliff2js and js2xliff converter xliff utils", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -516,3 +516,3 @@ [![CI](https://github.com/locize/xliff/actions/workflows/ci.yml/badge.svg)](https://github.com/locize/xliff/actions/workflows/ci.yml) [![travis](https://img.shields.io/travis/locize/xliff.svg)](https://travis-ci.org/locize/xliff) [![npm](https://img.shields.io/npm/v/xliff.svg)](https://npmjs.org/package/xliff) | ||
If you need to create your own inline element objects to construct a `source` or `target` array, you can use the `[makeInlineElement](./inline-elements/makeInlineElement.js)` function. | ||
If you need to create your own inline element objects to construct a `source` or `target` array, you can use the [`makeInlineElement()`](./lib/inline-elements/makeInlineElement.js) function. | ||
@@ -519,0 +519,0 @@ For example, suppose you have this string: |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
559420
11378