|
Play Framework/Scala example source code file (MessagesSpec.scala)
The MessagesSpec.scala Play Framework example source code/* * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> */ package play.it.i18n import play.api.test.{PlaySpecification, WithApplication, FakeApplication} import play.api.mvc.Controller import play.api.i18n._ import play.api.Mode object MessagesSpec extends PlaySpecification with Controller { "Messages" should { val app = FakeApplication() "provide default messages" in new WithApplication(app) { val msg = Messages("constraint.email")(Lang("en-US")) msg must ===("Email") } "permit default override" in new WithApplication(app) { val msg = Messages("constraint.required")(Lang("en-US")) msg must ===("Required!") } } "Messages@Java" should{ import play.i18n._ import java.util val app = FakeApplication() val enUS: Lang = new play.i18n.Lang(play.api.i18n.Lang("en-US")) "allow translation without parameters" in new WithApplication(app) { val msg = Messages.get(enUS, "constraint.email") msg must ===("Email") } "allow translation with any non-list parameter" in new WithApplication(app) { val msg = Messages.get(enUS, "constraint.min", "Croissant") msg must ===("Minimum value: Croissant") } "allow translation with any list parameter" in new WithApplication(app) { val msg = { val list: util.ArrayList[String] = new util.ArrayList[String]() list.add("Croissant") Messages.get(enUS, "constraint.min", list) } msg must ===("Minimum value: Croissant") } } } Other Play Framework source code examplesHere is a short list of links related to this Play Framework MessagesSpec.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.