Conf/Messages 游戏中的选择! + 斯卡拉

Conf/Messages Choice in Play! + Scala

我运行play 2.2中的示例代码"comuputer-database-jpa"

Conf/Messages

# Messages

computers.list.title={0,choice,0#No computers|1#One computer|1<{0,number,integer} computers} found

我想在我的错误消息中使用这个条件消息来使我的错误消息尽可能动态。在我的代码中,我传递了 2 个参数,其中 1 个是消息 ID。

@Messages(messageId,errors(1).getOrElse(""),errors(2).getOrElse(""))

相当于

@Messages(error.format,FIRST NAME)

也可以

@Messages(error.format,EMAIL)

如何在我的代码中使用条件 conf/messages?我尝试了一些使用样本的方法,但发生了错误。 代码:

error.format = Enter {0,choice,FIRST NAME#{0} in half-width alphanumeric|EMAIL#{0} in valid format.}

我做错了什么?

下面的代码将产生您正在寻找的东西

//html<br/>
@Messages("error.format",2, "name error","email error")
上例中的

号码2将显示消息"EMAIL in valid format"。如果将其更改为 1 它将显示消息 "FIRST NAME in half-width alphanumeric"

//messages<br/>
error.format = Enter {0,choice,1#FIRST NAME in half-width alphanumeric|2#EMAIL in valid format.}