如何设置播放以从自定义目录中读取消息文件? [英] How to set up Play to read message files from a custom directory?
问题描述
在build.scala
中,我更改了消息文件的路径,如下所示:
In build.scala
, I've changed the path of message files as follows:
val main = play.Project(appName, appVersion, appDependencies).settings(
lessEntryPoints <<= baseDirectory(_ / "app" / "assets" / "stylesheets" ** "main.less"),
resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository",
resolvers += "maven2 repository" at "http://repo1.maven.org/maven2/",
unmanagedBase <<= baseDirectory(_ / ".." / "messagesFiles")
)
messagesFiles
文件夹包含messages
和messages.fr
文件.
在应用程序启动时,未显示翻译的文本.为什么?
At application startup a translated text is not showing up. Why?
如何设置播放应用程序以读取位于conf
文件夹之外的自定义位置的消息文件?
How to set up a play application to read the messages files present in a custom location apart from conf
folder?
推荐答案
您尚未描述播放版本的环境,因此,我假设您使用的是最新版本的Play 2.2.2-RC1
.我的是...
You haven't described your environment regarding play version so let me assume you use the recent version Play 2.2.2-RC1
. Mine is...
[myFirstApp] $ show playVersion
[info] 2.2.2-RC1
鉴于播放版本,在大多数情况下,您可以使用build.sbt
配置项目.如果您的项目中没有它,请创建一个.
Given the play version, you can configure the project using build.sbt
in most cases. Create one if you don't have it in your project.
将以下行添加到build.sbt
,以指向特定于语言的消息文件所在的自定义目录.
Add the following line to build.sbt
to point at the custom directory where language-specific message files are.
unmanagedResourceDirectories in Compile += baseDirectory.value / "messagesFiles"
我不确定是否最好使用此方法来指定messages目录,但是鉴于sbt的工作原理,它可以解决问题.
I'm unsure whether it is the most recommended approach to specify the messages directory, but given how sbt works it does the trick.
您可以show
unmanagedResourceDirectories
设置的值,如下所示:
You can show
the value of the unmanagedResourceDirectories
setting as follows:
[myFirstApp] $ show unmanagedResourceDirectories
[info] List(/Users/jacek/sandbox/play-ground/myFirstApp/conf, /Users/jacek/sandbox/play-ground/myFirstApp/messagesFiles)
以上输出采用build.sbt
中的上述设置.
The above output assumes the above setting in build.sbt
.
在Play的早期版本(以及SBT)中,project/Build.scala
中的以下内容可以解决问题:
In the previous versions of Play (and hence SBT) the following in project/Build.scala
could do the trick:
unmanagedResourceDirectories in Compile <+= baseDirectory(_ / ".." / "messagesFiles" )
这篇关于如何设置播放以从自定义目录中读取消息文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!