locize / xliff

xliff2js and js2xliff converter xliff utils
MIT License
80 stars 37 forks source link

XLIFF to JSON doesn't ignore comments #24

Closed Robilol closed 5 years ago

Robilol commented 5 years ago

Hello,

I have some comments in my XLIFF files and i got an error with the function cause of them.

node_modules/xliff/xliff12ToJs.js:49

const key = transUnit.attributes.id;
TypeError: Cannot read property 'id' of undefined

Indeed the function try to get the ID on a comment type element :

console.log(transUnit)

...
{ type: 'element',
  name: 'trans-unit',
  attributes: { id: 'seo_anchor_city' },
  elements:
   [ { type: 'element', name: 'source', elements: [Array] },
     { type: 'element', name: 'target', elements: [Array] } ] }

{ type: 'comment', comment: '            comment ' }

I think you should probably add a check to get the ID attribute only on element type and ignore comment type

adrai commented 5 years ago

fixed with v4.3.1