autotolk 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ce724c992f0a77243f5b898ecd73f176917d2c3
|
|
4
|
+
data.tar.gz: f9028ac32fe73f94d8090b01984a33f4a8ca0e77
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c3015153e1af8a160a296eb12f4d568f38f1c3b97e1b1ea01ba9347d71c98b90a58bd49275f0b07aafaefd615b24ad34b2a6f3a13adbb68980d587514cbea5f0
|
|
7
|
+
data.tar.gz: 71945b75bd58832efecdf406f06adc13aed9e89c76799ac461485415e812eb4e54d9da63b1ba646d648daac4928151d8f70fa6f4489408fe8fcfce7c9c3e7626
|
data/README.md
CHANGED
|
@@ -26,7 +26,7 @@ And follow the instructions on the screen (you will have to add your bing tokens
|
|
|
26
26
|
|
|
27
27
|
## Usage
|
|
28
28
|
|
|
29
|
-
Now when you go to `/tolk/locales/xx` you will see
|
|
29
|
+
Now when you go to `/tolk/locales/xx` you will see a button `Start autotranslating!`. When you click on it, the translation will be automatic. The text areas will fill out with the translated text, so you could change it if needed and save.
|
|
30
30
|
|
|
31
31
|
## Issues
|
|
32
32
|
|
|
@@ -17,6 +17,6 @@ startTranslating = () ->
|
|
|
17
17
|
|
|
18
18
|
translate = (original, to, textarea) ->
|
|
19
19
|
$.get '/translate', {original: original, to: to}, ((response) ->
|
|
20
|
-
if response.status
|
|
20
|
+
if response.status >= 200 && response.status < 400
|
|
21
21
|
textarea.innerText = response.translated
|
|
22
22
|
), 'json'
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
require 'bing_translator'
|
|
2
|
-
|
|
3
1
|
class TranslationsController < ApplicationController
|
|
4
2
|
skip_before_action :authenticate_user!, :validate_subdomain
|
|
5
3
|
|
|
6
4
|
def translate
|
|
7
|
-
|
|
8
|
-
false, Autotolk.azure_account_key)
|
|
9
|
-
translated = translator.translate params[:original], :to => params[:to]
|
|
5
|
+
translated = AutoTranslator.new(original: params[:original], to: params[:to]).perform
|
|
10
6
|
render json: {status: 200, translated: translated}
|
|
11
7
|
rescue Exception => e
|
|
12
8
|
render json: {status: 500, error: e}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'bing_translator'
|
|
2
|
+
|
|
3
|
+
class AutoTranslator
|
|
4
|
+
|
|
5
|
+
def initialize parameters = { original: nil, to: nil }
|
|
6
|
+
@translator = nil
|
|
7
|
+
@translation = nil
|
|
8
|
+
@original = parameters[:original]
|
|
9
|
+
@to = parameters[:to]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def perform
|
|
13
|
+
set_translator
|
|
14
|
+
raw_translate
|
|
15
|
+
fix_special_characters
|
|
16
|
+
@translation
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def set_translator
|
|
22
|
+
@translator = BingTranslator.new( Autotolk.bing_client_id, Autotolk.bing_client_secret,
|
|
23
|
+
false, Autotolk.azure_account_key)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def raw_translate
|
|
27
|
+
@translation = @translator.translate @original, to: @to
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def fix_special_characters
|
|
31
|
+
@translation.gsub!('% {', '%{')
|
|
32
|
+
@translation.gsub!(/{(?<word>\w+)} %[^{]*/, '%{\k<word>}')
|
|
33
|
+
@translation.gsub!('---', '')
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/autotolk/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: autotolk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joanna Rajewska
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-03-
|
|
11
|
+
date: 2015-03-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -71,6 +71,7 @@ files:
|
|
|
71
71
|
- app/assets/javascripts/.DS_Store
|
|
72
72
|
- app/assets/javascripts/autotolk/locales.js.coffee
|
|
73
73
|
- app/controllers/translations_controller.rb
|
|
74
|
+
- app/services/auto_translator.rb
|
|
74
75
|
- autotolk.gemspec
|
|
75
76
|
- bin/console
|
|
76
77
|
- bin/setup
|