{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Readers.LaTeX.Lang
( setDefaultLanguage
, polyglossiaLangToBCP47
, babelLangToBCP47
, enquoteCommands
, inlineLanguageCommands
)
where
import qualified Data.Map as M
import Data.Text (Text)
import qualified Data.Text as T
import Text.Pandoc.Shared (extractSpaces)
import Text.Collate.Lang (Lang(..), renderLang)
import Text.Pandoc.Class (PandocMonad(..))
import Text.Pandoc.Translations (setTranslations)
import Text.Pandoc.Readers.LaTeX.Parsing
import Text.Pandoc.Parsing (updateState, option, getState, QuoteContext(..),
withQuoteContext)
import Text.Pandoc.Builder (Blocks, Inlines, setMeta, str, spanWith,
singleQuoted, doubleQuoted)
enquote :: PandocMonad m
=> LP m Inlines
-> Bool -> Maybe Text -> LP m Inlines
enquote :: forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Bool -> Maybe Text -> LP m Inlines
enquote LP m Inlines
tok Bool
starred Maybe Text
mblang = do
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
let lang :: Maybe Lang
lang = Maybe Text
mblang forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe Lang
babelLangToBCP47
let langspan :: Inlines -> Inlines
langspan = case Maybe Lang
lang of
Maybe Lang
Nothing -> forall a. a -> a
id
Just Lang
l -> Attr -> Inlines -> Inlines
spanWith (Text
"",[],[(Text
"lang", Lang -> Text
renderLang Lang
l)])
QuoteContext
quoteContext <- LaTeXState -> QuoteContext
sQuoteContext forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
if Bool
starred Bool -> Bool -> Bool
|| QuoteContext
quoteContext forall a. Eq a => a -> a -> Bool
== QuoteContext
InDoubleQuote
then Inlines -> Inlines
singleQuoted forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
langspan forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InSingleQuote LP m Inlines
tok
else Inlines -> Inlines
doubleQuoted forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
langspan forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InDoubleQuote LP m Inlines
tok
enquoteCommands :: PandocMonad m
=> LP m Inlines -> M.Map Text (LP m Inlines)
enquoteCommands :: forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Map Text (LP m Inlines)
enquoteCommands LP m Inlines
tok = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ (Text
"enquote*", forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Bool -> Maybe Text -> LP m Inlines
enquote LP m Inlines
tok Bool
True forall a. Maybe a
Nothing)
, (Text
"enquote", forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Bool -> Maybe Text -> LP m Inlines
enquote LP m Inlines
tok Bool
False forall a. Maybe a
Nothing)
, (Text
"foreignquote*", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Bool -> Maybe Text -> LP m Inlines
enquote LP m Inlines
tok Bool
True forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
, (Text
"foreignquote", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Bool -> Maybe Text -> LP m Inlines
enquote LP m Inlines
tok Bool
False forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
, (Text
"hyphenquote*", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Bool -> Maybe Text -> LP m Inlines
enquote LP m Inlines
tok Bool
True forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
, (Text
"hyphenquote", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Bool -> Maybe Text -> LP m Inlines
enquote LP m Inlines
tok Bool
False forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
]
foreignlanguage :: PandocMonad m => LP m Inlines -> LP m Inlines
foreignlanguage :: forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Inlines
foreignlanguage LP m Inlines
tok = do
Text
babelLang <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
case Text -> Maybe Lang
babelLangToBCP47 Text
babelLang of
Just Lang
lang -> Attr -> Inlines -> Inlines
spanWith (Text
"", [], [(Text
"lang", Lang -> Text
renderLang Lang
lang)]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
tok
Maybe Lang
_ -> LP m Inlines
tok
inlineLanguageCommands :: PandocMonad m
=> LP m Inlines -> M.Map Text (LP m Inlines)
inlineLanguageCommands :: forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Map Text (LP m Inlines)
inlineLanguageCommands LP m Inlines
tok =
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall a b. (a -> b) -> a -> b
$
(Text
"foreignlanguage", forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Inlines
foreignlanguage LP m Inlines
tok) forall a. a -> [a] -> [a]
:
(forall {a}.
(Semigroup a, IsString a) =>
(a, Text -> Lang) -> (a, LP m Inlines)
mk forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall k a. Map k a -> [(k, a)]
M.toList Map Text (Text -> Lang)
polyglossiaLangToBCP47)
where
mk :: (a, Text -> Lang) -> (a, LP m Inlines)
mk (a
polyglossia, Text -> Lang
bcp47Func) =
(a
"text" forall a. Semigroup a => a -> a -> a
<> a
polyglossia, forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> (Text -> Lang) -> LP m Inlines
inlineLanguage LP m Inlines
tok Text -> Lang
bcp47Func)
inlineLanguage :: PandocMonad m
=> LP m Inlines -> (Text -> Lang) -> LP m Inlines
inlineLanguage :: forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> (Text -> Lang) -> LP m Inlines
inlineLanguage LP m Inlines
tok Text -> Lang
bcp47Func = do
Text
o <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.filter (\Char
c -> Char
c forall a. Eq a => a -> a -> Bool
/= Char
'[' Bool -> Bool -> Bool
&& Char
c forall a. Eq a => a -> a -> Bool
/= Char
']')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Text
rawopt
let lang :: Text
lang = Lang -> Text
renderLang forall a b. (a -> b) -> a -> b
$ Text -> Lang
bcp47Func Text
o
(Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith (Text
"", [], [(Text
"lang", Text
lang)])) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
tok
setDefaultLanguage :: PandocMonad m => LP m Blocks
setDefaultLanguage :: forall (m :: * -> *). PandocMonad m => LP m Blocks
setDefaultLanguage = do
Text
o <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.filter (\Char
c -> Char
c forall a. Eq a => a -> a -> Bool
/= Char
'[' Bool -> Bool -> Bool
&& Char
c forall a. Eq a => a -> a -> Bool
/= Char
']')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Text
rawopt
Text
polylang <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
polylang Map Text (Text -> Lang)
polyglossiaLangToBCP47 of
Maybe (Text -> Lang)
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Just Text -> Lang
langFunc -> do
let l :: Lang
l = Text -> Lang
langFunc Text
o
forall (m :: * -> *). PandocMonad m => Lang -> m ()
setTranslations Lang
l
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
setMeta Text
"lang" forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str (Lang -> Text
renderLang Lang
l)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
polyglossiaLangToBCP47 :: M.Map T.Text (T.Text -> Lang)
polyglossiaLangToBCP47 :: Map Text (Text -> Lang)
polyglossiaLangToBCP47 = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ (Text
"arabic", \Text
o -> case (Char -> Bool) -> Text -> Text
T.filter (forall a. Eq a => a -> a -> Bool
/=Char
' ') Text
o of
Text
"locale=algeria" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"ar" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"DZ") [] [] []
Text
"locale=mashriq" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"ar" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"SY") [] [] []
Text
"locale=libya" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"ar" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"LY") [] [] []
Text
"locale=morocco" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"ar" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"MA") [] [] []
Text
"locale=mauritania" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"ar" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"MR") [] [] []
Text
"locale=tunisia" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"ar" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"TN") [] [] []
Text
_ -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"ar" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] [])
, (Text
"german", \Text
o -> case (Char -> Bool) -> Text -> Text
T.filter (forall a. Eq a => a -> a -> Bool
/=Char
' ') Text
o of
Text
"spelling=old" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"DE") [Text
"1901"] [] []
Text
"variant=austrian,spelling=old"
-> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"AT") [Text
"1901"] [] []
Text
"variant=austrian" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"AT") [] [] []
Text
"variant=swiss,spelling=old"
-> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"CH") [Text
"1901"] [] []
Text
"variant=swiss" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"CH") [] [] []
Text
_ -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] [])
, (Text
"lsorbian", \Text
_ -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"dsb" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] [])
, (Text
"greek", \Text
o -> case (Char -> Bool) -> Text -> Text
T.filter (forall a. Eq a => a -> a -> Bool
/=Char
' ') Text
o of
Text
"variant=poly" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"el" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"polyton") [] [] []
Text
"variant=ancient" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"grc" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] []
Text
_ -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"el" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] [])
, (Text
"english", \Text
o -> case (Char -> Bool) -> Text -> Text
T.filter (forall a. Eq a => a -> a -> Bool
/=Char
' ') Text
o of
Text
"variant=australian" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"en" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"AU") [] [] []
Text
"variant=canadian" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"en" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"CA") [] [] []
Text
"variant=british" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"en" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"GB") [] [] []
Text
"variant=newzealand" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"en" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"NZ") [] [] []
Text
"variant=american" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"en" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"US") [] [] []
Text
_ -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"en" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] [])
, (Text
"usorbian", \Text
_ -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"hsb" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] [])
, (Text
"latin", \Text
o -> case (Char -> Bool) -> Text -> Text
T.filter (forall a. Eq a => a -> a -> Bool
/=Char
' ') Text
o of
Text
"variant=classic" -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"la" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [Text
"x-classic"] [] []
Text
_ -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"la" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] [])
, (Text
"slovenian", \Text
_ -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"sl" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] [])
, (Text
"serbianc", \Text
_ -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"sr" (forall a. a -> Maybe a
Just Text
"Cyrl") forall a. Maybe a
Nothing [] [] [])
, (Text
"pinyin", \Text
_ -> Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"zh" (forall a. a -> Maybe a
Just Text
"Latn") forall a. Maybe a
Nothing [Text
"pinyin"] [] [])
, (Text
"afrikaans", \Text
_ -> Text -> Lang
simpleLang Text
"af")
, (Text
"amharic", \Text
_ -> Text -> Lang
simpleLang Text
"am")
, (Text
"assamese", \Text
_ -> Text -> Lang
simpleLang Text
"as")
, (Text
"asturian", \Text
_ -> Text -> Lang
simpleLang Text
"ast")
, (Text
"bulgarian", \Text
_ -> Text -> Lang
simpleLang Text
"bg")
, (Text
"bengali", \Text
_ -> Text -> Lang
simpleLang Text
"bn")
, (Text
"tibetan", \Text
_ -> Text -> Lang
simpleLang Text
"bo")
, (Text
"breton", \Text
_ -> Text -> Lang
simpleLang Text
"br")
, (Text
"catalan", \Text
_ -> Text -> Lang
simpleLang Text
"ca")
, (Text
"welsh", \Text
_ -> Text -> Lang
simpleLang Text
"cy")
, (Text
"czech", \Text
_ -> Text -> Lang
simpleLang Text
"cs")
, (Text
"coptic", \Text
_ -> Text -> Lang
simpleLang Text
"cop")
, (Text
"danish", \Text
_ -> Text -> Lang
simpleLang Text
"da")
, (Text
"divehi", \Text
_ -> Text -> Lang
simpleLang Text
"dv")
, (Text
"esperanto", \Text
_ -> Text -> Lang
simpleLang Text
"eo")
, (Text
"spanish", \Text
_ -> Text -> Lang
simpleLang Text
"es")
, (Text
"estonian", \Text
_ -> Text -> Lang
simpleLang Text
"et")
, (Text
"basque", \Text
_ -> Text -> Lang
simpleLang Text
"eu")
, (Text
"farsi", \Text
_ -> Text -> Lang
simpleLang Text
"fa")
, (Text
"finnish", \Text
_ -> Text -> Lang
simpleLang Text
"fi")
, (Text
"french", \Text
_ -> Text -> Lang
simpleLang Text
"fr")
, (Text
"friulan", \Text
_ -> Text -> Lang
simpleLang Text
"fur")
, (Text
"irish", \Text
_ -> Text -> Lang
simpleLang Text
"ga")
, (Text
"scottish", \Text
_ -> Text -> Lang
simpleLang Text
"gd")
, (Text
"ethiopic", \Text
_ -> Text -> Lang
simpleLang Text
"gez")
, (Text
"galician", \Text
_ -> Text -> Lang
simpleLang Text
"gl")
, (Text
"hebrew", \Text
_ -> Text -> Lang
simpleLang Text
"he")
, (Text
"hindi", \Text
_ -> Text -> Lang
simpleLang Text
"hi")
, (Text
"croatian", \Text
_ -> Text -> Lang
simpleLang Text
"hr")
, (Text
"magyar", \Text
_ -> Text -> Lang
simpleLang Text
"hu")
, (Text
"armenian", \Text
_ -> Text -> Lang
simpleLang Text
"hy")
, (Text
"gujarati", \Text
_ -> Text -> Lang
simpleLang Text
"gu")
, (Text
"interlingua", \Text
_ -> Text -> Lang
simpleLang Text
"ia")
, (Text
"indonesian", \Text
_ -> Text -> Lang
simpleLang Text
"id")
, (Text
"icelandic", \Text
_ -> Text -> Lang
simpleLang Text
"is")
, (Text
"italian", \Text
_ -> Text -> Lang
simpleLang Text
"it")
, (Text
"japanese", \Text
_ -> Text -> Lang
simpleLang Text
"jp")
, (Text
"khmer", \Text
_ -> Text -> Lang
simpleLang Text
"km")
, (Text
"kurmanji", \Text
_ -> Text -> Lang
simpleLang Text
"kmr")
, (Text
"kannada", \Text
_ -> Text -> Lang
simpleLang Text
"kn")
, (Text
"korean", \Text
_ -> Text -> Lang
simpleLang Text
"ko")
, (Text
"lao", \Text
_ -> Text -> Lang
simpleLang Text
"lo")
, (Text
"lithuanian", \Text
_ -> Text -> Lang
simpleLang Text
"lt")
, (Text
"latvian", \Text
_ -> Text -> Lang
simpleLang Text
"lv")
, (Text
"malayalam", \Text
_ -> Text -> Lang
simpleLang Text
"ml")
, (Text
"mongolian", \Text
_ -> Text -> Lang
simpleLang Text
"mn")
, (Text
"marathi", \Text
_ -> Text -> Lang
simpleLang Text
"mr")
, (Text
"dutch", \Text
_ -> Text -> Lang
simpleLang Text
"nl")
, (Text
"nynorsk", \Text
_ -> Text -> Lang
simpleLang Text
"nn")
, (Text
"norsk", \Text
_ -> Text -> Lang
simpleLang Text
"no")
, (Text
"nko", \Text
_ -> Text -> Lang
simpleLang Text
"nqo")
, (Text
"occitan", \Text
_ -> Text -> Lang
simpleLang Text
"oc")
, (Text
"oriya", \Text
_ -> Text -> Lang
simpleLang Text
"or")
, (Text
"punjabi", \Text
_ -> Text -> Lang
simpleLang Text
"pa")
, (Text
"polish", \Text
_ -> Text -> Lang
simpleLang Text
"pl")
, (Text
"piedmontese", \Text
_ -> Text -> Lang
simpleLang Text
"pms")
, (Text
"portuguese", \Text
_ -> Text -> Lang
simpleLang Text
"pt")
, (Text
"romansh", \Text
_ -> Text -> Lang
simpleLang Text
"rm")
, (Text
"romanian", \Text
_ -> Text -> Lang
simpleLang Text
"ro")
, (Text
"russian", \Text
_ -> Text -> Lang
simpleLang Text
"ru")
, (Text
"sanskrit", \Text
_ -> Text -> Lang
simpleLang Text
"sa")
, (Text
"samin", \Text
_ -> Text -> Lang
simpleLang Text
"se")
, (Text
"slovak", \Text
_ -> Text -> Lang
simpleLang Text
"sk")
, (Text
"albanian", \Text
_ -> Text -> Lang
simpleLang Text
"sq")
, (Text
"serbian", \Text
_ -> Text -> Lang
simpleLang Text
"sr")
, (Text
"swedish", \Text
_ -> Text -> Lang
simpleLang Text
"sv")
, (Text
"syriac", \Text
_ -> Text -> Lang
simpleLang Text
"syr")
, (Text
"tamil", \Text
_ -> Text -> Lang
simpleLang Text
"ta")
, (Text
"telugu", \Text
_ -> Text -> Lang
simpleLang Text
"te")
, (Text
"thai", \Text
_ -> Text -> Lang
simpleLang Text
"th")
, (Text
"turkmen", \Text
_ -> Text -> Lang
simpleLang Text
"tk")
, (Text
"turkish", \Text
_ -> Text -> Lang
simpleLang Text
"tr")
, (Text
"ukrainian", \Text
_ -> Text -> Lang
simpleLang Text
"uk")
, (Text
"urdu", \Text
_ -> Text -> Lang
simpleLang Text
"ur")
, (Text
"vietnamese", \Text
_ -> Text -> Lang
simpleLang Text
"vi")
]
simpleLang :: Text -> Lang
simpleLang :: Text -> Lang
simpleLang Text
l = Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
l forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] []
babelLangToBCP47 :: T.Text -> Maybe Lang
babelLangToBCP47 :: Text -> Maybe Lang
babelLangToBCP47 Text
s =
case Text
s of
Text
"austrian" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"AT") [Text
"1901"] [] []
Text
"naustrian" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"AT") [] [] []
Text
"swissgerman" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"CH") [Text
"1901"] [] []
Text
"nswissgerman" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"CH") [] [] []
Text
"german" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"DE") [Text
"1901"] [] []
Text
"ngerman" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"de" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"DE") [] [] []
Text
"lowersorbian" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"dsb" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] []
Text
"uppersorbian" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"hsb" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] [] []
Text
"polutonikogreek" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"el" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [Text
"polyton"] [] []
Text
"slovene" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text -> Lang
simpleLang Text
"sl"
Text
"australian" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"en" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"AU") [] [] []
Text
"canadian" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"en" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"CA") [] [] []
Text
"british" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"en" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"GB") [] [] []
Text
"newzealand" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"en" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"NZ") [] [] []
Text
"american" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"en" forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just Text
"US") [] [] []
Text
"classiclatin" -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Text
-> Maybe Text
-> [Text]
-> [(Text, [(Text, Text)])]
-> [Text]
-> Lang
Lang Text
"la" forall a. Maybe a
Nothing forall a. Maybe a
Nothing [Text
"x-classic"] [] []
Text
_ -> (forall a b. (a -> b) -> a -> b
$ Text
"") forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
s Map Text (Text -> Lang)
polyglossiaLangToBCP47