Making WordPress.org

Changeset 14582


Ignore:
Timestamp:
10/30/2025 11:04:28 AM (3 months ago)
Author:
amieiro
Message:

Translate: Skip the DeepL AJAX request if the locale is not supported

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/class-plugin.php

    r12873 r14582  
    66use GP_Locales;
    77use WordPressdotorg\GlotPress\TranslationSuggestions\Routes\Translation_Memory;
     8use WordPressdotorg\GlotPress\Bulk_Pretranslations\Deepl;
    89
    910class Plugin {
     
    131132        $get_openai_translations = ! empty( trim( gp_array_get( $gp_default_sort, 'openai_api_key' ) ) );
    132133        $get_deepl_translations  = ! empty( trim( gp_array_get( $gp_default_sort, 'deepl_api_key' ) ) );
    133 
     134        $deepl                   = new DeepL();
     135        $deepl_locale            = $deepl->get_deepl_locale( $args['locale_slug'] );
     136       
    134137        wp_localize_script(
    135138            'gp-translation-suggestions',
     
    140143                    'get_openai_translations' => $get_openai_translations,
    141144                    'get_deepl_translations'  => $get_deepl_translations,
     145                    'get_deepl_locale'        => $deepl_locale,
    142146                ),
    143147            )
     
    145149
    146150        gp_enqueue_script( 'gp-translation-suggestions' );
    147 
    148151        wp_add_inline_script(
    149152            'gp-translation-suggestions',
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/js/translation-suggestions.js

    r13763 r14582  
    308308     **/
    309309    function maybeFetchDeeplSuggestions( editor ) {
     310        // If the locale is not supported, do not fetch suggestions.
     311        if ( "" === gpTranslationSuggestions.get_external_translations.get_deepl_locale ) {
     312            return;
     313        }
    310314        maybeFetchExternalSuggestions( editor, 'DeepL', gpTranslationSuggestions.get_external_translations.get_deepl_translations, window.WPORG_TRANSLATION_MEMORY_DEEPL_API_URL );
    311315    }
Note: See TracChangeset for help on using the changeset viewer.