Skip to content

Commit e94d2a0

Browse files
committed
add load_locale()
1 parent f2f2af9 commit e94d2a0

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

ai_tutor.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,16 @@ def assignment_code(student_files:Tuple[pathlib.Path]) -> str:
333333
@functools.lru_cache
334334
def assignment_instruction(readme_file:pathlib.Path) -> str:
335335
return readme_file.read_text()
336+
337+
338+
@functools.lru_cache(maxsize=None)
339+
def load_locale(explain_in:str) -> Dict[str, str]:
340+
locale_folder = pathlib.Path(__file__).parent/'locale'
341+
assert locale_folder.exists(), f"Locale folder not found: {locale_folder}"
342+
assert locale_folder.is_dir(), f"Locale folder is not a directory: {locale_folder}"
343+
344+
locale_file = locale_folder/f'{explain_in}.json'
345+
assert locale_file.exists(), f"Locale file not found: {locale_file}"
346+
assert locale_file.is_file(), f"Locale file is not a file: {locale_file}"
347+
348+
return json.loads(locale_file.read_text())

0 commit comments

Comments
 (0)