Package play.i18n
Class MessagesApi
java.lang.Object
play.i18n.MessagesApi
The messages API.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionplay.api.i18n.MessagesApiasScala()Given a Result, return a new Result with the lang cookie discarded.Translates a message.Translates the first defined message.isDefinedAt(play.api.i18n.Lang lang, String key) Check if a message key is defined.booleanWhether the HTTP only attribute of the cookie should be set to true or not.An optional max age in seconds for the language Cookie.Name for the language Cookie.The value of the [[SameSite]] attribute of the cookie.booleanWhether the secure attribute of the cookie is true or not.preferred(Collection<Lang> candidates) Get a messages context appropriate for the given candidates.preferred(Http.RequestHeader request) Get a messages context appropriate for the given request.Given a Result and a Lang, return a new Result with the lang cookie set to the given Lang.
-
Constructor Details
-
MessagesApi
@Inject public MessagesApi(play.api.i18n.MessagesApi messages)
-
-
Method Details
-
asScala
public play.api.i18n.MessagesApi asScala()- Returns:
- the Scala versions of the Messages API.
-
get
Translates a message.Uses `java.text.MessageFormat` internally to format the message.
- Parameters:
lang- the message langkey- the message keyargs- the message arguments- Returns:
- the formatted message or a default rendering if the key wasn't defined
-
get
Translates the first defined message.Uses `java.text.MessageFormat` internally to format the message.
- Parameters:
lang- the message langkeys- the messages keysargs- the message arguments- Returns:
- the formatted message or a default rendering if the key wasn't defined
-
isDefinedAt
Check if a message key is defined.- Parameters:
lang- the message langkey- the message key- Returns:
- a Boolean
-
preferred
Get a messages context appropriate for the given candidates.Will select a language from the candidates, based on the languages available, and fallback to the default language if none of the candidates are available.
- Parameters:
candidates- the candidate languages- Returns:
- the most appropriate Messages instance given the candidate languages
-
preferred
Get a messages context appropriate for the given request.Will select a language from the request, based on the languages available, and fallback to the default language if none of the candidates are available.
- Parameters:
request- the incoming request- Returns:
- the preferred messages context for the request
-
setLang
Given a Result and a Lang, return a new Result with the lang cookie set to the given Lang.- Parameters:
result- the result where the lang will be set.lang- the lang to set on the result- Returns:
- a new result with the lang.
-
clearLang
Given a Result, return a new Result with the lang cookie discarded.- Parameters:
result- the result to clear the lang.- Returns:
- a new result with a cleared lang.
-
langCookieName
Name for the language Cookie. -
langCookieMaxAge
An optional max age in seconds for the language Cookie. -
langCookieSecure
public boolean langCookieSecure()Whether the secure attribute of the cookie is true or not. -
langCookieHttpOnly
public boolean langCookieHttpOnly()Whether the HTTP only attribute of the cookie should be set to true or not. -
langCookieSameSite
The value of the [[SameSite]] attribute of the cookie. If None, then no SameSite attribute is set.
-