# 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}