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.
Related
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!
I have an HTMl string that is stored in a database. When I go to set the value of a javascript variable with this string on the front-end via my templating engine (Leaf), it stores escaped as:
var string = <p>It's a round about way.</p> <p><!-- pagebreak -->But Maybe this is the way?</p>;
I'm trying to set this value as the content value for TinyMCE, but JavaScript produces an Unexpected EOF error when reading this string and points to a & character, which I presume is the first character of the new line. I tried on the back-end to replace occurrences of string \r\n with a so it would play nicer with JavaScript but the changes didn't seem to take. I tried encoding/decoding the string but that didn't help. Perhaps someone can help shed some light on this seemingly trivial task?
Thanks in advance.
Javascript was rendering \r\n characters found in the string instead of escaping them. Parsed it out in the server-side code instead of handling in JS.
I'm trying to replace a few empty href="" statements with computed URL's on pageload.
The replacement string, however, contains several &'s, which need to be in the href.
What ever I try, as soon as setAttribute("href", url); or $(id).attr('href', url) is used, all &'s are replaced by a & and the links fail.
How can I prevent this from happening? I'm pretty sure any code that ends in .href or contains href is going through a translation stage and will all fail.
You might have noticed that I've edited this message a lot of times because you simply cannot type a full '& a m p ;' in this box without it being translated to a '&' here too.
Let's step back a bit, and think about this from the ground up. The escape sequence &xxx; is the way to embed "special characters" into an HTML document. To be clear, it is an HTML escape sequence.
This way of escaping characters is useful because it means characters can be placed into an ASCII file that would otherwise be impossible to embed.
For example, the Euro sign (€) can be embedded using a numeric code representing its Unicode codepoint €. Or, a non-breaking space can be embedded using its character entity name, . (Aside: these characters would be easier to embed in a UTF-8 file, with no escaping needed, but that's beside the point here)
Now, because this escape sequence always begins with an ampersand, it means that a bare ampersand in an HTML document is ambiguous - as the browser reads through the document it doesn't know if you want an actual ampersand or whether there's an HTML entity escape sequence coming up. To remove this ambiguity, if you want to embed an ampersand in an HTML document then you need to escape it.
Let me highlight that sentence: To remove this ambiguity, if you want to embed an ampersand in an HTML document then you need to escape it.
Because this escaping only applies to HTML documents, if you are writing Javascript in a .js file then this escape sequence is irrelevant to you. You can just drop your ampersands in unescaped and there's no problem. What it means is, your Javascript files can replace the URLs with bare ampersands, no & needed.
As far as the browser is concerned, all of those URLs you write only contain bare ampersands. The escape sequence & is only needed to express those in HTML form, as soon as the browser has read the HTML then that escape sequence is forgotten about.
I've repeated myself a few times here but that's because I've tried to make it as clear as possible.
You have to replace & with & in the url, prior to setting href property of an a tag.
var url = 'www.example.com?a=1&b=2'
url = url.replace(/\&/g, '&')
$('a').attr('href', url)
I have a Spanish validation message which I'm trying to display using my JavaScript.
And all the special characters like above gets changed into & #243;.
And it is only happening when I'm using JavaScript, there are couple of more validation messages in Spanish which I'm displaying through server side and they are fine.
errorString = "<%:Validation.xyz %>";
I'm trying to get from resource file.
Can some one think of quick work around?
What you call garbage is actually but the HTML encoded value of the corresponding character and is there to prevent you from XSS. The encoding happens because you are using <%: which automatically HTML encodes the string but this shouldn't be a problem for your javascript. Example:
var text = 'hello ó';
document.getElementById('foo').innerHTML = text;
works just fine and displays hello ó in the corresponding DOM element.
Check if you saved your file with UTF-8 encoding (just in case). It happens that it goes into TFS without UTF8 BOM and then mess can happen on client side.
I have an html page were i can fill in some text and send (with javascript) this to an sql-database.
On my pc, everything works fine, but on another one (a french windows), it doesn't save my chars correctly.
french chars like é, è, â,.. were saved as 'É', or something like that.
I googled a lot but still did not found any solution, i'm also not able to reproduce the problem on my own pc..
"É" occurs when a character encoded in utf-8 (2 bytes) is read as latin (1 byte). The problem can be on the client side (e.g. by the use of escape) or on the server side (wrong parsing of the form's POST data, database encoding).
Make sure that your html pages encoding is set to something like UTF-8, UTF-16, etc... Also make sure that your strings are escaped properly in javascript.
You need to encode the file in ANSI. I do this my self. For example in notepad 2 you would click File->Encoding->ANSI and then save.