Play 2.0中的本地化网址?

Pet*_*rta 5 url seo playframework-2.0

昨天我们在我们当地的JUG上有一个Play 2.0演示,但我们无法弄清楚是否有可能有本地化的URL(用于SEO目的).

例如/ help,/ hilfe等应该指向同一个控制器,但应该使用不同的语言内容呈现模板.

在Play 2.0中有什么办法吗?

bie*_*ior 3

我喜欢你的问题,因为它至少对我来说很有创意:)检查这种方法对我是否有效:

conf/routes:

GET     /help     controllers.Application.helpIndex(lang = "en")
GET     /hilfe    controllers.Application.helpIndex(lang = "de")

GET     /help/:id     controllers.Application.helpTopic(lang = "en", id: Long)
GET     /hilfe/:id    controllers.Application.helpTopic(lang = "de", id: Long)
Run Code Online (Sandbox Code Playgroud)

controllers/Application.java:

public static Result helpIndex(String lang) {
    return ok("Display help's index in " + lang.toUpperCase());
}

public static Result helpTopic(String lang, Long id) {
    return ok("Display details of help topic no " + id + " in " + lang.toUpperCase());
}
Run Code Online (Sandbox Code Playgroud)

views/someView.scala.html:

<a href="@routes.Application.helpIndex("en")">Help index</a><br/>
<a href="@routes.Application.helpIndex("de")">Hilfe index</a><br/>

<a href="@routes.Application.helpTopic("en", 12)">Help topic no 12</a><br/>
<a href="@routes.Application.helpTopic("de", 12)">Hilfe topic no 12</a>
Run Code Online (Sandbox Code Playgroud)