Short version: Is there an attractive, simple way of implementing a language-specific url structure, ala. host.com/en/ or host.com/pt/ in Play 1.2.5?
I’m looking for a solution that doesn’t require changing all controllers, and the change should preferably only be to the routing file, as I don’t want two sets of redundant views – one for each language.
I already have a message.pt and message.en, and I have a way of switching between the two, but I’m a newb when it comes to routing.
I realize that the routing file can contain a route like: “/(en|pt)/” but I’m kinda stuck here.
I appologies if the question is a bit vague.
I’ll gladly clarify should the need arise.
I found a solution in some old change notes for Play 1.1:
http://www.playframework.org/documentation/1.2/releasenotes-1.1 (under “Global route arguments”). Odd that it isn’t mentioned anywhere else.
[Edited to include the entire working solution]
[Edit2 – Fixed a problem]
My routes file look like this:
The language controller looks like this atm:
The redirect method looks like this:
I had to choose between using a
@With(Language.class)annotation or changing the Controller super class. I choose the @With annotation.I’m pleased, it ended up being pretty simple.
I hope someone can benefit from the above.