@@ -174,6 +174,24 @@ async function setupCleanupHandlers() {
174
174
} ) ;
175
175
}
176
176
177
+ function needsTranslation ( enFilePath : string , lang : string ) : boolean {
178
+ const cnFilePath = enFilePath . replace (
179
+ enFilePath . sep + "en" + enFilePath . sep ,
180
+ enFilePath . sep + ".." + enFilePath . sep + "i18n" + enFilePath . sep + "translation_output" + enFilePath . sep + lang + enFilePath . sep
181
+ ) ;
182
+ try {
183
+ const cnStats = await fs . promise . stat ( cnFilePath ) ;
184
+ if ( ! cnStats . isFile ( ) ) {
185
+ return true ;
186
+ }
187
+
188
+ const enStats = await fs . promise . stat ( enFilePath ) ;
189
+ return enStats . mtime > cnStats . mtime ;
190
+ } catch ( error ) {
191
+ return true ;
192
+ }
193
+ }
194
+
177
195
// Function to recursively find all XML files in a directory
178
196
async function findAllXmlFiles ( directory : string ) : Promise < string [ ] > {
179
197
const files = await fs . promises . readdir ( directory ) ;
@@ -205,6 +223,7 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
205
223
206
224
// Get the absolute path to the xml/en directory using proper path resolution
207
225
const enDirPath = path . resolve ( __dirname , "../xml/en" ) ;
226
+ let absent : boolean = false ;
208
227
209
228
if ( process . argv [ 2 ] === "test" ) {
210
229
if ( process . argv . length !== 5 ) {
@@ -219,7 +238,10 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
219
238
console . error ( 'test error: ' , e ) ;
220
239
}
221
240
return ;
222
- } if ( process . argv [ 2 ] === "all" || process . argv . length <= 2 ) {
241
+ } if ( process . argv [ 2 ] === "all" || process . argv . length <= 2 || process . argv [ 2 ] === "abs" ) {
242
+ if ( process . argv [ 2 ] === "abs" ) {
243
+ absent = true ;
244
+ }
223
245
// Find all XML files
224
246
console . log ( `Scanning directory: ${ enDirPath } ` ) ;
225
247
filestoTranslate = await findAllXmlFiles ( enDirPath ) ;
@@ -250,6 +272,12 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
250
272
// Process each file in the batch, but handle errors individually
251
273
const results = await Promise . allSettled (
252
274
batch . map ( async file => {
275
+ if ( absent ) {
276
+ if ( ! needsTranslation ( file , lang ) ) {
277
+ console . log ( `Skipped translation for ${ file } to language ${ lang } (yarn trans abs)` ) ;
278
+ return { file, success : true } ;
279
+ }
280
+ }
253
281
try {
254
282
console . log ( `Starting translation for ${ file } ` ) ;
255
283
await translate ( lang , file ) ;
0 commit comments