@@ -100,13 +100,13 @@ const updateToast = (status, message, { count, sourceLocale }) => {
100100 * @param {CopyingFieldMap } args.copingFieldMap Copied or translated field values.
101101 */
102102const translateFields = async ( { currentValues, options, copingFieldMap } ) => {
103- const _translator = get ( translator ) ;
103+ const { serviceId , markdownSupported , translate } = get ( translator ) ;
104104 const { sourceLocale, targetLocale } = options ;
105105 const count = Object . keys ( copingFieldMap ) . length ;
106106 const countType = count === 1 ? 'one' : 'many' ;
107107
108108 const apiKey =
109- get ( prefs ) . apiKeys ?. [ _translator . serviceId ] ||
109+ get ( prefs ) . apiKeys ?. [ serviceId ] ||
110110 ( await new Promise ( ( resolve ) => {
111111 // The promise will be resolved once the user enters an API key on the dialog
112112 translatorApiKeyDialogState . set ( { show : true , multiple : count > 1 , resolve } ) ;
@@ -119,23 +119,21 @@ const translateFields = async ({ currentValues, options, copingFieldMap }) => {
119119 updateToast ( 'info' , 'translation.started' , { count, sourceLocale } ) ;
120120
121121 try {
122- const translatedValues = await _translator . translate (
122+ const translatedValues = await translate (
123123 Object . entries ( copingFieldMap ) . map ( ( [ , { value, isMarkdown } ] ) =>
124- // Convert the value from Markdown to HTML if the field is a markdown field, because the
125- // translator API expects HTML input
126- isMarkdown ? /** @type {string } */ ( marked . parse ( value ) ) : value ,
124+ // Convert the value from Markdown to HTML if needed
125+ isMarkdown && ! markdownSupported ? /** @type {string } */ ( marked . parse ( value ) ) : value ,
127126 ) ,
128127 { apiKey, sourceLocale, targetLocale } ,
129128 ) ;
130129
131130 Object . entries ( copingFieldMap ) . forEach ( ( [ _keyPath , { isMarkdown } ] , index ) => {
132131 const value = translatedValues [ index ] ;
133132
134- // Convert the value back to Markdown if the field is a markdown field
135- currentValues [ targetLocale ] [ _keyPath ] = isMarkdown
136- ? // @ts -ignore Silence a false type error
137- turndownService . turndown ( value )
138- : value ;
133+ // Convert the value back to Markdown if needed
134+ currentValues [ targetLocale ] [ _keyPath ] =
135+ // @ts -ignore Silence a false type error
136+ isMarkdown && ! markdownSupported ? turndownService . turndown ( value ) : value ;
139137 } ) ;
140138
141139 updateToast ( 'success' , `translation.complete.${ countType } ` , { count, sourceLocale } ) ;
0 commit comments