Fix encoding issue when loading i18n json file (#1341)

Co-authored-by: João Moura <joaomdmoura@gmail.com>
This commit is contained in:
Mr. Guo
2024-09-23 15:01:35 +08:00
committed by GitHub
parent 73497596ae
commit d43135ca45

View File

@@ -17,13 +17,13 @@ class I18N(BaseModel):
"""Load prompts from a JSON file."""
try:
if self.prompt_file:
with open(self.prompt_file, "r") as f:
with open(self.prompt_file, "r", encoding="utf-8") as f:
self._prompts = json.load(f)
else:
dir_path = os.path.dirname(os.path.realpath(__file__))
prompts_path = os.path.join(dir_path, "../translations/en.json")
with open(prompts_path, "r") as f:
with open(prompts_path, "r", encoding="utf-8") as f:
self._prompts = json.load(f)
except FileNotFoundError:
raise Exception(f"Prompt file '{self.prompt_file}' not found.")