@@ -140,6 +140,9 @@ func processFile(file string, adapter core.LanguageAdapter, store *mapping.Store
140140 newText string
141141 }
142142 var replacements []replacement
143+
144+ // Track comments that couldn't find translation
145+ missingTranslations := make (map [string ]bool )
143146
144147 lines := strings .Split (string (src ), "\n " )
145148
@@ -214,6 +217,9 @@ func processFile(file string, adapter core.LanguageAdapter, store *mapping.Store
214217 // Ensure the new ID has bilingual data
215218 store .Set (newID , cfg .SourceLanguage , enText )
216219 store .Set (newID , cfg .LocalLanguage , zhText )
220+ // Delete the old ID (based on Chinese text) to keep mappings clean
221+ store .Delete (id )
222+ log .Info ("Deleted old mapping ID: %s" , id )
217223 }
218224
219225 break
@@ -222,10 +228,11 @@ func processFile(file string, adapter core.LanguageAdapter, store *mapping.Store
222228 }
223229 }
224230
225- if ! found {
226- log .Warn ("未找到注释的英文翻译: '%s'" , normalizedCurrent )
227- // Return early to count this as missing
228- }
231+ if ! found {
232+ log .Warn ("未找到注释的英文翻译: '%s'" , normalizedCurrent )
233+ // Mark this comment as missing translation
234+ missingTranslations [c .ID ] = true
235+ }
229236 } else {
230237 // Apply Mode (EN -> ZH)
231238 // c.SourceText is EN
@@ -303,28 +310,8 @@ func processFile(file string, adapter core.LanguageAdapter, store *mapping.Store
303310 return 0
304311 }
305312
306- // Count missing translations
307- // Only count as missing if:
308- // 1. The comment ID exists in mappings
309- // 2. But the target language translation is missing
310- missingCount := 0
311- for _ , c := range comments {
312- if c .ID == "" {
313- c .ID = utils .GenerateCommentID (c )
314- }
315-
316- // Check if this comment ID exists in mappings
317- if transMap , exists := store .GetMapping ().Comments [c .ID ]; exists {
318- // ID exists, check if target language translation exists
319- if targetVal , hasTarget := transMap [convertTo ]; ! hasTarget || targetVal == "" {
320- // Target translation is missing
321- missingCount ++
322- log .Warn ("注释 ID %s 缺少 %s 翻译" , c .ID , convertTo )
323- }
324- }
325- // If ID doesn't exist in mappings at all, it's a new comment
326- // We don't count it as "missing translation" because it hasn't been scanned yet
327- }
313+ // Count missing translations based on what we tracked during conversion
314+ missingCount := len (missingTranslations )
328315
329316 if err := os .WriteFile (file , []byte (newSrc ), 0644 ); err != nil {
330317 log .Error ("写入文件 %s 失败: %v" , file , err )
0 commit comments