Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype SubscriptionKey = SubKey Text
- data AuthToken
- data AuthData = AuthData {}
- data TransData
- data Language
- = Afrikaans
- | Arabic
- | Bosnian
- | Bulgarian
- | Catalan
- | ChineseSimplified
- | ChineseTraditional
- | Croatian
- | Czech
- | Danish
- | Dutch
- | English
- | Estonian
- | Finnish
- | French
- | German
- | Greek
- | HaitianCreole
- | Hebrew
- | Hindi
- | HmongDaw
- | Hungarian
- | Indonesian
- | Italian
- | Japanese
- | Kiswahili
- | Klingon
- | KlingonPIqaD
- | Korean
- | Latvian
- | Lithuanian
- | Malay
- | Maltese
- | Norwegian
- | Persian
- | Polish
- | Portuguese
- | QueretaroOtomi
- | Romanian
- | Russian
- | SerbianCyrillic
- | SerbianLatin
- | Slovak
- | Slovenian
- | Spanish
- | Swedish
- | Thai
- | Turkish
- | Ukrainian
- | Urdu
- | Vietnamese
- | Welsh
- | YucatecMaya
- data TranslatorException
- newtype ArrayResponse = ArrayResponse {}
- data TransItem = TransItem {
- transText :: Text
- originalBreaks :: [Int]
- translatedBreaks :: [Int]
- data Sentence = Sentence {}
- lookupSubKey :: ExceptT TranslatorException IO SubscriptionKey
- issueToken :: Manager -> SubscriptionKey -> IO (Either TranslatorException AuthToken)
- issueAuth :: Manager -> SubscriptionKey -> ExceptT TranslatorException IO AuthData
- refresh :: TransData -> ExceptT TranslatorException IO AuthData
- initTransData :: SubscriptionKey -> ExceptT TranslatorException IO TransData
- initTransDataWith :: SubscriptionKey -> Manager -> ExceptT TranslatorException IO TransData
- checkAuth :: TransData -> ExceptT TranslatorException IO AuthData
- keepFreshAuth :: SubscriptionKey -> ExceptT TranslatorException IO TransData
- translate :: TransData -> Maybe Language -> Language -> Text -> ExceptT TranslatorException IO Text
- translateArray :: TransData -> Language -> Language -> [Text] -> ExceptT TranslatorException IO ArrayResponse
- translateArrayText :: TransData -> Language -> Language -> [Text] -> ExceptT TranslatorException IO [Text]
- translateArraySentences :: TransData -> Language -> Language -> [Text] -> ExceptT TranslatorException IO [[Sentence]]
- lookupSubKeyIO :: IO (Either TranslatorException SubscriptionKey)
- issueAuthIO :: Manager -> SubscriptionKey -> IO (Either TranslatorException AuthData)
- initTransDataIO :: SubscriptionKey -> IO (Either TranslatorException TransData)
- checkAuthIO :: TransData -> IO (Either TranslatorException AuthData)
- translateIO :: TransData -> Maybe Language -> Language -> Text -> IO (Either TranslatorException Text)
- translateArrayIO :: TransData -> Language -> Language -> [Text] -> IO (Either TranslatorException ArrayResponse)
- translateArrayTextIO :: TransData -> Language -> Language -> [Text] -> IO (Either TranslatorException [Text])
- translateArraySentencesIO :: TransData -> Language -> Language -> [Text] -> IO (Either TranslatorException [[Sentence]])
- simpleTranslate :: SubscriptionKey -> Manager -> Maybe Language -> Language -> Text -> IO (Either TranslatorException Text)
- basicTranslate :: Manager -> AuthToken -> Maybe Language -> Language -> Text -> IO (Either TranslatorException Text)
- basicTranslateArray :: Manager -> AuthToken -> Language -> Language -> [Text] -> IO (Either TranslatorException ArrayResponse)
- mkSentences :: [Text] -> ArrayResponse -> [[Sentence]]
Basic Types
newtype SubscriptionKey Source #
A key to your subscription to the service. Used to retrieve an AuthToken
.
Instances
Show SubscriptionKey Source # | |
Defined in Microsoft.Translator.API.Auth showsPrec :: Int -> SubscriptionKey -> ShowS # show :: SubscriptionKey -> String # showList :: [SubscriptionKey] -> ShowS # | |
IsString SubscriptionKey Source # | |
Defined in Microsoft.Translator.API.Auth fromString :: String -> SubscriptionKey # | |
ToHttpApiData SubscriptionKey Source # | |
Defined in Microsoft.Translator.API.Auth toUrlPiece :: SubscriptionKey -> Text # toEncodedUrlPiece :: SubscriptionKey -> Builder # toHeader :: SubscriptionKey -> ByteString # toQueryParam :: SubscriptionKey -> Text # |
The JSON Web Token issued by MS Microsoft.Translator token service. Consists of wrapped text. Valid for ten minutes.
Instances
Show AuthToken Source # | |
Generic AuthToken Source # | |
ToHttpApiData AuthToken Source # | |
Defined in Microsoft.Translator.API.Auth toUrlPiece :: AuthToken -> Text # toEncodedUrlPiece :: AuthToken -> Builder # toHeader :: AuthToken -> ByteString # toQueryParam :: AuthToken -> Text # | |
type Rep AuthToken Source # | |
Defined in Microsoft.Translator.API.Auth |
An AuthToken
together with the time it was recieved.
Each token is valid for 10 minutes.
The data to hold onto for making translation requests.
Includes your SubscriptionKey
, an AuthData
and an HTTPS Manager
.
Languages supported by MS Microsoft.Translator
Instances
ToHttpApiData Language Source # | |
Defined in Microsoft.Translator.Language toUrlPiece :: Language -> Text # toEncodedUrlPiece :: Language -> Builder # toHeader :: Language -> ByteString # toQueryParam :: Language -> Text # |
data TranslatorException Source #
Instances
Show TranslatorException Source # | |
Defined in Microsoft.Translator.Exception showsPrec :: Int -> TranslatorException -> ShowS # show :: TranslatorException -> String # showList :: [TranslatorException] -> ShowS # | |
Exception TranslatorException Source # | |
newtype ArrayResponse Source #
Instances
Show ArrayResponse Source # | |
Defined in Microsoft.Translator.API showsPrec :: Int -> ArrayResponse -> ShowS # show :: ArrayResponse -> String # showList :: [ArrayResponse] -> ShowS # | |
Generic ArrayResponse Source # | |
Defined in Microsoft.Translator.API type Rep ArrayResponse :: Type -> Type # from :: ArrayResponse -> Rep ArrayResponse x # to :: Rep ArrayResponse x -> ArrayResponse # | |
type Rep ArrayResponse Source # | |
Defined in Microsoft.Translator.API type Rep ArrayResponse = D1 (MetaData "ArrayResponse" "Microsoft.Translator.API" "microsoft-translator-0.1.2-2WixOZLIJMQ2W9Ir6On7A3" True) (C1 (MetaCons "ArrayResponse" PrefixI True) (S1 (MetaSel (Just "getArrayResponse") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [TransItem]))) |
TransItem | |
|
Instances
Show TransItem Source # | |
Generic TransItem Source # | |
type Rep TransItem Source # | |
Defined in Microsoft.Translator.API type Rep TransItem = D1 (MetaData "TransItem" "Microsoft.Translator.API" "microsoft-translator-0.1.2-2WixOZLIJMQ2W9Ir6On7A3" False) (C1 (MetaCons "TransItem" PrefixI True) (S1 (MetaSel (Just "transText") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text) :*: (S1 (MetaSel (Just "originalBreaks") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Int]) :*: S1 (MetaSel (Just "translatedBreaks") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Int])))) |
An original/translated sentence pair.
Instances
Eq Sentence Source # | |
Show Sentence Source # | |
Generic Sentence Source # | |
type Rep Sentence Source # | |
Defined in Microsoft.Translator type Rep Sentence = D1 (MetaData "Sentence" "Microsoft.Translator" "microsoft-translator-0.1.2-2WixOZLIJMQ2W9Ir6On7A3" False) (C1 (MetaCons "Sentence" PrefixI True) (S1 (MetaSel (Just "fromText") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text) :*: S1 (MetaSel (Just "toText") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text))) |
API functions
Authorization
lookupSubKey :: ExceptT TranslatorException IO SubscriptionKey Source #
Retrieve your subscription key from the TRANSLATOR_SUBSCRIPTION_KEY environment variable.
issueToken :: Manager -> SubscriptionKey -> IO (Either TranslatorException AuthToken) Source #
Retrieve a token from the API. It will be valid for 10 minutes.
issueAuth :: Manager -> SubscriptionKey -> ExceptT TranslatorException IO AuthData Source #
Retrieve a token, via issueToken
, and save it together with a timestamp.
initTransData :: SubscriptionKey -> ExceptT TranslatorException IO TransData Source #
Retrieve an AuthData
token and hold on to the new HTTPS manager.
initTransDataWith :: SubscriptionKey -> Manager -> ExceptT TranslatorException IO TransData Source #
Retrieve an AuthData
token and hold on to the HTTPS manager.
For when you want to supply a particular manager. Otherwise use initTransData
.
checkAuth :: TransData -> ExceptT TranslatorException IO AuthData Source #
If a token contained in a TransData
is expired or about to expire, refresh it.
keepFreshAuth :: SubscriptionKey -> ExceptT TranslatorException IO TransData Source #
Create a TransData
with a new auth token and fork a thread to refresh it every
9 minutes.
This is mostly a quick-and-dirty function for demo purposes and one-off projects.
You'll want to roll something more robust for production applications.
Translation
ExceptT variants
translate :: TransData -> Maybe Language -> Language -> Text -> ExceptT TranslatorException IO Text Source #
Translate text
translateArray :: TransData -> Language -> Language -> [Text] -> ExceptT TranslatorException IO ArrayResponse Source #
Translate a text array.
The ArrayResponse
you get back includes sentence break information.
translateArrayText :: TransData -> Language -> Language -> [Text] -> ExceptT TranslatorException IO [Text] Source #
Translate a text array, and just return the list of texts.
translateArraySentences :: TransData -> Language -> Language -> [Text] -> ExceptT TranslatorException IO [[Sentence]] Source #
Translate a text array, and split all the texts into constituent sentences, paired with the originals.
IO variants
lookupSubKeyIO :: IO (Either TranslatorException SubscriptionKey) Source #
Retrieve your subscription key from the TRANSLATOR_SUBSCRIPTION_KEY environment variable.
issueAuthIO :: Manager -> SubscriptionKey -> IO (Either TranslatorException AuthData) Source #
Retrieve a token, via issueToken
, and save it together with a timestamp.
initTransDataIO :: SubscriptionKey -> IO (Either TranslatorException TransData) Source #
Retrieve an AuthData
token and start up an HTTPS manager.
checkAuthIO :: TransData -> IO (Either TranslatorException AuthData) Source #
If a token contained in a TransData
is expired or about to expire, refresh it.
translateIO :: TransData -> Maybe Language -> Language -> Text -> IO (Either TranslatorException Text) Source #
Translate text.
translateArrayIO :: TransData -> Language -> Language -> [Text] -> IO (Either TranslatorException ArrayResponse) Source #
Translate a text array.
translateArrayTextIO :: TransData -> Language -> Language -> [Text] -> IO (Either TranslatorException [Text]) Source #
Translate a text array, and just return the list of texts.
translateArraySentencesIO :: TransData -> Language -> Language -> [Text] -> IO (Either TranslatorException [[Sentence]]) Source #
Translate a text array, and split all the texts into constituent sentences paired with the originals.
Minimalistic variants
simpleTranslate :: SubscriptionKey -> Manager -> Maybe Language -> Language -> Text -> IO (Either TranslatorException Text) Source #
Simplest possible translation function. Always needs to make a request for the JWT token first.
basicTranslate :: Manager -> AuthToken -> Maybe Language -> Language -> Text -> IO (Either TranslatorException Text) Source #
Most basic possible text translation function. For typical use-cases it will be much
more convenient to use functions from the Microsoft.Translator module, namely
translateIO
. See the README example.
basicTranslateArray :: Manager -> AuthToken -> Language -> Language -> [Text] -> IO (Either TranslatorException ArrayResponse) Source #
Most basic possible text list translation function. For typical use-cases it will
be much more convenient to use functions from the Microsoft.Translator module, namely
translateArrayIO
. See the README example.
Pure functions
mkSentences :: [Text] -> ArrayResponse -> [[Sentence]] Source #
Take the original texts and the ArrayResponse object, and apply the sentence break information to pair each sentence in the request to the translated text.