
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