@@ -58,20 +58,23 @@ void ConvertCsvToResw(string srcPath, string outPath, IEnumerable<string> langua
5858
5959 }
6060
61- // Print warnings (missing translations)
62- Console . ForegroundColor = ConsoleColor . Yellow ;
63-
64- foreach ( var item in Warnings )
65- Console . WriteLine ( item ) ;
66-
6761 // Print errors (invalid CSV files)
6862 Console . ForegroundColor = ConsoleColor . Red ;
6963
7064 foreach ( var item in Errors )
7165 Console . WriteLine ( item ) ;
7266
7367 if ( Errors . Count > 0 )
68+ {
69+ Console . WriteLine ( $ "Failed to generate .resw files due to { Errors . Count } errors.") ;
7470 Environment . Exit ( - 1 ) ;
71+ }
72+
73+ // Print warnings (missing translations)
74+ Console . ForegroundColor = ConsoleColor . Yellow ;
75+
76+ foreach ( var item in Warnings )
77+ Console . WriteLine ( item ) ;
7578
7679 Console . ForegroundColor = ConsoleColor . Green ;
7780
@@ -121,15 +124,47 @@ void ConvertCsvToResw(string srcPath, string outPath, IEnumerable<string> langua
121124 : Path . Combine ( outFolder . FullName , $ "Resources.lang-{ lang } .resw") ;
122125 var outputFile = new FileInfo ( outputPath ) ;
123126 File . WriteAllText ( outputFile . FullName , reswBuilder . ToString ( ) ) ;
124- Console . WriteLine ( $ "[INFO] 已生成资源文件: { outputFile . FullName } ") ;
127+ Console . WriteLine ( $ "[INFO] Generated translation for { lang } : { outputFile . FullName } ") ;
125128 }
126129}
127130
128131
129132// Parse a CSV file
130133IEnumerable < StringResource > ParseCsv ( FileInfo csvFile , string relativePath , IEnumerable < string > languages )
131134{
132- IEnumerable < StringResource > lines = CsvReader . ReadFromText ( File . ReadAllText ( csvFile . FullName ) )
135+ var csvLines = CsvReader . ReadFromText ( File . ReadAllText ( csvFile . FullName ) ) ;
136+
137+ // Check CSV headers
138+ var line = csvLines . FirstOrDefault ( ) ;
139+ if ( line is null ) // Empty file
140+ return [ ] ;
141+
142+ bool invalid = false ;
143+ if ( ! line . HasColumn ( "Id" ) )
144+ {
145+ Errors . Add ( $ "[ERROR] { relativePath } : Missing column \" Id\" ") ;
146+ invalid = true ;
147+ }
148+
149+ if ( ! line . HasColumn ( "Property" ) )
150+ {
151+ Errors . Add ( $ "[ERROR] { relativePath } : Missing column \" Property\" ") ;
152+ invalid = true ;
153+ }
154+
155+ foreach ( string lang in languages )
156+ {
157+ if ( ! line . HasColumn ( lang ) )
158+ {
159+ Errors . Add ( $ "[ERROR] { relativePath } : Missing column for translation to { lang } ") ;
160+ invalid = true ;
161+ }
162+ }
163+
164+ if ( invalid ) return [ ] ;
165+
166+ // Parse lines
167+ IEnumerable < StringResource > lines = csvLines
133168 . Select ( line => ParseLine ( line , relativePath , languages ) )
134169 . Where ( x => x is not null ) ! ;
135170 return lines ;
@@ -138,22 +173,16 @@ IEnumerable<StringResource> ParseCsv(FileInfo csvFile, string relativePath, IEnu
138173// Parse a line in the CSV file
139174StringResource ? ParseLine ( ICsvLine line , string relativePath , IEnumerable < string > languages )
140175{
141- // Error checking for CSV file
142- if ( ! line . HasColumn ( "Id" ) || string . IsNullOrWhiteSpace ( line [ "Id" ] ) )
143- {
144- Errors . Add ( $ "[ERROR]:at { relativePath } , Line { line . Index } : 资源Id 不能为空") ;
145- return null ;
146- }
147-
148- if ( ! line . HasColumn ( "Property" ) )
176+ // Error checking
177+ if ( string . IsNullOrWhiteSpace ( line [ "Id" ] ) )
149178 {
150- Errors . Add ( $ "[ERROR]:at { relativePath } , Line { line . Index } : 缺少Property列 ") ;
179+ Errors . Add ( $ "[ERROR] { relativePath } , Line { line . Index } : Id must not be empty ") ;
151180 return null ;
152181 }
153182
154183 if ( line [ "Id" ] . StartsWith ( '_' ) && ! string . IsNullOrEmpty ( line [ "Property" ] ) )
155184 {
156- Errors . Add ( $ "[ERROR]:at { relativePath } , Line { line . Index } : 资源Id 标记为后台代码,但 资源属性Id 又不为空 ") ;
185+ Errors . Add ( $ "[ERROR] { relativePath } , Line { line . Index } : Property must be empty for strings for code-behind ") ;
157186 return null ;
158187 }
159188
@@ -162,15 +191,9 @@ IEnumerable<StringResource> ParseCsv(FileInfo csvFile, string relativePath, IEnu
162191
163192 foreach ( string lang in languages )
164193 {
165- if ( ! line . HasColumn ( lang ) )
166- {
167- Errors . Add ( $ "[ERROR]:at { relativePath } , Line { line . Index } : 缺少语言 { lang } ") ;
168- return null ;
169- }
170-
171- if ( line [ lang ] == "" )
194+ if ( line [ lang ] == "" ) // Missing translation
172195 {
173- Warnings . Add ( $ "[WARN]:at { relativePath } , Line { line . Index } : 缺少 { lang } 的翻译 ") ;
196+ Warnings . Add ( $ "[WARNING] { relativePath } , Line { line . Index } : Missing translation to { lang } ") ;
174197 }
175198
176199 translations [ lang ] = line [ lang ] ;
0 commit comments