/** * Set the language for the current request, but don't * change the language cookie. This means the language * will be set for this request, but will not change for * future requests. * * @throws IllegalArgumentException If the given language * is not supported by the application. */ public void setTransientLang(Lang lang) { if (Lang.availables().contains(lang)) { this.lang = lang; } else { throw new IllegalArgumentException("Language not supported in this application: " + lang + " not in Lang.availables()"); } }
/** * Change durably the lang for the current user. * @param lang New Lang object to use * @return true if the requested lang was supported by the application, otherwise false */ public boolean changeLang(Lang lang) { if (Lang.availables().contains(lang)) { this.lang = lang; scala.Option<String> domain = play.api.mvc.Session.domain(); response.setCookie(Play.langCookieName(), lang.code(), null, play.api.mvc.Session.path(), domain.isDefined() ? domain.get() : null, Play.langCookieSecure(), Play.langCookieHttpOnly()); return true; } else { return false; } }