| 1 |
<?php |
| 2 |
|
| 3 |
function deepl_language_selector( |
| 4 |
$type = 'target', |
| 5 |
$id = 'deepl_language_selector', |
| 6 |
$selected = false |
| 7 |
) { |
| 8 |
$languages = DeepLConfiguration::DefaultsAllLanguages(); |
| 9 |
|
| 10 |
$wp_locale = get_locale(); |
| 11 |
|
| 12 |
$default_target_language = DeepLConfiguration::getDefaultTargetLanguage(); |
| 13 |
|
| 14 |
if( $type == 'target' && $selected == false ) { |
| 15 |
$selected = $default_target_language; |
| 16 |
//plouf( $languages ); |
| 17 |
} |
| 18 |
|
| 19 |
$html = ''; |
| 20 |
|
| 21 |
$html .= "\n" . '<select id="' . $id . '" name="' . $id . '">'; |
| 22 |
|
| 23 |
if( $type == 'source' ) $html .= ' |
| 24 |
<option value="auto">' . __( 'Automatic', 'wpdeepl' ) . '</option>'; |
| 25 |
|
| 26 |
foreach( $languages as $ln_id => $language ) { |
| 27 |
if( |
| 28 |
$default_target_language |
| 29 |
&& $ln_id == $default_target_language |
| 30 |
&& $type == 'source' |
| 31 |
) { |
| 32 |
continue; |
| 33 |
} |
| 34 |
|
| 35 |
$html .= ' |
| 36 |
<option value="' . $ln_id .'"'; |
| 37 |
|
| 38 |
if( $ln_id == $selected ) { |
| 39 |
$html .= ' selected="selected"'; |
| 40 |
} |
| 41 |
$label = ( $wp_locale && isset( $language['labels'][$wp_locale] )) ? $language['labels'][$wp_locale] : $language['labels']['fr_FR']; |
| 42 |
$html .= '>' . $label. '</option>'; |
| 43 |
} |
| 44 |
if( $type == 'target' ) $html .= ' |
| 45 |
<option value="notranslation">' . __( 'Dont\'t translate', 'wpdeepl' ) . '</option>'; |
| 46 |
|
| 47 |
$html .="\n</select>"; |
| 48 |
|
| 49 |
return $html; |
| 50 |
} |
| 51 |
|
| 52 |
function deepl_show_usage() { |
| 53 |
?> |
| 54 |
<h3><?php _e( 'Usage', 'wpdeepl' ); ?></h3> |
| 55 |
<?php |
| 56 |
$DeepLApiUsage = new DeepLApiUsage(); |
| 57 |
$usage = $DeepLApiUsage->request(); |
| 58 |
|
| 59 |
if( $usage && is_array( $usage ) && array_key_exists( 'character_count', $usage ) && array_key_exists( 'character_limit', $usage )) : |
| 60 |
$ratio = round( 100 * ( $usage['character_count'] / $usage['character_limit'] ), 3 ); |
| 61 |
$left_chars = $usage['character_limit'] - $usage['character_count']; |
| 62 |
|
| 63 |
?> |
| 64 |
<div class="progress-bar blue"> |
| 65 |
<span style="width: <?php echo round( (100 - $ratio ), 0 ); ?>%"><b><?php printf( __( '%s characters remaining', 'wpdeepl' ), number_format( $left_chars )); ?></b></span> |
| 66 |
<div class="progress-text"><?php |
| 67 |
printf( __( '%s / %s characters translated', 'wpdeepl' ), $usage['character_count'], $usage['character_limit'] ); |
| 68 |
echo " - " . $ratio; ?> %</div> |
| 69 |
<small class="request_time"><?php printf( __( 'Request done in: %f milliseconds', 'wpdeepl' ), $DeepLApiUsage->getRequestTime( true )) ?></small> |
| 70 |
</div> |
| 71 |
<?php |
| 72 |
endif; |
| 73 |
} |