1

Play2 中的内部化可以通过Message.get("home.title")语言文件来完成。当您将一个充满文本内容的页面内化而不仅仅是一个特定的标题或链接时会怎样?

例如,为表示产品信息的长页面执行Messagefile :

_First header_ 
Some paragraphs of text
...
_Tenth header_
Tenth paragraph and more text*

消息文件

一种)
product.info = "<many paragraphs of text including headers>"

将一页拆分为 html 元素

b)

   product.info.h1 = "<first header>"
   product.info.p1 = "<first para>"
   product.info.p2 = "<2nd para>"

对我来说,这两种解决方案听起来都不对。首先,单个键具有巨大的价值似乎是不好的约定,而后者将单个页面分成数十个键听起来也不好。

大型网站通常遵循在 URL中包含语言惯例www.site.com/en-us/product/1。所以问题是,我如何以这种方式做,并且以这种方式做的更好吗?我不仅可以很容易地翻译成十几种语言,而且还可以进行几十次布局更改。

我可以使用使用Messagefile的全局代码片段来处理具有少量文本且不经常更改的元素,例如导航/view/global/header/somenavbar.scala.html,但最终我只有一个复杂的文件夹结构。

另一种方式,一种最佳实践,在 Play 2 中用于内部化而不是消息文件?

4

1 回答 1

1

在play_authenticate Java 示例中查看 Joscha Feth 的解决方案。

有 3 种语言的电子邮件模板,用于电子邮件确认密码重置等。

每种“类型”电子邮件的模板 && 每种语言都保存在单个文件中,即:

对于每个“类型”,都有一个“父”模板,其中包含一个条件(常见的 Scalamatch 检查模板文档的标签部分),该条件根据检测到的语言返回渲染视图:

Finally, yes, at the beginning I also thought that some kind of madness, but believe me, that technique can be useful. There's field for further improvements I think. Maybe it would be better to move the language conditioning to the controller, hm I think that depends on many factors and it will be great if you'll find a time to investigate this topic.

于 2012-08-24T18:46:32.840 回答