Skip to content

Commit d2230a7

Browse files
authored
feat: lang config loaded by file name (#187)
1 parent f268b23 commit d2230a7

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

api/config.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,27 +192,18 @@ def load_lang_config():
192192
},
193193
"default": "en"
194194
}
195-
try:
196-
# If environment variable is set, use the directory specified by it
197-
if CONFIG_DIR:
198-
config_path = Path(CONFIG_DIR) / "lang.json"
199-
else:
200-
# Otherwise use default directory
201-
config_path = Path(__file__).parent / "config" / "lang.json"
202195

203-
logger.info(f"Loading language configuration from {config_path}")
196+
loaded_config = load_json_config("lang.json") # Let load_json_config handle path and loading
204197

205-
if not config_path.exists():
206-
logger.warning(f"Language configuration file {config_path} does not exist")
207-
return default_config
208-
return load_json_config(config_path)
209-
except json.JSONDecodeError as e:
210-
logger.error(f"Error decoding JSON from language configuration file {config_path}: {str(e)}")
198+
if not loaded_config:
211199
return default_config
212-
except Exception as e:
213-
logger.error(f"Error loading language configuration file {config_path}: {str(e)}")
200+
201+
if "supported_languages" not in loaded_config or "default" not in loaded_config:
202+
logger.warning("Language configuration file 'lang.json' is malformed. Using default language configuration.")
214203
return default_config
215204

205+
return loaded_config
206+
216207
# Default excluded directories and files
217208
DEFAULT_EXCLUDED_DIRS: List[str] = [
218209
# Virtual environments and package managers

0 commit comments

Comments
 (0)