function csp_po_ajax_handle_translate_by_google() {
	csp_po_check_security();
	// reference documentation: http://code.google.com/intl/de-DE/apis/ajaxlanguage/documentation/reference.html
	// example 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello%20world&langpair=en%7Cit'
	$msgid = $_POST['msgid'];
	$search = array('\\\\\\\"', '\\\\\"','\\\\n', '\\\\r', '\\\\t', '\\\\$','\\0', "\\'", '\\\\');
	$replace = array('\"', '"', "\n", "\r", "\\t", "\\$", "\0", "'", "\\");
	$msgid = str_replace( $search, $replace, $msgid );
	$res = csp_fetch_remote_content("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&format=html&q=".urlencode($msgid)."&langpair=en%7C".$_POST['destlang']);
	if ($res) {
		header('Content-Type: application/json');
		echo $res;
	}
	else{
		header('Status: 404 Not Found');
		header('HTTP/1.1 404 Not Found');
		load_plugin_textdomain(CSP_PO_TEXTDOMAIN, PLUGINDIR.'/codestyling-localization','codestyling-localization');
		_e("Sorry, Google Translation is not available.", CSP_PO_TEXTDOMAIN);		
	}
	exit();
}
function csp_po_ajax_handle_translate_by_google()
{
    csp_po_check_security();
    if (!defined('TRANSLATION_API_PER_USER_DONE')) {
        csp_po_init_per_user_trans();
    }
    // reference documentation: http://code.google.com/intl/de-DE/apis/ajaxlanguage/documentation/reference.html
    // example API v1 - 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello%20world&langpair=en%7Cit'
    // example API v2 - [ GET https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world ]
    $msgid = $_POST['msgid'];
    $search = array('\\\\\\\\"', '\\\\\\"', '\\\\n', '\\\\r', '\\\\t', '\\\\$', '\\0', "\\'", '\\\\');
    $replace = array('\\"', '"', "\n", "\r", "\\t", "\\\$", "", "'", "\\");
    $msgid = str_replace($search, $replace, $msgid);
    add_filter('https_ssl_verify', '__return_false');
    //OLD: $res = csp_fetch_remote_content("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&format=html&q=".urlencode($msgid)."&langpair=en%7C".$_POST['destlang']);
    $res = csp_fetch_remote_content("https://www.googleapis.com/language/translate/v2?key=" . (defined('GOOGLE_TRANSLATE_KEY') ? GOOGLE_TRANSLATE_KEY : '') . "&source=en&target=" . $_POST['destlang'] . "&q=" . urlencode($msgid));
    if ($res) {
        header('Content-Type: application/json');
        echo $res;
    } else {
        header('Status: 404 Not Found');
        header('HTTP/1.1 404 Not Found');
        load_plugin_textdomain(CSP_PO_TEXTDOMAIN, PLUGINDIR . '/codestyling-localization/languages', 'codestyling-localization/languages');
        _e("Sorry, Google Translation is not available.", CSP_PO_TEXTDOMAIN);
    }
    exit;
}