Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found a solution in some old change notes for Play 1.1: <a href="http://www.playframework.org/documentation/1.2/releasenotes-1.1" rel="nofollow">http://www.playframework.org/documentation/1.2/releasenotes-1.1</a> (under "Global route arguments"). Odd that it isn't mentioned anywhere else.</p> <p>[Edited to include the entire working solution] [Edit2 - Fixed a problem]</p> <p>My routes file look like this:</p> <pre><code># Home page GET /{lang}/? Application.index GET / Application.redirect GET /{lang}/woops/? Application.underConstruction </code></pre> <p>The language controller looks like this atm:</p> <pre><code>public class Language extends Controller { @Before static void detectLangInURL() { String url = request.url; if (url.length() &gt; 2 &amp;&amp; isSupported(getFromUrl(url))) { String lang = getFromUrl(url); if (!Lang.get().equals(lang)) { Lang.change(lang); response.setCookie("lang", lang, "60d"); } renderArgs.put("lang", Lang.get()); routeArgs.put("lang", Lang.get()); } } private static String getFromUrl(String url) { String[] s = url.split("[/]"); if (s.length &gt; 1) return s[1]; else return ""; } private static boolean isSupported(String lang) { if (lang.length() == 0) return false; String[] langList = Play.configuration.get("application.langs").toString().split(","); for (int i = 0; i &lt; langList.length; i++) { if (langList[i].compareToIgnoreCase(lang) == 0) return true; } return false; } } </code></pre> <p>The redirect method looks like this:</p> <pre><code>public static void redirect() { Cookie lang = request.current().cookies.get("lang"); if (lang != null &amp;&amp; !lang.value.isEmpty()) Lang.change(lang.value); redirect(Lang.get() + "/"); } </code></pre> <p>I had to choose between using a <code>@With(Language.class)</code> annotation or changing the Controller super class. I choose the @With annotation.</p> <p>I'm pleased, it ended up being pretty simple. I hope someone can benefit from the above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload