Translate.hex

mIRC Scripting Guest 9 Views Size: 1.55 KB Posted on: Jun 27, 26 @ 4:35 PM
  1. ; A translation script for HexDroid
  2. ; Translations appear underneath the original as a "↳ ..." line.
  3. ; Network to the LibreTranslate endpoint must be permitted by the host.
  4. ; Point %ep at your own self-hosted LibreTranslate for privacy/no rate limits.
  5.  
  6. on LOAD {
  7.   set %lang $setting(applang)
  8.   if ($len(%lang) == 0) { set %lang en }
  9.   ; ===== EDIT THESE ===
  10.   set %ep https://libretranslate.com/translate   ; your LibreTranslate endpoint
  11.   set %apikey                                     ; API key (blank = self-hosted)
  12. }
  13.  
  14. ; auto-translate every incoming line that isn't ours; thread the buffer + the
  15. ; original text through as context ($1 = buffer, $2- = original) so the callback
  16. ; can place the result and skip same-language messages.
  17. on TEXT {
  18.   if ($isme == false) {
  19.     if ($len(%apikey) > 0) { http.post %ep q=$urlencode($text)&source=auto&target=%lang&api_key=%apikey tr_auto $buffer $text }
  20.     else { http.post %ep q=$urlencode($text)&source=auto&target=%lang tr_auto $buffer $text }
  21.   }
  22. }
  23.  
  24. on SIGNAL:tr_auto {
  25.   if ($httpok == true) {
  26.     set %out $json($httpbody,translatedText)
  27.     if ($len(%out) > 0) { if (%out != $2-) { echo $1%out } }
  28.   }
  29. }
  30.  
  31. ; manual: /tr <text>
  32. alias tr {
  33.   if ($len(%apikey) > 0) { http.post %ep q=$urlencode($1-)&source=auto&target=%lang&api_key=%apikey tr_show $chan }
  34.   else { http.post %ep q=$urlencode($1-)&source=auto&target=%lang tr_show $chan }
  35. }
  36. on SIGNAL:tr_show {
  37.   if ($httpok == true) { echo $1$json($httpbody,translatedText) }
  38.   else { echo $1 *** translate failed ($httpstatus) }
  39. }

Raw Paste

Comments 0
Login to post a comment.
  • No comments yet. Be the first.
Login to post a comment. Login or Register
We use cookies. To comply with GDPR in the EU and the UK we have to show you these.

We use cookies and similar technologies to keep this website functional (including spam protection via Google reCAPTCHA or Cloudflare Turnstile), and — with your consent — to measure usage and show ads. See Privacy.