I'm using Cloud Translate API to translate lots of strings but sometimes I get back results like this:
votre \u00e9v\u00e9nement une exp\u00e9rience unique.
I have to use search and replace inside my IDE to fix it but I was wondering if there's a way to replace these weird characters for their real characers using PHP?
EDIT:
This is my code to translate right now:
$htmlString = '';
$source = 'es';
$target = 'fr';
$key = 'dkfvñkdmgbñmb-8';
$translate = new TranslateClient([
'key' => $key
]);
//$trans = new GoogleTranslate();
$newArray = [];
$json = File::get(base_path() . '/resources/lang/español.json');
$array = json_decode($json, true);
foreach ($array as $key => $value)
{
//$result = $trans->translate($source, $target, $value);
$text_translated = $translate->translate($value, [
'source' => $source,
'target' => $target,
'format' => 'text'
])['text'];
$string = $text_translated;
$string = preg_replace('/%u([0-9A-F]+)/', '&#x$1;', $string);
$newArray[$key] = html_entity_decode($string);
//sleep(1);
usleep( 500000 );
}
$fileName = '/temp/translated-'.rand(1,1000).'.json';
Storage::disk('public')->put($fileName, json_encode($newArray));