doushi9444 2017-11-12 23:56
浏览 47
已采纳

变量中的法语“'”阻止其呈现

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

  • 写回答

1条回答 默认 最新

  • doucandiao9180 2017-11-13 00:05
    关注

    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'] ?>`;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数