Javascript Convert French Special Characters

In my application MVC 3 I have several posts resx files with lines such as: "Editer groupe détails". All of them are used for window titles or acknowledgments / warnings. Thus, in order to be able to use them in my various .js files, I created a Javascript object called localizedRessources on my main page. The problem is that the lines change in this object, for example, the above line becomes "Editer groupe détails".

What are my options here? Is there a special function that tells JS not to encode them? Is there a way to directly use strings in my .js files? (this works, by the way, in some cases, but I would prefer not to have too much js code in my cshtml files).

I have a tag <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">added to my element <head>for all pages, so I'm fine. Any suggestion is welcome.

+4
source share
1 answer

According to your comment

<script type="text/javascript" charset="utf-8">
/*...*/
var localizedResources = { 
   FailedUploadErrorMessage: '@Resources.GeneralLocalization.FailedUploadErrorMessage'
/*...*/ 

You tried to render javaScript using ASP.NET MVC Razor. Typically, Razor avoids special characters for objects, for example, &become &amp;unnamed objects, such as ébecome &#233;. In javaScript, you need these characters that are native to UTF-8/16 (or, if it is really impossible, encoded as \u00E9).

Razor @ , HTML.

javaScript , Razors,

<script type="text/javascript" charset="utf-8">
/*...*/
var localizedResources = { 
   FailedUploadErrorMessage: '@Html.Raw(Resources.GeneralLocalization.FailedUploadErrorMessage)'
/*...*/

oops: javaScript UTF-16 ( )

+3

Source: https://habr.com/ru/post/1525186/


All Articles