angular fail using letters ø, æ, å, maybe something about i18n - javascript

i'm having some problem with my angular.
I can't make it use the letters "æ,ø,å"
I tried installing I18N, but doesn't seems to do anything.
when i navigate to a page url which contains one of the letters, it's convert it to something like this
Ops%EF%BF%BDtning
And it should be something like
Opsætning
And the same thing happen when i use it on the pages. like shown here
I been using angular a long time, but this problem have never happen for me before. can anyone share some wisdom. Im sure it's something stupid little mistake i just can't see my self.
anyway, thanks for your time,

Make sure to set the right charset, in your case utf-8
meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1' />
You might have to convert your files to use utf-8 (Notepad++ has a 'Convert to UTF-8' function)
Alternatively you could use HTML special character codes for: æ ('&aelig';), ø ('&oslash';), å ('&aring';)
You can read more about the use of special characters in HTML, XML and JS here

Related

Using special symbols in HTML and Javascript

I'm trying to figure out what is the proper way to use the "not" operator (Negation) which looks like: ¬ (UTF-8: U+00AC) in JavaScript. I could use:
<span>¬A</span>
But I'm not sure if it is the proper way and if its been supported on all (or most) of the modern browsers and mobile. I tried to find a previous topic on this matter but could not find any. The wanted result is to display this operator beside A.
Correct escape sequences for HTML are: &#x00AC, followed by ';A', and for javascript - either '\xACA' or '\u00ACA'.
"meta charset" is always advisable to include, but it does not affect the escapes.
I added ';' after the HTML escape sequence: for some reason it wasn't needed if instead of 'A' there is, for example, 'k', I didn't know. Semicolon has to be added.
If you are properly using UTF-8 (which is to say that your HTML, JS, and CSS files are all encoded in UTF-8, <meta charset="utf-8"> is present in the <head>, and HTTP headers all define the charset as UTF-8), there should be no need to encode the symbol at all. Simply write ¬, exactly as you have done here.
The only symbols you need to encode are < and & (also ' and/or " in attributes). Most would also recommend encoding > and the non-breaking space, to avoid confusion. I encode all of these, but nothing else.

Angular translate UTF8 characters (pascalprecht.translate)

I am having problems with UTF8 characters while using SanitizeValueStrategy('sanitize'). I have to use it since the client is using the language files to edit texts and he might use tags like <b> or <i>...
I need to use only the json file for translations. The client won't touch the app code to change any text. JSON file:
{
"H1": "Typy domů",
"NAME": "Křestní"
}
The problems, thought, only occurs while using angular's interpolation:
<h1 translate>houseTypes.H1</h1>
Typy domů
I can use this method to put text inside of element's body, but this problems still occurs for attributes.
<input placeholder="'houseTypes.NAME'|translate"></h1>
Křestní
The questions is:
How can I get UTF8 characters to be written correctly, while only using the JSON static file loader in interpolations, or any other way in attributes as is placeholder.
For anyone struggeling upon finding way how to make UTF-8 character normal even in {{interpolations}}, this is the way to do it:
$translateProvider.useSanitizeValueStrategy('sanitizeParameters');
This way the sanitize will be always made even in interpolations.
You have two options:
Use the strategy sanitizeParameters which will only sanitize the dynamic parameters, but not the actual translation (template). If you have the translation under control (but not the dynamic values), this will work.
Use the strategy escape (or escapeParameters) which does not use sanitization but escaping.
For me the problem was solved when i set SanitizeValueStrategy to null
$translateProvider.useSanitizeValueStrategy(null);

HTML Encoded strings recognized by the javascript engine, how's it possible?

Well. This night was a very strange night to me. I am sorry to create a new question after creating two other questions previously, but this is another argument at all. If I get an answer here, I'll get an answer to those questions too so please somebody listen to me and try to understand.
It all began with a simple script JS to be generated through an aspx codebehind file.
On a control, I had to put a JavaScript in this way:
this.MyTxtBox.Attributes["onfocus"] = "windows.alert('Hello World!');";
OK. You might think, where's the problem? The problem is that ASP.NET 4.0 encodes everything, and I say everything in order to avoid XSS to be performed on a site. Well this might not seem a problem but if you look at the rendered page you'll make a jump on the chair like I did:
<textarea id="..." onfocus="windows.alert('Hello World!');"></textarea>
As you can see the html, the final html is a bit odd... JavaScript engine should not accept this situation.
So I started this questions:
ASP.NET quote character encoding causes problems when setting a control's property
Asp.Net encoding configuration
Well I still haven't got any answer YES we could not understand what the hell it is necessary to modify in the .net configuration in order not to let this situation happen.
But now I consider one thing, one important thing: JavaScript engine works!
Even with that odd code that should not be interpreted...
I hope everything was clear until now... The question now comes:
Is this a normal situation for the JavaScript engine?
Does every browser will correctly interpret a JavaScript having quotes replaced with their encoded strings?
If this is true I have to suppose that the .net does not provide a mechanism to avoid encoding just for this reason!
Re:
<textarea id="..." onfocus="windows.alert('Hello World!');"></textarea>
There's nothing odd about that (other than your using windows.alert instead of window.alert). It should work fine (and does; example). The HTML parser parses HTML attribute values, and handles processing entities like '. The JavaScript source code it eventually hands to the JavaScript interpreter will have quotes in it. The browser doesn't hand the literal characters & # 3 9 ; to the JavaScript interpreter.
It's just the same as:
<input type='text' value="This is a 'funny' value too">
The HTML parser processes the entities, and the actual value assigned to the input is This is a "funny" value too.
Incidentally, this is also why this seemingly-innocent HTML is actually wrong and will fail validation (although most browsers will allow it):
<a href='http://www.google.com/search?q=foo&hl=en'>Search for foo</a>
More correctly, that should be:
<a href='http://www.google.com/search?q=foo&hl=en'>Search for foo</a>
<!-- ^^^^^--- difference here -->
...because the HTML parser parses the value, then assigns the parsed result to the href attribute. And of course, an & introduces a character entity and so to literally get an & you must use & everywhere in HTML. (Again, most browsers will let you get away with it if what follows the & doesn't look like an entity. But that can and will bite you.)

Why can't I display a pound (£) symbol in HTML?

I'm trying to display the pound symbol in HTML (from PHP) but all I get is a symbol with a question mark.
The following are things that I've tried.
In PHP:
header('Content-type: text/html; charset=utf-8');
In HTML, put this in the head tag:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
I tried displaying it using a javascript function which converts it to:
&#65533;
I suppose it would help if I knew what I was doing... but I guess that's why I'm asking this question :)
Educated guess: You have a ISO-8859-1 encoded pound sign in a UTF-8 encoded page.
Make sure your data is in the right encoding and everything will work fine.
Use £. I had the same problem and solved it using jQuery:
$(this).text('&#163;');
If you try this and it does not work, just change the jQuery methods,
$(this).html('&#163;');
This always work in all contexts...
1st: the pound symbol is a "special" char in utf8 encoding (try saving £$ in a iso-8859-1 (or iso-8859-15) file and you will get ä when encoding using header)
2nd: change your encoding to utf8 form the file.
there are plenty of methods to do it.
notepad and notepad++ are great sugestions.
3rd: use ob_start(); (in php) BEFORE YOU MAKE ANY OUTPUT if you are getting weird encoding errors, like missing the encoding sometimes.
and YES, this solves it!
this kind of errors occurs when a page is encoded in windows-1252(ANSI),ASCII,iso-8859-1(5) and then you have all the others in utf8.
this is a terrible error and can cause weird things like session_start(); not working.
4th: other php solutions:
utf8_encode('£');
htmlentities('£');
echo '&pound;';
5th: javascript solutions:
document.getElementById('id_goes_here').innerText.replace('£','&pound;');
document.getElementById('id_goes_here').innerText.replace('£',"\u00A3");
$(this).html().replace('£','&pound;'); //jquery
$(this).html().replace('£',"\u00A3"); //jquery
String.fromCharCode('163');
you MUST send £, so it will repair the broken encoded code point.
please, avoid these solutions!
use php!
these solutions only show how to 'fix' the error, and the last one only to create the well-encoded char.
Have you tried displaying a £ ?
Here is an overwhelming list.
You could try using £ or £ instead of embedding the character directly; if you embed it directly, you're more likely to run into encoding issues in which your editor saves the file is ISO-8859-1 but it's interpreted as UTF-8, or vice versa.
If you want to embed it (or other Unicode characters) directly, make sure you actually save your file as UTF-8, and set the encoding as you did with the Content-Type header. Make sure when you get the file from the server that the header is present and correct, and that the file hasn't been transcoded by the web server.
Or for other code equivalents try:
£
£
You need to save your PHP script file in UTF-8 encoding, and leave the <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> in the HTML.
For text editor, I recommend Notepad++, because it can detect and display the actual encoding of the file (in the lower right corner of the editor), and you can convert it as well.
This works in all chrome, IE, Firefox.
In Database > table > field type .for example set the symbol column TO varchar(2) utf8_bin
php code:
$symbol = '£';
echo mb_convert_encoding($symbol, 'UTF-8', 'HTML-ENTITIES');
or
html_entity_decode($symbol, ENT_NOQUOTES, 'UTF-8');
And also make sure set the HTML OR XML encoding to encoding="UTF-8"
Note: You should make sure that database, document type and php code all have a same encoding
How ever the better solution would be using £

french chars html - javascript

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.

Categories