1

I searched around quite a bit but couldn't find a solution for my problem.

My app uses i18next and it works fine except for one issue: german umlauts (ü,ö,ä) are displayed as �.

I don't understand were I got it wrong, since this example app has no problem with umlauts: http://i18next-example1.eu01.aws.af.cm/?setLng=de-DE (github: https://github.com/rbeere/i18next-jade-express-sample)

How can I figure this one out?

G McLuhan
  • 294
  • 1
  • 4
  • 14

1 Answers1

4

The culprit might be:

  • The Translation.json file is not saved as UTF8.
  • If any specific fonts are used, their Unicode support is very very limited (this is very unlikely with modern fonts).
  • layout.jade file doesn't declare the page encoding. Therefore it's up to the browser to auto-detect it. No matter if this fixes the problem or not, it's a good practice to declare the page encoding in the header:

    meta(http-equiv="Content-Type",content="text/html; charset=utf-8")
    
  • Content-Type HTTP header field is not set properly. Change the HTTP response as follows:

    app.get('/', function(req, res) {
         res.header("Content-Type", "text/html; charset=utf-8");
         res.render('index', { title: 'Localization with Express, Jade and i18next-node'});
    });
    
Shervin
  • 1,936
  • 17
  • 27
  • Thank you for the answer! I use standard fonts so that is not the problem. `Translation.json` is now saved as UTF-8 but neither that nor the encoding declaration did it. Do you have other ideas? – G McLuhan Aug 17 '13 at 11:44
  • @GMcLuhan, does your actual application get the content from a DB or from a file? If DB, did you check the DB encoding? Because the only that I could generate this issue was to have the content (in case of the example from the file) in Latin-1 (ISO-8859-1) and have the response in UTF8. – Shervin Aug 17 '13 at 18:30
  • They are purely from the file, which is now encoded in UTF-8. It's really weird because I think my application works just like to one I linked above. That one works fine, when I run it on my server, but mine throws all these �. – G McLuhan Aug 18 '13 at 10:59
  • Interesting. Last thing which comes to mind is the `Content-Type` HTTP header field. I added it to the answer. It might help if you add Node.js version you're running on your server as well as HTTP headers. – Shervin Aug 18 '13 at 15:43
  • Thank you, that's it! Here's what works and here's what does not: 1. All strings handled by i18next have umlauts, no � characters (Whohoo!). 2. Everything else (like express.js error messages and plain text in the `.jade` files). But I'm ok with it since I want every text string to be handled by i18next (or do you have an awesome hint for this, too?). – G McLuhan Aug 18 '13 at 20:00
  • Glad that it worked. Regarding non-`i18next` strings, is it possible that encoding of `.jade` file is still Latin-1? Again, I only can generate the issue under that circumstance. – Shervin Aug 18 '13 at 22:02
  • 1
    And that solved that: saving the `.jade` as UTF-8 let the encoding be perfect! Thank you once again and may this help people in the future. – G McLuhan Aug 18 '13 at 23:08