问题描述
我进行了很多搜索,但是找不到解决我问题的方法.
I searched around quite a bit but couldn't find a solution for my problem.
我的应用程序使用i18next,除了一个问题之外,它都可以正常工作:德语变音符号(ü,ö,ä)显示为``.
My app uses i18next and it works fine except for one issue: german umlauts (ü,ö,ä) are displayed as �.
我不明白我是否理解错了,因为此示例应用程序的变音符没有问题: http://i18next-example1.eu01.aws.af.cm/?setLng=de-DE (github: https://github.com/rbeere/i18next-jade-express-sample )
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?
推荐答案
罪魁祸首可能是:
-
Translation.json
文件未保存为UTF8. - 如果有具体使用了字体,它们的Unicode支持非常有限(这是现代字体是不太可能的.)
-
layout.jade
文件未声明页面编码.因此,由浏览器自动检测它.不管是否解决了问题,在标头中声明页面编码都是一个好习惯:
- The
Translation.json
file is not saved as UTF8. - If any specificfonts are used, their Unicode support is very very limited (this isvery 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标头字段设置不正确.更改HTTP响应,如下所示:
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'});
});
这篇关于如何使i18next-node以正确的方式显示变音符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!