@@ -12,54 +12,60 @@ export default new Command()
1212 . description ( 'Process i18n with Replexica' )
1313 . helpOption ( '-h, --help' , 'Show help' )
1414 . action ( async ( ) => {
15- const initSpinner = Ora ( ) ;
16- initSpinner . start ( 'Loading Replexica build data...' ) ;
15+ const spinner = Ora ( ) ;
16+ spinner . start ( 'Loading Replexica build data...' ) ;
1717 const buildData = await loadBuildData ( ) ;
1818 if ( ! buildData ) {
19- initSpinner . fail ( `Couldn't load Replexica build data. Did you forget to run 'replexica i18n'?` ) ;
19+ spinner . fail ( `Couldn't load Replexica build data. Did you forget to run 'replexica i18n'?` ) ;
2020 return process . exit ( 1 ) ;
2121 }
2222
2323 const localeSource = buildData . settings ?. locale ?. source ;
2424 if ( ! localeSource ) {
25- initSpinner . fail ( `No source locale found in Replexica build data. Please check your Replexica configuration and run 'replexica i18n' again.` ) ;
25+ spinner . fail ( `No source locale found in Replexica build data. Please check your Replexica configuration and run 'replexica i18n' again.` ) ;
2626 return process . exit ( 1 ) ;
2727 }
2828
2929 const localeTargets = buildData . settings ?. locale ?. targets || [ ] ;
3030 if ( ! localeTargets . length ) {
31- initSpinner . fail ( `No target locales found in Replexica build data. Please check your Replexica configuration and run 'replexica i18n' again.` ) ;
31+ spinner . fail ( `No target locales found in Replexica build data. Please check your Replexica configuration and run 'replexica i18n' again.` ) ;
3232 return process . exit ( 1 ) ;
3333 }
3434
3535 const localeSourceData = await loadLocaleData ( localeSource ) ;
3636 if ( ! localeSourceData ) {
37- initSpinner . fail ( `Couldn't load source locale data for source locale ${ localeSource } . Did you forget to run 'replexica i18n'?` ) ;
37+ spinner . fail ( `Couldn't load source locale data for source locale ${ localeSource } . Did you forget to run 'replexica i18n'?` ) ;
3838 return process . exit ( 1 ) ;
3939 }
4040
41- initSpinner . succeed ( 'Replexica build data loaded!' ) ;
42-
43- for ( const target of localeTargets ) {
44- const targetSpinner = Ora ( ) ;
45- targetSpinner . start ( `Processing i18n for ${ target } ...` ) ;
46- const result = await processI18n (
47- { source : localeSource , target } ,
48- buildData . meta ,
49- localeSourceData ,
50- ) ;
51- targetSpinner . succeed ( `i18n processed for ${ target } !` ) ;
52-
53- targetSpinner . start ( `Saving full i18n data for ${ target } ...` ) ;
54- await saveFullLocaleData ( target , result . data ) ;
55- targetSpinner . succeed ( `Full i18n data saved for ${ target } !` ) ;
56-
57- targetSpinner . start ( `Saving client i18n data for ${ target } ...` ) ;
58- await saveClientLocaleData ( target , result . data , buildData . meta ) ;
59- targetSpinner . succeed ( `Client i18n data saved for ${ target } !` ) ;
41+ spinner . succeed ( 'Replexica build data loaded!' ) ;
42+
43+
44+ for ( let i = 0 ; i < localeTargets . length ; i ++ ) {
45+ const targetLocale = localeTargets [ i ] ;
46+ const resultData : any = { } ;
47+
48+ const localeEntries = Object . entries ( localeSourceData || { } ) ;
49+ for ( let j = 0 ; j < localeEntries . length ; j ++ ) {
50+ const [ localeFileId , localeFileData ] = localeEntries [ j ] ;
51+ spinner . start ( `[${ targetLocale } ] Processing file ${ j + 1 } /${ localeEntries . length } ...` ) ;
52+
53+ const partialLocaleData = { [ localeFileId ] : localeFileData } ;
54+ const result = await processI18n (
55+ { source : localeSource , target : targetLocale } ,
56+ buildData . meta ,
57+ partialLocaleData ,
58+ ) ;
59+ resultData [ localeFileId ] = result . data [ localeFileId ] ;
60+
61+ spinner . succeed ( `[${ targetLocale } ] File ${ j + 1 } /${ localeEntries . length } processed!` ) ;
62+ }
63+
64+ await saveFullLocaleData ( targetLocale , resultData ) ;
65+ await saveClientLocaleData ( targetLocale , resultData , buildData . meta ) ;
6066 }
6167
62- initSpinner . succeed ( 'Replexica i18n processing complete!' ) ;
68+ spinner . succeed ( 'Replexica i18n processing complete!' ) ;
6369 } ) ;
6470
6571async function processI18n (
0 commit comments