@@ -72,25 +72,35 @@ export interface FlowTransformOptions {
7272 * @default 'errors.flow.generic'
7373 */
7474 defaultErrorKey ?: string ;
75+ /**
76+ * Whether to resolve translation strings or keep them as i18n keys
77+ * @default true
78+ */
79+ resolveTranslations ?: boolean ;
7580}
7681
7782/**
7883 * Transform and resolve translations in components from flow response.
79- * This function extracts components from the response meta structure and resolves
84+ * This function extracts components from the response meta structure and optionally resolves
8085 * any translation strings within them.
8186 *
8287 * @param response - The flow response object containing components in meta structure
8388 * @param t - Translation function from useTranslation hook
84- * @returns Array of flow components with resolved translations
89+ * @param resolveTranslations - Whether to resolve translation strings or keep them as i18n keys (default: true)
90+ * @returns Array of flow components with resolved or unresolved translations
8591 */
86- export const transformComponents = ( response : any , t : UseTranslation [ 't' ] ) : EmbeddedFlowComponent [ ] => {
92+ export const transformComponents = (
93+ response : any ,
94+ t : UseTranslation [ 't' ] ,
95+ resolveTranslations : boolean = true ,
96+ ) : EmbeddedFlowComponent [ ] => {
8797 if ( ! response ?. data ?. meta ?. components ) {
8898 return [ ] ;
8999 }
90100
91101 const components : EmbeddedFlowComponent [ ] = response . data . meta . components ;
92102
93- return resolveTranslationsInArray ( components , t ) ;
103+ return resolveTranslations ? resolveTranslationsInArray ( components , t ) : components ;
94104} ;
95105
96106/**
@@ -154,7 +164,7 @@ export const normalizeFlowResponse = (
154164 flowId : string ;
155165 components : EmbeddedFlowComponent [ ] ;
156166} => {
157- const { throwOnError = true , defaultErrorKey = 'errors.flow.generic' } = options ;
167+ const { throwOnError = true , defaultErrorKey = 'errors.flow.generic' , resolveTranslations = true } = options ;
158168
159169 // Check if this is an error response
160170 const errorMessage : string | null = checkForErrorResponse ( response , t , defaultErrorKey ) ;
@@ -166,6 +176,6 @@ export const normalizeFlowResponse = (
166176
167177 return {
168178 flowId : response . flowId ,
169- components : transformComponents ( response , t ) ,
179+ components : transformComponents ( response , t , resolveTranslations ) ,
170180 } ;
171181} ;
0 commit comments