]> Git — Sourcephile - comptalang.git/blob - cli/Hcompta/CLI/I18N.hs
Correction : Lib.Parsec : évite une dépendance directe vers mtl-2.0.
[comptalang.git] / cli / Hcompta / CLI / I18N.hs
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE OverloadedStrings #-}
5 {-# OPTIONS_GHC -fno-warn-orphans #-}
6 module Hcompta.CLI.I18N where
7
8 import qualified Data.Text
9 import Data.Text (Text)
10 -- import qualified Data.Monoid
11
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(..), (<>))
17
18 (#) :: ToDoc () a => a -> W.Doc
19 (#) = toDoc ()
20
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
26 toDoc _ = W.int
27 instance ToDoc m Integer where
28 toDoc _ = W.integer
29 instance ToDoc m Unit where
30 toDoc _ = Ledger.Write.unit
31 instance ToDoc m Amount where
32 toDoc _ = Ledger.Write.amount
33
34 data Message
35 = Message_ERROR
36 | Message_no_ledger_file_given
37 | Message_at
38 {message_line :: Int
39 ,message_col :: Int
40 }
41 | Message_in_file
42 {message_path :: FilePath
43 ,message_line :: Int
44 ,message_col :: Int
45 }
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
53 {message_Unit :: Unit
54 ,message_Amount :: Amount}
55 | Message_year_or_day_is_missing {}
56 | Message_invalid_date
57 {message_Year :: Integer
58 ,message_Month :: Int
59 ,message_Day :: Int
60 }
61 | Message_invalid_time_of_day
62 { message_Hour :: Int
63 , message_Month :: Int
64 , message_Second :: Integer
65 }
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 {}
71 | Message_unknown {}
72 | Message_or {}
73 | Message_Balance_total {}
74 | Message_Balance_debit {}
75 | Message_Balance_credit {}
76 | Message_Account {}
77
78 type Lang = String
79
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
87
88 render_en_US :: Message -> W.Doc
89 render_en_US m =
90 case m of
91 Message_ERROR ->
92 "ERROR"
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 ->
118 "found : " <> (#)doc
119 Message_sysunexpect doc ->
120 "is written : " <> (#)doc
121 Message_expect doc ->
122 "but expect : " <> (#)doc
123 Message_message doc ->
124 (#)doc
125 Message_sysunexpect_end_of_input ->
126 "end of file unexpected"
127 Message_unknown ->
128 "unkown"
129 Message_or ->
130 "or"
131 Message_Balance_total ->
132 "Balance"
133 Message_Balance_debit ->
134 "Debit"
135 Message_Balance_credit ->
136 "Credit"
137 Message_Account ->
138 "Account"
139
140 render_fr_FR :: Message -> W.Doc
141 render_fr_FR m =
142 case m of
143 Message_ERROR ->
144 "ERREUR"
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 ->
176 (#)doc
177 Message_sysunexpect_end_of_input ->
178 "fin de fichier inattendue"
179 Message_unknown ->
180 "inconnu"
181 Message_or ->
182 "ou"
183 Message_Balance_total ->
184 "Solde"
185 Message_Balance_debit ->
186 "Débit"
187 Message_Balance_credit ->
188 "Crédit"
189 Message_Account ->
190 "Compte"