How to get i18next-node to display umlauts the right way?

若如初见. 提交于 2019-12-10 11:44:06

问题


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?


回答1:


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'});
    });
    


来源:https://stackoverflow.com/questions/18277858/how-to-get-i18next-node-to-display-umlauts-the-right-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!