diff options
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/Controller/SignIn.hs | 8 | ||||
-rw-r--r-- | src/server/Model/Json/MessagePart.hs | 18 | ||||
-rw-r--r-- | src/server/Model/Json/Translation.hs | 4 | ||||
-rw-r--r-- | src/server/Model/Message.hs | 5 | ||||
-rw-r--r-- | src/server/Model/Message/Key.hs | 12 | ||||
-rw-r--r-- | src/server/Model/Message/Parts.hs | 23 | ||||
-rw-r--r-- | src/server/Model/Message/Translations.hs | 25 |
7 files changed, 75 insertions, 20 deletions
diff --git a/src/server/Controller/SignIn.hs b/src/server/Controller/SignIn.hs index 1110c72..263e470 100644 --- a/src/server/Controller/SignIn.hs +++ b/src/server/Controller/SignIn.hs @@ -31,6 +31,8 @@ import Model.Database import Model.User import Model.SignIn import Model.Json.Message +import Model.Message.Key +import Model.Message (getMessage) import qualified View.Mail.SignIn as SignIn @@ -48,11 +50,11 @@ signInAction config login = Right _ -> status ok200 Left _ -> - errorResponse "Sorry, we failed to send you the sign up email." + errorResponse (getMessage SendEmailFail) Nothing -> - errorResponse "You are not authorized to sign in." + errorResponse (getMessage Unauthorized) else - errorResponse "Please enter a valid email address." + errorResponse (getMessage EnterValidEmail) errorResponse :: Text -> ActionM () errorResponse msg = do diff --git a/src/server/Model/Json/MessagePart.hs b/src/server/Model/Json/MessagePart.hs new file mode 100644 index 0000000..0753d7c --- /dev/null +++ b/src/server/Model/Json/MessagePart.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE DeriveGeneric #-} + +module Model.Json.MessagePart + ( MessagePart(..) + ) where + +import Data.Text (Text) + +import Data.Aeson +import GHC.Generics + +data MessagePart = + Order Int + | Str Text + deriving (Eq, Show, Generic) + +instance FromJSON MessagePart +instance ToJSON MessagePart diff --git a/src/server/Model/Json/Translation.hs b/src/server/Model/Json/Translation.hs index 7291157..9dcfe80 100644 --- a/src/server/Model/Json/Translation.hs +++ b/src/server/Model/Json/Translation.hs @@ -9,9 +9,11 @@ import GHC.Generics import Data.Aeson import Data.Text +import Model.Json.MessagePart + data Translation = Translation { key :: Text - , message :: Text + , message :: [MessagePart] } deriving (Show, Generic) instance FromJSON Translation diff --git a/src/server/Model/Message.hs b/src/server/Model/Message.hs index 8475740..12893b8 100644 --- a/src/server/Model/Message.hs +++ b/src/server/Model/Message.hs @@ -19,11 +19,10 @@ getMessage :: Key -> Text getMessage = getVarMessage [] getVarMessage :: [Text] -> Key -> Text -getVarMessage values key = - replaceParts values (getParts (getNonFormattedMessage lang key)) +getVarMessage values key = replaceParts values (getNonFormattedMessage lang key) getTranslations :: Translations getTranslations = Translations (map getTranslation [minBound..]) getTranslation :: Key -> Translation -getTranslation key = Translation (T.pack . show $ key) (getNonFormattedMessage lang key) +getTranslation key = Translation (T.pack . show $ key) (getParts $ getNonFormattedMessage lang key) diff --git a/src/server/Model/Message/Key.hs b/src/server/Model/Message/Key.hs index 59a5dbc..e1a382c 100644 --- a/src/server/Model/Message/Key.hs +++ b/src/server/Model/Message/Key.hs @@ -4,7 +4,17 @@ module Model.Message.Key data Key = - January + -- Sign in + + SharedCost + | SignIn + | SendEmailFail + | Unauthorized + | EnterValidEmail + + -- Dates + + | January | February | March | April diff --git a/src/server/Model/Message/Parts.hs b/src/server/Model/Message/Parts.hs index b7855f8..d065cf2 100644 --- a/src/server/Model/Message/Parts.hs +++ b/src/server/Model/Message/Parts.hs @@ -11,28 +11,27 @@ import qualified Data.Text as T import Text.ParserCombinators.Parsec -replaceParts :: [Text] -> [Part] -> Text -replaceParts values = T.concat . map (replacePart values) +import Model.Json.MessagePart -replacePart :: [Text] -> Part -> Text +replaceParts :: [Text] -> Text -> Text +replaceParts values message = + T.concat . map (replacePart values) $ getParts message + +replacePart :: [Text] -> MessagePart -> Text replacePart _ (Str str) = str -replacePart values (Num n) = +replacePart values (Order n) = fromMaybe (T.concat ["{", T.pack (show n), "}"]) . listToMaybe . drop (n - 1) $ values -data Part = - Num Int - | Str Text - -getParts :: Text -> [Part] +getParts :: Text -> [MessagePart] getParts str = case parse partsParser "" (T.unpack str) of Right parts -> parts Left _ -> [] -partsParser :: Parser [Part] +partsParser :: Parser [MessagePart] partsParser = many partParser -partParser :: Parser Part +partParser :: Parser MessagePart partParser = - (do _ <- string "{"; n <- read <$> many1 digit; _ <- string "}"; return (Num n)) + (do _ <- string "{"; n <- read <$> many1 digit; _ <- string "}"; return (Order n)) <|> (do str <- T.pack <$> many1 (noneOf "{"); return (Str str)) diff --git a/src/server/Model/Message/Translations.hs b/src/server/Model/Message/Translations.hs index 289b714..2cc1761 100644 --- a/src/server/Model/Message/Translations.hs +++ b/src/server/Model/Message/Translations.hs @@ -14,6 +14,31 @@ getNonFormattedMessage = m m :: Lang -> Key -> Text +m l SharedCost = + case l of + English -> "Shared Cost" + French -> "Partage des frais" + +m l SignIn = + case l of + English -> "Sign in" + French -> "Connexion" + +m l SendEmailFail = + case l of + English -> "Sorry, we failed to send you the sign up email." + French -> "Désolé, nous n'avons pas pu vous envoyer le courriel de connexion." + +m l Unauthorized = + case l of + English -> "You are not authorized to sign in." + French -> "Vous n'êtes pas authorisé à vous connecter." + +m l EnterValidEmail = + case l of + English -> "Please enter a valid email address." + French -> "Entrez s'il vous plait un email valide." + m l January = case l of English -> "January" |