@@ -173,6 +173,24 @@ async function setupCleanupHandlers() {
173
173
} ) ;
174
174
}
175
175
176
+ async function needsTranslation ( enFilePath : string , lang : string ) : boolean {
177
+ const cnFilePath = enFilePath . replace (
178
+ path . sep + "en" + path . sep ,
179
+ path . sep + ".." + path . sep + "i18n" + path . sep + "translation_output" + path . sep + lang + path . sep
180
+ ) ;
181
+ try {
182
+ const cnStats = await fs . promises . stat ( cnFilePath ) ;
183
+ if ( ! cnStats . isFile ( ) ) {
184
+ return true ;
185
+ }
186
+
187
+ const enStats = await fs . promises . stat ( enFilePath ) ;
188
+ return enStats . mtime > cnStats . mtime ;
189
+ } catch ( error ) {
190
+ return true ;
191
+ }
192
+ }
193
+
176
194
// Function to recursively find all XML files in a directory
177
195
async function findAllXmlFiles ( directory : string ) : Promise < string [ ] > {
178
196
const files = await fs . promises . readdir ( directory ) ;
@@ -195,30 +213,6 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
195
213
return xmlFiles ;
196
214
}
197
215
198
- // Function to check if a file needs translation
199
- async function needsTranslation ( enFilePath : string , lang : string ) : Promise < boolean > {
200
- // Generate the corresponding cn file path
201
- const cnFilePath = enFilePath . replace (
202
- path . sep + "en" + path . sep ,
203
- path . sep + lang + path . sep
204
- ) ;
205
-
206
- try {
207
- // Check if CN file exists
208
- const cnStats = await fs . promises . stat ( cnFilePath ) ;
209
- if ( ! cnStats . isFile ( ) ) {
210
- return true ; // CN path exists but is not a file (unusual case)
211
- }
212
-
213
- // Compare modification times
214
- const enStats = await fs . promises . stat ( enFilePath ) ;
215
- return enStats . mtime > cnStats . mtime ; // Return true if EN file is newer
216
- } catch ( error ) {
217
- // If we get an error, it's likely because the CN file doesn't exist
218
- return true ; // Need to translate since CN file doesn't exist
219
- }
220
- }
221
-
222
216
export default async function fancyName ( path : string , language : string ) {
223
217
const fullPath = PathGenerator ( path ) ;
224
218
await translate ( language , fullPath ) ;
@@ -261,7 +255,7 @@ export default async function fancyName(path: string, language: string) {
261
255
}
262
256
// Find all XML files
263
257
console . log ( `Scanning directory: ${ enDirPath } ` ) ;
264
- filestoTranslate = await findAllXmlFiles ( enDirPath ) ;
258
+ filesToTranslate = await findAllXmlFiles ( enDirPath ) ;
265
259
} else {
266
260
const [ , , ...xmlFiles ] = process . argv ;
267
261
filesToTranslate = xmlFiles . map ( file => path . join ( __dirname , ".." , file ) ) ;
@@ -290,10 +284,8 @@ export default async function fancyName(path: string, language: string) {
290
284
const results = await Promise . allSettled (
291
285
batch . map ( async file => {
292
286
if ( absent ) {
293
- if ( ! needsTranslation ( file , lang ) ) {
294
- console . log (
295
- `Skipped translation for ${ file } to language ${ lang } (yarn trans abs)`
296
- ) ;
287
+ if ( ! ( await needsTranslation ( file , lang ) ) ) {
288
+ console . log ( `Skipped translation for ${ file } to language ${ lang } (yarn trans abs)` ) ;
297
289
return { file, success : true } ;
298
290
}
299
291
}
0 commit comments