File size: 856 Bytes
dc9f7f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# languages.py

import json
import os

# Path to the languages JSON file
LANGUAGES_JSON_PATH = os.path.join(os.path.dirname(__file__), 'languages.json')

def load_languages():
    """
    Loads the list of languages from the JSON file.
    Returns a list of language dictionaries.
    """
    try:
        with open(LANGUAGES_JSON_PATH, 'r', encoding='utf-8') as file:
            data = json.load(file)
            return data.get('languages', [])
    except FileNotFoundError:
        print(f"Error: {LANGUAGES_JSON_PATH} not found.")
        return []
    except json.JSONDecodeError as e:
        print(f"Error parsing {LANGUAGES_JSON_PATH}: {e}")
        return []

# Load languages at module import
LANGUAGES = load_languages()

# Create a dictionary for quick access (code -> name)
LANGUAGE_DICT = {lang['code']: lang['name'] for lang in LANGUAGES}