-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accept arbitrary strings as the language
- Loading branch information
Showing
5 changed files
with
19 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,20 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Language where | ||
module Language where | ||
|
||
import Data.Aeson.Types | ||
import Control.Monad | ||
import Data.Text | ||
import Control.Applicative ((<$>)) | ||
|
||
|
||
data Language = En | De | Fr | ||
newtype Language = Language String | ||
|
||
defaultLanguage :: Language | ||
defaultLanguage = En | ||
defaultLanguage = Language "en" | ||
|
||
ppLang :: Language -> String | ||
ppLang En = "en" | ||
ppLang De = "de" | ||
ppLang Fr = "fr" | ||
ppLang (Language l) = l | ||
|
||
instance ToJSON Language where | ||
toJSON = toJSON . ppLang | ||
|
||
instance FromJSON Language where | ||
parseJSON (String "en") = return En | ||
parseJSON (String "de") = return De | ||
parseJSON (String "fr") = return Fr | ||
parseJSON (String s) = fail $ "Unknown language \"" ++ unpack s ++ "\"." | ||
parseJSON _ = mzero | ||
parseJSON s = Language <$> parseJSON s | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters