-
Notifications
You must be signed in to change notification settings - Fork 3
/
ajax.php
25 lines (18 loc) · 880 Bytes
/
ajax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
// Setup an AJAX action to close the donation nag banner on the overview page.
function gp_machine_translate_action_callback() {
GLOBAL $gp_machine_translate;
if( ! isset( $gp_machine_translate ) ) {
wp_send_json( array( 'success' => false, 'message' => 'GlotPress not yet loaded.' ) );
}
$locale = $_POST['locale'];
$strings = array( $_POST['original'] );
$new_string = $gp_machine_translate->batchTranslate( $locale, $strings );
if( is_wp_error( $new_string ) ) {
$translations = array( 'success' => false, 'error' => array( 'message' => $new_string->get_error_message(), 'reason' => $new_string->get_error_data() ) );
} else {
$translations = array( 'success' => true, 'data' => array( 'translatedText' => $new_string ) );
}
wp_send_json( $translations );
}
add_action( 'wp_ajax_gp_machine_translate', 'gp_machine_translate_action_callback' );