Localized URLs in Play 2.0?

Yesterday we had a presentation of Play 2.0 on our local JUG , but we couldn't figure out if it was possible to have localized URLs (for SEO purposes).

For example, / help, / hilfe, etc. must point to the same controller, but the template should be displayed with different language content.

Is there a way to do this in Play 2.0?

+5
source share
4 answers

I like your question because it was creative, at least for me :) Check out this approach, which it works for me:

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)

controllers/Application.java

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

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

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>
+3
source

(This is a different approach than in the previous answer , therefore added as a separate one)

- mapping table , :

urlpath              record_id    lang
/help/some-topic     12           en
/hilfe/ein-topic     12           de

conf/routes, , Dynamic parts spanning several / (. ), ..:

GET    /:topic    controller.Application.customDbRouter(topic:String)

, conf/routes, "" , return notFound() .

+1

Play 1.2.x, 2.x, . , , EN, DE ..

SEO "" URL- Sitemaps.

,

GET  /action/:param/:seo-string   Controller.methodAction(param)

seo-string , Sitemap:

/action/1/english-text
/action/1/german-text

. , URL- , URL- HTML 5.

This is extra work, but if you really want to ...

0
source

All Articles