19
19
20
20
namespace AutoResxTranslator
21
21
{
22
- public partial class frmMain : Form
22
+ public partial class frmMain : Form
23
23
{
24
24
public frmMain ( )
25
25
{
@@ -258,7 +258,7 @@ void TranslateResxFiles()
258
258
} ;
259
259
260
260
IsBusy ( true ) ;
261
- new Action < string , string , TranslationOptions , List < string > , string , ResxProgressCallback , bool , bool > ( TranslateResxFilesAsync ) . BeginInvoke (
261
+ new Action < string , string , TranslationOptions , List < string > , string , ResxProgressCallback , bool , bool , bool , string > ( TranslateResxFilesAsync ) . BeginInvoke (
262
262
txtSourceResx . Text ,
263
263
srcLng ,
264
264
translationOptions ,
@@ -267,6 +267,8 @@ void TranslateResxFiles()
267
267
ResxWorkingProgress ,
268
268
translateFromKey ,
269
269
checkBoxTranslateOnlyNew . Checked ,
270
+ chkCSVOutput . Checked ,
271
+ txtCSVOutputDir . Text ,
270
272
( x ) => IsBusy ( false ) ,
271
273
null ) ;
272
274
}
@@ -280,7 +282,9 @@ async void TranslateResxFilesAsync(
280
282
List < string > desLanguages , string destDir ,
281
283
ResxProgressCallback progress ,
282
284
bool translateFromKey ,
283
- bool translateOnlyNewKeys )
285
+ bool translateOnlyNewKeys ,
286
+ bool generateCsv ,
287
+ string generateCsvDir )
284
288
{
285
289
int max = 0 ;
286
290
int pos = 0 ;
@@ -300,7 +304,10 @@ async void TranslateResxFilesAsync(
300
304
var dataList = ResxTranslator . ReadResxData ( doc ) ;
301
305
max = dataList . Count ;
302
306
303
- string [ ] CSVOutputArray = new string [ max ] ;
307
+ string [ ] csvOutputDataBuffer = null ;
308
+ if ( generateCsv )
309
+ csvOutputDataBuffer = new string [ max ] ;
310
+
304
311
List < XmlNode > destinationDataList = null ;
305
312
var destTranslateOnlyNewKeys =
306
313
translateOnlyNewKeys &&
@@ -339,8 +346,8 @@ async void TranslateResxFilesAsync(
339
346
if ( destNode == keyNode )
340
347
{
341
348
valueNode . InnerText = ResxTranslator . GetDataValueNode ( destinationDataList . ElementAt ( destIndex ) ) . InnerText ;
342
- if ( chkCSVOutput . Checked )
343
- CSVOutputArray [ index ] = keyNode + "," + valueNode . InnerText ;
349
+ if ( generateCsv )
350
+ csvOutputDataBuffer [ index ] = keyNode + "," + valueNode . InnerText ;
344
351
continue ;
345
352
}
346
353
else
@@ -420,20 +427,23 @@ async void TranslateResxFilesAsync(
420
427
catch { }
421
428
}
422
429
}
423
- if ( chkCSVOutput . Checked )
424
- CSVOutputArray [ index ] = keyNode + "," + valueNode . InnerText ;
430
+ if ( generateCsv )
431
+ csvOutputDataBuffer [ index ] = keyNode + "," + valueNode . InnerText ;
425
432
}
426
433
}
427
434
finally
428
435
{
429
- // now save that shit !
436
+ // now save the data !
430
437
doc . Save ( destFile ) ;
431
- if ( chkCSVOutput . Checked )
438
+
439
+ if ( generateCsv )
432
440
{
433
- if ( ! Directory . Exists ( txtCSVOutputDir . Text ) )
434
- Directory . CreateDirectory ( txtCSVOutputDir . Text ) ;
435
- File . WriteAllLines ( txtCSVOutputDir . Text + "\\ " + sourceResxFilename + "." + destLng + ".resx.csv" , new string [ ] { "KEY,Value" } , System . Text . Encoding . UTF8 ) ;
436
- File . AppendAllLines ( txtCSVOutputDir . Text + "\\ " + sourceResxFilename + "." + destLng + ".resx.csv" , CSVOutputArray , System . Text . Encoding . UTF8 ) ;
441
+ if ( ! Directory . Exists ( generateCsvDir ) )
442
+ Directory . CreateDirectory ( generateCsvDir ) ;
443
+ var csvFile = Path . Combine ( generateCsvDir , sourceResxFilename + "." + destLng + ".resx.csv" ) ;
444
+
445
+ File . WriteAllLines ( csvFile , new string [ ] { "KEY,Value" } , Encoding . UTF8 ) ;
446
+ File . AppendAllLines ( csvFile , csvOutputDataBuffer , Encoding . UTF8 ) ;
437
447
}
438
448
}
439
449
}
@@ -795,15 +805,18 @@ private void RbtnMsTranslateService_CheckedChanged(object sender, EventArgs e)
795
805
txtMsTranslationRegion . Enabled = rbtnMsTranslateService . Checked ;
796
806
}
797
807
798
- private void chkCSVOutput_CheckedChanged ( object sender , EventArgs e )
799
- {
808
+ private void chkCSVOutput_CheckedChanged ( object sender , EventArgs e )
809
+ {
800
810
txtCSVOutputDir . Enabled = btnSelectCSVOutputDir . Enabled = chkCSVOutput . Checked ;
801
- }
811
+ }
802
812
803
- private void btnSelectCSVOutputDir_Click ( object sender , EventArgs e )
804
- {
805
- var dlg = new FolderBrowserDialog ( ) ;
806
- dlg . ShowNewFolderButton = true ;
813
+ private void btnSelectCSVOutputDir_Click ( object sender , EventArgs e )
814
+ {
815
+ var dlg = new FolderBrowserDialog
816
+ {
817
+ ShowNewFolderButton = true ,
818
+ Description = "Please select output directory for CSV files:"
819
+ } ;
807
820
if ( txtCSVOutputDir . Text . Length > 0 )
808
821
{
809
822
dlg . SelectedPath = txtCSVOutputDir . Text ;
@@ -813,5 +826,5 @@ private void btnSelectCSVOutputDir_Click(object sender, EventArgs e)
813
826
txtCSVOutputDir . Text = dlg . SelectedPath ;
814
827
}
815
828
}
816
- }
829
+ }
817
830
}
0 commit comments