1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE OverloadedStrings #-}
5 {-# OPTIONS_GHC -fno-warn-orphans #-}
6 module Hcompta.CLI.I18N where
8 import qualified Data.Text
9 import Data.Text (Text)
10 -- import qualified Data.Monoid
12 import qualified Hcompta.Format.Ledger.Write as Ledger.Write
13 import Hcompta.Model.Amount.Unit (Unit)
14 import Hcompta.Model.Amount (Amount)
15 import qualified Hcompta.Lib.Leijen as W
16 import Hcompta.Lib.Leijen (ToDoc(..), (<>))
18 (#) :: ToDoc () a => a -> W.Doc
21 instance ToDoc m Text where
22 toDoc _ = W.strict_text
23 instance ToDoc m String where
24 toDoc _ = W.strict_text . Data.Text.pack
25 instance ToDoc m Int where
27 instance ToDoc m Integer where
29 instance ToDoc m Unit where
30 toDoc _ = Ledger.Write.unit
31 instance ToDoc m Amount where
32 toDoc _ = Ledger.Write.amount
36 | Message_no_ledger_file_given
42 {message_path :: FilePath
46 | Message_failed_to_read_file
47 {message_path :: FilePath}
48 | Message_failed_to_include_file
49 {message_path :: FilePath}
50 | Message_the_following_transaction_is_not_equilibrated_because {}
51 | Message_the_following_virtual_transaction_is_not_equilibrated_because {}
52 | Message_unit_sums_up_to_the_non_null_amount
54 ,message_Amount :: Amount}
55 | Message_year_or_day_is_missing {}
56 | Message_invalid_date
57 {message_Year :: Integer
61 | Message_invalid_time_of_day
63 , message_Month :: Int
64 , message_Second :: Integer
66 | Message_unexpect {message_Doc :: W.Doc}
67 | Message_sysunexpect {message_Msg :: String}
68 | Message_expect {message_Doc :: W.Doc}
69 | Message_message {message_Msg :: String}
70 | Message_sysunexpect_end_of_input {}
73 | Message_Balance_total {}
74 | Message_Balance_debit {}
75 | Message_Balance_credit {}
80 render :: [Lang] -> Message -> W.Doc
81 render ("fr" :_) = render_fr_FR
82 render ("fr_FR":_) = render_fr_FR
83 render ("en" :_) = render_en_US
84 render ("en_US":_) = render_en_US
85 render (_:xs) = render xs
86 render _ = render_en_US
88 render_en_US :: Message -> W.Doc
93 Message_no_ledger_file_given ->
94 "no ledger file given, please use:" <> W.line <>
95 "- either -i FILE parameter" <> W.line <>
96 "- or LEDGER_FILE environment variable."
97 Message_at line col ->
98 "(line " <> (#)line <> ", column " <> (#)col <> ")"
99 Message_in_file path line col ->
100 "(line " <> (#)line <> ", column " <> (#)col <> ") in: " <> (#)path
101 Message_failed_to_read_file path ->
102 "failed to read file: " <> (#)path
103 Message_failed_to_include_file path ->
104 "failed to include file: " <> (#)path
105 Message_the_following_transaction_is_not_equilibrated_because ->
106 "the following transaction is not equilibrated, because:"
107 Message_the_following_virtual_transaction_is_not_equilibrated_because ->
108 "the following virtual transaction is not equilibrated, because:"
109 Message_unit_sums_up_to_the_non_null_amount unit amount ->
110 " - unit " <> (#)unit <> " sums up to the non-null amount: " <> (#)amount
111 Message_year_or_day_is_missing ->
112 "year or day is missing"
113 Message_invalid_date year month day ->
114 "invalid date (year " <> (#)year <> ", month " <> (#)month <> ", day " <> (#)day <> ")"
115 Message_invalid_time_of_day hour minute second ->
116 "invalid time of day (hour " <> (#)hour <> ", minute " <> (#)minute <> ", second " <> (#)second <> ")"
117 Message_unexpect doc ->
119 Message_sysunexpect doc ->
120 "is written : " <> (#)doc
121 Message_expect doc ->
122 "but expect : " <> (#)doc
123 Message_message doc ->
125 Message_sysunexpect_end_of_input ->
126 "end of file unexpected"
131 Message_Balance_total ->
133 Message_Balance_debit ->
135 Message_Balance_credit ->
140 render_fr_FR :: Message -> W.Doc
145 Message_no_ledger_file_given ->
146 "aucun fichier indiqué, veuillez utiliser :" <> W.line <>
147 " - soit le paramètre -i FICHIER," <> W.line <>
148 " - soit la variable d’environnement LEDGER_FILE."
149 Message_at line col ->
150 "(ligne " <> (#)line <> ", colonne " <> (#)col <> ")"
151 Message_in_file path line col ->
152 "(ligne " <> (#)line <> ", colonne " <> (#)col <> ") dans : " <> (#)path
153 Message_failed_to_read_file path ->
154 "échec de la lecture du fichier : " <> (#)path
155 Message_failed_to_include_file path ->
156 "échec à l’inclusion du fichier : " <> (#)path
157 Message_the_following_transaction_is_not_equilibrated_because ->
158 "la transaction suivante n’est pas équilibrée, car :"
159 Message_the_following_virtual_transaction_is_not_equilibrated_because ->
160 "la transaction virtuelle suivante n’est pas équilibrée, car :"
161 Message_unit_sums_up_to_the_non_null_amount unit amount ->
162 " - l’unité " <> (#)unit <> " a le solde non-nul : " <> (#)amount
163 Message_year_or_day_is_missing ->
164 "l’année ou le jour est manquant-e"
165 Message_invalid_date year month day ->
166 "date incorrecte (année " <> (#)year <> ", mois " <> (#)month <> ", jour " <> (#)day <> ")"
167 Message_invalid_time_of_day hour minute second ->
168 "heure incorrecte (heure " <> (#)hour <> ", minute " <> (#)minute <> ", seconde " <> (#)second <> ")"
169 Message_unexpect doc ->
170 "trouve : " <> (#)doc
171 Message_sysunexpect doc ->
172 "est écrit : " <> (#)doc
173 Message_expect doc ->
174 "mais s’attend à : " <> (#)doc
175 Message_message doc ->
177 Message_sysunexpect_end_of_input ->
178 "fin de fichier inattendue"
183 Message_Balance_total ->
185 Message_Balance_debit ->
187 Message_Balance_credit ->