diff --git a/grunt/helpers/Translate.js b/grunt/helpers/Translate.js index 32519a797..4047738ea 100644 --- a/grunt/helpers/Translate.js +++ b/grunt/helpers/Translate.js @@ -191,22 +191,41 @@ class Translate { return prev; }, {}); + // xliff 2.0 + // const output = ` + // + // ${Object.entries(outputGroupedByFile).map(([fileName, entries]) => { + // return ` + // ${entries.map(item => { + // const value = /[<>&"'/]/.test(item.value) + // ? `` + // : item.value; + // return ` + // + // ${value} + // ${value} + // + // + // `; + // }).filter(Boolean).join('')} + // `; + // }).join('')}`; + + // xliff 1.2 const output = ` - + ${Object.entries(outputGroupedByFile).map(([fileName, entries]) => { - return ` + return ` ${entries.map(item => { const value = /[<>&"'/]/.test(item.value) ? `` : item.value; - return ` - - ${value} - ${value} - - + return ` + ${value} + ${value} + `; - }).filter(Boolean).join('')} + }).filter(Boolean).join('')} `; }).join('')}`; const filePath = path.join(outputFolder, 'source.xlf'); @@ -330,14 +349,27 @@ ${entries.map(item => { attributeNamePrefix: '' }); const xml = parser.parse(XMLData); + // xliff 2.0 + // for (const file of xml.xliff.file) { + // for (const unit of file.unit) { + // const [ id, ...path ] = unit.id.split('/'); + // importData.push({ + // file: file.id, + // id, + // path: path.filter(Boolean).join('/'), + // value: unit.segment.target['#text'] + // }); + // } + // } + // xliff 1.2 for (const file of xml.xliff.file) { - for (const unit of file.unit) { + for (const unit of file.body['trans-unit']) { const [ id, ...path ] = unit.id.split('/'); importData.push({ - file: file.id, + file: file.original, id, path: path.filter(Boolean).join('/'), - value: unit.segment.target['#text'] + value: unit.source }); } }