| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 2 | + | |
| 3 | 3 | function deepl_translate( $source_lang = false, $target_lang = false, $strings = array(), $cache_prefix = '', $allow_cache = true ) { |
| 4 | 4 | $DeepLApiTranslate = new DeepLApiTranslate(); |
| 5 | 5 | $DeepLApiTranslate->setCachePrefix( $cache_prefix ); |
| 6 | 6 | $DeepLApiTranslate->allowCache( $allow_cache ); |
| @@ -10,9 +10,8 @@ | ||
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | //var_dump($target_lang); die('okzerzererrzer'); |
| 13 | 13 | if ( !$DeepLApiTranslate->setLangTo( $target_lang ) ) { |
| 14 | - /* translators: target language asked */ | |
| 15 | 14 | return new WP_Error( sprintf( __( "Target language '%s' not valid", 'wpdeepl' ), $target_lang ) ); |
| 16 | 15 | } |
| 17 | 16 | |
| 18 | 17 | $DeepLApiTranslate->setTagHandling( 'html' ); |
| @@ -21,9 +20,9 @@ | ||
| 21 | 20 | |
| 22 | 21 | $DeepLApiTranslate = apply_filters('deepl_translate_DeepLApiTranslate_before', $DeepLApiTranslate ); |
| 23 | 22 | |
| 24 | 23 | //echo "\n pour lang $target_lang , formality = " . DeepLConfiguration::getFormalityLevel( $target_lang) ; |
| 25 | -// wpdeepl_debug_display($DeepLApiTranslate); die('oazeaz+e48az4ea698k'); | |
| 24 | +// plouf($DeepLApiTranslate); die('oazeaz+e48az4ea698k'); | |
| 26 | 25 | |
| 27 | 26 | $translations = $DeepLApiTranslate->getTranslations( $strings ); |
| 28 | 27 | |
| 29 | 28 | if ( is_wp_error( $translations ) ) { |
| @@ -45,14 +44,14 @@ | ||
| 45 | 44 | |
| 46 | 45 | |
| 47 | 46 | function deepl_show_usage() { |
| 48 | 47 | ?> |
| 49 | - <h3><?php esc_html_e( 'Usage', 'wpdeepl' ); ?></h3> | |
| 48 | + <h3><?php _e( 'Usage', 'wpdeepl' ); ?></h3> | |
| 50 | 49 | <?php |
| 51 | 50 | $DeepLApiUsage = new DeepLApiUsage(); |
| 52 | 51 | $usage = $DeepLApiUsage->request(); |
| 53 | 52 | |
| 54 | - //wpdeepl_debug_display($usage); wpdeepl_debug_display($DeepLApiUsage); | |
| 53 | + //plouf($usage); plouf($DeepLApiUsage); | |
| 55 | 54 | |
| 56 | 55 | if ( $usage && is_array( $usage ) && array_key_exists( 'character_count', $usage ) && array_key_exists( 'character_limit', $usage )) : |
| 57 | 56 | $ratio = round( 100 * ( $usage['character_count'] / $usage['character_limit'] ), 3 ); |
| 58 | 57 | $left_chars = $usage['character_limit'] - $usage['character_count']; |
| @@ -58,40 +57,20 @@ | ||
| 58 | 57 | $left_chars = $usage['character_limit'] - $usage['character_count']; |
| 59 | 58 | |
| 60 | 59 | ?> |
| 61 | 60 | <div class="progress-bar blue"> |
| 62 | - <span style="width: <?php echo esc_attr( round( (100 - absint( $ratio ) ), 0 ) ); ?>%"><b><?php | |
| 63 | - echo esc_html( | |
| 64 | - sprintf( | |
| 65 | - /* translators: characters remaining */ | |
| 66 | - __( '%s characters remaining', 'wpdeepl' ), | |
| 67 | - // L'argument est déjà sécurisé par esc_html(), on le laisse tel quel. | |
| 68 | - number_format( $left_chars ) | |
| 69 | - ) | |
| 70 | - ); ?></b></span> | |
| 61 | + <span style="width: <?php echo round( (100 - $ratio ), 0 ); ?>%"><b><?php printf( __( '%s characters remaining', 'wpdeepl' ), number_format( $left_chars )); ?></b></span> | |
| 71 | 62 | <div class="progress-text"><?php |
| 72 | - echo esc_html( | |
| 73 | - sprintf( | |
| 74 | - /* translators: characters translated / limit */ | |
| 75 | - __( '%1$s / %2$s characters translated', 'wpdeepl' ), | |
| 76 | - esc_html( number_format_i18n( $usage['character_count'] ) ), | |
| 77 | - esc_html( number_format_i18n( $usage['character_limit'] ) ) | |
| 78 | - )); | |
| 79 | - echo " - " . esc_html( $ratio ); ?> %</div> | |
| 80 | - <small class="request_time"><?php | |
| 81 | - echo esc_html( sprintf( | |
| 82 | - /* translators: time for the request */ | |
| 83 | - __( 'Request done in: %f milliseconds', 'wpdeepl' ), | |
| 84 | - esc_html( $DeepLApiUsage->getRequestTime( true ) ) | |
| 85 | - )); ?></small> | |
| 63 | + printf( __( '%s / %s characters translated', 'wpdeepl' ), number_format_i18n( $usage['character_count'] ), number_format_i18n( $usage['character_limit'] ) ); | |
| 64 | + echo " - " . ( $ratio ); ?> %</div> | |
| 65 | + <small class="request_time"><?php printf( __( 'Request done in: %f milliseconds', 'wpdeepl' ), $DeepLApiUsage->getRequestTime( true )) ?></small> | |
| 86 | 66 | </div> |
| 87 | 67 | <?php |
| 88 | 68 | else : |
| 89 | - esc_html_e('No response from the server', 'wpdeepl'); | |
| 90 | - ?><br /><?php | |
| 91 | - /* translators: link to the DeepL website */ | |
| 92 | - echo wp_kses_post( sprintf(__('Did you select the right server ? If yes, check your plan on <a href="%s">DeepL Pro website</a>. "DeepL API" should be included in it.', 'wpdeepl' ), | |
| 69 | + _e('No response from the server', 'wpdeepl'); | |
| 70 | + echo '<br />'; | |
| 71 | + printf(__('Did you select the right server ? If yes, check your plan on <a href="%s">DeepL Pro website</a>. "DeepL API" should be included in it.', 'wpdeepl' ), | |
| 93 | 72 | 'https://www.deepl.com/pro-account/plan' |
| 94 | - )); | |
| 73 | + ); | |
| 95 | 74 | |
| 96 | 75 | endif; |
| 97 | 76 | } |