@@ -86,6 +86,18 @@ function makeChunks(assetData: any) {
8686 return chunks ;
8787}
8888
89+ const mapLocales = ( { masterLocale, locale, locales } : any ) => {
90+ if ( locales ?. masterLocale ?. [ masterLocale ?? '' ] === locale ) {
91+ return Object ?. keys ( locales ?. masterLocale ) ?. [ 0 ]
92+ }
93+ for ( const [ key , value ] of Object ?. entries ?.( locales ) ?? { } ) {
94+ if ( typeof value !== 'object' && value === locale ) {
95+ return key ;
96+ }
97+ }
98+ return locale . toLowerCase ( ) ;
99+ }
100+
89101const transformCloudinaryObject = ( input : any ) => {
90102 const result : any = [ ] ;
91103 if ( ! Array . isArray ( input ) ) {
@@ -702,18 +714,6 @@ const createEnvironment = async (packagePath: any, destination_stack_id: string,
702714 }
703715} ;
704716
705- const mapLocales = ( { masterLocale, locale, locales } : any ) => {
706- console . info ( "🚀 ~ mapLocales ~ locales?.masterLocale?.[masterLocale ?? ''] :" , locales , locales ?. masterLocale , locale )
707- if ( locales ?. masterLocale ?. [ masterLocale ?? '' ] === locale ) {
708- return Object ?. keys ( locales ?. masterLocale ) ?. [ 0 ]
709- }
710- for ( const [ key , value ] of Object ?. entries ?.( locales ) ?? { } ) {
711- if ( typeof value !== 'object' && value === locale ) {
712- return key ;
713- }
714- }
715- return locale . toLowerCase ( ) ;
716- }
717717
718718/**
719719 * Creates and processes entries from a given package file and saves them to the destination stack directory.
@@ -888,6 +888,10 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
888888 }
889889} ;
890890
891+ function getKeyByValue ( obj : Record < string , string > , targetValue : string ) : string | undefined {
892+ return Object . entries ( obj ) . find ( ( [ _ , value ] ) => value === targetValue ) ?. [ 0 ] ;
893+ }
894+
891895/**
892896 * Processes and creates locale configurations from a given package file and saves them to the destination stack directory.
893897 *
@@ -912,7 +916,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
912916 *
913917 * @throws Will log errors encountered during file reading, processing, or writing of locale configurations.
914918 */
915- const createLocale = async ( packagePath : string , destination_stack_id : string , projectId : string ) => {
919+ const createLocale = async ( packagePath : string , destination_stack_id : string , projectId : string , project : any ) => {
916920 const srcFunc = 'createLocale' ;
917921 const localeSave = path . join ( DATA , destination_stack_id , LOCALE_DIR_NAME ) ;
918922 const globalFieldSave = path . join ( DATA , destination_stack_id , GLOBAL_FIELDS_DIR_NAME ) ;
@@ -936,30 +940,30 @@ const createLocale = async (packagePath: string, destination_stack_id: string, p
936940 )
937941 await customLogger ( projectId , destination_stack_id , 'error' , message ) ;
938942 }
939-
940- await Promise . all ( locales . map ( async ( localeData : any ) => {
941- const title = localeData . sys . id ;
943+ const fallbackMapLocales : any = { ...project ?. master_locale ?? { } , ...project ?. locales ?? { } }
944+ await Promise ?. all ( locales ?. map ?.( async ( localeData : any ) => {
945+ const currentMapLocale = getKeyByValue ?.( fallbackMapLocales , localeData ?. code ) ?? `${ localeData . code . toLowerCase ( ) } ` ;
946+ const title = localeData ?. sys ?. id ;
942947 const newLocale : Locale = {
943- code : ` ${ localeData . code . toLowerCase ( ) } ` ,
944- name : localeCodes ?. [ localeData . code . toLowerCase ( ) ] || "English - United States" ,
945- fallback_locale : "" ,
948+ code : currentMapLocale ,
949+ name : localeCodes ?. [ currentMapLocale ] || "English - United States" ,
950+ fallback_locale : getKeyByValue ( fallbackMapLocales , localeData ?. fallbackCode ) ?? '' ,
946951 uid : `${ title } ` ,
947952 } ;
948953
949954 if ( localeData . default === true ) {
950955 msLocale [ title ] = newLocale ;
951956 const message = getLogMessage (
952957 srcFunc ,
953- `Master Locale ${ newLocale . code } has been successfully transformed.` ,
958+ `Master Locale ${ newLocale ? .code } has been successfully transformed.` ,
954959 { }
955960 )
956961 await customLogger ( projectId , destination_stack_id , 'info' , message ) ;
957962 } else {
958- newLocale . name = `${ localeData . name } ` ;
959963 allLocales [ title ] = newLocale ;
960964 const message = getLogMessage (
961965 srcFunc ,
962- `Locale ${ newLocale . code } has been successfully transformed.` ,
966+ `Locale ${ newLocale ? .code } has been successfully transformed.` ,
963967 { }
964968 )
965969 await customLogger ( projectId , destination_stack_id , 'info' , message ) ;
0 commit comments