
I'm playing with yesod http://docs.yesodweb.com/yesod/, and I have a few questions: Here's an excerpt from yesod/tutorial/i18n.lhs **NOTE: This tutorial requires the development version of Yesod (version 0.4.0). The [tutorial main page]($root/yesod/tutorial/) has instructions on setting up your environment.** Where is $root? I thought it was where yesod-examples-0.4.0 was installed. But if this is the case, I'm not finding these instructions. This makes me think I am confused about the directory $root represents. I was playing around with the code and made some changes. Here is the line in question, with the complete code below for context.
instance Yesod I18N where approot _ = ""
This does what I expect it to do, it runs the program when I open up http://my.blog.server/ however, I wanted to see what would happen if I played around with it a little bit. I want the same program to run when I point my browser to http://my.blog.server/blog so I made this change
approot _ = "/blog"
but now when I point my browser to http://my.blog.server/blog it gets re-written to http:/my.blog.server/blog/blog and then this error message Not Found /blog/blog Not sure what is going on here, could someone enlighten me? --- title: Multi-lingual -- Tutorials -- Yesod --- **NOTE: This tutorial requires the development version of Yesod (version 0.4.0). The [tutorial main page]($root/yesod/tutorial/) has instructions on setting up your environment.**
{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-}
import Yesod import Data.Monoid (mempty)
data I18N = I18N
mkYesod "I18N" [$parseRoutes| / HomepageR GET /set/#String SetLangR GET |]
instance Yesod I18N where approot _ = "/blog"
getHomepageR :: Handler I18N RepHtml getHomepageR = do ls <- languages let hello = chooseHello ls let choices = [ ("en", "English") , ("es", "Spanish") , ("he", "Hebrew") ] applyLayout "I18N Homepage" mempty [$hamlet| %h1 $hello$ %p In other languages: %ul $forall choices choice %li %a!href=@SetLangR.fst.choice@ $snd.choice$ |]
chooseHello :: [String] -> String chooseHello [] = "Hello" chooseHello ("he":_) = "ש×~\×~U×~]" chooseHello ("es":_) = "Hola" chooseHello (_:rest) = chooseHello rest
getSetLangR :: String -> Handler I18N () getSetLangR lang = do setLanguage lang redirect RedirectTemporary HomepageR
main :: IO () main = basicHandler 3000 I18N