@@ -177,21 +177,7 @@ def collect_longrepr_from_multiple_reports(pytest_json_report_paths:Tuple[pathli
177177
178178@functools .lru_cache
179179def 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
197183def 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
209195def 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
230203def 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
250210def 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
289219def 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
334234def 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 ())
0 commit comments