使用 i18n URL 的 Krakenjs 路由

Krakenjs routes with i18n URLs

我想在 Kraken.JS 中建立一个包含多语言内容的博客。 我应该如何构建 controller/model/routes 以获取这些 URL:

/en-US/article/hello-world
/de-DE/article/hello-world
/it-IT/article/hello-world

slug (hello-world) 不必国际化。 我不想将控制器复制到以下文件中:

controllers/en-US/article/index.js
controllers/de-DE/article/index.js
controllers/it-IT/article/index.js

有没有更漂亮的方法只用一个控制器文件来做到这一点?

是的,可以使用单个控制器完成:

查看此示例以获取有关如何完成此操作的说明https://github.com/krakenjs/kraken-example-with-i18n#adding-a-hook-to-set-the-locale-on-the-fly

执行此操作的一种方法如下:

router.get('/:locale/article/:article_name', function (req, res) {
    res.cookie('locale', req.params.locale);
    res.redirect('/article/:article_name');
});

只有一个控制器: controller/article/index.js