From d25b857d8317d729995d6aa25db7a83fe92a07ef Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Fri, 14 Aug 2015 09:23:12 +0200 Subject: Translating dates --- src/client/View/Date.elm | 32 ++++++++++++++++++++++++++++++++ src/client/View/Payments.elm | 2 +- src/client/View/Payments/Table.elm | 26 +++++++++++--------------- 3 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 src/client/View/Date.elm (limited to 'src/client') diff --git a/src/client/View/Date.elm b/src/client/View/Date.elm new file mode 100644 index 0000000..c96e99e --- /dev/null +++ b/src/client/View/Date.elm @@ -0,0 +1,32 @@ +module View.Date + ( renderDate + ) where + +import Date exposing (..) + +import Model.Translations exposing (..) + +renderDate : Date -> Translations -> String +renderDate date translations = + let params = + [ toString (Date.day date) + , (getMessage (getMonthKey (Date.month date)) translations) + , toString (Date.year date) + ] + in getVarMessage params "Date" translations + +getMonthKey : Month -> String +getMonthKey month = + case month of + Jan -> "January" + Feb -> "February" + Mar -> "March" + Apr -> "April" + May -> "May" + Jun -> "June" + Jul -> "July" + Aug -> "August" + Sep -> "September" + Oct -> "October" + Nov -> "November" + Dec -> "December" diff --git a/src/client/View/Payments.elm b/src/client/View/Payments.elm index ba930b5..c79b9c5 100644 --- a/src/client/View/Payments.elm +++ b/src/client/View/Payments.elm @@ -17,5 +17,5 @@ renderPayments model paymentView = div [ class "payments" ] [ addPayment model paymentView.add - , paymentsTable paymentView.payments + , paymentsTable model paymentView.payments ] diff --git a/src/client/View/Payments/Table.elm b/src/client/View/Payments/Table.elm index 847c620..e5c1a9a 100644 --- a/src/client/View/Payments/Table.elm +++ b/src/client/View/Payments/Table.elm @@ -10,12 +10,14 @@ import Date exposing (Date) import String exposing (append) +import Model exposing (Model) import Model.Payment exposing (Payments, Payment) import View.Icon exposing (renderIcon) +import View.Date exposing (renderDate) -paymentsTable : Payments -> Html -paymentsTable payments = +paymentsTable : Model -> Payments -> Html +paymentsTable model payments = table [] ([ tr @@ -25,27 +27,21 @@ paymentsTable payments = , th [ class "user" ] [ renderIcon "user" ] , th [ class "date" ] [ renderIcon "calendar" ] ] - ] ++ (paymentLines payments)) + ] ++ (paymentLines model payments)) -paymentLines : Payments -> List Html -paymentLines payments = +paymentLines : Model -> Payments -> List Html +paymentLines model payments = payments |> List.sortBy (Date.toTime << .creation) |> List.reverse - |> List.map paymentLine + |> List.map (paymentLine model) -paymentLine : Payment -> Html -paymentLine payment = +paymentLine : Model -> Payment -> Html +paymentLine model payment = tr [] [ td [] [ text payment.name ] , td [] [ text ((toString payment.cost) ++ " €") ] , td [] [ text payment.userName ] - , td [] [ text (renderDate payment.creation) ] + , td [] [ text (renderDate payment.creation model.translations) ] ] - -renderDate : Date -> String -renderDate date = - toString (Date.day date) - |> flip append (" " ++ (toString (Date.month date)) ++ ".") - |> flip append (" " ++ (toString (Date.year date))) -- cgit v1.2.3