@@ -251,6 +251,13 @@ function _wp_connectors_init(): void {
251251 * @param WP_Connector_Registry $registry The connector registry instance.
252252 */
253253function _wp_connectors_register_default_ai_providers ( WP_Connector_Registry $ registry ): void {
254+ // English source strings for built-in descriptions (used to avoid replacing translated defaults with duplicate English from provider metadata).
255+ $ default_ai_provider_description_i18n = array (
256+ 'anthropic ' => 'Text generation with Claude. ' ,
257+ 'google ' => 'Text and image generation with Gemini and Imagen. ' ,
258+ 'openai ' => 'Text and image generation with GPT and Dall-E. ' ,
259+ );
260+
254261 // Built-in connectors.
255262 $ defaults = array (
256263 'anthropic ' => array (
@@ -324,7 +331,13 @@ function _wp_connectors_register_default_ai_providers( WP_Connector_Registry $re
324331 $ defaults [ $ connector_id ]['name ' ] = $ name ;
325332 }
326333 if ( $ description ) {
327- $ defaults [ $ connector_id ]['description ' ] = $ description ;
334+ // Keep the translated default when metadata repeats the same English string.
335+ if (
336+ ! isset ( $ default_ai_provider_description_i18n [ $ connector_id ] ) ||
337+ $ description !== $ default_ai_provider_description_i18n [ $ connector_id ]
338+ ) {
339+ $ defaults [ $ connector_id ]['description ' ] = $ description ;
340+ }
328341 }
329342 if ( $ logo_url ) {
330343 $ defaults [ $ connector_id ]['logo_url ' ] = $ logo_url ;
@@ -690,4 +703,47 @@ function _wp_connectors_get_connector_script_module_data( array $data ): array {
690703 $ data ['connectors ' ] = $ connectors ;
691704 return $ data ;
692705}
706+
707+ /**
708+ * Outputs wp.i18n locale data for a route content script module by inlining it on the
709+ * page prerequisites script. Route content is loaded as an ES module, which is not
710+ * registered in {@see WP_Scripts}, so {@see wp_set_script_translations()} cannot attach
711+ * JSON translations to it without a companion script handle sharing the same source URL.
712+ *
713+ * @since 7.0.1
714+ * @access private
715+ *
716+ * @param string $prerequisites_script_handle Registered script handle for the page prerequisites script.
717+ * @param string $route_name Route directory name under `wp-includes/build/routes/`.
718+ */
719+ function _wp_add_inline_route_content_script_translations ( $ prerequisites_script_handle , $ route_name ) {
720+ $ asset_path = ABSPATH . WPINC . '/build/routes/ ' . $ route_name . '/content.min.asset.php ' ;
721+ if ( ! file_exists ( $ asset_path ) ) {
722+ return ;
723+ }
724+
725+ $ content_asset = require $ asset_path ;
726+ $ extension = defined ( 'SCRIPT_DEBUG ' ) && SCRIPT_DEBUG ? '.js ' : '.min.js ' ;
727+ $ translation_handle = 'wp-routes- ' . str_replace ( '/ ' , '- ' , $ route_name ) . '-content ' ;
728+ $ content_src = includes_url ( 'build/routes/ ' . $ route_name . '/content ' . $ extension );
729+
730+ wp_register_script (
731+ $ translation_handle ,
732+ $ content_src ,
733+ array ( 'wp-i18n ' ),
734+ $ content_asset ['version ' ] ?? false ,
735+ true
736+ );
737+ wp_set_script_translations ( $ translation_handle , 'default ' );
738+
739+ $ translations = wp_scripts ()->print_translations ( $ translation_handle , false );
740+ wp_deregister_script ( $ translation_handle );
741+
742+ if ( ! $ translations ) {
743+ return ;
744+ }
745+
746+ wp_add_inline_script ( $ prerequisites_script_handle , $ translations , 'before ' );
747+ }
748+
693749add_filter ( 'script_module_data_options-connectors-wp-admin ' , '_wp_connectors_get_connector_script_module_data ' );
0 commit comments