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

Helgi Kristvin Sigurbjarnarson helgikrs at gmail.com
Tue Feb 22 04:27:10 CET 2011


On Mon, Feb 21, 2011 at 09:20:29AM +0200, Michael Snoyman wrote:
> Let's look at a more concrete example: you have an online store
> selling male dogs and female cats. So you would have:
> 
>     data Basket = Basket { maleDogs :: Int, femaleCats :: Int }
> 
> What you need is a function such as:
> 
>     renderBasket :: Basket -> String
> 
> for each language. In English, this could be something like:
> 
>     pluralize :: Int -> (String, String) -> String
>     pluralize 1 (x, _) = x
>     pluralize _ (_, x) = x
> 
>     renderBasket (Basket dogs cats) = concat
>         [ "You have decided to purchase "
>         , show dogs
>         , pluralize dogs ("dog", "dogs")
>         , " and "
>         , show cats
>         , pluralize cats ("cat", "cats")
>         ]

How would you handle declensions and conjugations? Create a new datatype
for every context? For (a silly) example the online store
list nicely what's in your basket in a sidebar like so:

In your cart:
 * 3 dogs

and later, after you purchased they can say "You just bought 3 dogs",
now, in english the "3 dogs" translation can be shared, but in some languages
(e.g. Icelandic) they can not ("3 hundar" and "þú varst að kaupa 3 hunda").
The former is nominative and the latter is dative. But then again,
creating a datatype and translating the same words again and again is
really repetative.

-- 
Helgi Kristvin Sigurbjarnarson <helgikrs (at) gmail (dot) com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110222/1ba96061/attachment.pgp>


More information about the web-devel mailing list