Added get_language instead of config.get("LANGUGE")

This commit is contained in:
Mathieu B 2021-07-27 16:27:55 +02:00
parent 775e0fbfdf
commit 2990a9e464
4 changed files with 17 additions and 10 deletions

View File

@ -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):

View File

@ -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()

View File

@ -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)

View File

@ -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)