Added get_language instead of config.get("LANGUGE")
This commit is contained in:
parent
775e0fbfdf
commit
2990a9e464
@ -17,9 +17,9 @@ def tokenize(sentence):
|
|||||||
# English, Danish, Estonian, French, Greek, Norwegian, Portuguese, Spanish, Turkish,
|
# English, Danish, Estonian, French, Greek, Norwegian, Portuguese, Spanish, Turkish,
|
||||||
# Czech, Dutch, Finnish, German, Italian, Polish, Slovene, and Swedish
|
# 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,
|
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):
|
def stem(word):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import requests as requests
|
import requests as requests
|
||||||
|
|
||||||
from utils import config_utils
|
from utils import languages_utils
|
||||||
|
|
||||||
|
|
||||||
def tell_me_a_joke():
|
def tell_me_a_joke():
|
||||||
@ -8,7 +8,7 @@ def tell_me_a_joke():
|
|||||||
# response = intents_utils.get_response(tag)
|
# response = intents_utils.get_response(tag)
|
||||||
|
|
||||||
# french jokes
|
# 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
|
# the token used might be revoked at any time, please register on www.blagues-api.fr and replace it
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
'https://www.blagues-api.fr/api/random',
|
'https://www.blagues-api.fr/api/random',
|
||||||
@ -24,7 +24,7 @@ def tell_me_a_joke():
|
|||||||
return joke + " /pause:2s/ " + answer
|
return joke + " /pause:2s/ " + answer
|
||||||
|
|
||||||
# english jokes
|
# 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')
|
response = requests.get('https://v2.jokeapi.dev/joke/Any?type=twopart')
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import os
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
import get_path_file
|
import get_path_file
|
||||||
from utils import config_utils
|
from utils import languages_utils
|
||||||
|
|
||||||
all_intents = dict()
|
all_intents = dict()
|
||||||
path = os.path.dirname(get_path_file.__file__)
|
path = os.path.dirname(get_path_file.__file__)
|
||||||
@ -78,12 +78,10 @@ def get_responses(intent_tag):
|
|||||||
|
|
||||||
|
|
||||||
def get_lang_for_intent(intent_tag):
|
def get_lang_for_intent(intent_tag):
|
||||||
language = config_utils.get_in_config('LANGUAGE')
|
|
||||||
|
|
||||||
# first we check the intent
|
# first we check the intent
|
||||||
if exists(intent_tag):
|
if exists(intent_tag):
|
||||||
lang_path = str(get_all_intents().get(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):
|
if os.path.exists(lang_path):
|
||||||
lang_file = open(lang_path)
|
lang_file = open(lang_path)
|
||||||
|
@ -2,14 +2,23 @@ import json
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import get_path_file
|
import get_path_file
|
||||||
|
from utils import config_utils
|
||||||
|
|
||||||
path = os.path.dirname(get_path_file.__file__)
|
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)
|
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'))
|
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:
|
if name in config_json:
|
||||||
return config_json.get(name)
|
return config_json.get(name)
|
||||||
|
Reference in New Issue
Block a user