{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, ExistentialQuantification, DeriveDataTypeable #-}
module Text.Localize.Types where
import Control.Applicative
import qualified Data.Map as M
import qualified Data.ByteString as B
import qualified Data.Text.Lazy as T
import qualified Data.Text.Encoding as TE
import qualified Data.Gettext as Gettext
type LanguageId = String
type Context = B.ByteString
type TranslationSource = B.ByteString
data Translations = Translations {
Translations -> Map LanguageId Catalog
tMap :: M.Map LanguageId Gettext.Catalog }
instance Show Translations where
show :: Translations -> LanguageId
show Translations
t = LanguageId
"<Translations to languages: " LanguageId -> ShowS
forall a. [a] -> [a] -> [a]
++ ([LanguageId] -> LanguageId
unwords ([LanguageId] -> LanguageId) -> [LanguageId] -> LanguageId
forall a b. (a -> b) -> a -> b
$ Map LanguageId Catalog -> [LanguageId]
forall k a. Map k a -> [k]
M.keys (Map LanguageId Catalog -> [LanguageId])
-> Map LanguageId Catalog -> [LanguageId]
forall a b. (a -> b) -> a -> b
$ Translations -> Map LanguageId Catalog
tMap Translations
t) LanguageId -> ShowS
forall a. [a] -> [a] -> [a]
++ LanguageId
">"
class (Monad m, Applicative m) => Localized m where
getLanguage :: m LanguageId
getTranslations :: m Translations
getContext :: m (Maybe Context)
getContext = Maybe Context -> m (Maybe Context)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Context
forall a. Maybe a
Nothing
toText :: TranslationSource -> T.Text
toText :: Context -> Text
toText Context
bstr = Text -> Text
T.fromStrict (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Context -> Text
TE.decodeUtf8 Context
bstr