如何在Play2.0框架的build.scala中递归添加消息文件

时间:2014-02-17 05:54:51

标签: scala playframework-2.0

我有路径中每种语言的消息文件:release/linux/mhome/user/config/languages/sv/messages.sv

我还必须在Build.scala中提及每个消息文件的路径,如下所示:

unmanagedResourceDirectories in Compile <+= baseDirectory(_ /  ".." / ".." / ".." / "release" / "linux" / "mhome" / "user" / "config" / "languages" / "zh" ),
unmanagedResourceDirectories in Compile <+= baseDirectory(_ /  ".." / ".." / ".." / "release" / "linux" / "mhome" / "user" / "config" / "languages" / "en" ),
unmanagedResourceDirectories in Compile <+= baseDirectory(_ /  ".." / ".." / ".." / "release" / "linux" / "mhome" / "user" / "config" / "languages" / "fr" ),

但我需要在Build.scala中添加路径直到语言文件夹,并在classpath中递归添加所有消息文件。怎么做到这一点?

1 个答案:

答案 0 :(得分:0)

难题的第一部分是使用&lt; ++ =将多个条目添加到一次性列表的设置键

unmanagedResourceDirectories in Compile <++= baseDirectory { dir => 
  ... something that returns a Seq[File] ...
}

第二部分是sbt PathFinder(http://www.scala-sbt.org/0.13.1/docs/Detailed-Topics/Paths.html),它允许你指定通配符模式来查找文件:

val pathFinder = (".." / "shortened" / "for"/ "brevity" / "languages") ** "*"
val matching: Seq[File] = pathFinder.get    

如果您需要,PathFinder API还允许您进行更高级的过滤。