Hi!,
I am using the following code and this is working fine with smarty/php. I only wonder how leave the tags in place as it brakes the output from the api. Can someone give me some direction how to solve this?
Thanks!
[[php]]
$vars = $this->get_template_vars();
$vertaling = strip_tags($vars['entry']['introduction'] . $vars['entry']['body']);
$url = 'https://libretranslate.org/translate';
$data = array(
'q' => $vertaling,
'source' => 'nl',
'target' => 'en',
'format' => 'text'
);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode($data)
)
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($response !== false) {
$responseData = json_decode($response, true);
$translatedText = $responseData['translatedText'];
echo $translatedText;
} else {
echo 'Vertaling is mislukt';
}
[[/php]]