First of all, I didn't try solving your problem and am just going to
state what I remember from my experience creating my current
defaultLayout.
I remember that the type of widgetToPageContent is restrictive in the
sense that you can't do exactly what you want. AFAIR, the easiest
workaround is to use
mr <- getMessageRender
and instead of _{MsgApplicationName}, use #{mr MsgApplicationName}.
That'll allow you to avoid the "i" version.
HTH,
On Thu, Jun 6, 2013 at 4:55 PM, G. Ralph Kuntz, MD <
grku...@gmail.com> wrote:
> Crosspost from StackOverFlow (no answers):
>
> I am trying to convert the tutorial code in Chapter 2 of the forthcoming
> "Play for Scala" book from Scala to Haskell (using Yesod). I am getting an
> error trying to "internationalize" my `defaultLayout`. I am (purposely) not
> using a scaffolded Yesod site because I am trying to understand the
> internals. Here is my code:
>
> {-# 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
>
> The error I get trying to build or run it with `runhaskell` is
>
> 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;
> .... }
>
> The error occurs on the `ihamlet` code.
>
> I believe that `headTags` is a `HtmlUrl`. I also think I need to convert
> that to a `HtmlUrlI18n`, but can't figure out how.
>
> Can I do the same thing (define `defaultLayout`) as a widget (using
> `whamlet`) then convert it to a `PageContent` using `widgetToPageContent`,
> then to a `RepHtml` (not sure how), instead of using `ihamlet`? Will that
> solve the i18n problem?
>
> I have tried Googling for a couple of hours but cannot find any extensive
> examples that create a new `defaultLayout` with i18n.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Yesod Web Framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
yesodweb+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>
--
Felipe.