From f8c5ce08352950f4e74f3c51aa16ef366a9de9c7 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Wed, 12 Aug 2015 11:37:29 +0200 Subject: Translating payment screen except dates --- src/client/Model/View/Payment/Add.elm | 16 +++++++++------- src/client/View/Page.elm | 2 +- src/client/View/Payments.elm | 7 ++++--- src/client/View/Payments/Add.elm | 10 ++++++---- src/server/Model/Message/Key.hs | 10 ++++++++++ src/server/Model/Message/Translations.hs | 24 ++++++++++++++++++++++++ 6 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/client/Model/View/Payment/Add.elm b/src/client/Model/View/Payment/Add.elm index 4665180..5428c3d 100644 --- a/src/client/Model/View/Payment/Add.elm +++ b/src/client/Model/View/Payment/Add.elm @@ -9,6 +9,8 @@ import Result as Result exposing (Result(..)) import Utils.Validation exposing (..) +import Model.Translations exposing (..) + type alias AddPayment = { name : String , nameError : Maybe String @@ -24,13 +26,13 @@ initAddPayment = , costError = Nothing } -validateName : String -> Result String String -validateName name = +validateName : String -> Translations -> Result String String +validateName name translations = name - |> validateNonEmpty "The category is required." + |> validateNonEmpty (getMessage "CategoryRequired" translations) -validateCost : String -> Result String Int -validateCost cost = +validateCost : String -> Translations -> Result String Int +validateCost cost translations = cost - |> validateNonEmpty "The cost is required." - |> flip Result.andThen (validateNumber "The cost must be a number.") + |> validateNonEmpty (getMessage "CostRequired" translations) + |> flip Result.andThen (validateNumber (getMessage "CostMustBeNumber" translations)) diff --git a/src/client/View/Page.elm b/src/client/View/Page.elm index f7292ed..7015317 100644 --- a/src/client/View/Page.elm +++ b/src/client/View/Page.elm @@ -28,4 +28,4 @@ renderMain model = SignInView signInView -> renderSignIn model signInView PaymentView paymentsView -> - renderPayments paymentsView + renderPayments model paymentsView diff --git a/src/client/View/Payments.elm b/src/client/View/Payments.elm index 7f0c66b..ba930b5 100644 --- a/src/client/View/Payments.elm +++ b/src/client/View/Payments.elm @@ -5,16 +5,17 @@ module View.Payments import Html exposing (..) import Html.Attributes exposing (..) +import Model exposing (Model) import Model.Payment exposing (Payments) import Model.View.PaymentView exposing (PaymentView) import View.Payments.Add exposing (addPayment) import View.Payments.Table exposing (paymentsTable) -renderPayments : PaymentView -> Html -renderPayments paymentView = +renderPayments : Model -> PaymentView -> Html +renderPayments model paymentView = div [ class "payments" ] - [ addPayment paymentView.add + [ addPayment model paymentView.add , paymentsTable paymentView.payments ] diff --git a/src/client/View/Payments/Add.elm b/src/client/View/Payments/Add.elm index d1431b8..3aa44c8 100644 --- a/src/client/View/Payments/Add.elm +++ b/src/client/View/Payments/Add.elm @@ -14,7 +14,9 @@ import Update exposing (..) import Update.Payment exposing (..) import Update.Payment.Add exposing (..) +import Model exposing (Model) import Model.View.Payment.Add exposing (..) +import Model.Translations exposing (getMessage) import View.Events exposing (onSubmitPrevDefault) import View.Icon exposing (renderIcon) @@ -22,11 +24,11 @@ import View.Icon exposing (renderIcon) import Utils.Maybe exposing (isJust) import Utils.Either exposing (toMaybeError) -addPayment : AddPayment -> Html -addPayment addPayment = +addPayment : Model -> AddPayment -> Html +addPayment model addPayment = H.form [ class "add" - , case (validateName addPayment.name, validateCost addPayment.cost) of + , case (validateName addPayment.name model.translations, validateCost addPayment.cost model.translations) of (Ok name, Ok cost) -> onSubmitPrevDefault serverCommunications.address (SC.AddPayment name cost) (resName, resCost) -> @@ -69,6 +71,6 @@ addPayment addPayment = text "" , button [ type' "submit" ] - [ text "Add" ] + [ text (getMessage "Add" model.translations)] ] ] diff --git a/src/server/Model/Message/Key.hs b/src/server/Model/Message/Key.hs index 50486be..9b5c69e 100644 --- a/src/server/Model/Message/Key.hs +++ b/src/server/Model/Message/Key.hs @@ -40,4 +40,14 @@ data Key = | Date + -- Validation + + | CategoryRequired + | CostRequired + | CostMustBeNumber + + -- Payments + + | Add + deriving (Enum, Bounded, Show) diff --git a/src/server/Model/Message/Translations.hs b/src/server/Model/Message/Translations.hs index d680e6e..5a626ed 100644 --- a/src/server/Model/Message/Translations.hs +++ b/src/server/Model/Message/Translations.hs @@ -160,3 +160,27 @@ m l Date = case l of English -> "{2} {1}, {3}" French -> "{1} {2} {3}" + +-- Validation + +m l CategoryRequired = + case l of + English -> "The category is required." + French -> "La catégorie est requise." + +m l CostRequired = + case l of + English -> "The cost is required." + French -> "Le coût est requis." + +m l CostMustBeNumber = + case l of + English -> "The cost must be a number." + French -> "Le coût doit être un nombre." + +-- Payments + +m l Add = + case l of + English -> "Add" + French -> "Ajouter" -- cgit v1.2.3