[web-devel] [Yesod] rendering different templates for different languages
Dmitry Kurochkin
dmitry.kurochkin at gmail.com
Wed Feb 23 12:05:15 CET 2011
On Mon, 21 Feb 2011 12:16:23 +0800, Max Cantor <mxcantor at gmail.com> wrote:
> This isn't pretty, cut you could do something like:
>
> getRootR = do
> currentLanguage <- getCurrentLanguage
> defaultLayout $ do
> let widget "EN" = $(widgetFile $ "en/homepage")
> widget "ES" = $(widgetFile $ "es/homepage")
> widget "JP" = $(widgetFile $ "jp/homepage")
> ...
> addWidget (widget currentLanguage)
>
> might be able to do some TH to clean it up. it requires hard coding your languages, but might be a quick little hack to get it working..
>
Thanks Max. Not the most elegant solution, but seems the best option in
my case. These templates are basically static HTML-formatted text, so I
do not want to translate individual strings, but rather the whole text.
Though, I created a small set of helpers to do some basic string
translation for other places. Would be nice to have a full-featured
localization support in Yesod.
Regards,
Dmitry
> max
>
>
> On Feb 21, 2011, at 5:19 AM, Dmitry Kurochkin wrote:
>
> > 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
> >
> > _______________________________________________
> > web-devel mailing list
> > web-devel at haskell.org
> > http://www.haskell.org/mailman/listinfo/web-devel
>
More information about the web-devel
mailing list