def translate_report(report_id): report = Report.query.get(report_id) api = UnbabelApi(username=app.config['UNBABEL_USERNAME'], api_key=app.config['UNBABEL_API_KEY'], sandbox=True) callback_url = '{}/translate_report_callback/{}'.format( app.config['ROOT_URL'], report_id) api.post_translations(text=report.original_text, source_language=report.original_language, target_language='en', callback_url=callback_url)
def test_unbabelAPI(self): api = UnbabelApi( username=TestConfig.UNBABEL_SANDBOX_USERNAME, api_key=TestConfig.UNBABEL_SANDBOX_KEY, sandbox=True, ) response = api.post_translations( text='Test translation', target_language='es', source_language='en', ) # Testing response fields self.assertEqual(response.status, 'new') self.assertTrue(response.uid) self.assertEqual(response.target_language, 'es') self.assertEqual(response.source_language, 'en') # Testing unused fields consistency self.assertIsNone(response.translation) self.assertIsNone(response.client) self.assertIsNone(response.balance) self.assertIsNone(response.order_number) self.assertIsNone(response.origin) self.assertIsNone(response.price_plan) self.assertIsNone(response.topics) self.assertTrue(response.price) self.assertEqual(response.translators, []) # Testing formats self.assertEqual(response.text_format, 'text') self.assertIn('Test translation', response.text)
def translate_tweet(tweet, target_lang): api = UnbabelApi(username=UNBABEL_USER,api_key=UNBABEL_KEY,sandbox=True) status = api.post_translations(text=str(tweet),target_language=target_lang, callback_url='http://twitterfishing.herokuapp.com/fish/handle_translation/') uid = status.uid return uid