Sha256: 027c358cc28eefca662d99cb6226b3ff1e999b449da7e43f1b4cd5d7871ea210

Contents?: true

Size: 1021 Bytes

Versions: 2

Compression:

Stored size: 1021 Bytes

Contents

autotranslatingClicked = 0

$(document).on 'ready page:load', ->
  $( "#container div.translations" ).prepend( "<div id='autotranslate' style='text-align: right;'><button> Start autotranslating!</button></div>" )
  $('div#autotranslate').on 'click', 'button', ->
    startTranslating()

startTranslating = () ->
  autotranslatingClicked += 1
  to_lang = document.URL.split('/').slice(-1).pop()
  $translation_rows = $('table.translations tbody tr:not(:first-child)')
  for $translation_row in $translation_rows
    original = $translation_row.querySelector('td.original textarea#translations__original_text').innerText
    $translationArea = $translation_row.querySelector('td.translation textarea')
    if $translationArea.innerText == '' && autotranslatingClicked == 1
      translate(original, to_lang, $translationArea)

translate = (original, to, textarea) ->
  $.get '/translate', {original: original, to: to}, ((response) ->
    if response.status == 200
      textarea.innerText = response.translated
  ), 'json'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
autotolk-0.1.2 app/assets/javascripts/autotolk/locales.js.coffee
autotolk-0.1.3 app/assets/javascripts/autotolk/locales.js.coffee