【发布时间】:2013-06-02 17:49:18
【问题描述】:
我正在尝试将即将出版的“Play for Scala”一书的第 2 章中的教程代码从 Scala 转换为 Haskell(使用 Yesod)。我在尝试“国际化”我的 defaultLayout 时遇到错误。我(故意)不使用脚手架 Yesod 站点,因为我试图了解内部结构。这是我的代码:
{-# LANGUAGE FlexibleInstances
, MultiParamTypeClasses
, OverloadedStrings
, QuasiQuotes
, TemplateHaskell
, TypeFamilies #-}
module Main where
import Text.Hamlet (ihamlet)
import Yesod
import Yesod.Static
staticFiles "static"
data PlayTutorial = PlayTutorial
{ getStatic :: Static
}
mkMessage "PlayTutorial" "messages" "en"
mkYesod "PlayTutorial" [parseRoutes|
/ RootR GET
/static StaticR Static getStatic
|]
instance Yesod PlayTutorial where
defaultLayout contents = do
PageContent title headTags bodyTags <- widgetToPageContent $ do
addStylesheet $ StaticR stylesheets_bootstrap_css
addStylesheet $ StaticR stylesheets_main_css
contents
ihamletToRepHtml [ihamlet|
$doctype 5
<html>
<head>
<title>#{title}
^{headTags}
<body>
<div ."screenshot">
<div ."navbar navbar-fixed-top">
<div ."container">
<a ."brand" href=@{RootR}>
_{MsgApplicationName}
<div ."container">
^{bodyTags}
|]
getRootR :: Handler RepHtml
getRootR = defaultLayout [whamlet|Hello, World!|]
main :: IO ()
main = do
static@(Static settings) <- static "static"
warp 8080 $ PlayTutorial static
我尝试使用runhaskell 构建或运行它的错误是
src/Main.hs:34:31:
Couldn't match type `Text.Blaze.Internal.MarkupM ()'
with `[(Data.Text.Internal.Text, Data.Text.Internal.Text)]
-> Data.Text.Internal.Text'
Expected type: Text.Hamlet.Render (Route PlayTutorial)
Actual type: Text.Hamlet.Translate (Route PlayTutorial)
In the first argument of `headTags', namely `_mrender_a7j2'
In a stmt of a 'do' block: headTags _mrender_a7j2 _urender_a7j1
In the expression:
do { id
((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
"<!DOCTYPE html>\
\<html><head><title>");
id (toHtml title);
id
((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "</title>");
headTags _mrender_a7j2 _urender_a7j1;
.... }
ihamlet 代码出现错误。
我相信headTags 是HtmlUrl。我还认为我需要将其转换为 HtmlUrlI18n,但不知道如何。
我可以做同样的事情(定义defaultLayout)作为一个小部件(使用whamlet)然后使用widgetToPageContent将其转换为PageContent,然后转换为RepHtml(不确定如何),而不是使用ihamlet?这会解决 i18n 问题吗?
我已经用谷歌搜索了几个小时,但找不到任何使用 i18n 创建新 defaultLayout 的广泛示例。
【问题讨论】:
标签: haskell internationalization yesod