Welcome Guest, Not a member yet? Register   Sign In
API response breaking special characters in French
#1

(This post was last modified: 08-16-2021, 01:02 AM by gosocial2. Edit Reason: emphasize the $message )

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.

CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface.

Reply
#2

Try changing the nwssage string.
PHP Code:
// change this
$message 'L\'enregistrement de Ville a été supprimé avec succès.';

// to this
$message "L\'enregistrement de Ville a été supprimé avec succès."

Not tested, but sometimes it depends on the type of quotes.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 08-17-2021, 06:11 AM by gosocial2.)

This is the part I have to reveal
Code:
$message = lang('Basic.global.deleteSuccess');
Even when
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]);
return $response

and in JS
Code:
$.ajax({
    url: `<?= route_to('cities') ?>/${dataId}`,
    method: 'DELETE',
}).done((data, textStatus, jqXHR) => {
    alert(data.msg);
    // instead of alert(jqXHR.statusText); worked !!!
});

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
$message 'L\'enregistrement de Ville a été supprimé avec succès.';

// to this
$message "L\'enregistrement de Ville a été supprimé avec succès."

Not tested, but sometimes it depends on the type of quotes.

CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface.

Reply




Theme © iAndrew 2016 - Forum software by © MyBB