Search code examples
javascriptphpincludecharacterfrench

French " ' " in variable blocks its presentation


Vague language issue in french. I am building a website with 5 languages. I have setup language files with among others French which i include using PHP

$lang['Description'] = 'Photos';
$lang['cookie']= "En utilisant notre site Web, vous acceptez que nous utilisions des cookies pour stocker des informations temporaires concernant votre utilisation. Cette information ne sera jamais utilisée à d autres fins!";
$lang['regio']='Region';
$lang['Viewkalender0'] = "Vous avez une réservation en cours qui doit être traitée avant qu'une réservation ultérieure puisse avoir lieu.";

I ask for these variables with JS function checkCookie() {

var regular=getCookie("Homecheznous-Roullens");
if (regular=="Accepted") {
    document.getElementById('cookie').innerHTML=regular;
} else {
   var x= '<?php echo $lang['cookie'] ?>';
   document.getElementById('cookie').innerHTML=x;
   }
}

I can switch between languages without problem, getting the right contents. BUT as soon as I correct the French in "d'autres" only adding the "'" the French contents do not show up. Everything else in the language files still comes up, so the language file is still accepted, and also furtheron in the file I use often the ' without problem. I know about the sensibility of PHP JS and so on on " or ' or vv.That is why you already see that i surrounded this variable with "". It works flawlessly with the variable Viewkalender0 with "qu'une" . ?? Somebody having a clue ?? Cookie is not set BTW. And as soon as i remove the ',the text shows up.

Have a nice day, Johan


Solution

  • i think the problem is in your declaration of the variable

    var x= '<?php echo $lang['cookie'] ?>';
    

    so this is replaced server side by for example

    var x= 'qu'une';
    

    so it's normal that x doesn't get the right text.

    Solition 1 : escape the ' symbole using \

    qu'une  should be qu\'une 
    

    solution 2 :

    try and change

    var x = "<?php echo $lang['cookie'] ?>";
    

    or using escma6

    var x = `<?php echo $lang['cookie'] ?>`;