多语言快递应用 [英] Multilanguage express app

查看:81
本文介绍了多语言快递应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么是在Express中以相同布局实现相同内容的多种版本/语言的最佳方法.

I wonder what would be the best way to implement multiple versions / languages of the same content in the same layout in express.

我应该这样做吗?

app.get("/", function(req, res) {
    res.render(language + "/index");
});

还是有一种更聪明/更好的方法?

Or is there a smarter / better way?

推荐答案

我建议仅保留一个模板,就好像每种语言使用一个模板一样,它很快就会失控,更不用说复制很多内容了(而且您也会在模板中放入少量的逻辑").许多应用程序使用名为gettext的工具来进行国际化.在 https://github.com/DanielBaulig/node-gettext

I would suggest to keep only one template, as if you use one template per language it will get out of hand very quickly, let alone duplicate much content (and the small amount of "logic" you would put in a template too). Many applications use a tool called gettext to do the internationalization thing. There is a node.js library for it at https://github.com/DanielBaulig/node-gettext

或者还有 i18n-node .似乎与express js的集成度更高.

Alternatively there is also i18n-node. It appears to have a bit more integration with express js.

这篇关于多语言快递应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆