| Constructor and Description |
|---|
MessagesImpl(NinjaProperties ninjaProperties,
Lang lang) |
| Modifier and Type | Method and Description |
|---|---|
Optional<String> |
get(String key,
Context context,
Optional<Result> result,
Object... parameter)
Get a translated string.
|
Optional<String> |
get(String key,
Optional<String> language,
Object... params)
Get a translated string.
|
Map<Object,Object> |
getAll(Context context,
Optional<Result> result)
Returns all messages for the default language in that context / result.
|
Map<Object,Object> |
getAll(Optional<String> language) |
String |
getWithDefault(String key,
String defaultMessage,
Context context,
Optional<Result> result,
Object... params)
Gets a message for a message key.
|
String |
getWithDefault(String key,
String defaultMessage,
Optional<String> language,
Object... params)
Gets a message for a message key.
|
@Inject public MessagesImpl(NinjaProperties ninjaProperties, Lang lang)
public Optional<String> get(String key, Context context, Optional<Result> result, Object... parameter)
Messagesget in interface Messageskey - The key used in your message file (conf/messages.properties)context - The context used to determine the language.result - The result used to determine the language.parameter - Parameters to use in formatting the message of the key (in
MessageFormat).public Optional<String> get(String key, Optional<String> language, Object... params)
MessagesMessages#get(String, Context, Result, Object...)get in interface Messageskey - The key used in your message file (conf/messages.properties)language - The language to get. Can be null - then the default language
is returned. It also looks for a fallback. Eg. A request for
"en-US" will fallback to "en" if there is no matching language
file.params - Parameters to use in formatting the message of the key (in
MessageFormat).public Map<Object,Object> getAll(Context context, Optional<Result> result)
Messagespublic Map<Object,Object> getAll(Optional<String> language)
getAll in interface Messageslanguage - The language to get. May be absent - then the default language
is returned. It also looks for a fallback. Eg. A request for
"en-US" will fallback to "en" if there is no matching language
file.
language can also be the complete Accept-Language header: en-US,en;q=0.8,de;q=0.6public String getWithDefault(String key, String defaultMessage, Context context, Optional<Result> result, Object... params)
MessagesgetWithDefault in interface Messageskey - The key used in your message file (conf/messages.properties)defaultMessage - A default message that will be used when no matching message
can be retrieved.context - The context used to determine the language.result - The result used to determine the language. May be absentparams - Parameters to use in formatting the message of the key (in
MessageFormat).public String getWithDefault(String key, String defaultMessage, Optional<String> language, Object... params)
MessagesMessages#getWithDefault(String, Context, Result, Object...)getWithDefault in interface Messageskey - The key used in your message file (conf/messages.properties)defaultMessage - A default message that will be used when no matching message
can be retrieved.language - The language to get. May be absent - then the default language
is returned. It also looks for a fallback. Eg. A request for
"en-US" will fallback to "en" if there is no matching language
file.Copyright © 2019 ninjaframework. All rights reserved.