Change Firefox default encoding for text files

10

2

Text files do not include character encoding information, so Firefox has no way of knowing which one is correct. Through the menu ViewText encoding I can select the appropriate encoding. I find myself doing this every time I open a text file, as it appears to be always set to Western by default, but my text files are always Unicode (UTF-8). Is there any way to set the default encoding to Unicode rather than Western?

gerrit

Posted 2017-06-01T13:56:45.237

Reputation: 1 357

I guess my first question is why are you using a browser to open plain text files? Or if a browser is needed, why not add a encoding header? Beyond that, what version (locale) of Firefox do you have installed? If I recall en-US version defaults to Unicode but some European country versions default to Western. – user3169 – 2017-06-02T05:43:59.820

@user3169 I use Firefox to open text files on the local filesystem for printing, because I find that I have easier control over print output than when printing with (for example) a2ps or vi. My Firefox is in English, it might be en-uk though, not sure — how can I tell? Not sure what you mean by adding an encoding header to a plain text file? – gerrit – 2017-06-02T13:39:52.247

What is your OS? In Windows 7, you can see it in Program Files\Mozilla Firefox\install.log. Or you can (after backing up your profiles folder to be safe) uninstall the current installation and install with the installer you want (https://ftp.mozilla.org/pub/firefox/releases/). For FF questions you should include FF version and your OS in your question.

– user3169 – 2017-06-02T22:52:59.427

Sometimes in a web page html source you will see something like <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> in the header. If you add such at the top of your text file, FF might select it for you. I am not an html expert but I think you get the idea. – user3169 – 2017-06-02T22:57:35.953

Possible duplicate here: https://superuser.com/questions/1062409/how-to-set-the-default-encoding-to-unicode?rq=1

– Brōtsyorfuzthrāx – 2017-09-05T22:58:33.493

Answers

6

If changing the default encoding for all offline files (not only text files) would also work for you, then there is now (I'm not sure since when, but it works in Firefox 59.0) an option to change the default encoding to UTF-8 in about:config: set the value of intl.charset.fallback.utf8_for_file to true.

Aside: it appears that one of the purposes of preventing the setting of the default encoding for online files is to avoid fingerprinting.

See also similar questions on stackoverflow (with the actual answer (used here)) and unix.stackexchange (with an interesting discussion of some of the rationale).

aplaice

Posted 2017-06-01T13:56:45.237

Reputation: 255

1

I don't see a way to change the default encoding in Firefox 54.0 from about:config, but you can manually change it every time you view the page, from the view menu (not ideal, I know). I don't see any extensions that let you do it, either (although I'm sure someone could make one). It might be a gargantuan task, but you could always try to edit the Firefox source code to allow for this, and then compile it.

You might be interested in making it so a text editor of your choice (one that supports Unicode) will open the page source (or the txt file) instead of Firefox doing it (you can use control+u to open a txt file that is displaying in the current tab, or if it's not a txt file it'll open the webpage's HTML source code, in your favorite text editor). To do that,

  1. Open about:config in your URL bar.
  2. Search for view_source.editor.external (change it to true) and view_source.editor.path (change it to the path of your text editor; make sure it's the full path).
  3. Restart your browser.

Then it'll launch a temporary file with the text of the page source in your text editor (which for a text file is the actual text file). I tested it and it works.

The glaring problem with this is it won't let you click to open scripts referenced in the source code if you're viewing HTML source code (if you have a habit of clicking links to script files).

It appears that another version of Firefox had the ability to set the default encoding once upon a time, but that doesn't exist in 54.0 on Xubuntu.

Brōtsyorfuzthrāx

Posted 2017-06-01T13:56:45.237

Reputation: 163

1Well, yes. One of the reasons that I use Firefox to open a text file is because I prefer its printing options over either a2ps or vim, so perhaps my question here is rather an XY problem. – gerrit – 2017-09-06T09:34:43.230