autotolk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +2 -0
- data/app/assets/.DS_Store +0 -0
- data/app/assets/javascripts/.DS_Store +0 -0
- data/app/assets/javascripts/autotolk/locales.js.coffee +19 -0
- data/app/assets/javascripts/locales.js.coffee +20 -0
- data/app/controllers/translations_controller.rb +15 -0
- data/autotolk.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/autotolk/engine.rb +5 -0
- data/lib/autotolk/version.rb +3 -0
- data/lib/autotolk.rb +14 -0
- data/lib/generators/autotolk/install_generator.rb +39 -0
- data/lib/generators/templates/autotolk.rb +4 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aacdfc88653cd3aefdc2a7579ae07e0c963dd634
|
4
|
+
data.tar.gz: cc6c387a087178af7dbec505323982563144df4a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64844424b966835cb9d518bcb7ca66939443a98f8336a3a88b9da9620056e4d71d61f8b41eece362c4b2cc517d7f3cff7ac68c4b899b016714ff65a2a312db43
|
7
|
+
data.tar.gz: f4660d4ffddc01349bdef1659c67a66219722181106954794fe9ccadbaa706791b6169aea3f5f638f31f827fd0a7b49b63abc04948259aa938720efba08d91fc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Joanna Rajewska
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Autotolk
|
2
|
+
|
3
|
+
This gem makes locales in tolk translate automatically (using bing).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'autotolk'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install autotolk
|
20
|
+
|
21
|
+
And then:
|
22
|
+
|
23
|
+
$ rails g autotolk:install
|
24
|
+
|
25
|
+
And follow the instructions on the screen (you will have to add your bing tokens to make it work).
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Now when you go to `/tolk/locales/xx` you will see an alert informing you that when you double click anywhere, 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
|
+
|
31
|
+
## Issues
|
32
|
+
|
33
|
+
If you have any issues with this gem, feel free to add a new issue on Github.
|
34
|
+
|
35
|
+
## Todo
|
36
|
+
|
37
|
+
TESTS!! :)
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( https://github.com/rajaaa92/autotolk/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$(document).on 'ready page:load', ->
|
2
|
+
if document.URL.includes("tolk/locales")
|
3
|
+
alert "Double click anywhere to start autotranslating."
|
4
|
+
autotranslatingClicked = 0
|
5
|
+
$('#container').dblclick ->
|
6
|
+
autotranslatingClicked += 1
|
7
|
+
to_lang = document.URL.split('/').slice(-1).pop()
|
8
|
+
$translation_rows = $('table.translations tbody tr:not(:first-child)')
|
9
|
+
for $translation_row in $translation_rows
|
10
|
+
original = $translation_row.querySelector('td.original textarea#translations__original_text').innerText
|
11
|
+
$translationArea = $translation_row.querySelector('td.translation textarea')
|
12
|
+
if $translationArea.innerText == '' && autotranslatingClicked == 1
|
13
|
+
translate(original, to_lang, $translationArea)
|
14
|
+
|
15
|
+
translate = (original, to, textarea) ->
|
16
|
+
$.get '/translate', {original: original, to: to}, ((response) ->
|
17
|
+
if response.status == 200
|
18
|
+
textarea.innerText = response.translated
|
19
|
+
), 'json'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$(document).on 'ready page:load', ->
|
2
|
+
if document.URL.includes("tolk/locales")
|
3
|
+
alert "Double click anywhere to start autotranslating."
|
4
|
+
autotranslatingClicked = 0
|
5
|
+
$('#container').dblclick ->
|
6
|
+
autotranslatingClicked += 1
|
7
|
+
to_lang = document.URL.split('/').slice(-1).pop()
|
8
|
+
$translation_rows = $('table.translations tbody tr:not(:first-child)')
|
9
|
+
for $translation_row in $translation_rows
|
10
|
+
original = $translation_row.querySelector('td.original textarea#translations__original_text').innerText
|
11
|
+
$translationArea = $translation_row.querySelector('td.translation textarea')
|
12
|
+
if $translationArea.innerText == '' && autotranslatingClicked == 1
|
13
|
+
translate(original, to_lang, $translationArea)
|
14
|
+
|
15
|
+
translate = (original, to, textarea) ->
|
16
|
+
$.get '/translate', {original: original, to: to}, ((response) ->
|
17
|
+
alert 'udalo sie'
|
18
|
+
if response.status == 200
|
19
|
+
textarea.innerText = response.translated
|
20
|
+
), 'json'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bing_translator'
|
2
|
+
|
3
|
+
class TranslationsController < ApplicationController
|
4
|
+
skip_before_action :authenticate_user!, :validate_subdomain
|
5
|
+
|
6
|
+
def translate
|
7
|
+
translator = BingTranslator.new( Autotolk.bing_client_id, Autotolk.bing_client_secret,
|
8
|
+
false, Autotolk.azure_account_key)
|
9
|
+
translated = translator.translate params[:original], :to => params[:to]
|
10
|
+
render json: {status: 200, translated: translated}
|
11
|
+
rescue Exception => e
|
12
|
+
render json: {status: 500, error: e}
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/autotolk.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'autotolk/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "autotolk"
|
8
|
+
spec.version = Autotolk::VERSION
|
9
|
+
spec.authors = ["Joanna Rajewska"]
|
10
|
+
spec.email = ["contact@rajewska.asia"]
|
11
|
+
|
12
|
+
if spec.respond_to?(:metadata)
|
13
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
14
|
+
end
|
15
|
+
|
16
|
+
spec.summary = %q{This gem makes locales in tolk translate automatically (using bing).}
|
17
|
+
spec.homepage = "https://github.com/rajaaa92/autotolk"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_dependency "bing_translator", "~> 4.4.0"
|
28
|
+
end
|
29
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "autotolk"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/autotolk.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "autotolk/version"
|
2
|
+
|
3
|
+
module Autotolk
|
4
|
+
require 'autotolk/engine' if defined?(Rails)
|
5
|
+
|
6
|
+
# bing config
|
7
|
+
mattr_accessor :bing_client_id
|
8
|
+
@@bing_client_id = nil
|
9
|
+
mattr_accessor :bing_client_secret
|
10
|
+
@@bing_client_secret = nil
|
11
|
+
mattr_accessor :azure_account_key
|
12
|
+
@@azure_account_key = nil
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Autotolk
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
|
8
|
+
argument :_namespace, :type => :string, :required => false, :desc => "Tolk url namespace"
|
9
|
+
desc "Autotolk installation generator"
|
10
|
+
def install
|
11
|
+
display "Overriding tolk/application.js..."
|
12
|
+
create_file "app/assets/javascripts/tolk/application.js", "//= require tolk/layout.js\n//= require tolk/actions.js\n//= require tolk/interpolations.js\n//= require autotolk/locales.js
|
13
|
+
"
|
14
|
+
display "Disabling overridden file in main application.js..."
|
15
|
+
inject_into_file "app/assets/javascripts/application.js", "\n//= stub tolk/application", after: "//= require_tree ."
|
16
|
+
|
17
|
+
display "Adding autotolk to routes..."
|
18
|
+
inject_into_file "config/routes.rb", "\nmatch 'translate' => 'translations#translate', via: :get", after: "mount Tolk::Engine, at: '/tolk', as: 'tolk'"
|
19
|
+
|
20
|
+
display "Creating initalizer..."
|
21
|
+
initializer = (File.open(Rails.root.join("config/initializers/autotolk.rb")) rescue nil).try :read
|
22
|
+
unless initializer
|
23
|
+
template "autotolk.rb", "config/initializers/autotolk.rb"
|
24
|
+
else
|
25
|
+
display "You already have a config file. I'm generating a new 'autotolk.rb.example' that you can review."
|
26
|
+
template "autotolk.rb", "config/initializers/autotolk.rb.example"
|
27
|
+
end
|
28
|
+
display "Initializer created. Visit config/initializers/autotolk.rb to change your tokens.", :magenta
|
29
|
+
|
30
|
+
display "Job's done, hope everything went well. Now your locales will be translated automatically when you visit /tolk/locales/XX!", :blue
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def display output, color = :black
|
36
|
+
say(" - #{output}", color)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,4 @@
|
|
1
|
+
Autotolk.bing_client_id = 'please-change-me-at-config-initializers-autotolk'
|
2
|
+
Autotolk.bing_client_secret = 'please-change-me-at-config-initializers-autotolk'
|
3
|
+
Autotolk.azure_account_key = 'please-change-me-at-config-initializers-autotolk'
|
4
|
+
# http://blogs.msdn.com/b/translation/p/gettingstarted1.aspx
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: autotolk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joanna Rajewska
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bing_translator
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.4.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.4.0
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- contact@rajewska.asia
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- app/assets/.DS_Store
|
71
|
+
- app/assets/javascripts/.DS_Store
|
72
|
+
- app/assets/javascripts/autotolk/locales.js.coffee
|
73
|
+
- app/assets/javascripts/locales.js.coffee
|
74
|
+
- app/controllers/translations_controller.rb
|
75
|
+
- autotolk.gemspec
|
76
|
+
- bin/console
|
77
|
+
- bin/setup
|
78
|
+
- lib/autotolk.rb
|
79
|
+
- lib/autotolk/engine.rb
|
80
|
+
- lib/autotolk/version.rb
|
81
|
+
- lib/generators/autotolk/install_generator.rb
|
82
|
+
- lib/generators/templates/autotolk.rb
|
83
|
+
homepage: https://github.com/rajaaa92/autotolk
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata:
|
87
|
+
allowed_push_host: https://rubygems.org
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.6
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: This gem makes locales in tolk translate automatically (using bing).
|
108
|
+
test_files: []
|