/** * Get the message at the given key. * * Uses `java.text.MessageFormat` internally to format the message. * * @param key the message key * @param args the message arguments * @return the formatted message or a default rendering if the key wasn't defined */ public String at(String key, Object... args) { return messages.get(lang, key, args); }
/** * Translates a message. * * Uses `java.text.MessageFormat` internally to format the message. * * @param lang the message lang * @param key the message key * @param args the message arguments * @return the formatted message or a default rendering if the key wasn't defined */ public String get(play.api.i18n.Lang lang, String key, Object... args) { Buffer<Object> scalaArgs = convertArgsToScalaBuffer(args); return messages.apply(key, scalaArgs, lang); }
/** * Check if a message key is defined. * * @param key the message key * @return a Boolean */ public Boolean isDefinedAt(String key) { return messagesApi.isDefinedAt(lang, key); }
/** * @return the messages for the current lang * * @deprecated Deprecated as of 2.7.0. <a href="https://www.playframework.com/documentation/latest/JavaHttpContextMigration27">See migration guide.</a>. */ @Deprecated public Messages messages() { Request request = lang != null ? request().withTransientLang(lang) : request(); return messagesApi().preferred(request); }
/** * 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; } }
/** * Clear the lang for the current user. * * @deprecated Deprecated as of 2.7.0. Use {@link MessagesApi#clearLang(Result)}. */ @Deprecated public void clearLang() { this.lang = null; scala.Option<String> domain = sessionDomain(); response.discardCookie(messagesApi().langCookieName(), sessionPath(), domain.isDefined() ? domain.get() : null, messagesApi().langCookieSecure()); }
/** * Converts the varargs to a scala buffer, * takes care of wrapping varargs into a intermediate list if necessary * * @param args the message arguments * @return scala type for message processing */ private static Buffer<Object> convertArgsToScalaBuffer(final Object... args) { return scala.collection.JavaConverters.asScalaBufferConverter(wrapArgsToListIfNeeded(args)).asScala(); }
@Override public play.api.i18n.Messages asScala() { return new play.api.i18n.MessagesImpl(lang, messagesApi.asScala()); } }
/** * Clears the lang cookie from this result. For example: * * <pre> * {@code * public Result action() { * ok("Hello").withoutLang(messagesApi); * } * } * </pre> * * Where {@code messagesApi} were injected. * * @param messagesApi the messages api implementation * @return a new result without the lang * * @see MessagesApi#clearLang(Result) */ public Result withoutLang(MessagesApi messagesApi) { return messagesApi.clearLang(this); }
/** * @return the messages for the current lang * * @deprecated Deprecated as of 2.7.0. <a href="https://www.playframework.com/documentation/latest/JavaHttpContextMigration27">See migration guide.</a>. */ @Deprecated public Messages messages() { Request request = lang != null ? request().withTransientLang(lang) : request(); return messagesApi().preferred(request); }
/** * 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; } }
/** * Clear the lang for the current user. * * @deprecated Deprecated as of 2.7.0. Use {@link MessagesApi#clearLang(Result)}. */ @Deprecated public void clearLang() { this.lang = null; scala.Option<String> domain = sessionDomain(); response.discardCookie(messagesApi().langCookieName(), sessionPath(), domain.isDefined() ? domain.get() : null, messagesApi().langCookieSecure()); }
/** * Converts the varargs to a scala buffer, * takes care of wrapping varargs into a intermediate list if necessary * * @param args the message arguments * @return scala type for message processing */ private static Seq<Object> convertArgsToScalaBuffer(final Object... args) { return scala.collection.JavaConverters.asScalaBufferConverter(wrapArgsToListIfNeeded(args)).asScala().toList(); }
@Override public play.api.i18n.Messages asScala() { return new play.api.i18n.MessagesImpl(lang, messagesApi.asScala()); } }
/** * Clears the lang cookie from this result. For example: * * <pre> * {@code * public Result action() { * ok("Hello").withoutLang(messagesApi); * } * } * </pre> * * Where {@code messagesApi} were injected. * * @param messagesApi the messages api implementation * @return a new result without the lang * * @see MessagesApi#clearLang(Result) */ public Result withoutLang(MessagesApi messagesApi) { return messagesApi.clearLang(this); }
/** * Get the message at the given key. * * Uses `java.text.MessageFormat` internally to format the message. * * @param key the message key * @param args the message arguments * @return the formatted message or a default rendering if the key wasn't defined */ public String at(String key, Object... args) { return messagesApi.get(lang, key, args); }
/** * @return the messages for the current lang * * @deprecated Deprecated as of 2.7.0. <a href="https://www.playframework.com/documentation/latest/JavaHttpContextMigration27">See migration guide.</a>. */ @Deprecated public Messages messages() { Request request = lang != null ? request().withTransientLang(lang) : request(); return messagesApi().preferred(request); }
/** * 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; } }
/** * Translates a message. * * Uses `java.text.MessageFormat` internally to format the message. * * @param lang the message lang * @param key the message key * @param args the message arguments * @return the formatted message or a default rendering if the key wasn't defined */ public String get(play.api.i18n.Lang lang, String key, Object... args) { Seq<Object> scalaArgs = convertArgsToScalaBuffer(args); return messages.apply(key, scalaArgs, lang); }
/** * Clear the lang for the current user. * * @deprecated Deprecated as of 2.7.0. Use {@link MessagesApi#clearLang(Result)}. */ @Deprecated public void clearLang() { this.lang = null; scala.Option<String> domain = sessionDomain(); response.discardCookie(messagesApi().langCookieName(), sessionPath(), domain.isDefined() ? domain.get() : null, messagesApi().langCookieSecure()); }