@@ -108,7 +108,7 @@ async function translate(language: string, filePath: string) {
108
108
}
109
109
console . log ( `Done translating all segments.` ) ;
110
110
const output_path = fileURLToPath (
111
- import . meta. resolve ( "../../xml/translations " + filePath )
111
+ import . meta. resolve ( "../../xml_cn " + filePath )
112
112
) ;
113
113
114
114
// Ensure directory exists
@@ -140,7 +140,7 @@ async function translate(language: string, filePath: string) {
140
140
141
141
clean . on ( "text" , text => {
142
142
if ( currDepth >= 1 ) {
143
- translated += text ;
143
+ translated += escapeXML ( text ) ;
144
144
}
145
145
} ) ;
146
146
@@ -166,6 +166,22 @@ async function translate(language: string, filePath: string) {
166
166
translated += `<!-- ${ comment } -->` ;
167
167
} ) ;
168
168
169
+ clean . on ( "error" , error => {
170
+ console . log (
171
+ "error encountered when validating XML: " +
172
+ error +
173
+ "\nvalidating section: " +
174
+ chunk . substring ( 0 , 100 ) + "..."
175
+ ) ;
176
+
177
+ // Attempt to recover using the internal parser
178
+ try {
179
+ clean . _parser . resume ( ) ;
180
+ } catch ( e ) {
181
+ console . log ( "Failed to resume parser:" , e ) ;
182
+ }
183
+ } ) ;
184
+
169
185
let translated = "" ;
170
186
171
187
try {
@@ -174,7 +190,7 @@ async function translate(language: string, filePath: string) {
174
190
content : `Translate this content to ${ language } .
175
191
IMPORTANT: You MUST search the uploaded reference file for any technical terms and use EXACTLY the translations specified there.
176
192
If a term exists in the reference file, use that translation without deviation.
177
- Do not modify XML tags, content of XML tags and structure. Do not say anything else. Only translate the content and return the xml as is .
193
+ Do not modify XML tags, attributes of XML tags and structure. Do not say anything else.
178
194
Content to translate:
179
195
${ chunk } `
180
196
} ) ;
@@ -225,4 +241,4 @@ function formatAttributes(attrs) {
225
241
226
242
function escapeXML ( str : string ) : string {
227
243
return str . replace ( / & (? ! (?: a m p ; | l t ; | g t ; | a p o s ; | q u o t ; ) ) / g, "&" ) ;
228
- }
244
+ }
0 commit comments