@@ -63,8 +63,8 @@ var BundledFormat;
63
63
BundledFormat . is = is ;
64
64
} ) ( BundledFormat || ( BundledFormat = { } ) ) ;
65
65
class Line {
66
+ buffer = [ ] ;
66
67
constructor ( indent = 0 ) {
67
- this . buffer = [ ] ;
68
68
if ( indent > 0 ) {
69
69
this . buffer . push ( new Array ( indent + 1 ) . join ( ' ' ) ) ;
70
70
}
@@ -79,6 +79,7 @@ class Line {
79
79
}
80
80
exports . Line = Line ;
81
81
class TextModel {
82
+ _lines ;
82
83
constructor ( contents ) {
83
84
this . _lines = contents . split ( / \r \n | \r | \n / ) ;
84
85
}
@@ -87,6 +88,10 @@ class TextModel {
87
88
}
88
89
}
89
90
class XLF {
91
+ project ;
92
+ buffer ;
93
+ files ;
94
+ numberOfMessages ;
90
95
constructor ( project ) {
91
96
this . project = project ;
92
97
this . buffer = [ ] ;
@@ -168,55 +173,55 @@ class XLF {
168
173
line . append ( content ) ;
169
174
this . buffer . push ( line . toString ( ) ) ;
170
175
}
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 } ` ) ) ;
189
183
}
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.` ) ) ;
214
187
}
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 ) ;
215
220
} ) ;
216
- resolve ( files ) ;
217
221
} ) ;
218
- } ) ;
219
- } ;
222
+ } ;
223
+ }
224
+ exports . XLF = XLF ;
220
225
function sortLanguages ( languages ) {
221
226
return languages . sort ( ( a , b ) => {
222
227
return a . id < b . id ? - 1 : ( a . id > b . id ? 1 : 0 ) ;
0 commit comments