Making WordPress.org

Changeset 12873


Ignore:
Timestamp:
08/31/2023 10:50:11 AM (2 years ago)
Author:
amieiro
Message:

Translate: Add a link to the OpenAI and DeepL configuration

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

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/css/translation-suggestions.css

    r12510 r12873  
    104104    background: #B5E1B9;
    105105}
     106
     107.translation-suggestion__footer_message__for_suggestions {
     108    font-size: 12px;
     109}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/class-plugin.php

    r12751 r12873  
    173173        $query_tm = mb_strlen( $entry->singular ) <= 420;
    174174
     175        // Used to add a link to add the OpenAI and the DeepL keys.
     176        // We only show this link if the user has not added any of these keys yet.
     177        $gp_default_sort = get_user_option( 'gp_default_sort' );
     178        $openai_key      = trim( gp_array_get( $gp_default_sort, 'openai_api_key' ) );
     179        $deepl_key       = trim( gp_array_get( $gp_default_sort, 'deepl_api_key' ) );
    175180        ?>
    176181        <details open class="suggestions__translation-memory<?php echo $query_tm ? '' : ' initialized'; ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'translation-memory-suggestions-' . $entry->original_id ) ); ?>">
     
    181186                <p class="no-suggestions">No suggestions.</p>
    182187            <?php endif; ?>
     188
     189            <?php if ( empty( $openai_key ) && empty( $deepl_key ) ) : ?>
     190                <p class="translation-suggestion__footer_message__for_suggestions">Get translation suggestions from <a href="https://translate.wordpress.org/settings/" target="_blank">OpenAI</a>  and from <a href="https://translate.wordpress.org/settings/" target="_blank">DeepL</a>. <a href="https://make.wordpress.org/polyglots/2023/03/29/adding-chatgpt-and-deepl-in-the-translation-memory/" target="_blank">More info</a>.</p>
     191            <?php endif; ?>
    183192        </details>
    184193
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/js/translation-suggestions.js

    r12765 r12873  
    2828    * Stores the external translations used.
    2929    * @type {object}
    30     */
     30    */
    3131   var externalSuggestion = {};
    3232
     
    6363            $container.append( cachedSuggestion );
    6464            removeNoSuggestionsMessage( $container );
     65            moveFooterToTheBottom( $container );
    6566            copyTranslationMemoryToSidebarTab( $container );
    6667            return;
     
    8586                storeTheSuggestionInTheCache( type, originalId, response.data );
    8687                removeNoSuggestionsMessage( $container );
     88                moveFooterToTheBottom( $container );
    8789                copyTranslationMemoryToSidebarTab( $container );
    8890            } else {
     
    196198    function copyTranslationMemoryToSidebarTab( $container ){
    197199        var editor = $container.closest( '.editor' );
    198         var divSidebarWithTM = editor.find( '.meta.translation-memory' ).first();
     200        var divSidebarWithTM = editor.find( '.meta.translation-memory' ).first();
    199201        var divId = divSidebarWithTM.attr( 'data-row-id' );
    200202        var TMcontainer = editor.find( '.suggestions__translation-memory' );
     
    358360            removeNoSuggestionsDuplicateMessage( $container );
    359361        }
     362    }
     363
     364    /**
     365     * Moves the footer with the link to OpenAI and DeepL to the bottom of the container.
     366     *
     367     * This is needed because the suggestions are loaded asynchronously.
     368     *
     369     * @param {object} $container The container where the suggestions are stored.
     370     *
     371     * @return {void}
     372     */
     373    function moveFooterToTheBottom( $container ) {
     374        var footer = $container.find( '.translation-suggestion__footer_message__for_suggestions' );
     375        if ( ! footer ) {
     376            return;
     377        }
     378        $container.append( footer );
    360379    }
    361380
Note: See TracChangeset for help on using the changeset viewer.