force eclipse to ignore character encoding attribute - html

I'm working with a web framework that uses a dynamic character encoding in its html templates, like this:
<meta charset="${_response_encoding}">
The problem is when I try to edit this file in Eclipse, Eclipse thinks this is a literal encoding type, and thus refuses to open the file, saying:
"Unsupported Character Encoding" Character encoding
"${_response_encoding}" is not supported by this platform.
Is there any way to tell Eclipse to stop trying to be "smart" (because it plainly isn't) and just show me the text? I've tried using "Open With... Text Editor" but still same result.

Change the content type for HTML files:
Go to Windows -> preferences -> General -> Content types and change encoding (set them to utf-8) for all the file extensions you need.

Choose "Other" and then select UTF-8. Then your template will render as normal.

I had a similar problem, except I was receiving the error message when trying to save the document after changing the character encoding. I resolved the problem by doing the following in Eclipse before putting in the non-standard charset value:
Rename the file to have a non-HTML file extension.
Open the file using an editor other than the HTML one.
Change the charset value to the non-standard value you want.
Rename the file to have the original extension.
Open the file.
Follow the buttons and prompts to set the character encoding to the real encoding of the file.
After this, the file should still be usable while still having the non-standard charset value.

If you're having Eclipse treat it like an HTML file, it is being smart. That's not a valid encoding name. Have you tried just templating the entire meta tag?

(as mentioned in a comment) In Eclipse Indigo, when opening the file you see the Unsupported character encoding message along with a Set Encoding button. Us that button to set the UTF-8 encoding. Eclipse does not change the variable in the HTML file.
True, this is done on a file-by-file basis, however, in my project I import the same meta header file for every screen. Actually, I have only two files to setup (those that are logged in and those that are not).

Related

Is there any annotation / comments I can put in file for PhpStorm to force file encoding?

We are using Windows-1252 character-set in one of our files. I have set proper file encoding in Phpstorm > Settings for this particular PHP file. Remaining project is UTF8. This works for me.
The problem comes with other developers in my organization. They have UTF encoding set in their settings and they don't have this file specific custom settings. When they save anything in this file, it converts the special characters.
Is there any doc block OR annotation like
// #FILE_ENCODING Windows-1252
that I can put in my PHP file so PhpStorm auto detects it?

Razor not rendering special characters properly

I'm generating cshtml files dynamically for our CMS and using UTF-8 as encoding. I also tried to open those files using Notepad++ and it says that the encoding is UTF-8.
And I just use the controller's View() method to serve the page:
return View(path);
But it still improperly renders the special characters to a wrong one. Like 'α' becoming 'α', or single quote becoming '’'. The generated files when inspecting contains the correct characters, but when it getting served, it shows incorrect characters.
I found the issue and solution. The cshtml files should be written not by simple UTF8 format, but UTF8-BOM file format. Non-BOM UTF8 cshtml files' special characters were converted into something when getting served through return View(path);.

HTML charset metatag - what charset should I specify?

I recently ran an HTML file I was writing through this on-line HTML validator, and one of the diagnostics I got said,
The character encoding was not declared. Proceeding using
"windows-1252".
When I create a webpage, I write it in a text editor, which saves it as DOS-text (with CR-LF line endings). When I upload the file to my web-hosting provider, it gets converted (I think) on the server to Unix text (LF line endings). My text editor can also save files as Unicode including UTF-8, but I rarely find that necessary.
The standard online advice about specifying the character encoding in a web document is to include, just under the <head> tag, <meta charset="utf-8">. There is also advice that you should ensure that what you specify does not conflict with the information sent by the server in the HTTP headers when serving the document. Using Rex Swain's [online] HTTP viewer, I see that in the HTTP headers it just says,
Content-Type:·text/html
Should I follow the standard advice to specify the charset as UTF-8, even though the html file is never saved as such, or should I specify it as windows-1252, as assumed by that online validator, or as ISO-8859-1 as per one of the example values on W3Schools? Also, some examples of the charset metatag show it terminated as />. Which is the preferred syntax, and should there be a space before the slash?

How do I change the "actual encoding" of my HTML document?

I ran my web page through the W3C HTML validator and received this error.
The encoding ascii is not the preferred name of the character
encoding in use. The preferred name is us-ascii. (Charmod C024) ✉
Line 5, Column 70: Internal encoding declaration utf-8 disagrees with
the actual encoding of the document (us-ascii).
<meta http-equiv="content-type" content="text/html;charset=utf-8">
Apparently, I am not "actually" using UTF-8 even though I specified UTF-8 in my meta tag.
How do I, well, "actually" use UTF-8? What does that even mean?
The HTML5 mode of the validator treats a mismatch between encoding declarations as an error. In the message, “internal encoding declaration” refers to a meta tag such as <meta charset=utf-8>, and “actual encoding” (misleadingly) refers to encoding declaration in HTTP headers.
According to current HTML specifications (HTML5 is just a draft), the mismatch is not an error, and the HTTP headers win.
There is no real problem if your document only contains Ascii characters. Ascii-encoded data is trivially UTF-8 encoded too, because in UTF-8, any Ascii character is represented as a single byte, with the same value as in Ascii.
It depends on the software used server-side whether and how you can change the HTTP headers. If they now specify charset=ascii, as it seems, it is not a real problem except in validation, provided that you keep using Ascii characters only. But it is somewhat odd and outdated. Try to have the encoding information there changed to charset=utf-8. You need not change the actual encoding, but if you later add non-Ascii characters, make sure you save the file as UTF-8 encoded by selecting a suitable command or option in the authoring program.
Open your file in notepad, then save as > UTF-8 (next to the save button).
On unix-like system you might use iconv tool to convert file from one encoding to another.
It can also be used from the scope of programming language(e.g. php).
The proper function has same name:
http://www.php.net/manual/en/function.iconv.php
Specifying encoding is one thing. Saving documents in a proper encoding is another.
Edit your documents in editors supporting UTF-8 encoding. Preferably UTF-8 without BOM. Notepad++ may be a good start.
Have a read too: UTF-8 all the way through.

Chrome Extension internationalization error?

When i add "default_locale": "en", to my manifest file, then package it and try to upload it, i get the error message saying, An error occurred: Message JSON file must be in UTF-8 encoding. ... But this is how they tell you to set it up in their i18n page... What is the problem?
I'm not sure he's missing the Byte Order Mark -- which is neither required nor recommended in UTF-8 (as endianness isn't relevant) -- I think it's just the file encoding. I believe Notepad adds the BOM by default when you save as UTF-8, but I always save files without it as some programs that receive UTF-8 data don't expect the BOM.
But yes, bottom line, go to the file and Save As in UTF-8. If you are using Notepad, I'd recommend using a different editor -- for JS something lightweight like Notepad++ works well -- so that you can change the default encoding, among many other benefits.
It seems that you simply missing Byte Order Mask in front of your manifest file. If you are on Windows simply open it in Notepad, click File -> Save As and choose UTF-8 from Encoding combo box.
Obviously you can use other tools to "convert" to UTF-8...
just solved the issue... After googling awhile... turns out MS notepad is inadequate even with utf-8 encoding... Download "Notepad2"... and set the encoding to utf-8... somehow it works now!