@@ -173,6 +173,24 @@ async function setupCleanupHandlers() {
173173 } ) ;
174174}
175175
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+
176194// Function to recursively find all XML files in a directory
177195async function findAllXmlFiles ( directory : string ) : Promise < string [ ] > {
178196 const files = await fs . promises . readdir ( directory ) ;
@@ -195,30 +213,6 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
195213 return xmlFiles ;
196214}
197215
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-
222216export default async function fancyName ( path : string , language : string ) {
223217 const fullPath = PathGenerator ( path ) ;
224218 await translate ( language , fullPath ) ;
@@ -261,7 +255,7 @@ export default async function fancyName(path: string, language: string) {
261255 }
262256 // Find all XML files
263257 console . log ( `Scanning directory: ${ enDirPath } ` ) ;
264- filestoTranslate = await findAllXmlFiles ( enDirPath ) ;
258+ filesToTranslate = await findAllXmlFiles ( enDirPath ) ;
265259 } else {
266260 const [ , , ...xmlFiles ] = process . argv ;
267261 filesToTranslate = xmlFiles . map ( file => path . join ( __dirname , ".." , file ) ) ;
@@ -290,10 +284,8 @@ export default async function fancyName(path: string, language: string) {
290284 const results = await Promise . allSettled (
291285 batch . map ( async file => {
292286 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)` ) ;
297289 return { file, success : true } ;
298290 }
299291 }
0 commit comments