blob: 848a83a1e830d35a91ad8ab47463c9d2c3c98b61 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Text.Pandoc.Citeproc.Data
(biblatexStringMap)
where
import Data.FileEmbed
import Data.ByteString (ByteString)
import qualified Data.Map as M
import qualified Data.Text.Encoding as TE
import qualified Data.Text as T
import Data.Text (Text)
import Text.Pandoc.Citeproc.Util (toIETF)
import Text.Collate.Lang (Lang(..), parseLang)
biblatexLocalizations :: [(FilePath, ByteString)]
biblatexLocalizations = $(embedDir "citeproc/biblatex-localization")
-- biblatex localization keys, from files at
-- http://github.com/plk/biblatex/tree/master/tex/latex/biblatex/lbx
biblatexStringMap :: M.Map Text (M.Map Text (Text, Text))
biblatexStringMap = foldr go mempty biblatexLocalizations
where
go (fp, bs) =
let ls = T.lines $ TE.decodeUtf8 bs
in case parseLang (toIETF $ T.takeWhile (/= '.') $ T.pack fp) of
Right lang | length ls > 4
-> M.insert (langLanguage lang)
(toStringMap $ map (T.splitOn "|") ls)
_ -> id
toStringMap = foldr go' mempty
go' [term, x, y] = M.insert term (x, y)
go' _ = id
|