From 2990a9e464ed4b4537f4c69f9da34e6b46214dbc Mon Sep 17 00:00:00 2001 From: Mathieu B Date: Tue, 27 Jul 2021 16:27:55 +0200 Subject: [PATCH] Added get_language instead of config.get("LANGUGE") --- ia/nltk_utils.py | 4 ++-- skills/entertainement/jokes/intent.py | 6 +++--- utils/intents_utils.py | 6 ++---- utils/languages_utils.py | 11 ++++++++++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ia/nltk_utils.py b/ia/nltk_utils.py index bdf69bf..ecfa341 100644 --- a/ia/nltk_utils.py +++ b/ia/nltk_utils.py @@ -17,9 +17,9 @@ def tokenize(sentence): # English, Danish, Estonian, French, Greek, Norwegian, Portuguese, Spanish, Turkish, # Czech, Dutch, Finnish, German, Italian, Polish, Slovene, and Swedish - print(languages_utils.get_language_name(config_utils.get_in_config("LANGUAGE"))) + print(languages_utils.get_language_full_name()) return nltk.word_tokenize(sentence, - language=languages_utils.get_language_name(config_utils.get_in_config("LANGUAGE"))) + language=languages_utils.get_language_full_name()) def stem(word): diff --git a/skills/entertainement/jokes/intent.py b/skills/entertainement/jokes/intent.py index e54a015..c490434 100644 --- a/skills/entertainement/jokes/intent.py +++ b/skills/entertainement/jokes/intent.py @@ -1,6 +1,6 @@ import requests as requests -from utils import config_utils +from utils import languages_utils def tell_me_a_joke(): @@ -8,7 +8,7 @@ def tell_me_a_joke(): # response = intents_utils.get_response(tag) # french jokes - if config_utils.get_in_config("LANGUAGE").startswith("fr-"): + if languages_utils.get_language().startswith("fr-"): # the token used might be revoked at any time, please register on www.blagues-api.fr and replace it response = requests.get( 'https://www.blagues-api.fr/api/random', @@ -24,7 +24,7 @@ def tell_me_a_joke(): return joke + " /pause:2s/ " + answer # english jokes - elif config_utils.get_in_config("LANGUAGE").startswith("en-"): + elif languages_utils.get_language().startswith("en-"): response = requests.get('https://v2.jokeapi.dev/joke/Any?type=twopart') data = response.json() diff --git a/utils/intents_utils.py b/utils/intents_utils.py index 890f82b..5f23a27 100644 --- a/utils/intents_utils.py +++ b/utils/intents_utils.py @@ -4,7 +4,7 @@ import os import random import get_path_file -from utils import config_utils +from utils import languages_utils all_intents = dict() path = os.path.dirname(get_path_file.__file__) @@ -78,12 +78,10 @@ def get_responses(intent_tag): def get_lang_for_intent(intent_tag): - language = config_utils.get_in_config('LANGUAGE') - # first we check the intent if exists(intent_tag): lang_path = str(get_all_intents().get(intent_tag)) - lang_path = lang_path + 'lang/' + language + '.json' + lang_path = lang_path + 'lang/' + languages_utils.get_language() + '.json' if os.path.exists(lang_path): lang_file = open(lang_path) diff --git a/utils/languages_utils.py b/utils/languages_utils.py index 046773d..531ff4f 100644 --- a/utils/languages_utils.py +++ b/utils/languages_utils.py @@ -2,14 +2,23 @@ import json import os import get_path_file +from utils import config_utils path = os.path.dirname(get_path_file.__file__) -def get_language_name(name): +def get_language(): + return config_utils.get_in_config("LANGUAGE") + + +def get_language_full_name(name=None): """ Return for exemple french for fr-fr, english for en-en, etc (savec in languages.json in the config folder) """ config_json = json.load(open(path + "/config/languages.json", encoding='utf-8', mode='r')) + + if name is None: + name = get_language() + if name in config_json: return config_json.get(name)