[web-devel] [Yesod] rendering different templates for different languages

Dmitry Kurochkin dmitry.kurochkin at gmail.com
Sun Feb 20 22:19:09 CET 2011


Hi all.

I want a handler to render different templates for different languages.
I have getCurrentLanguage function and now I try to do something like:

    getRootR = do
        currentLanguage <- getCurrentLanguage
        defaultLayout $ do
            addWidget $(widgetFile $ currentLanguage ++ "/homepage")

This results in:

    GHC stage restriction: `currentLanguage'
      is used in a top-level splice or annotation,
      and must be imported, not defined locally

This makes sense to me, because TH is calculated at compile time. I
would like to hear ideas how to work around this restriction. Perhaps
there is an existing solution in Yesod?

At the moment, the best I could think of is smth like this:

    getRootR = do
        currentLanguage <- getCurrentLanguage
        defaultLayout $ do
            case currentLanguage of
                "en" -> addWidget $(widgetFile  "en/homepage")
                ... and so on for each language ...

Obviously, this is not a solution taking in account that there are many
languages and many handlers.

I was considering creating a global (template file name -> rendered
template) map. But I am not sure this is really feasible.

Regards,
  Dmitry



More information about the web-devel mailing list