randydev commited on
Commit
dc9f7f9
·
verified ·
1 Parent(s): 9627e8d

Update chatbot/plugins/languages.py

Browse files
Files changed (1) hide show
  1. chatbot/plugins/languages.py +29 -8
chatbot/plugins/languages.py CHANGED
@@ -1,8 +1,29 @@
1
- LANGUAGES = {
2
- "en": "English",
3
- "id": "Indonesian",
4
- "es": "Spanish",
5
- "fr": "French",
6
- "de": "German",
7
- "jp": "Japanese",
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}