Skip to content

Commit 1dee51a

Browse files
authored
Merge pull request #10 from kangwonlee/feature/locale-json
Feature/locale json
2 parents 521ef17 + d362ed2 commit 1dee51a

18 files changed

+196
-140
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
!entrypoint.py
44
!requirements.txt
55
!ai_tutor.py
6+
!locale/*.json

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111

1212
### Changed
13-
* move README before pytest longrepr
1413

1514

1615
### Deprecated
@@ -22,6 +21,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2221
### Fixed
2322

2423

24+
## [v0.1.5] - 2024-10-20
25+
26+
### Added
27+
* Swedish support
28+
29+
### Changed
30+
* move README before pytest longrepr
31+
32+
2533
## [v0.1.4] - 2024-10-09
2634

2735
### Added

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ FROM cicirello/pyaction:4
1515
COPY entrypoint.py /entrypoint.py
1616
COPY requirements.txt /requirements.txt
1717
COPY ai_tutor.py /ai_tutor.py
18+
COPY locale/ /locale/
1819

1920
RUN python3 -m pip install --upgrade pip
2021
RUN python3 -m pip install -r /requirements.txt

ai_tutor.py

Lines changed: 22 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,7 @@ def collect_longrepr_from_multiple_reports(pytest_json_report_paths:Tuple[pathli
177177

178178
@functools.lru_cache
179179
def get_directive(explanation_in:str) -> str:
180-
d = {
181-
'Korean': '숙제 답안으로 제출한 코드가 오류를 일으킨 원인을 입문자 용어만으로 중복 없는 간결한 문장으로 설명하시오.',
182-
'English': 'Explain in beginner terms, without duplicates, the cause of the error in the code submitted as homework.',
183-
'Bahasa Indonesia': 'Jelaskan dalam istilah pemula, tanpa duplikat, penyebab kesalahan dalam kode yang dikirim sebagai pekerjaan rumah.',
184-
'Chinese': '请用初学者术语简洁地解释作业提交的代码出错的原因,不要重复。',
185-
'French': '''Expliquez en termes de débutant, sans doublons, la cause de l'erreur dans le code soumis comme devoir.''',
186-
'German': 'Erklären Sie in Anfängerterminologie ohne Duplikate die Ursache des Fehlers im als Hausaufgabe eingereichten Code.',
187-
'Italian': 'Spiega in termini per principianti, senza duplicati, la causa dell\'errore nel codice inviato come compito.',
188-
'Japanese': '宿題の回答として提出されたコードがエラーの原因を、初心者向けの用語で重複なく簡潔に説明してください。',
189-
'Nederlands': 'Leg in beginners termen, zonder duplicaten, de oorzaak van de fout in de code die als huiswerk is ingediend uit.',
190-
'Spanish': 'Explique en términos para principiantes, sin duplicados, la causa del error en el código enviado como tarea.',
191-
'Thai': 'อธิบายด้วยภาษาของผู้เริ่มต้นโดยไม่ซ้ำซ้อนว่าสาเหตุของข้อผิดพลาดในรหัสที่ส่งเป็นการบ้านคืออะไร',
192-
'Vietnamese': 'Hãy giải thích lỗi trong đoạn mã bài tập đã nộp bằng ngôn ngữ dễ hiểu dành cho người mới bắt đầu, và đừng lặp lại thông tin.',
193-
}
194-
return f"{d[explanation_in]}\n"
180+
return f"{load_locale(explanation_in)['directive']}\n"
195181

196182

197183
def collect_longrepr(data:Dict[str, str]) -> List[str]:
@@ -207,121 +193,35 @@ def collect_longrepr(data:Dict[str, str]) -> List[str]:
207193

208194
@functools.lru_cache
209195
def get_report_header(explanation_in:str) -> str:
210-
d = {
211-
'Korean': "오류 메시지 시작",
212-
'English': "Error Message Start",
213-
'Bahasa Indonesia': "Pesan Kesalahan Dimulai",
214-
'Chinese': "错误消息开始",
215-
'French': '''Message d'erreur commence''',
216-
'German': "Fehlermeldung beginnt",
217-
'Italian': "Messaggio di errore inizia",
218-
'Japanese': "エラーメッセージ開始",
219-
'Nederlands': "Foutmelding begint",
220-
'Spanish': "Mensaje de error comienza",
221-
'Thai': "ข้อความผิดพลาดเริ่มต้น",
222-
'Vietnamese': "Thông báo lỗi bắt đầu",
223-
}
196+
224197
return (
225-
f"## {d[explanation_in]}\n"
198+
f"## {load_locale(explanation_in)['report_header']}\n"
226199
)
227200

228201

229202
@functools.lru_cache
230203
def get_report_footer(explanation_in:str) -> str:
231-
d = {
232-
'Korean': "오류 메시지 끝",
233-
'English': "Error Message End",
234-
'Bahasa Indonesia': "Pesan Kesalahan Berakhir",
235-
'Chinese': "错误消息结束",
236-
'French': '''Message d'erreur fin''',
237-
'German': "Fehlermeldung endet",
238-
'Italian': "Messaggio di errore finisce",
239-
'Japanese': "エラーメッセージ終わり",
240-
'Nederlands': "Foutmelding eindigt",
241-
'Spanish': "Mensaje de error termina",
242-
'Thai': "ข้อความผิดพลาดสิ้นสุด",
243-
'Vietnamese': "Thông báo lỗi kết thúc",
244-
}
204+
245205
return (
246-
f"## {d[explanation_in]}\n"
206+
f"## {load_locale(explanation_in)['report_footer']}\n"
247207
)
248208

249209

250210
def get_instruction_block(readme_file:pathlib.Path, explanation_in:str='Korean',) -> str:
251211

252-
d_instruction_start = {
253-
'Korean': "과제 지침 시작",
254-
'English': "Assignment Instruction Start",
255-
'Bahasa Indonesia': "Instruksi Tugas Dimulai",
256-
'Chinese': "作业说明开始",
257-
'French': '''Début de l'instruction de la tâche''',
258-
'German': "Start der Aufgabenanweisung",
259-
'Italian': "Inizio dell'istruzione dell'assegnazione",
260-
'Japanese': "課題指示開始",
261-
'Nederlands': "Start van de taakinstructie",
262-
'Spanish': "Inicio de la instrucción de la tarea",
263-
'Thai': "คำแนะนำการบ้านเริ่มต้น",
264-
'Vietnamese': "Bắt đầu hướng dẫn nhiệm vụ",
265-
}
266-
267-
d_instruction_end = {
268-
'Korean': "과제 지침 끝",
269-
'English': "Assignment Instruction End",
270-
'Bahasa Indonesia': "Instruksi Tugas Berakhir",
271-
'Chinese': "作业说明结束",
272-
'French': '''Fin de l'instruction de la tâche''',
273-
'German': "Ende der Aufgabenanweisung",
274-
'Italian': "Fine dell'istruzione dell'assegnazione",
275-
'Japanese': "課題指示終わり",
276-
'Nederlands': "Einde van de taakinstructie",
277-
'Spanish': "Fin de la instrucción de la tarea",
278-
'Thai': "คำแนะนำการบ้านสิ้นสุด",
279-
'Vietnamese': "Kết thúc hướng dẫn nhiệm vụ",
280-
}
281-
282212
return (
283-
f"## {d_instruction_start[explanation_in]}\n"
213+
f"## {load_locale(explanation_in)['instruction_start']}\n"
284214
f"{assignment_instruction(readme_file)}\n"
285-
f"## {d_instruction_end[explanation_in]}\n"
215+
f"## {load_locale(explanation_in)['instruction_end']}\n"
286216
)
287217

288218

289219
def get_student_code_block(student_files:Tuple[pathlib.Path], explanation_in:str) -> str:
290220

291-
d_homework_start = {
292-
'Korean': "숙제 제출 코드 시작",
293-
'English': "Homework Submission Code Start",
294-
'Bahasa Indonesia': "Kode Pengumpulan Tugas Dimulai",
295-
'Chinese': "作业提交代码开始",
296-
'French': '''Début du code de soumission des devoirs''',
297-
'German': "Code für die Einreichung von Hausaufgaben von hier aus",
298-
'Italian': "Inizio del codice di invio dei compiti",
299-
'Japanese': "宿題提出コード開始",
300-
'Nederlands': "Huiswerk inzendcode begint",
301-
'Spanish': "Inicio del código de envío de tareas",
302-
'Thai': "เริ่มส่งรหัสการบ้าน",
303-
'Vietnamese': "Bắt đầu mã nộp bài tập",
304-
}
305-
306-
d_homework_end = {
307-
'Korean': "숙제 제출 코드 끝",
308-
'English': "Homework Submission Code End",
309-
'Bahasa Indonesia': "Kode Pengumpulan Tugas Berakhir",
310-
'Chinese': "作业提交代码结束",
311-
'French': '''Fin du code de soumission des devoirs''',
312-
'German': "Ende der Hausaufgaben-Einreichungscodes",
313-
'Italian': "Fine del codice di invio dei compiti",
314-
'Japanese': "宿題提出コード終わり",
315-
'Nederlands': "Huiswerk inzendcode eindigt",
316-
'Spanish': "Fin del código de envío de tareas",
317-
'Thai': "จบรหัสส่งการบ้าน",
318-
'Vietnamese': "Mã nộp bài tập kết thúc",
319-
}
320-
321221
return (
322-
f"\n\n## {d_homework_start[explanation_in]}\n"
222+
f"\n\n## {load_locale(explanation_in)['homework_start']}\n"
323223
f"{assignment_code(student_files)}\n"
324-
f"## {d_homework_end[explanation_in]}\n"
224+
f"## {load_locale(explanation_in)['homework_end']}\n"
325225
)
326226

327227

@@ -333,3 +233,16 @@ def assignment_code(student_files:Tuple[pathlib.Path]) -> str:
333233
@functools.lru_cache
334234
def assignment_instruction(readme_file:pathlib.Path) -> str:
335235
return readme_file.read_text()
236+
237+
238+
@functools.lru_cache(maxsize=None)
239+
def load_locale(explain_in:str) -> Dict[str, str]:
240+
locale_folder = pathlib.Path(__file__).parent/'locale'
241+
assert locale_folder.exists(), f"Locale folder not found: {locale_folder}"
242+
assert locale_folder.is_dir(), f"Locale folder is not a directory: {locale_folder}"
243+
244+
locale_file = locale_folder/f'{explain_in}.json'
245+
assert locale_file.exists(), f"Locale file not found: {locale_file}"
246+
assert locale_file.is_file(), f"Locale file is not a file: {locale_file}"
247+
248+
return json.loads(locale_file.read_text())

locale/Bahasa Indonesia.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"directive": "Jelaskan dalam istilah pemula, tanpa duplikat, penyebab kesalahan dalam kode yang dikirim sebagai pekerjaan rumah.",
3+
"report_header": "Pesan Kesalahan Dimulai",
4+
"report_footer": "Pesan Kesalahan Berakhir",
5+
"instruction_start": "Instruksi Tugas Dimulai",
6+
"instruction_end": "Instruksi Tugas Berakhir",
7+
"homework_start": "Kode Pengumpulan Tugas Dimulai",
8+
"homework_end": "Kode Pengumpulan Tugas Berakhir"
9+
}

locale/Chinese.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"directive": "请用初学者术语简洁地解释作业提交的代码出错的原因,不要重复。",
3+
"report_header": "错误消息开始",
4+
"report_footer": "错误消息结束",
5+
"instruction_start": "作业说明开始",
6+
"instruction_end": "作业说明结束",
7+
"homework_start": "作业提交代码开始",
8+
"homework_end": "作业提交代码结束"
9+
}

locale/English.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"directive": "Explain in beginner terms, without duplicates, the cause of the error in the code submitted as homework.",
3+
"report_header": "Error Message Start",
4+
"report_footer": "Error Message End",
5+
"instruction_start": "Assignment Instruction Start",
6+
"instruction_end": "Assignment Instruction End",
7+
"homework_start": "Homework Submission Code Start",
8+
"homework_end": "Homework Submission Code End"
9+
}

locale/French.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"directive": "Expliquez en termes de débutant, sans doublons, la cause de l'erreur dans le code soumis comme devoir.",
3+
"report_header": "Message d'erreur commence",
4+
"report_footer": "Message d'erreur fin",
5+
"instruction_start": "Début de l'instruction de la tâche",
6+
"instruction_end": "Fin de l'instruction de la tâche",
7+
"homework_start": "Début du code de soumission des devoirs",
8+
"homework_end": "Fin du code de soumission des devoirs"
9+
}

locale/German.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"directive": "Erklären Sie in Anfängerterminologie ohne Duplikate die Ursache des Fehlers im als Hausaufgabe eingereichten Code.",
3+
"report_header": "Fehlermeldung beginnt",
4+
"report_footer": "Fehlermeldung endet",
5+
"instruction_start": "Start der Aufgabenanweisung",
6+
"instruction_end": "Ende der Aufgabenanweisung",
7+
"homework_start": "Code für die Einreichung von Hausaufgaben von hier aus",
8+
"homework_end": "Ende der Hausaufgaben-Einreichungscodes"
9+
}

locale/Italian.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"directive": "Spiega in termini per principianti, senza duplicati, la causa dell'errore nel codice inviato come compito.",
3+
"report_header": "Messaggio di errore inizia",
4+
"report_footer": "Messaggio di errore finisce",
5+
"instruction_start": "Inizio dell'istruzione dell'assegnazione",
6+
"instruction_end": "Fine dell'istruzione dell'assegnazione",
7+
"homework_start": "Inizio del codice di invio dei compiti",
8+
"homework_end": "Fine del codice di invio dei compiti"
9+
}

0 commit comments

Comments
 (0)