Skip to content

Commit

Permalink
do not error on empty groups, fixes #53
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Feb 28, 2022
1 parent cf8e78f commit 1b47d87
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 6.0.2

- do not error on empty groups [#53](https://github.com/locize/xliff/issues/53)

### 6.0.1

- handle empty xliff files [#52](https://github.com/locize/xliff/pull/52)
Expand Down
1 change: 1 addition & 0 deletions lib/xliff12ToJs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const xliff12ToJsClb = (str, options, cb) => {
function createUnits (childElements) {
return childElements.reduce((parent, child) => {
const key = child.attributes.id
if (!child.elements) return parent
const children = child.elements.filter((e) => e.name === 'trans-unit' || e.name === 'group')
if (children.length) {
parent[key] = createGroupTag(child, children)
Expand Down
2 changes: 2 additions & 0 deletions lib/xliff2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const xliffToJsClb = (str, options, cb) => {
}

function createUnits (parent, initValues) {
if (!parent.elements) return {}
return parent.elements.reduce((file, unit) => {
const key = unit.attributes.id
const additionalAttributes = unit.attributes
Expand Down Expand Up @@ -85,6 +86,7 @@ function createUnits (parent, initValues) {

function createUnit (unit, initValues) {
// source, target, note
if (!unit.elements) return undefined
return unit.elements.reduce((unit, segment) => {
if (['segment', 'notes'].indexOf(segment.name) < 0) return unit
segment.elements.forEach((element) => {
Expand Down
3 changes: 3 additions & 0 deletions xliff.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ var xliff12ToJsClb = function xliff12ToJsClb(str, options, cb) {
function createUnits(childElements) {
return childElements.reduce(function (parent, child) {
var key = child.attributes.id;
if (!child.elements) return parent;
var children = child.elements.filter(function (e) {
return e.name === 'trans-unit' || e.name === 'group';
});
Expand Down Expand Up @@ -1088,6 +1089,7 @@ var xliffToJsClb = function xliffToJsClb(str, options, cb) {
};

function createUnits(parent, initValues) {
if (!parent.elements) return {};
return parent.elements.reduce(function (file, unit) {
var key = unit.attributes.id;
var additionalAttributes = unit.attributes;
Expand Down Expand Up @@ -1125,6 +1127,7 @@ function createUnits(parent, initValues) {
}

function createUnit(unit, initValues) {
if (!unit.elements) return undefined;
return unit.elements.reduce(function (unit, segment) {
if (['segment', 'notes'].indexOf(segment.name) < 0) return unit;
segment.elements.forEach(function (element) {
Expand Down
2 changes: 1 addition & 1 deletion xliff.min.js

Large diffs are not rendered by default.

0 comments on commit 1b47d87

Please sign in to comment.