Making WordPress.org

Changeset 12580


Ignore:
Timestamp:
05/09/2023 01:10:28 PM (3 years ago)
Author:
amieiro
Message:

Translation: If the TM has a translation with 100% of accuracy, we copy it to the translation textarea

File:
1 edited

Legend:

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

    r12527 r12580  
    1616                        if ( response.success ) {
    1717                                $container.append( response.data );
     18                                addSuggestionToTranslation( response.data );
    1819                        } else {
    1920                                $container.append( $( '<span/>', { 'text': 'Error while loading suggestions.' } ) );
     
    3233                        removeNoSuggestionsMessage( $container );
    3334                } );
     35        }
     36
     37        /**
     38         * Add the suggestion from the translation memory to the translation textarea if
     39         * the suggestion has 100% of accuracy.
     40         *
     41         * @return {void}
     42         **/
     43        function addSuggestionToTranslation( data ) {
     44                var suggestions = $( data ).find( '.translation-suggestion.with-tooltip.translation' );
     45                if ( ! suggestions.length ) {
     46                        return;
     47                }
     48                for ( var i = 0; i < suggestions.length; i++ ) {
     49                        var score = $( suggestions[i] ).find( '.translation-suggestion__score' );
     50                        if ( score.length > 0 && score.text() === '100%' ) {
     51                                var translation = $( suggestions[i] ).find( '.translation-suggestion__translation' );
     52                                if ( translation.length > 0 ) {
     53                                        var activeTextarea = $gp.editor.current.find( '.textareas.active textarea' );
     54                                        if ( ! activeTextarea.length ) {
     55                                                return;
     56                                        }
     57                                        activeTextarea.val( translation.text() ).focus();
     58                                        break;
     59                                }
     60                        }
     61                }
    3462        }
    3563
Note: See TracChangeset for help on using the changeset viewer.