2013-03-08 54 views
1

我已經通過文件讀取設置明確的語言:http://www.playframework.com/documentation/2.1.0/ScalaI18N 和這個職位: i18n error: controller and templates uses different implicit languages ,它看起來簡單,從請求頭隱式設置的語言,如果有一個隱式請求。在我的應用程序中,我需要根據某種邏輯(不依賴請求頭中的語言)在所有模板中設置語言。有沒有辦法做到這一點?斯卡拉發揮國際化:如何在所有模板

回答

2

是的,您需要在您的視圖中添加一個額外的隱含參數是這樣的:

@(form:Form[_])(implicit lang:play.api.i18n.Lang) 

然後在你的控制器中添加這樣一行:

// this retrieves the language from the configuration, 
// replace it with your own logic 
implicit val defaultLang = Lang.availables.headOption.getOrElse(Lang.defaultLang) 
+0

你可以省略形式只需要這樣做:'@()(implicit lang:play.api.i18n.Lang)',表單只是一個例子 – EECOLOR 2013-03-08 23:20:33