jsmessages.api

JsMessages

class JsMessages extends AnyRef

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

Typical usage:

import play.api.mvc._
import play.api.Play.current
import jsmessages.api.JsMessages

object Application extends Controller {
  val jsMessages = JsMessages.default

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

Then on client-side:

console.log(Messages("greeting", "Julien")); // prints "Hello, Julien!"
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: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

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

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

    Definition Classes
    Any
  6. 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.

  7. 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.

  8. final val allMessagesJson: JsValue

    Same as allMessages, but as a JSON value.

  9. def apply(namespace: Option[String] = None)(implicit lang: Lang): 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.

    lang

    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.

  10. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  11. def clone(): AnyRef

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

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

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

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

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

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

    Definition Classes
    Any
  18. def messages(implicit lang: Lang): Map[String, String]

    lang

    Language 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.

  19. def messagesString(implicit lang: Lang): String

    lang

    Language 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.

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

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

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

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

    Definition Classes
    AnyRef
  24. def toString(): String

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

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from AnyRef

Inherited from Any

Ungrouped