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

Michael Snoyman michael at snoyman.com
Tue Feb 22 06:16:22 CET 2011


On Tue, Feb 22, 2011 at 5:27 AM, Helgi Kristvin Sigurbjarnarson
<helgikrs at gmail.com> wrote:
> 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.

Unfortunately, such is the nature of the beast. People sent some good
links after my i18n blog post, and the recurring theme is you can
*never* translate a fragment of a phrase, only an entire phrase. So
yes, there will be some repetition, but at least we'll be correct.

Personally, I don't have a huge amount of experience with i18n, but in
the one project that I *do* deal with it regularly (the DITA-OT[1]),
this is the approach taken as well.

Michael

[1] http://sourceforge.net/projects/dita-ot/



More information about the web-devel mailing list