From 406b40e60525975b2091738165fa263be75c1fdb Mon Sep 17 00:00:00 2001 From: Rogerio Chaves Date: Thu, 19 Jan 2017 09:55:51 -0200 Subject: [PATCH] Move Fields translations to Fields value to reduce duplication --- jarbas/frontend/elm/Internationalization.elm | 206 +------------------ jarbas/frontend/elm/Reimbursement/Fields.elm | 123 +++++++---- jarbas/frontend/elm/Reimbursement/View.elm | 75 +++---- 3 files changed, 133 insertions(+), 271 deletions(-) diff --git a/jarbas/frontend/elm/Internationalization.elm b/jarbas/frontend/elm/Internationalization.elm index 391d622..cd2289f 100644 --- a/jarbas/frontend/elm/Internationalization.elm +++ b/jarbas/frontend/elm/Internationalization.elm @@ -1,4 +1,4 @@ -module Internationalization exposing (Language(..), TranslationId(..), translate) +module Internationalization exposing (Language(..), TranslationId(..), TranslationSet, translate, translateSet) type alias TranslationSet = @@ -26,45 +26,7 @@ type TranslationId | FieldsetCompanyDetails | FieldsetCurrencyDetails | FieldsetCurrencyDetailsLink - | FieldYear - | FieldDocumentId - | FieldApplicantId - | FieldTotalReimbursementValue - | FieldTotalNetValue - | FieldReimbursementNumbers - | FieldNetValues - | FieldCongresspersonId - | FieldCongressperson - | FieldCongresspersonName - | FieldCongresspersonDocument - | FieldState - | FieldParty - | FieldTermId - | FieldTerm - | FieldSubquotaId - | FieldSubquotaDescription - | FieldSubquotaGroupId - | FieldSubquotaGroupDescription - | FieldCompany - | FieldCnpjCpf - | FieldDocumentType - | FieldDocumentNumber - | FieldDocumentValue - | FieldIssueDate - | FieldIssueDateStart - | FieldIssueDateEnd | FieldIssueDateValidation - | FieldMonth - | FieldClaimDate - | FieldRemarkValue - | FieldInstallment - | FieldBatchNumber - | FieldReimbursementValues - | FieldPassenger - | FieldLegOfTheTrip - | FieldProbability - | FieldSuspicions - | EmptyField | ReimbursementSource | ReimbursementChamberOfDeputies | ReceiptFetch @@ -173,161 +135,10 @@ translate lang trans = TranslationSet "check the currency rate on " "veja a cotação em " - FieldYear -> - TranslationSet "Year" - "Ano" - - FieldDocumentId -> - TranslationSet "Document ID" - "ID do documento" - - FieldApplicantId -> - TranslationSet "Applicant ID" - "Identificador do Solicitante" - - FieldTotalReimbursementValue -> - TranslationSet "Total reimbursement value" - "Valor total dos reembolsos" - - FieldTotalNetValue -> - TranslationSet "Total net value" - "Valor líquido total" - - FieldReimbursementNumbers -> - TranslationSet "Reimbursement number" - "Número dos reembolsos" - - FieldNetValues -> - TranslationSet "Net values" - "Valores líquidos" - - FieldCongresspersonId -> - TranslationSet "Congressperson ID" - "Cadastro do Parlamentar" - - FieldCongressperson -> - TranslationSet "Congressperson" - "Deputado(a)" - - FieldCongresspersonName -> - TranslationSet "Congressperson nome" - "Nome do(a) deputado(a)" - - FieldCongresspersonDocument -> - TranslationSet "Congressperson document" - "Número da Carteira Parlamentar" - - FieldState -> - TranslationSet "State" - "UF" - - FieldParty -> - TranslationSet "Party" - "Partido" - - FieldTermId -> - TranslationSet "Term ID" - "Código da legislatura" - - FieldTerm -> - TranslationSet "Term" - "Número da legislatura" - - FieldSubquotaId -> - TranslationSet "Subquota number" - "Número da Subcota" - - FieldSubquotaDescription -> - TranslationSet "Subquota" - "Subquota" - - FieldSubquotaGroupId -> - TranslationSet "Subquota group number" - "Número da especificação da subcota" - - FieldSubquotaGroupDescription -> - TranslationSet "Subquota group" - "Especificação da subcota" - - FieldCompany -> - TranslationSet "Company" - "Fornecedor" - - FieldCnpjCpf -> - TranslationSet "CNPJ or CPF" - "CNPJ ou CPF" - - FieldDocumentType -> - TranslationSet "Document type" - "Tipo do documento" - - FieldDocumentNumber -> - TranslationSet "Document number" - "Número do documento" - - FieldDocumentValue -> - TranslationSet "Expense value" - "Valor da despesa" - - FieldIssueDate -> - TranslationSet "Expense date" - "Data da despesa" - - FieldIssueDateStart -> - TranslationSet "Expense date (start)" - "Data da despesa (início)" - - FieldIssueDateEnd -> - TranslationSet "Expense date (end)" - "Data da despesa (fim)" - FieldIssueDateValidation -> TranslationSet "Please use the YYYY-MM-DD format" "Por favor, utilize o formato YYYY-MM-DD" - FieldClaimDate -> - TranslationSet "Claim date" - "Data do pedido de reembolso" - - FieldMonth -> - TranslationSet "Month" - "Mês" - - FieldRemarkValue -> - TranslationSet "Remark value" - "Valor da glosa" - - FieldInstallment -> - TranslationSet "Installment" - "Número da parcela" - - FieldBatchNumber -> - TranslationSet "Batch number" - "Número do lote" - - FieldReimbursementValues -> - TranslationSet "Reimbursement values" - "Valor dos reembolsos" - - FieldPassenger -> - TranslationSet "Passenger" - "Passageiro" - - FieldLegOfTheTrip -> - TranslationSet "Leg of the trip" - "Trecho" - - FieldProbability -> - TranslationSet "Probability" - "Probabilidade" - - FieldSuspicions -> - TranslationSet "Suspicions" - "Suspeitas" - - EmptyField -> - TranslationSet "" "" - ReimbursementSource -> TranslationSet "Source: " "Fonte: " @@ -552,9 +363,14 @@ translate lang trans = TranslationSet "" "" in - case lang of - English -> - translationSet.english + translateSet lang translationSet + + +translateSet : Language -> TranslationSet -> String +translateSet lang translationSet = + case lang of + English -> + translationSet.english - Portuguese -> - translationSet.portuguese + Portuguese -> + translationSet.portuguese diff --git a/jarbas/frontend/elm/Reimbursement/Fields.elm b/jarbas/frontend/elm/Reimbursement/Fields.elm index a52acd3..f8ade7d 100644 --- a/jarbas/frontend/elm/Reimbursement/Fields.elm +++ b/jarbas/frontend/elm/Reimbursement/Fields.elm @@ -1,6 +1,6 @@ module Reimbursement.Fields exposing (..) -import Internationalization exposing (Language(..), TranslationId(..), translate) +import Internationalization exposing (Language(..), TranslationId(..), TranslationSet, translateSet) import List.Extra @@ -17,6 +17,7 @@ type Label | ReimbursementNumbers | NetValues | CongresspersonId + | Congressperson | CongresspersonName | CongresspersonDocument | State @@ -35,6 +36,7 @@ type Label | IssueDate | IssueDateStart | IssueDateEnd + | ClaimDate | Month | RemarkValue | Installment @@ -161,114 +163,157 @@ getLabel (Field label _) = getLabelTranslation : Language -> Field -> String getLabelTranslation language (Field label _) = let - translationId = + translationSet = case label of Year -> - FieldYear + TranslationSet "Year" + "Ano" DocumentId -> - FieldDocumentId + TranslationSet "Document ID" + "ID do documento" ApplicantId -> - FieldApplicantId + TranslationSet "Applicant ID" + "Identificador do Solicitante" TotalReimbursementValue -> - FieldTotalReimbursementValue + TranslationSet "Total reimbursement value" + "Valor total dos reembolsos" TotalNetValue -> - FieldTotalNetValue + TranslationSet "Total net value" + "Valor líquido total" ReimbursementNumbers -> - FieldReimbursementNumbers + TranslationSet "Reimbursement number" + "Número dos reembolsos" NetValues -> - FieldNetValues + TranslationSet "Net values" + "Valores líquidos" CongresspersonId -> - FieldCongresspersonId + TranslationSet "Congressperson ID" + "Cadastro do Parlamentar" + + Congressperson -> + TranslationSet "Congressperson" + "Deputado(a)" CongresspersonName -> - FieldCongresspersonName + TranslationSet "Congressperson nome" + "Nome do(a) deputado(a)" CongresspersonDocument -> - FieldCongresspersonDocument + TranslationSet "Congressperson document" + "Número da Carteira Parlamentar" State -> - FieldState + TranslationSet "State" + "UF" Party -> - FieldParty + TranslationSet "Party" + "Partido" TermId -> - FieldTermId + TranslationSet "Term ID" + "Código da legislatura" Term -> - FieldTerm + TranslationSet "Term" + "Número da legislatura" SubquotaId -> - FieldSubquotaId + TranslationSet "Subquota number" + "Número da Subcota" SubquotaDescription -> - FieldSubquotaDescription + TranslationSet "Subquota" + "Subquota" SubquotaGroupId -> - FieldSubquotaGroupId + TranslationSet "Subquota group number" + "Número da especificação da subcota" SubquotaGroupDescription -> - FieldSubquotaGroupDescription + TranslationSet "Subquota group" + "Especificação da subcota" Company -> - FieldCompany + TranslationSet "Company" + "Fornecedor" CnpjCpf -> - FieldCnpjCpf + TranslationSet "CNPJ or CPF" + "CNPJ ou CPF" DocumentType -> - FieldDocumentType + TranslationSet "Document type" + "Tipo do documento" DocumentNumber -> - FieldDocumentNumber + TranslationSet "Document number" + "Número do documento" DocumentValue -> - FieldDocumentValue + TranslationSet "Expense value" + "Valor da despesa" IssueDate -> - FieldIssueDate + TranslationSet "Expense date" + "Data da despesa" IssueDateStart -> - FieldIssueDateStart + TranslationSet "Expense date (start)" + "Data da despesa (início)" IssueDateEnd -> - FieldIssueDateEnd + TranslationSet "Expense date (end)" + "Data da despesa (fim)" + + ClaimDate -> + TranslationSet "Claim date" + "Data do pedido de reembolso" Month -> - FieldMonth + TranslationSet "Month" + "Mês" RemarkValue -> - FieldRemarkValue + TranslationSet "Remark value" + "Valor da glosa" Installment -> - FieldInstallment + TranslationSet "Installment" + "Número da parcela" BatchNumber -> - FieldBatchNumber + TranslationSet "Batch number" + "Número do lote" ReimbursementValues -> - FieldReimbursementValues + TranslationSet "Reimbursement values" + "Valor dos reembolsos" Passenger -> - FieldPassenger + TranslationSet "Passenger" + "Passageiro" LegOfTheTrip -> - FieldLegOfTheTrip + TranslationSet "Leg of the trip" + "Trecho" Probability -> - FieldProbability + TranslationSet "Probability" + "Probabilidade" Suspicions -> - FieldSuspicions + TranslationSet "Suspicions" + "Suspeitas" Empty -> - EmptyField + TranslationSet "" "" in - translate language translationId + translateSet language translationSet diff --git a/jarbas/frontend/elm/Reimbursement/View.elm b/jarbas/frontend/elm/Reimbursement/View.elm index 9660d82..74b05ff 100644 --- a/jarbas/frontend/elm/Reimbursement/View.elm +++ b/jarbas/frontend/elm/Reimbursement/View.elm @@ -29,6 +29,7 @@ import Reimbursement.Receipt.View as ReceiptView import Reimbursement.SameDay.View as SameDay import Reimbursement.SameSubquota.View as SameSubquota import Reimbursement.Update exposing (Msg(..), onlyDigits, totalPages) +import Reimbursement.Fields as Fields exposing (Field(..), Label(..), getLabelTranslation) import String @@ -238,8 +239,8 @@ viewError lang error = text "" -viewReimbursementBlockLine : ( String, String ) -> Html Msg -viewReimbursementBlockLine ( label, value ) = +viewReimbursementBlockLine : Language -> Field -> Html Msg +viewReimbursementBlockLine lang field = let styles = [ Options.css "display" "flex" @@ -254,8 +255,8 @@ viewReimbursementBlockLine ( label, value ) = [ Options.css "display" "flex" , Options.css "flex-direction" "row" ] - [ Options.styled span (Typography.body2 :: labelStyles) [ text label ] - , Options.styled span (Typography.body1 :: styles) [ text value ] + [ Options.styled span (Typography.body2 :: labelStyles) [ text <| Fields.getLabelTranslation lang field ] + , Options.styled span (Typography.body1 :: styles) [ text <| Fields.getValue field ] ] @@ -292,7 +293,7 @@ viewPs lang reimbursement = ] -viewReimbursementBlock : Language -> Reimbursement -> ( String, String, List ( String, String ) ) -> Html Msg +viewReimbursementBlock : Language -> Reimbursement -> ( String, String, List Field ) -> Html Msg viewReimbursementBlock lang reimbursement ( title, icon, fields ) = let iconTag = @@ -308,7 +309,7 @@ viewReimbursementBlock lang reimbursement ( title, icon, fields ) = [ Options.styled p [ Typography.subhead ] [ iconTag, text (" " ++ title) ] - , List.ul [] (List.map viewReimbursementBlockLine fields) + , List.ul [] (List.map (viewReimbursementBlockLine lang) fields) , ps ] @@ -340,19 +341,19 @@ viewSummaryBlock lang reimbursement = ] fields = - [ ( translate lang FieldCongressperson, congressperson ) - , ( translate lang FieldIssueDate, formatDate lang reimbursement.issueDate ) - , ( translate lang FieldClaimDate, claimedDate ) - , ( translate lang FieldSubquotaDescription, subquota ) - , ( translate lang FieldSubquotaGroupDescription, Maybe.withDefault "" reimbursement.subquotaGroupDescription ) - , ( translate lang FieldCompany, viewCompany reimbursement ) - , ( translate lang FieldDocumentValue, formatPrice lang reimbursement.documentValue ) - , ( translate lang FieldRemarkValue, maybeFormatPrice lang reimbursement.remarkValue ) - , ( translate lang FieldTotalNetValue, formatPrice lang reimbursement.totalNetValue ) - , ( translate lang FieldTotalReimbursementValue, maybeFormatPrice lang reimbursement.totalReimbursementValue ) - , ( translate lang FieldSuspicions, viewSuspicions lang reimbursement.suspicions ) + [ Field Congressperson <| congressperson + , Field IssueDate <| formatDate lang reimbursement.issueDate + , Field ClaimDate <| claimedDate + , Field SubquotaDescription <| subquota + , Field SubquotaGroupDescription <| Maybe.withDefault "" reimbursement.subquotaGroupDescription + , Field Company <| viewCompany reimbursement + , Field DocumentValue <| formatPrice lang reimbursement.documentValue + , Field RemarkValue <| maybeFormatPrice lang reimbursement.remarkValue + , Field TotalNetValue <| formatPrice lang reimbursement.totalNetValue + , Field TotalReimbursementValue <| maybeFormatPrice lang reimbursement.totalReimbursementValue + , Field Suspicions <| viewSuspicions lang reimbursement.suspicions ] - |> List.filter (\( key, value ) -> String.isEmpty value |> not) + |> List.filter (Fields.getValue >> String.isEmpty >> not) in viewReimbursementBlock lang reimbursement ( translate lang FieldsetSummary, "list", fields ) @@ -366,21 +367,21 @@ viewReimbursementDetails lang reimbursement = |> String.join ", " documentType = - DocumentType reimbursement.documentType + Internationalization.DocumentType reimbursement.documentType |> translate lang fields = - [ ( translate lang FieldApplicantId, toString reimbursement.applicantId ) - , ( translate lang FieldDocumentId, toString reimbursement.documentId ) - , ( translate lang FieldNetValues, formatPrices lang reimbursement.netValues ) - , ( translate lang FieldReimbursementValues, maybeFormatPrices lang reimbursement.reimbursementValues ) - , ( translate lang FieldReimbursementNumbers, reimbursements ) - , ( translate lang FieldDocumentType, documentType ) - , ( translate lang FieldDocumentNumber, Maybe.withDefault "" reimbursement.documentNumber ) - , ( translate lang FieldInstallment, viewMaybeIntButZero reimbursement.installment ) - , ( translate lang FieldBatchNumber, viewMaybeIntButZero reimbursement.batchNumber ) + [ Field ApplicantId <| toString reimbursement.applicantId + , Field DocumentId <| toString reimbursement.documentId + , Field NetValues <| formatPrices lang reimbursement.netValues + , Field ReimbursementValues <| maybeFormatPrices lang reimbursement.reimbursementValues + , Field ReimbursementNumbers <| reimbursements + , Field Fields.DocumentType <| documentType + , Field DocumentNumber <| Maybe.withDefault "" reimbursement.documentNumber + , Field Installment <| viewMaybeIntButZero reimbursement.installment + , Field BatchNumber <| viewMaybeIntButZero reimbursement.batchNumber ] - |> List.filter (\( key, value ) -> String.isEmpty value |> not) + |> List.filter (Fields.getValue >> String.isEmpty >> not) in viewReimbursementBlock lang reimbursement ( translate lang FieldsetReimbursement, "folder", fields ) @@ -389,12 +390,12 @@ viewCongressPersonDetails : Language -> Reimbursement -> Html Msg viewCongressPersonDetails lang reimbursement = let fields = - [ ( translate lang FieldCongresspersonId, viewMaybeIntButZero reimbursement.congresspersonId ) - , ( translate lang FieldCongresspersonDocument, viewMaybeIntButZero reimbursement.congresspersonDocument ) - , ( translate lang FieldTerm, toString reimbursement.term ) - , ( translate lang FieldTermId, viewMaybeIntButZero reimbursement.termId ) + [ Field CongresspersonId <| viewMaybeIntButZero reimbursement.congresspersonId + , Field CongresspersonDocument <| viewMaybeIntButZero reimbursement.congresspersonDocument + , Field Term <| toString reimbursement.term + , Field TermId <| viewMaybeIntButZero reimbursement.termId ] - |> List.filter (\( key, value ) -> String.isEmpty value |> not) + |> List.filter (Fields.getValue >> String.isEmpty >> not) in viewReimbursementBlock lang reimbursement ( translate lang FieldsetCongressperson, "face", fields ) @@ -403,10 +404,10 @@ viewTrip : Language -> Reimbursement -> Html Msg viewTrip lang reimbursement = let fields = - [ ( translate lang FieldPassenger, Maybe.withDefault "" reimbursement.passenger ) - , ( translate lang FieldLegOfTheTrip, Maybe.withDefault "" reimbursement.legOfTheTrip ) + [ Field Passenger <| Maybe.withDefault "" reimbursement.passenger + , Field LegOfTheTrip <| Maybe.withDefault "" reimbursement.legOfTheTrip ] - |> List.filter (\( key, value ) -> String.isEmpty value |> not) + |> List.filter (Fields.getValue >> String.isEmpty >> not) in if List.isEmpty fields then text ""