jsmessages

JsMessages

Related Doc: package jsmessages

class JsMessages extends AnyRef

Generate a JavaScript function computing localized messages of a Play application.

Typical usage (from within a Play controller):

val jsMessages: JsMessages = ???

val messages = Action { implicit request =>
  Ok(jsMessages(Some("window.Messages")))
}

Then on client-side:

console.log(Messages("greeting", "Julien")); // prints "Hello, Julien!"

See JsMessagesFactory to know how to get a JsMessages instance.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. JsMessages
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new JsMessages(allMessagesData: Map[String, Map[String, String]])

    allMessagesData

    All the messages of the application, as a map of (lang -> map(key -> message pattern)). As it is the case in Play, JsMessages assumes that “default” messages are indexed by the "default" and "default.play" language codes.

Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  4. def all(namespace: Option[String] = None): JavaScript

    Generates a JavaScript function computing localized messages in all the languages of the application.

    Generates a JavaScript function computing localized messages in all the languages of the application.

    For example:

    val messages = Action {
      Ok(jsMessages.all(Some("window.Messages")))
    }

    Then use it in your JavaScript code as follows:

    alert(Messages('en', 'greeting', 'World'));

    Provided you have the following message in your conf/messages file:

    greeting=Hello {0}!

    Note that, given a message key, the JavaScript function will search the corresponding message in the following locations, in order: the language (e.g. in the conf/messages.fr-FR file), the language country (e.g. conf/messages.fr), the application default messages (conf/messages) and the Play default messages.

    Note: This implementation does not handle quotes escaping in patterns and subformats (see http://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html)

    namespace

    Optional JavaScript namespace to use to put the function definition. If not set, this function will just generate a function. Otherwise it will generate a function and assign it to the given namespace. Note: you can set something like Some("var Messages") to use a fresh variable.

  5. lazy val allMessages: Map[String, Map[String, String]]

    Messages for each available lang of the application.

    Messages for each available lang of the application.

    The message corresponding to a given key is found by searching in the following locations, in order: the language (e.g. in the conf/messages.fr-FR file), the language country (e.g. conf/messages.fr), the application default messages (conf/messages) and the Play default messages.

  6. final val allMessagesJson: JsValue

    Same as allMessages, but as a JSON value.

  7. def apply(namespace: Option[String] = None)(implicit messages: Messages): JavaScript

    Generates a JavaScript function computing localized messages in the given implicit Lang.

    Generates a JavaScript function computing localized messages in the given implicit Lang.

    For example:

    val messages = Action { implicit request =>
      Ok(jsMessages(Some("window.Messages")))
    }

    Then use it in your JavaScript code as follows:

    alert(Messages('greeting', 'World'));

    Provided you have the following message in your conf/messages file:

    greeting=Hello {0}!

    Note: This implementation does not handle quotes escaping in patterns and subformats (see http://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html)

    namespace

    Optional JavaScript namespace to use to put the function definition. If not set, this function will just generate a function. Otherwise it will generate a function and assign it to the given namespace. Note: you can set something like Some("var Messages") to use a fresh variable.

    messages

    Messages instance defining the language to use. The message corresponding to a given key is found by searching in the following locations, in order: the language (e.g. in the conf/messages.fr-FR file), the language country (e.g. conf/messages.fr), the application default messages (conf/messages) and the Play default messages.

  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  16. def messages(implicit messages: Messages): Map[String, String]

    messages

    Messages instance containing the lang to retrieve messages for

    returns

    The messages defined for the given language lang, as a map of (key -> message). The message corresponding to a given key is found by searching in the following locations, in order: the language (e.g. in the conf/messages.fr-FR file), the language country (e.g. conf/messages.fr), the application default messages (conf/messages) and the Play default messages.

  17. def messagesString(implicit messages: Messages): String

    messages

    Messages instance containing the lang to retrieve messages for

    returns

    The JSON formatted string of the for the given language lang. This is strictly equivalent to Json.toJson(jsMessages.messages).toString, but may be faster due to the use of caching.

  18. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  19. final def notify(): Unit

    Definition Classes
    AnyRef
  20. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  21. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  22. def toString(): String

    Definition Classes
    AnyRef → Any
  23. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped