From aeaba9bcc55cb18d09f86f98f1a2c29e648e7305 Mon Sep 17 00:00:00 2001 From: samerbam Date: Tue, 5 Sep 2023 11:11:21 -0400 Subject: [PATCH] added in some comments --- backend/skills/translations.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/skills/translations.py b/backend/skills/translations.py index 4034464..10ed1f0 100644 --- a/backend/skills/translations.py +++ b/backend/skills/translations.py @@ -3,12 +3,21 @@ from skills.config import deepl_api_key from skills.config import google_api_key +""" +Reading material for this: + +https://www.deepl.com/en/docs-api +https://cloud.google.com/translate/docs/overview +""" + class Translations: def __init__(self): self.trigger_phrase = "translate" + + # These vars would be good canidates for a future monitoring dashboard self.total_chars_translated = 0 self.deepl_chars_translated = 0 - self.googl_chars_translated = 0 #only increment if successful translation (according to api, it only counts towards the quota if you ) + self.googl_chars_translated = 0 #only increment if api charged for the characters (read docs to figure this out) self.free_monthly_char_limit_googl = 500000 self.free_monthly_char_limit_deepl = 500000 self.supported_deepl_langs = ["list of supported languages"] @@ -24,6 +33,8 @@ class Translations: def translate_deepl(self, text, language): + self.deepl_chars_translated += len(text) + headers = { 'Authorization': 'DeepL-Auth-Key ' + deepl_api_key, 'Content-Type': 'application/json', @@ -36,8 +47,13 @@ class Translations: response = requests.post('https://api-free.deepl.com/v2/translate', headers=headers, json=json_data) + return response + def translate_google(self, text, language): - pass #TODO: add in google translate api, probably using python client library for google api + self.google_chars_translated += len(text) + + + return "" #TODO: add in google translate api, probably using python client library for google api def translate(self, text):