简体   繁体   English

如何在kraken.js中定义相对于URL的语言环境?

[英]How to define a locale relative to the url in kraken.js?

I've follow the kraken.js example to get i18n for my website. 我已按照kraken.js示例为网站获取i18n。 So now, 1 template file is rendered in each set-up language. 因此,现在,每种设置语言都会渲染1个模板文件。

For example : index.dust can be rendered in French, English and Dutch. 例如:index.dust可以用法语,英语和荷兰语呈现。 What I'm trying to achieve now is, if a user goes to : 我现在想要实现的是,如果用户转到:

<site>/accueil -> website in french
<site>/home -> website in english

And so on. 等等。

The kraken.js example relies on cookies. kraken.js示例依赖于cookie。 But if the user comes for the first time, the actual config will render a page in french (default locale) even if he came with an english url. 但是,如果用户是第一次来,则实际配置将以法语(默认语言环境)呈现页面,即使他带有英语网址也是如此。

I thought about an array for each route:locale (/accueil, /home, /startseite, etc) to define the locality but this is far from a clean code PLUS I will have to manually edit the array for every page added. 我想到了每个路由的数组:区域设置(/ accueil,/ home,/ startseite等)以定义位置,但这与干净的代码相去甚远,而且我必须为添加的每个页面手动编辑数组。

Does anyone have a better idea ? 有谁有更好的主意吗?

Thx. 谢谢。

好吧,我使用了上面描述的数组。

让中间件或参数处理程序从URL中的参数分配语言环境,而不是使用cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM