; A translation script for HexDroid ; Translations appear underneath the original as a "↳ ..." line. ; Network to the LibreTranslate endpoint must be permitted by the host. ; Point %ep at your own self-hosted LibreTranslate for privacy/no rate limits. on LOAD { set %lang $setting(applang) if ($len(%lang) == 0) { set %lang en } ; ===== EDIT THESE === set %ep https://libretranslate.com/translate ; your LibreTranslate endpoint set %apikey ; API key (blank = self-hosted) } ; auto-translate every incoming line that isn't ours; thread the buffer + the ; original text through as context ($1 = buffer, $2- = original) so the callback ; can place the result and skip same-language messages. on TEXT { if ($isme == false) { if ($len(%apikey) > 0) { http.post %ep q=$urlencode($text)&source=auto&target=%lang&api_key=%apikey tr_auto $buffer $text } else { http.post %ep q=$urlencode($text)&source=auto&target=%lang tr_auto $buffer $text } } } on SIGNAL:tr_auto { if ($httpok == true) { set %out $json($httpbody,translatedText) if ($len(%out) > 0) { if (%out != $2-) { echo $1 ↳ %out } } } } ; manual: /tr alias tr { if ($len(%apikey) > 0) { http.post %ep q=$urlencode($1-)&source=auto&target=%lang&api_key=%apikey tr_show $chan } else { http.post %ep q=$urlencode($1-)&source=auto&target=%lang tr_show $chan } } on SIGNAL:tr_show { if ($httpok == true) { echo $1 ↳ $json($httpbody,translatedText) } else { echo $1 *** translate failed ($httpstatus) } }