@@ -63,8 +63,8 @@ var BundledFormat;
6363 BundledFormat . is = is ;
6464} ) ( BundledFormat || ( BundledFormat = { } ) ) ;
6565class Line {
66+ buffer = [ ] ;
6667 constructor ( indent = 0 ) {
67- this . buffer = [ ] ;
6868 if ( indent > 0 ) {
6969 this . buffer . push ( new Array ( indent + 1 ) . join ( ' ' ) ) ;
7070 }
@@ -79,6 +79,7 @@ class Line {
7979}
8080exports . Line = Line ;
8181class TextModel {
82+ _lines ;
8283 constructor ( contents ) {
8384 this . _lines = contents . split ( / \r \n | \r | \n / ) ;
8485 }
@@ -87,6 +88,10 @@ class TextModel {
8788 }
8889}
8990class XLF {
91+ project ;
92+ buffer ;
93+ files ;
94+ numberOfMessages ;
9095 constructor ( project ) {
9196 this . project = project ;
9297 this . buffer = [ ] ;
@@ -168,55 +173,55 @@ class XLF {
168173 line . append ( content ) ;
169174 this . buffer . push ( line . toString ( ) ) ;
170175 }
171- }
172- exports . XLF = XLF ;
173- XLF . parse = function ( xlfString ) {
174- return new Promise ( ( resolve , reject ) => {
175- const parser = new xml2js . Parser ( ) ;
176- const files = [ ] ;
177- parser . parseString ( xlfString , function ( err , result ) {
178- if ( err ) {
179- reject ( new Error ( `XLF parsing error: Failed to parse XLIFF string. ${ err } ` ) ) ;
180- }
181- const fileNodes = result [ 'xliff' ] [ 'file' ] ;
182- if ( ! fileNodes ) {
183- reject ( new Error ( `XLF parsing error: XLIFF file does not contain "xliff" or "file" node(s) required for parsing.` ) ) ;
184- }
185- fileNodes . forEach ( ( file ) => {
186- const name = file . $ . original ;
187- if ( ! name ) {
188- reject ( new Error ( `XLF parsing error: XLIFF file node does not contain original attribute to determine the original location of the resource file.` ) ) ;
176+ static parse = function ( xlfString ) {
177+ return new Promise ( ( resolve , reject ) => {
178+ const parser = new xml2js . Parser ( ) ;
179+ const files = [ ] ;
180+ parser . parseString ( xlfString , function ( err , result ) {
181+ if ( err ) {
182+ reject ( new Error ( `XLF parsing error: Failed to parse XLIFF string. ${ err } ` ) ) ;
189183 }
190- const language = file . $ [ 'target-language' ] ;
191- if ( ! language ) {
192- reject ( new Error ( `XLF parsing error: XLIFF file node does not contain target-language attribute to determine translated language.` ) ) ;
193- }
194- const messages = { } ;
195- const transUnits = file . body [ 0 ] [ 'trans-unit' ] ;
196- if ( transUnits ) {
197- transUnits . forEach ( ( unit ) => {
198- const key = unit . $ . id ;
199- if ( ! unit . target ) {
200- return ; // No translation available
201- }
202- let val = unit . target [ 0 ] ;
203- if ( typeof val !== 'string' ) {
204- // We allow empty source values so support them for translations as well.
205- val = val . _ ? val . _ : '' ;
206- }
207- if ( ! key ) {
208- reject ( new Error ( `XLF parsing error: trans-unit ${ JSON . stringify ( unit , undefined , 0 ) } defined in file ${ name } is missing the ID attribute.` ) ) ;
209- return ;
210- }
211- messages [ key ] = decodeEntities ( val ) ;
212- } ) ;
213- files . push ( { messages, name, language : language . toLowerCase ( ) } ) ;
184+ const fileNodes = result [ 'xliff' ] [ 'file' ] ;
185+ if ( ! fileNodes ) {
186+ reject ( new Error ( `XLF parsing error: XLIFF file does not contain "xliff" or "file" node(s) required for parsing.` ) ) ;
214187 }
188+ fileNodes . forEach ( ( file ) => {
189+ const name = file . $ . original ;
190+ if ( ! name ) {
191+ reject ( new Error ( `XLF parsing error: XLIFF file node does not contain original attribute to determine the original location of the resource file.` ) ) ;
192+ }
193+ const language = file . $ [ 'target-language' ] ;
194+ if ( ! language ) {
195+ reject ( new Error ( `XLF parsing error: XLIFF file node does not contain target-language attribute to determine translated language.` ) ) ;
196+ }
197+ const messages = { } ;
198+ const transUnits = file . body [ 0 ] [ 'trans-unit' ] ;
199+ if ( transUnits ) {
200+ transUnits . forEach ( ( unit ) => {
201+ const key = unit . $ . id ;
202+ if ( ! unit . target ) {
203+ return ; // No translation available
204+ }
205+ let val = unit . target [ 0 ] ;
206+ if ( typeof val !== 'string' ) {
207+ // We allow empty source values so support them for translations as well.
208+ val = val . _ ? val . _ : '' ;
209+ }
210+ if ( ! key ) {
211+ reject ( new Error ( `XLF parsing error: trans-unit ${ JSON . stringify ( unit , undefined , 0 ) } defined in file ${ name } is missing the ID attribute.` ) ) ;
212+ return ;
213+ }
214+ messages [ key ] = decodeEntities ( val ) ;
215+ } ) ;
216+ files . push ( { messages, name, language : language . toLowerCase ( ) } ) ;
217+ }
218+ } ) ;
219+ resolve ( files ) ;
215220 } ) ;
216- resolve ( files ) ;
217221 } ) ;
218- } ) ;
219- } ;
222+ } ;
223+ }
224+ exports . XLF = XLF ;
220225function sortLanguages ( languages ) {
221226 return languages . sort ( ( a , b ) => {
222227 return a . id < b . id ? - 1 : ( a . id > b . id ? 1 : 0 ) ;
0 commit comments