Update chatbot/plugins/languages.py
Browse files- chatbot/plugins/languages.py +29 -8
chatbot/plugins/languages.py
CHANGED
@@ -1,8 +1,29 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# languages.py
|
2 |
+
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Path to the languages JSON file
|
7 |
+
LANGUAGES_JSON_PATH = os.path.join(os.path.dirname(__file__), 'languages.json')
|
8 |
+
|
9 |
+
def load_languages():
|
10 |
+
"""
|
11 |
+
Loads the list of languages from the JSON file.
|
12 |
+
Returns a list of language dictionaries.
|
13 |
+
"""
|
14 |
+
try:
|
15 |
+
with open(LANGUAGES_JSON_PATH, 'r', encoding='utf-8') as file:
|
16 |
+
data = json.load(file)
|
17 |
+
return data.get('languages', [])
|
18 |
+
except FileNotFoundError:
|
19 |
+
print(f"Error: {LANGUAGES_JSON_PATH} not found.")
|
20 |
+
return []
|
21 |
+
except json.JSONDecodeError as e:
|
22 |
+
print(f"Error parsing {LANGUAGES_JSON_PATH}: {e}")
|
23 |
+
return []
|
24 |
+
|
25 |
+
# Load languages at module import
|
26 |
+
LANGUAGES = load_languages()
|
27 |
+
|
28 |
+
# Create a dictionary for quick access (code -> name)
|
29 |
+
LANGUAGE_DICT = {lang['code']: lang['name'] for lang in LANGUAGES}
|