/** * 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; } }
/** * 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. * * @deprecated Deprecated as of 2.7.0. Use {@link MessagesApi#setLang(Result, Lang)}. */ @Deprecated public boolean changeLang(Lang lang) { if (langs().availables().contains(lang)) { this.lang = lang; scala.Option<String> domain = sessionDomain(); Cookie langCookie = new Cookie(messagesApi().langCookieName(), lang.code(), null, sessionPath(), domain.isDefined() ? domain.get() : null, messagesApi().langCookieSecure(), messagesApi().langCookieHttpOnly(), messagesApi().langCookieSameSite().orElse(null) ); response.setCookie(langCookie); return true; } else { return false; } }
/** * 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. * * @deprecated Deprecated as of 2.7.0. Use {@link MessagesApi#setLang(Result, Lang)}. */ @Deprecated public boolean changeLang(Lang lang) { if (langs().availables().contains(lang)) { this.lang = lang; scala.Option<String> domain = sessionDomain(); Cookie langCookie = new Cookie(messagesApi().langCookieName(), lang.code(), null, sessionPath(), domain.isDefined() ? domain.get() : null, messagesApi().langCookieSecure(), messagesApi().langCookieHttpOnly(), messagesApi().langCookieSameSite().orElse(null) ); response.setCookie(langCookie); return true; } else { return false; } }
/** * 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. * * @deprecated Deprecated as of 2.7.0. Use {@link MessagesApi#setLang(Result, Lang)}. */ @Deprecated public boolean changeLang(Lang lang) { if (langs().availables().contains(lang)) { this.lang = lang; scala.Option<String> domain = sessionDomain(); Cookie langCookie = new Cookie(messagesApi().langCookieName(), lang.code(), null, sessionPath(), domain.isDefined() ? domain.get() : null, messagesApi().langCookieSecure(), messagesApi().langCookieHttpOnly(), messagesApi().langCookieSameSite().orElse(null) ); response.setCookie(langCookie); return true; } else { return false; } }
private static List<Locale> requestAcceptedLanguages(final Http.Context context, final ProjectContext projectContext) { return context.request().acceptLanguages().stream() .map(lang -> Locale.forLanguageTag(lang.code())) .filter(projectContext::isLocaleSupported) .collect(toList()); }