Skip to content

Commit

Permalink
fix: 채팅 번역이 안되는 경우 처리
Browse files Browse the repository at this point in the history
- 채팅에 번역이 안되는 문장이 있을 경우 원래 문자열이 반환된다.
  • Loading branch information
zzawang authored and JYKIM317 committed Dec 5, 2024
1 parent fca33bd commit 432f4c2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions chatServer/utils/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ async function translate(text, lang?) {
if (results[idx].match(/event:result/)) {
const result = results[idx].match(/data:(.+)/);
const data = JSON.parse(result[1]);
const translates = data.message.content.split('\n').reduce((obj, cur) => {
const content = data.message.content;

const translates = content.split('\n').reduce((obj, cur) => {
const [key, value] = cur.split(':');
if (!translationMap.has(key)) return obj;
obj[key.trim()] = value.trim();
return obj;
}, {});

return translates[translationMap.get(lang)];
return translates[translationMap.get(lang)] ?? text;
}
}

Expand Down

0 comments on commit 432f4c2

Please sign in to comment.