API response breaking special characters in French - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: API response breaking special characters in French (/showthread.php?tid=79921) |
API response breaking special characters in French - gosocial2 - 08-15-2021 Hi all, I've encountered a very odd issue after translating a CI 4.1.3 app to French in which XHR response is received with messed up characters by the browser. <?php $id = 'doesntMatter'; $message = 'L\'enregistrement de Ville a été supprimé avec succès.'; $locale = $this->request->getLocale(); log_message('debug', 'locale: ', $locale); // it is 'fr' alright ?> When using: <?php return redirect()->to(route_to('cities'))->with('success', $message); ?> Browser outputs: L'enregistrement de Ville a été supprimé avec succès. But when using it in a RESTful controller as an API reponse: <?php $reponse = $this->respondDeleted(['id' => $id], $message); log_message('debug', var_export($response, true)); return $response; ?> In the log, $message is dumped correctly, but the browser outputs: L'enregistrement de Ville a été supprimé avec succès. I'm 100% positive that all PHP files and request headers are UTF-8. (Occurred with both Chrome and Safari) This looks like a framework bug, but I will appreciate any workaround suggestions to fix it before a possible bugfix. RE: API response breaking special characters in French - InsiteFX - 08-16-2021 Try changing the nwssage string. PHP Code: // change this Not tested, but sometimes it depends on the type of quotes. RE: API response breaking special characters in French - gosocial2 - 08-17-2021 This is the part I have to reveal Code: $message = lang('Basic.global.deleteSuccess'); PHP Code: $message = "L\'enregistrement de Ville a été supprimé avec succès."; did not change the result, but changing respondDeleted(...) method to the following: PHP Code: $response = $this->respondDeleted(['id' => $id, 'msg'=>$message]); and in JS Code: $.ajax({ I have yet to work out what happens with PHP Code: $this->failServerError( ... ) though. InsiteFX said: Try changing the nwssage string. PHP Code: // change this Not tested, but sometimes it depends on the type of quotes. |