Special characters are parsed as � - javascript

For context, have .NET Core web application which contains a React app. When adding German translations to the app (containing all kinds of special characters such as ä, ö, ...), they show up as �.
The translations are usually kept in a json file which we import in the react component. We also tried adding the file to the wwwroot and downloading it from there, but it gives the same result.
The HTML uses utf-8, so we don't know what's causing these characters to be parsed that way.
Are we missing some setting? Help is very much appreciated.

As it turns out, my files weren't saved in Unicode format. Case closed!

Related

How to escape smart quote in French characters while displaying on JSP

Currently, our application supports i18n.
We have one property file for each Locale.
For English, we were able to successfully display the placeholder defined in the property file.
Problem
When we change the Locale / Language settings in the application from English to French we were unable to replace the placeholder.
Placeholder - String Date - This is being successfully returned from the controller but still we couldn't replace on the UI page.
This is because the complete value for the key specified in the JSP is not being rendered properly for French Locale & as a result placeholder is not being replaced.
The special character with which we are facing issue is smart quote (d'essai)
Unicode for this character: U+00B4
We have tried placing UTF-8 encoding in the JSP page using Meta & Page directives but still, it didn't resolve the issue.
Any help is highly appreciated.
My Code Snippet
<fmt:message bundle="${myBundle}" key="myKey"><fmt:param value="${nextDateInString}"/></fmt:message>
Votre période d’essai gratuit prend fin le {0}
As you can see {0} is not getting replaced dynamically for French locale whereas for English it is working as expected.
Tried using StringEscapeUtils.escapeJavascript(myMessageFromProperties)
also did not help
The single quote is a special character in MessageFormat-Strings used to quote text, which the is then not processed. See Java API for MessageFormat.
You need two single quotes to escape it and display one single quote.

JavaScript to Python: simplify encoding of HTML string

I have a JavaScript module that needs to encode an HTML string that includes entities, and that needs to be correctly received in a Python 2.7 module.
The following works for every example I've tried:
On the sending side in JavaScript:
btoa(unescape(encodeURIComponent(*html-string*)))
On the receiving side in Python 2.7:
base64.b64decode(self.request.get(u'*parameter-name*'))
But that's a lot of conversions.
I've tried many other approaches. For example, I of course tried it without unescape(encodeURIComponent(...)), and I've tried replacing unescape (which is deprecated) with decodeURI and with decodeURIComponent. None of those attempts worked.
I also tried sending with encodeURIComponent() and receiving with urllib.unquote(), which didn't crash and retained all my content, but inserted some garbage characters.
Any suggestion for a simpler approach than the one I ended up with would be appreciated.
NOTE: I don't know whether it's relevant, but the JavaScript module is in an Ionic/AngularJS project and the parameter is being serialized with $httpParamSerializerJQLike. Meanwhile, the Python 2.7 module is in a GAE application and the request is being handled by webapp2.

JS Problem with encoding decoding UTF?

I'm dealing with a JSON file that i cannot modify, i have to keep it AS IS.
it contains text, with all the apostrophes converted to ’, and other special chars here and there...
what is that? unicode? how can i convert to the regular apostrophe?
i placed already the META tag utf-8 on the header but it doesn't seem to change anything...
What mime type is your JSON response being sent with? (Look in the headers in FireBug or the Developer Console.) It seems that you one of these steps is using a different encoding:
The JSON string generated by the web server
The mime type encoding sent along with the response
The mime type of your HTML page
The mime type for your JavaScript code
If you supply the community with actual code, or better yet a working reproducible test case, then the community can better help you.
what is that?
It is an attempt to interpret data stored in one character encoding as data stored in a different character encoding.
To ensure everything displays correctly you need to:
Pick an encoding (UTF-8 is a good bet)
Store everything in that encoding
Configure your editor to use it!
Configure your database (if applicable) to use it!
Ensure any server side code you use expects UTF-8 input and gives UTF-8 output
Configure your webserver to include charset=utf-8 on the Content-Type HTTP header
The W3C has a good introductory article on the subject, which has links to lots of useful further reading at the end.

Problem with special characters when Minifying JS

I'm using MVC ScriptManager to Compress and concatenate all my .js files. It works very well, except that if a *.js has a special character such as "á, à" it turns to "Ã!".
I'm trying to change the source code but with no success so far.
Does anyone have an idea what this could be?
Thanks!!
You can write them like \u00f1. Here you can look up the special characters: http://www.fileformat.info/info/unicode/char/search.htm
It looks like the source file encoding is ANSI, and the output is encoded as UTF-8.
In VS use the Advanced Save Options from the File menu to save the original .js file as UTF-8 with a signature (code page 65001).
I make a point of saving all text-type files (.cs, .js, .css, etc.) as UTF-8 to avoid any of these issues later on.

JCSompress - dealing with special characters in JS files?

I'm in the initial stages of investigating JSCompress for MSBUILD : http://msbuildtasks.tigris.org/
For my initial testing I have a few JS files over which I am running this task, some of the files include already minified JS files (JQuery Library etc..) and some files contain Special characters.
When the task runs everytime it encounters a special character in JS file it throws an error on the screen. How should I overcome this error so that it ignores special characters.
I do not want to exclude any files on the basis of wildcard on filenames (e.g. **\jquery*.js) since a developer can use the name as part of some other JS file which will then get excluded without minifying.
Is there a way to achieve this or should I be looking at other tools ?
Thanks !
Use the replace method to replace the special characters with a character entity of your own creation. Then after you have evaluated all the code use the replace method again to revert the special character conversion. I found I had to do this in my Pretty Diff tool because JavaScript cannot evaluate the difference between single and double quotes passed as string literals.

Categories