【问题标题】:Play Framework 2.4.0 with I18n: two languages in the same page使用 I18n 播放 Framework 2.4.0:同一页面中的两种语言
【发布时间】:2015-06-16 18:12:40
【问题描述】:

如何在同一页面中将 Messages("home.title") 与 IT 和 EN 一起使用? 在依赖注入之前我做了:

Messages("home.title")(Lang("IT")) 
Messages("home.title")(Lang("EN"))

但现在不行了。

【问题讨论】:

    标签: scala internationalization playframework-2.4


    【解决方案1】:

    如果你的控制器看起来像这样

    class MyController extends Controller { def doSomething = Action {...} }
    

    不是这样的

    class MyController (val messagesApi: MessagesApi) extends Controller with I18nSupport { def doSomething = Action {...} }
    

    那么您可以在模板中使用以下方法:

    @import play.i18n._
    <html>
        ...
        <h1>@Messages.get(Lang.forCode("IT"), "home.title")</h1>
        ...
        <h1>@Messages.get(Lang.forCode("EN"), "home.title")</h1>
        ...
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-27
      • 2012-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多