1919
2020namespace AutoResxTranslator
2121{
22- public partial class frmMain : Form
22+ public partial class frmMain : Form
2323 {
2424 public frmMain ( )
2525 {
@@ -258,7 +258,7 @@ void TranslateResxFiles()
258258 } ;
259259
260260 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 (
262262 txtSourceResx . Text ,
263263 srcLng ,
264264 translationOptions ,
@@ -267,6 +267,8 @@ void TranslateResxFiles()
267267 ResxWorkingProgress ,
268268 translateFromKey ,
269269 checkBoxTranslateOnlyNew . Checked ,
270+ chkCSVOutput . Checked ,
271+ txtCSVOutputDir . Text ,
270272 ( x ) => IsBusy ( false ) ,
271273 null ) ;
272274 }
@@ -280,7 +282,9 @@ async void TranslateResxFilesAsync(
280282 List < string > desLanguages , string destDir ,
281283 ResxProgressCallback progress ,
282284 bool translateFromKey ,
283- bool translateOnlyNewKeys )
285+ bool translateOnlyNewKeys ,
286+ bool generateCsv ,
287+ string generateCsvDir )
284288 {
285289 int max = 0 ;
286290 int pos = 0 ;
@@ -300,7 +304,10 @@ async void TranslateResxFilesAsync(
300304 var dataList = ResxTranslator . ReadResxData ( doc ) ;
301305 max = dataList . Count ;
302306
303- string [ ] CSVOutputArray = new string [ max ] ;
307+ string [ ] csvOutputDataBuffer = null ;
308+ if ( generateCsv )
309+ csvOutputDataBuffer = new string [ max ] ;
310+
304311 List < XmlNode > destinationDataList = null ;
305312 var destTranslateOnlyNewKeys =
306313 translateOnlyNewKeys &&
@@ -339,8 +346,8 @@ async void TranslateResxFilesAsync(
339346 if ( destNode == keyNode )
340347 {
341348 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 ;
344351 continue ;
345352 }
346353 else
@@ -420,20 +427,23 @@ async void TranslateResxFilesAsync(
420427 catch { }
421428 }
422429 }
423- if ( chkCSVOutput . Checked )
424- CSVOutputArray [ index ] = keyNode + "," + valueNode . InnerText ;
430+ if ( generateCsv )
431+ csvOutputDataBuffer [ index ] = keyNode + "," + valueNode . InnerText ;
425432 }
426433 }
427434 finally
428435 {
429- // now save that shit !
436+ // now save the data !
430437 doc . Save ( destFile ) ;
431- if ( chkCSVOutput . Checked )
438+
439+ if ( generateCsv )
432440 {
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 ) ;
437447 }
438448 }
439449 }
@@ -795,15 +805,18 @@ private void RbtnMsTranslateService_CheckedChanged(object sender, EventArgs e)
795805 txtMsTranslationRegion . Enabled = rbtnMsTranslateService . Checked ;
796806 }
797807
798- private void chkCSVOutput_CheckedChanged ( object sender , EventArgs e )
799- {
808+ private void chkCSVOutput_CheckedChanged ( object sender , EventArgs e )
809+ {
800810 txtCSVOutputDir . Enabled = btnSelectCSVOutputDir . Enabled = chkCSVOutput . Checked ;
801- }
811+ }
802812
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+ } ;
807820 if ( txtCSVOutputDir . Text . Length > 0 )
808821 {
809822 dlg . SelectedPath = txtCSVOutputDir . Text ;
@@ -813,5 +826,5 @@ private void btnSelectCSVOutputDir_Click(object sender, EventArgs e)
813826 txtCSVOutputDir . Text = dlg . SelectedPath ;
814827 }
815828 }
816- }
829+ }
817830}
0 commit comments