{-# LANGUAGE OverloadedLists, OverloadedStrings, TemplateHaskell #-}
module Text.Numerals.Languages.French (
french
, ordinize'
, negativeWord', zeroWord', oneWord'
, lowWords', midWords', highWords'
, merge'
) where
import Data.Text(Text, isSuffixOf, pack, snoc)
import Data.Vector(Vector)
import Text.Numerals.Algorithm(HighNumberAlgorithm(LongScale), NumeralsAlgorithm, numeralsAlgorithm)
import Text.Numerals.Algorithm.Template(ordinizeFromDict)
import Text.Numerals.Class(FreeMergerFunction, valueSplit)
import Text.Numerals.Internal(_divisable100, _mergeWith, _mergeWithSpace, _mergeWithHyphen, _million, _showIntegral, _stripLastIf, _thousand)
$(pure (ordinizeFromDict "_ordinize'" [
("cinq", "cinqu")
, ("neuf", "neuv")
] 'id))
french :: NumeralsAlgorithm
french = numeralsAlgorithm negativeWord' zeroWord' oneWord' lowWords' midWords' (valueSplit highWords') merge' ordinize' shortOrdinal'
negativeWord' :: Text
negativeWord' = "moins"
zeroWord' :: Text
zeroWord' = "zéro"
oneWord' :: Text
oneWord' = "un"
lowWords' :: Vector Text
lowWords' = [
"deux"
, "trois"
, "quatre"
, "cinq"
, "six"
, "sept"
, "huit"
, "neuf"
, "dix"
, "onze"
, "douze"
, "treize"
, "quatorze"
, "quinze"
, "seize"
, "dix-sept"
, "dix-huit"
, "dix-neuf"
, "vingt"
]
midWords' :: [(Integer, Text)]
midWords' = [
(1000, "mille")
, (100, "cent")
, (80, "quatre-vingts")
, (60, "soixante")
, (50, "cinquante")
, (40, "quarante")
, (30, "trente")
]
merge' :: FreeMergerFunction
merge' 1 r | r < _million = const id
| otherwise = _merge' 1 r
merge' l r = \ta tb -> _merge' l r (_firstWithoutS l r ta) (_secondWithS l r tb)
_firstWithoutS :: Integral i => i -> i -> Text -> Text
_firstWithoutS l r t
| (_divisable100 (l + 20) || (_divisable100 l && l < _thousand)) && r < _million = _stripLastIf 's' t
| otherwise = t
_secondWithS :: Integral i => i -> i -> Text -> Text
_secondWithS l r t
| l < _thousand && r /= _thousand && _divisable100 r && not ("s" `isSuffixOf` t) = snoc t 's'
| otherwise = t
_merge' :: Integral i => i -> i -> Text -> Text -> Text
_merge' l r | r >= l || l >= 100 = _mergeWithSpace
| r `mod` 10 == 1 && l /= 80 = _mergeWith " et "
| otherwise = _mergeWithHyphen
ordinize' :: Text -> Text
ordinize' "un" = "premier"
ordinize' t = _stripLastIf 'e' (_ordinize' t) <> "ième"
highWords' :: HighNumberAlgorithm
highWords' = LongScale "illion" "illiard"
shortOrdinal' :: Integral i
=> i
-> Text
shortOrdinal' = pack . (`_showIntegral` "e")