@@ -10,7 +10,7 @@ import { JSDOM } from "jsdom";
1010import { jsonToHtml , jsonToMarkdown , htmlToJson } from '@contentstack/json-rte-serializer' ;
1111
1212
13- import { CHUNK_SIZE , MIGRATION_DATA_CONFIG , LOCALE_MAPPER } from "../constants/index.js" ;
13+ import { CHUNK_SIZE , LOCALE_MAPPER , MIGRATION_DATA_CONFIG } from "../constants/index.js" ;
1414import { Locale } from "../models/types.js" ;
1515import jsonRTE from "./contentful/jsonRTE.js" ;
1616import { getAllLocales , getLogMessage } from "../utils/index.js" ;
@@ -703,6 +703,7 @@ const createEnvironment = async (packagePath: any, destination_stack_id: string,
703703} ;
704704
705705const mapLocales = ( { masterLocale, locale, locales } : any ) => {
706+ console . info ( "🚀 ~ mapLocales ~ locales?.masterLocale?.[masterLocale ?? ''] :" , locales , locales ?. masterLocale , locale )
706707 if ( locales ?. masterLocale ?. [ masterLocale ?? '' ] === locale ) {
707708 return Object ?. keys ( locales ?. masterLocale ) ?. [ 0 ]
708709 }
@@ -740,7 +741,7 @@ const mapLocales = ({ masterLocale, locale, locales }: any) => {
740741 *
741742 * @throws Will log errors encountered during file reading, processing, or writing of entries.
742743 */
743- const createEntry = async ( packagePath : any , destination_stack_id : string , projectId : string , contentTypes : any , mapperKeys : any , master_locale : string ) : Promise < void > => {
744+ const createEntry = async ( packagePath : any , destination_stack_id : string , projectId : string , contentTypes : any , mapperKeys : any , master_locale : string , project : any ) : Promise < void > => {
744745 const srcFunc = 'createEntry' ;
745746 try {
746747 const entriesSave = path . join ( DATA , destination_stack_id , ENTRIES_DIR_NAME ) ;
@@ -749,7 +750,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
749750 const data = await fs . promises . readFile ( packagePath , "utf8" ) ;
750751 const entries = JSON . parse ( data ) ?. entries ;
751752 const content = JSON . parse ( data ) ?. contentTypes ;
752-
753+ const LocaleMapper = { masterLocale : project ?. master_locale ?? LOCALE_MAPPER ?. masterLocale , ... project ?. locales ?? { } } ;
753754 if ( entries && entries . length > 0 ) {
754755 const assetId = await readFile ( assetsSave , ASSETS_SCHEMA_FILE ) ?? [ ] ;
755756 const entryId = await readFile ( path . join ( DATA , destination_stack_id , REFERENCES_DIR_NAME ) , REFERENCES_FILE_NAME ) ;
@@ -799,13 +800,13 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
799800 } ) ;
800801 const pathName = getDisplayName ( name , displayField ) ;
801802 locales . forEach ( ( locale ) => {
802- const localeCode = mapLocales ( { masterLocale : master_locale , locale, locales : LOCALE_MAPPER } ) ;
803+ const localeCode = mapLocales ( { masterLocale : master_locale , locale, locales : LocaleMapper } ) ;
803804 const publishDetails = Object ?. values ?.( environmentsId ) ?. length ? Object ?. values ?.( environmentsId )
804805 . filter ( ( env : any ) => env ?. name === environment_id )
805806 ?. map ( ( env : any ) => ( {
806807 environment : env ?. uid ,
807808 version : 1 ,
808- locale : locale ?. toLowerCase ?. ( ) ,
809+ locale : localeCode ,
809810 } ) ) : [ ] ;
810811 const title = fields ?. [ pathName ] ?. [ locale ] || "" ;
811812 const urlTitle = title
@@ -816,7 +817,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
816817 title : title ?. trim ?.( ) === "" ? ( urlTitle || id ) : title ,
817818 uid : id ,
818819 url : `/${ name ?. toLowerCase ?.( ) } /${ urlTitle } ` ,
819- locale : locale ?. toLowerCase ?. ( ) ,
820+ locale : localeCode ,
820821 publish_details : publishDetails ,
821822 } ;
822823 // Format object keys to snake_case
@@ -843,11 +844,13 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
843844 for await ( const [ localeKey , localeValues ] of Object . entries (
844845 values as { [ key : string ] : any }
845846 ) ) {
847+ const localeCode = mapLocales ( { masterLocale : master_locale , locale : localeKey , locales : LocaleMapper } ) ;
846848 const chunks = makeChunks ( localeValues ) ;
849+ console . info ( "🚀 ~ forawait ~ localeCode:" , localeCode )
847850 for ( const [ entryKey , entryValue ] of Object . entries ( localeValues ) ) {
848851 const message = getLogMessage (
849852 srcFunc ,
850- `Entry title "${ ( entryValue as { title : string } ) ?. title } "(${ ctName } ) in the ${ localeKey } locale has been successfully transformed.` ,
853+ `Entry title "${ ( entryValue as { title : string } ) ?. title } "(${ ctName } ) in the ${ localeCode } locale has been successfully transformed.` ,
851854 { }
852855 ) ;
853856 await customLogger ( projectId , destination_stack_id , "info" , message ) ;
@@ -856,7 +859,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
856859 let chunkIndex = 1 ;
857860 const filePath = path . join (
858861 entriesSave ,
859- ctName , localeKey . toLowerCase ( )
862+ ctName , localeCode
860863 ) ;
861864 for await ( const [ chunkId , chunkData ] of Object . entries ( chunks ) ) {
862865 refs [ chunkIndex ++ ] = `${ chunkId } -entries.json` ;
0 commit comments