kykint

Support more languages

Showing 1 changed file with 6 additions and 6 deletions
...@@ -63,17 +63,17 @@ bot.on('message', (msg) => { ...@@ -63,17 +63,17 @@ bot.on('message', (msg) => {
63 var result = { type: 'text', text: '' }; 63 var result = { type: 'text', text: '' };
64 64
65 // Check if detection was successful 65 // Check if detection was successful
66 - console.log(detect_body.langCode); 66 + console.log('Language detected: ' + detect_body.langCode);
67 67
68 - // Translate using papago, only Korean and English are supported atm 68 + // Translate using papago
69 - if (detect_body.langCode == 'ko' || detect_body.langCode == 'en') { 69 + // Target defaults to English for Korean source, or Korean for all other langs
70 - source = detect_body.langCode == 'ko' ? 'ko' : 'en'; 70 + if (detect_body.langCode != 'unk') {
71 + source = detect_body.langCode;
71 target = source == 'ko' ? 'en' : 'ko'; 72 target = source == 'ko' ? 'en' : 'ko';
72 73
73 // Papago translation options 74 // Papago translation options
74 var translate_options = { 75 var translate_options = {
75 url: translate_api_url, 76 url: translate_api_url,
76 - // 한국어(source : ko), 영어(target: en), 카톡에서 받는 메시지(text)
77 form: { 77 form: {
78 'source': source, // Translate from source 78 'source': source, // Translate from source
79 'target': target, // to target 79 'target': target, // to target
...@@ -100,7 +100,7 @@ bot.on('message', (msg) => { ...@@ -100,7 +100,7 @@ bot.on('message', (msg) => {
100 } 100 }
101 // Language not detected 101 // Language not detected
102 else { 102 else {
103 - result.text = '언어를 감지할 수 없습니다. \n 번역 언어는 한글 또는 영어만 가능합니다.'; 103 + result.text = '언어를 감지할 수 없습니다.';
104 bot.sendMessage(chatId, result.text); 104 bot.sendMessage(chatId, result.text);
105 } 105 }
106 } 106 }
......