Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localized URLs in Play 2.0?

Yesterday we had a Play 2.0 presentation at our local JUG but we couldn't figure out whether it is possible to have localized URLs (for SEO purposes).

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

Is there any way to do this in Play 2.0?

like image 397
Petteri H Avatar asked May 04 '12 12:05

Petteri H


1 Answers

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

You can also create some kind of mapping table in DB where you can store full paths to records with different params:

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

than in conf/routes file you need to use rule allowing you to use Dynamic parts spanning several / (see routing doc) ie:

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

You can also mix both - standard routing mechanismus with custom one by placing above rule at the end of your conf/routes file if no 'static' rule will be available, then it will try to find it in mapping table or will return notFound() Result.

like image 155
biesior Avatar answered Nov 01 '22 07:11

biesior