@@ -259,14 +259,15 @@ void TranslateResxFiles()
259259 } ;
260260
261261 IsBusy ( true ) ;
262- new Action < string , string , TranslationOptions , List < string > , string , ResxProgressCallback , bool > ( TranslateResxFilesAsync ) . BeginInvoke (
262+ new Action < string , string , TranslationOptions , List < string > , string , ResxProgressCallback , bool , bool > ( TranslateResxFilesAsync ) . BeginInvoke (
263263 txtSourceResx . Text ,
264264 srcLng ,
265265 translationOptions ,
266266 destLanguages ,
267267 txtOutputDir . Text ,
268268 ResxWorkingProgress ,
269269 translateFromKey ,
270+ checkBoxTranslateOnlyNew . Checked ,
270271 ( x ) => IsBusy ( false ) ,
271272 null ) ;
272273 }
@@ -279,7 +280,8 @@ async void TranslateResxFilesAsync(
279280 TranslationOptions translationOptions ,
280281 List < string > desLanguages , string destDir ,
281282 ResxProgressCallback progress ,
282- bool translateFromKey )
283+ bool translateFromKey ,
284+ bool translateOnlyNewKeys )
283285 {
284286 int max = 0 ;
285287 int pos = 0 ;
@@ -298,14 +300,18 @@ async void TranslateResxFilesAsync(
298300 doc . Load ( sourceResx ) ;
299301 var dataList = ResxTranslator . ReadResxData ( doc ) ;
300302 max = dataList . Count ;
301- List < XmlNode > targetDataList = new List < XmlNode > ( ) ;
302- bool FileExist = File . Exists ( destFile ) ;
303- if ( checkBoxTranslateOnlyNew . Checked && FileExist )
304- {
305- var Targetdoc = new XmlDocument ( ) ;
306- Targetdoc . Load ( destFile ) ;
307303
308- targetDataList = ResxTranslator . ReadResxData ( Targetdoc ) ;
304+
305+ List < XmlNode > destinationDataList = null ;
306+ var destTranslateOnlyNewKeys =
307+ translateOnlyNewKeys &&
308+ File . Exists ( destFile ) ;
309+
310+ if ( destTranslateOnlyNewKeys )
311+ {
312+ var destDoc = new XmlDocument ( ) ;
313+ destDoc . Load ( destFile ) ;
314+ destinationDataList = ResxTranslator . ReadResxData ( destDoc ) ;
309315 }
310316
311317 pos = 0 ;
@@ -314,33 +320,33 @@ async void TranslateResxFilesAsync(
314320
315321 try
316322 {
317- int indexCorrection = 0 ;
323+ int destIndexCorrection = 0 ;
318324 foreach ( var ( node , index ) in dataList . Select ( ( n , i ) => ( n , i ) ) )
319325 {
320326 status = "Translating language: " + destLng ;
321327 pos += 1 ;
322328 progress . BeginInvoke ( max , pos , status , null , null ) ;
323329 var valueNode = ResxTranslator . GetDataValueNode ( node ) ;
324- var orgText = translateFromKey ? ResxTranslator . GetDataKeyName ( node ) : valueNode . InnerText ;
325- if ( checkBoxTranslateOnlyNew . Checked && FileExist )
330+ if ( valueNode == null )
331+ continue ;
332+
333+ var keyNode = ResxTranslator . GetDataKeyName ( node ) ;
334+ var orgText = translateFromKey ? keyNode : valueNode . InnerText ;
335+
336+ if ( destTranslateOnlyNewKeys )
326337 {
327- int Destindex = index - indexCorrection ;
328- if ( ResxTranslator . GetDataKeyName ( targetDataList . ElementAt ( Destindex ) ) == ResxTranslator . GetDataKeyName ( node ) )
338+ int destIndex = index - destIndexCorrection ;
339+ if ( ResxTranslator . GetDataKeyName ( destinationDataList . ElementAt ( destIndex ) ) == keyNode )
329340 {
330- valueNode . InnerText = ResxTranslator . GetDataValueNode ( targetDataList . ElementAt ( Destindex ) ) . InnerText ;
331- indexCorrection ++ ;
341+ valueNode . InnerText = ResxTranslator . GetDataValueNode ( destinationDataList . ElementAt ( destIndex ) ) . InnerText ;
342+ destIndexCorrection ++ ;
332343 continue ;
333344 }
334-
335345 }
336346
337- if ( valueNode == null ) continue ;
338-
339-
340347 if ( string . IsNullOrWhiteSpace ( orgText ) )
341348 continue ;
342349
343-
344350 if ( translationOptions . ServiceType == ServiceTypeEnum . Google )
345351 {
346352 // There is no longer a key to validate
@@ -364,8 +370,7 @@ async void TranslateResxFilesAsync(
364370
365371 if ( ! success )
366372 {
367- var key = ResxTranslator . GetDataKeyName ( node ) ;
368- status = "Translating language: " + destLng + " , key '" + key + "' failed to translate in try " + trycount ;
373+ status = "Translating language: " + destLng + " , key '" + keyNode + "' failed to translate in try " + trycount ;
369374 progress . BeginInvoke ( max , pos , status , null , null ) ;
370375 }
371376
@@ -378,10 +383,9 @@ async void TranslateResxFilesAsync(
378383 else
379384 {
380385 hasErrors = true ;
381- var key = ResxTranslator . GetDataKeyName ( node ) ;
382386 try
383387 {
384- string message = "\r \n Key '" + key + "' translation to language '" + destLng + "' failed." ;
388+ string message = "\r \n Key '" + keyNode + "' translation to language '" + destLng + "' failed." ;
385389 File . AppendAllText ( errorLogFile , message ) ;
386390 }
387391 catch
@@ -594,18 +598,25 @@ private void btnSelectResxSource_Click(object sender, EventArgs e)
594598 {
595599 txtOutputDir . Text = Path . GetDirectoryName ( txtSourceResx . Text ) ;
596600 }
597- string [ ] filePaths = Directory . GetFiles ( Path . GetDirectoryName ( txtSourceResx . Text ) , "*.resx" ) ;
601+
602+ // reset selection
598603 foreach ( int i in lstResxLanguages . CheckedIndices )
599604 lstResxLanguages . Items [ i ] . Checked = false ;
600- foreach ( var file in filePaths )
605+
606+ // select based on what is in destination
607+ string [ ] languageFilesInDir = Directory . GetFiles ( Path . GetDirectoryName ( txtSourceResx . Text ) , "*.resx" ) ;
608+
609+ foreach ( var lngFile in languageFilesInDir )
601610 {
602- var haslng = ReadLanguageName ( file ) ;
603- if ( haslng != "" )
611+ var languageTag = ReadLanguageName ( lngFile ) ;
612+ if ( languageTag != "" )
604613 {
605- var haskey = _languages . FirstOrDefault ( x => string . Compare ( x . Key , haslng , StringComparison . InvariantCultureIgnoreCase ) == 0 ) ;
614+ var haskey = _languages . FirstOrDefault ( x => x . Key . Equals ( languageTag , StringComparison . InvariantCultureIgnoreCase ) ) ;
615+
606616 lstResxLanguages . Items [ lstResxLanguages . Items . IndexOfKey ( haskey . Key ) ] . Checked = true ;
607617 }
608618 }
619+
609620 var lng = ReadLanguageName ( txtSourceResx . Text ) ;
610621 var key = _languages . FirstOrDefault ( x => string . Compare ( x . Key , lng , StringComparison . InvariantCultureIgnoreCase ) == 0 ) ;
611622 if ( key . Key != null )
0 commit comments