microsoft-translator 0.1.0.0 → 0.1.1
raw patch · 5 files changed
+34/−14 lines, 5 filesdep ~basedep ~http-mediadep ~servantPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, http-media, servant, servant-client, time
API changes (from Hackage documentation)
Files
- ChangeLog.md +5/−1
- microsoft-translator.cabal +16/−7
- src/Microsoft/Translator/API.hs +11/−4
- src/Microsoft/Translator/API/Auth.hs +1/−0
- src/Microsoft/TranslatorExample.hs +1/−2
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for microsoft-translator -## 0.1.0.0 -- YYYY-mm-dd+## 0.1.0.0 -- 2017-12-03 * First version. Released on an unsuspecting world.++## 0.1.1 -- 2017-12-19++* Relax package bounds to accommodate GHC 8.0
microsoft-translator.cabal view
@@ -1,30 +1,39 @@ name: microsoft-translator-version: 0.1.0.0+version: 0.1.1 synopsis: Bindings to the Microsoft Translator API-description: Bindings to the Microsoft Translator API+description:+ Bindings to the text portion of the <https://www.microsoft.com/en-us/translator/products.aspx Microsoft Translator API>.+ .+ The service has a free tier allowing for 2 million translated characters per month.+ .+ The supported endpoints allow for translating (lists of) text, and provide+ sentence-break information about both the original and returned passages.+ license: MIT license-file: LICENSE author: Cliff Harvey maintainer: cs.hbar@gmail.com copyright: Cliff Harvey 2017+homepage: https://github.com/BlackBrane/microsoft-translator category: Natural Language build-type: Simple extra-source-files: ChangeLog.md cabal-version: >=1.10+tested-with: GHC == 8.0.2, GHC == 8.2.2 library - build-depends: base >= 4.10 && < 4.11- , servant >= 0.11 && < 0.12- , servant-client >= 0.11 && < 0.12+ build-depends: base >= 4.9 && < 4.11+ , servant >= 0.9 && < 0.13+ , servant-client >= 0.9 && < 0.13 , text >= 1.2 && < 1.3 , http-client >= 0.5 && < 0.6 , http-client-tls >= 0.3 && < 0.4- , http-media >= 0.7 && < 0.8+ , http-media >= 0.6 && < 0.8 , bytestring >= 0.10 && < 0.11 , http-api-data >= 0.3 && < 0.4 , mtl >= 2.2 && < 2.3- , time >= 1.8 && < 1.9+ , time >= 1.6 && < 1.9 , xml >= 1.3 && < 1.4 , safe >= 0.3 && < 0.4
src/Microsoft/Translator/API.hs view
@@ -6,6 +6,7 @@ {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} +-- | Servant types and client for the API module Microsoft.Translator.API ( basicTranslate@@ -40,8 +41,8 @@ import Text.XML.Light.Types -baseUrl :: BaseUrl-baseUrl = BaseUrl Https "api.microsofttranslator.com" 443 "/V2/Http.svc"+apiBaseUrl :: BaseUrl+apiBaseUrl = BaseUrl Https "api.microsofttranslator.com" 443 "/V2/Http.svc" -- | MS Microsoft.Translator API -- http://docs.microsofttranslator.com/text-translate.html#!/default/get_Translate@@ -156,18 +157,24 @@ arrayClient :: Maybe AuthToken -> ArrayRequest -> ClientM ArrayResponse transClient :<|> arrayClient = client (Proxy @ API) +-- | 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+-- 'Microsoft.Translator.translateIO'. See the README example. basicTranslate :: Manager -> AuthToken -> Maybe Language -> Language -> Text -> IO (Either TranslatorException Text) basicTranslate man tok from to txt = bimap APIException getTransText <$> runClientM (transClient (Just tok) (Just txt) from (Just to))- (ClientEnv man baseUrl)+ (ClientEnv man apiBaseUrl) +-- | 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+-- 'Microsoft.Translator.translateArrayIO'. See the README example. basicTranslateArray :: Manager -> AuthToken -> Language -> Language -> [Text] -> IO (Either TranslatorException ArrayResponse) basicTranslateArray man tok from to txts = bimap APIException id <$> runClientM (arrayClient (Just tok) (ArrayRequest from to txts))- (ClientEnv man baseUrl)+ (ClientEnv man apiBaseUrl)
src/Microsoft/Translator/API/Auth.hs view
@@ -7,6 +7,7 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} +-- | Servant types and client for the authorization API module Microsoft.Translator.API.Auth ( SubscriptionKey (..)
src/Microsoft/TranslatorExample.hs view
@@ -13,8 +13,7 @@ -- set your subscription key in the TRANSLATOR_SUBSCRIPTION_KEY environment var Right transData <- runExceptT (lookupSubKey >>= initTransData) forever $ do- T.putStr "> "+ T.putStr "\n> " str <- T.getLine Right txt <- translateIO transData Nothing ChineseTraditional str T.putStrLn txt- T.putStrLn ""