{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Hcompta.CLI.I18N where import qualified Data.Text import Data.Text (Text) -- import qualified Data.Monoid import qualified Hcompta.Format.Ledger.Write as Ledger.Write import Hcompta.Model.Amount.Unit (Unit) import Hcompta.Model.Amount (Amount) import qualified Hcompta.Lib.Leijen as W import Hcompta.Lib.Leijen (ToDoc(..), (<>)) (#) :: ToDoc () a => a -> W.Doc (#) = toDoc () instance ToDoc m Text where toDoc _ = W.strict_text instance ToDoc m String where toDoc _ = W.strict_text . Data.Text.pack instance ToDoc m Int where toDoc _ = W.int instance ToDoc m Integer where toDoc _ = W.integer instance ToDoc m Unit where toDoc _ = Ledger.Write.unit instance ToDoc m Amount where toDoc _ = Ledger.Write.amount data Message = Message_ERROR | Message_no_ledger_file_given | Message_at {message_line :: Int ,message_col :: Int } | Message_in_file {message_path :: FilePath ,message_line :: Int ,message_col :: Int } | Message_failed_to_read_file {message_path :: FilePath} | Message_failed_to_include_file {message_path :: FilePath} | Message_the_following_transaction_is_not_equilibrated_because {} | Message_the_following_virtual_transaction_is_not_equilibrated_because {} | Message_unit_sums_up_to_the_non_null_amount {message_Unit :: Unit ,message_Amount :: Amount} | Message_year_or_day_is_missing {} | Message_invalid_date {message_Year :: Integer ,message_Month :: Int ,message_Day :: Int } | Message_invalid_time_of_day { message_Hour :: Int , message_Month :: Int , message_Second :: Integer } | Message_unexpect {message_Doc :: W.Doc} | Message_sysunexpect {message_Msg :: String} | Message_expect {message_Doc :: W.Doc} | Message_message {message_Msg :: String} | Message_sysunexpect_end_of_input {} | Message_unknown {} | Message_or {} | Message_Balance_total {} | Message_Balance_debit {} | Message_Balance_credit {} | Message_Account {} type Lang = String render :: [Lang] -> Message -> W.Doc render ("fr" :_) = render_fr_FR render ("fr_FR":_) = render_fr_FR render ("en" :_) = render_en_US render ("en_US":_) = render_en_US render (_:xs) = render xs render _ = render_en_US render_en_US :: Message -> W.Doc render_en_US m = case m of Message_ERROR -> "ERROR" Message_no_ledger_file_given -> "no ledger file given, please use:" <> W.line <> "- either -i FILE parameter" <> W.line <> "- or LEDGER_FILE environment variable." Message_at line col -> "(line " <> (#)line <> ", column " <> (#)col <> ")" Message_in_file path line col -> "(line " <> (#)line <> ", column " <> (#)col <> ") in: " <> (#)path Message_failed_to_read_file path -> "failed to read file: " <> (#)path Message_failed_to_include_file path -> "failed to include file: " <> (#)path Message_the_following_transaction_is_not_equilibrated_because -> "the following transaction is not equilibrated, because:" Message_the_following_virtual_transaction_is_not_equilibrated_because -> "the following virtual transaction is not equilibrated, because:" Message_unit_sums_up_to_the_non_null_amount unit amount -> " - unit " <> (#)unit <> " sums up to the non-null amount: " <> (#)amount Message_year_or_day_is_missing -> "year or day is missing" Message_invalid_date year month day -> "invalid date (year " <> (#)year <> ", month " <> (#)month <> ", day " <> (#)day <> ")" Message_invalid_time_of_day hour minute second -> "invalid time of day (hour " <> (#)hour <> ", minute " <> (#)minute <> ", second " <> (#)second <> ")" Message_unexpect doc -> "found : " <> (#)doc Message_sysunexpect doc -> "is written : " <> (#)doc Message_expect doc -> "but expect : " <> (#)doc Message_message doc -> (#)doc Message_sysunexpect_end_of_input -> "end of file unexpected" Message_unknown -> "unkown" Message_or -> "or" Message_Balance_total -> "Balance" Message_Balance_debit -> "Debit" Message_Balance_credit -> "Credit" Message_Account -> "Account" render_fr_FR :: Message -> W.Doc render_fr_FR m = case m of Message_ERROR -> "ERREUR" Message_no_ledger_file_given -> "aucun fichier indiqué, veuillez utiliser :" <> W.line <> " - soit le paramètre -i FICHIER," <> W.line <> " - soit la variable d’environnement LEDGER_FILE." Message_at line col -> "(ligne " <> (#)line <> ", colonne " <> (#)col <> ")" Message_in_file path line col -> "(ligne " <> (#)line <> ", colonne " <> (#)col <> ") dans : " <> (#)path Message_failed_to_read_file path -> "échec de la lecture du fichier : " <> (#)path Message_failed_to_include_file path -> "échec à l’inclusion du fichier : " <> (#)path Message_the_following_transaction_is_not_equilibrated_because -> "la transaction suivante n’est pas équilibrée, car :" Message_the_following_virtual_transaction_is_not_equilibrated_because -> "la transaction virtuelle suivante n’est pas équilibrée, car :" Message_unit_sums_up_to_the_non_null_amount unit amount -> " - l’unité " <> (#)unit <> " a le solde non-nul : " <> (#)amount Message_year_or_day_is_missing -> "l’année ou le jour est manquant-e" Message_invalid_date year month day -> "date incorrecte (année " <> (#)year <> ", mois " <> (#)month <> ", jour " <> (#)day <> ")" Message_invalid_time_of_day hour minute second -> "heure incorrecte (heure " <> (#)hour <> ", minute " <> (#)minute <> ", seconde " <> (#)second <> ")" Message_unexpect doc -> "trouve : " <> (#)doc Message_sysunexpect doc -> "est écrit : " <> (#)doc Message_expect doc -> "mais s’attend à : " <> (#)doc Message_message doc -> (#)doc Message_sysunexpect_end_of_input -> "fin de fichier inattendue" Message_unknown -> "inconnu" Message_or -> "ou" Message_Balance_total -> "Solde" Message_Balance_debit -> "Débit" Message_Balance_credit -> "Crédit" Message_Account -> "Compte"