Safe Haskell | None |
---|---|
Language | Haskell2010 |
- 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
.
The JSON Web Token issued by MS Microsoft.Translator token service. Consists of wrapped text. Valid for ten minutes.
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
data TranslatorException Source #
newtype ArrayResponse Source #
TransItem | |
|
An original/translated sentence pair.
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.