@@ -6,7 +6,6 @@ import path from "path";
6
6
import { fileURLToPath } from "url" ;
7
7
import { dirname } from "path" ;
8
8
import OpenAI from "openai" ;
9
- import { permission } from "process" ;
10
9
11
10
// Get the directory name of the current module
12
11
const __filename = fileURLToPath ( import . meta. url ) ;
@@ -174,10 +173,13 @@ async function setupCleanupHandlers() {
174
173
} ) ;
175
174
}
176
175
177
- async function needsTranslation ( enFilePath : string , lang : string ) : boolean {
176
+ async function needsTranslation (
177
+ enFilePath : string ,
178
+ lang : string
179
+ ) : Promise < boolean > {
178
180
const cnFilePath = enFilePath . replace (
179
181
path . sep + "en" + path . sep ,
180
- path . sep + ".." + path . sep + "i18n" + path . sep + "translation_output" + path . sep + lang + path . sep
182
+ path . sep + lang + path . sep
181
183
) ;
182
184
try {
183
185
const cnStats = await fs . promises . stat ( cnFilePath ) ;
@@ -214,11 +216,18 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
214
216
return xmlFiles ;
215
217
}
216
218
219
+ export default async function fancyName ( path : string , language : string ) {
220
+ const fullPath = PathGenerator ( path ) ;
221
+ await translate ( language , fullPath ) ;
222
+ }
223
+
217
224
( async ( ) => {
218
225
await setupCleanupHandlers ( ) ;
219
226
220
227
try {
221
- const languages : string [ ] = await getDirectories ( path . join ( __dirname , "ai_files" ) ) ;
228
+ const languages : string [ ] = await getDirectories (
229
+ path . join ( __dirname , "ai_files" )
230
+ ) ;
222
231
console . dir ( languages ) ;
223
232
224
233
// Get the absolute path to the xml/en directory using proper path resolution
@@ -231,14 +240,19 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
231
240
return ;
232
241
}
233
242
try {
234
- console . log ( ' start translating, may take a while ...' ) ;
243
+ console . log ( " start translating, may take a while ..." ) ;
235
244
const fullPath = PathGenerator ( process . argv [ 3 ] ) ;
236
245
await translate ( process . argv [ 4 ] , fullPath ) ;
237
246
} catch ( e ) {
238
- console . error ( ' test error: ' , e ) ;
247
+ console . error ( " test error: " , e ) ;
239
248
}
240
249
return ;
241
- } if ( process . argv [ 2 ] === "all" || process . argv . length <= 2 || process . argv [ 2 ] === "abs" ) {
250
+ }
251
+ if (
252
+ process . argv [ 2 ] === "all" ||
253
+ process . argv . length <= 2 ||
254
+ process . argv [ 2 ] === "abs"
255
+ ) {
242
256
if ( process . argv [ 2 ] === "abs" ) {
243
257
absent = true ;
244
258
}
@@ -274,7 +288,9 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
274
288
batch . map ( async file => {
275
289
if ( absent ) {
276
290
if ( ! ( await needsTranslation ( file , lang ) ) ) {
277
- console . log ( `Skipped translation for ${ file } to language ${ lang } (yarn trans abs)` ) ;
291
+ console . log (
292
+ `Skipped translation for ${ file } to language ${ lang } (yarn trans abs)`
293
+ ) ;
278
294
return { file, success : true } ;
279
295
}
280
296
}
0 commit comments