tr4n5l4te 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +86 -19
- data/CHANGELOG +6 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +39 -23
- data/README.md +7 -1
- data/Rakefile +2 -0
- data/exe/translate +1 -0
- data/lib/tr4n5l4te/agent.rb +8 -4
- data/lib/tr4n5l4te/configuration.rb +2 -0
- data/lib/tr4n5l4te/language.rb +108 -103
- data/lib/tr4n5l4te/runner.rb +18 -7
- data/lib/tr4n5l4te/translator.rb +6 -3
- data/lib/tr4n5l4te/version.rb +3 -1
- data/lib/tr4n5l4te.rb +2 -0
- data/tr4n5l4te.gemspec +4 -1
- metadata +26 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b2e251b178f16e954b56a61d499486d4e369f66bee5f68ed016ac16270ef7a5
|
4
|
+
data.tar.gz: 41894125f771195f11788b26781e1122aa27e39abf8674544aedbd9424d1a19b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16490612ad1a9683ef67626f15120748e7e6c52f78684cc8a50053ae272e2ee45583ce7880ccc00e4a125b28a16dd0cc9b50bcb3c2f89b1c62843a1ef34a4ff3
|
7
|
+
data.tar.gz: ef4b21e7beb0888aee641f23f812690794317fe5da708b6d62b47cdc5fdfa9cbca2c2cd5c1b1f29961bcbab6d5b27b92d2f4922ba22f0916a382863d4ff5cfde
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
AllCops:
|
2
|
-
|
2
|
+
TargetRubyVersion: 2.4
|
3
|
+
|
3
4
|
Include:
|
4
5
|
- '**/*.gemspec'
|
5
6
|
- '**/*.podspec'
|
@@ -12,9 +13,19 @@ AllCops:
|
|
12
13
|
- '**/Podfile'
|
13
14
|
- '**/Thorfile'
|
14
15
|
- '**/Vagrantfile'
|
16
|
+
- '**/*.rb'
|
15
17
|
Exclude:
|
18
|
+
- 'Capfile'
|
19
|
+
- 'tmp/**/*'
|
20
|
+
- 'log/**/*'
|
21
|
+
- 'db/**/*'
|
16
22
|
- 'vendor/**/*'
|
17
23
|
- 'stubs/**/*'
|
24
|
+
- 'bin/**/*'
|
25
|
+
- 'node_modules/**/*'
|
26
|
+
- 'features/step_definitions/*'
|
27
|
+
- 'config/deploy.rb'
|
28
|
+
- 'config/deploy/**/*.rb'
|
18
29
|
|
19
30
|
# Checks formatting of special comments
|
20
31
|
CommentAnnotation:
|
@@ -31,18 +42,9 @@ CommentAnnotation:
|
|
31
42
|
Style/Documentation:
|
32
43
|
Enabled: false
|
33
44
|
|
34
|
-
Style/FileName:
|
35
|
-
Enabled: false
|
36
|
-
|
37
|
-
Style/AlignParameters:
|
38
|
-
EnforcedStyle: with_fixed_indentation
|
39
|
-
|
40
45
|
Style/RegexpLiteral:
|
41
46
|
Enabled: false
|
42
47
|
|
43
|
-
Style/EmptyLinesAroundBlockBody:
|
44
|
-
Enabled: false
|
45
|
-
|
46
48
|
Style/RaiseArgs:
|
47
49
|
Enabled: false
|
48
50
|
|
@@ -55,37 +57,102 @@ Style/SignalException:
|
|
55
57
|
Style/ClassAndModuleChildren:
|
56
58
|
Enabled: false
|
57
59
|
|
58
|
-
Style/
|
60
|
+
Style/TrivialAccessors:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Style/NumericLiterals:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Style/EmptyMethod:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
Style/MixinUsage:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Style/AndOr:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
Style/FrozenStringLiteralComment:
|
76
|
+
EnforcedStyle: always
|
77
|
+
|
78
|
+
# String#format is private now
|
79
|
+
Style/FormatString:
|
80
|
+
Enabled: false
|
81
|
+
|
82
|
+
Style/Alias:
|
83
|
+
EnforcedStyle: prefer_alias_method
|
84
|
+
|
85
|
+
########################################
|
86
|
+
# Layout Cops
|
87
|
+
|
88
|
+
Layout/LineLength:
|
89
|
+
Max: 110
|
90
|
+
Exclude:
|
91
|
+
- 'app/views/**/*'
|
92
|
+
|
93
|
+
Layout/ParameterAlignment:
|
94
|
+
EnforcedStyle: with_fixed_indentation
|
95
|
+
|
96
|
+
Layout/ArgumentAlignment:
|
97
|
+
EnforcedStyle: with_fixed_indentation
|
98
|
+
|
99
|
+
Layout/AssignmentIndentation:
|
100
|
+
Enabled: false
|
101
|
+
|
102
|
+
Layout/EmptyLinesAroundBlockBody:
|
103
|
+
Enabled: false
|
104
|
+
|
105
|
+
Layout/MultilineMethodCallIndentation:
|
59
106
|
EnforcedStyle: indented
|
60
107
|
IndentationWidth: 4
|
61
108
|
|
62
|
-
|
109
|
+
Layout/CaseIndentation:
|
63
110
|
Enabled: false
|
64
111
|
|
65
|
-
|
112
|
+
Layout/ElseAlignment:
|
66
113
|
Enabled: false
|
67
114
|
|
68
|
-
|
115
|
+
Layout/EndAlignment:
|
116
|
+
EnforcedStyleAlignWith: variable
|
117
|
+
|
118
|
+
########################################
|
119
|
+
# Naming Cops
|
120
|
+
|
121
|
+
Naming/FileName:
|
69
122
|
Enabled: false
|
70
123
|
|
71
124
|
########################################
|
72
|
-
#
|
125
|
+
# Security Cops
|
73
126
|
|
74
|
-
|
127
|
+
Security/Eval:
|
75
128
|
Enabled: true
|
76
129
|
|
130
|
+
########################################
|
131
|
+
# Lint Cops
|
132
|
+
|
77
133
|
Lint/AssignmentInCondition:
|
78
134
|
Enabled: false
|
79
135
|
|
80
136
|
########################################
|
81
137
|
# Metrics Cops
|
82
138
|
|
83
|
-
Metrics/LineLength:
|
84
|
-
Max: 110
|
85
|
-
|
86
139
|
Metrics/MethodLength:
|
87
140
|
CountComments: false # count full line comments?
|
88
141
|
Max: 20
|
89
142
|
|
90
143
|
Metrics/ClassLength:
|
91
144
|
Max: 120
|
145
|
+
|
146
|
+
Metrics/AbcSize:
|
147
|
+
Max: 20
|
148
|
+
|
149
|
+
Metrics/BlockLength:
|
150
|
+
Enabled: true
|
151
|
+
Exclude:
|
152
|
+
- spec/**/*
|
153
|
+
|
154
|
+
########################################
|
155
|
+
# Bundler Cops
|
156
|
+
|
157
|
+
Bundler/OrderedGems:
|
158
|
+
Enabled: false
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
*0.1.6* (January 14, 2020)
|
2
|
+
|
3
|
+
* Fix rubocop violations
|
4
|
+
* Upgrade gems to address CVEs
|
5
|
+
* Pass `permitted_classes` array to allow new YAML.safe_load to work properly
|
6
|
+
|
1
7
|
*0.1.5* (May 06, 2019)
|
2
8
|
|
3
9
|
* Fixed phantomjs selector, migration to Optimist gem - Thanks @kirylpl
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tr4n5l4te (0.1.
|
4
|
+
tr4n5l4te (0.1.6)
|
5
5
|
capybara (~> 2.6)
|
6
6
|
colored (~> 1)
|
7
7
|
midwire_common (~> 0.1)
|
@@ -11,8 +11,9 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
addressable (2.
|
15
|
-
public_suffix (>= 2.0.2, <
|
14
|
+
addressable (2.7.0)
|
15
|
+
public_suffix (>= 2.0.2, < 5.0)
|
16
|
+
ast (2.4.0)
|
16
17
|
capybara (2.18.0)
|
17
18
|
addressable
|
18
19
|
mini_mime (>= 0.1.3)
|
@@ -24,16 +25,20 @@ GEM
|
|
24
25
|
coderay (1.1.2)
|
25
26
|
colored (1.2)
|
26
27
|
diff-lcs (1.3)
|
27
|
-
docile (1.3.
|
28
|
-
|
28
|
+
docile (1.3.2)
|
29
|
+
jaro_winkler (1.5.4)
|
30
|
+
json (2.3.0)
|
29
31
|
method_source (0.9.2)
|
30
32
|
midwire_common (0.3.0)
|
31
33
|
thor (~> 0.19)
|
32
|
-
mini_mime (1.0.
|
34
|
+
mini_mime (1.0.2)
|
33
35
|
mini_portile2 (2.4.0)
|
34
|
-
nokogiri (1.10.
|
36
|
+
nokogiri (1.10.7)
|
35
37
|
mini_portile2 (~> 2.4.0)
|
36
38
|
optimist (3.0.0)
|
39
|
+
parallel (1.19.1)
|
40
|
+
parser (2.7.0.2)
|
41
|
+
ast (~> 2.4.0)
|
37
42
|
poltergeist (1.18.1)
|
38
43
|
capybara (>= 2.1, < 4)
|
39
44
|
cliver (~> 0.3.1)
|
@@ -43,33 +48,43 @@ GEM
|
|
43
48
|
method_source (~> 0.9.0)
|
44
49
|
pry-nav (0.3.0)
|
45
50
|
pry (>= 0.9.10, < 0.13.0)
|
46
|
-
public_suffix (
|
47
|
-
rack (2.
|
51
|
+
public_suffix (4.0.3)
|
52
|
+
rack (2.1.1)
|
48
53
|
rack-test (1.1.0)
|
49
54
|
rack (>= 1.0, < 3)
|
55
|
+
rainbow (3.0.0)
|
50
56
|
rake (10.5.0)
|
51
|
-
rspec (3.
|
52
|
-
rspec-core (~> 3.
|
53
|
-
rspec-expectations (~> 3.
|
54
|
-
rspec-mocks (~> 3.
|
55
|
-
rspec-core (3.
|
56
|
-
rspec-support (~> 3.
|
57
|
-
rspec-expectations (3.
|
57
|
+
rspec (3.9.0)
|
58
|
+
rspec-core (~> 3.9.0)
|
59
|
+
rspec-expectations (~> 3.9.0)
|
60
|
+
rspec-mocks (~> 3.9.0)
|
61
|
+
rspec-core (3.9.1)
|
62
|
+
rspec-support (~> 3.9.1)
|
63
|
+
rspec-expectations (3.9.0)
|
58
64
|
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
-
rspec-support (~> 3.
|
60
|
-
rspec-mocks (3.
|
65
|
+
rspec-support (~> 3.9.0)
|
66
|
+
rspec-mocks (3.9.1)
|
61
67
|
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
-
rspec-support (~> 3.
|
63
|
-
rspec-support (3.
|
64
|
-
|
68
|
+
rspec-support (~> 3.9.0)
|
69
|
+
rspec-support (3.9.2)
|
70
|
+
rubocop (0.79.0)
|
71
|
+
jaro_winkler (~> 1.5.1)
|
72
|
+
parallel (~> 1.10)
|
73
|
+
parser (>= 2.7.0.1)
|
74
|
+
rainbow (>= 2.2.2, < 4.0)
|
75
|
+
ruby-progressbar (~> 1.7)
|
76
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
77
|
+
ruby-progressbar (1.10.1)
|
78
|
+
simplecov (0.17.1)
|
65
79
|
docile (~> 1.1)
|
66
80
|
json (>= 1.8, < 3)
|
67
81
|
simplecov-html (~> 0.10.0)
|
68
82
|
simplecov-html (0.10.2)
|
69
83
|
thor (0.20.3)
|
70
|
-
|
84
|
+
unicode-display_width (1.6.0)
|
85
|
+
websocket-driver (0.7.1)
|
71
86
|
websocket-extensions (>= 0.1.0)
|
72
|
-
websocket-extensions (0.1.
|
87
|
+
websocket-extensions (0.1.4)
|
73
88
|
xpath (3.2.0)
|
74
89
|
nokogiri (~> 1.8)
|
75
90
|
|
@@ -81,6 +96,7 @@ DEPENDENCIES
|
|
81
96
|
pry-nav
|
82
97
|
rake (~> 10.0)
|
83
98
|
rspec (~> 3.0)
|
99
|
+
rubocop
|
84
100
|
simplecov (~> 0.11)
|
85
101
|
tr4n5l4te!
|
86
102
|
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Tr4n5l4te
|
2
2
|
|
3
|
-
**Version: 0.1.
|
3
|
+
**Version: 0.1.6**
|
4
4
|
|
5
5
|
Use Google Translate without an API key.
|
6
6
|
|
@@ -88,6 +88,12 @@ Please be kind or Google is likely to ban your IP address.
|
|
88
88
|
|
89
89
|
Bug reports and pull requests are welcome on GitHub at https://github.com/midwire/tr4n5l4te.
|
90
90
|
|
91
|
+
### Contributors
|
92
|
+
|
93
|
+
Thanks to all of those who contribute!
|
94
|
+
|
95
|
+
* @kirylpl - Fixed phantomjs selector, migration to Optimist gem
|
96
|
+
|
91
97
|
## License
|
92
98
|
|
93
99
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/exe/translate
CHANGED
data/lib/tr4n5l4te/agent.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'capybara'
|
2
4
|
require 'capybara/poltergeist'
|
3
5
|
require 'yaml'
|
@@ -16,7 +18,7 @@ module Tr4n5l4te
|
|
16
18
|
|
17
19
|
class Agent
|
18
20
|
# rubocop:disable Metrics/LineLength
|
19
|
-
DEFAULT_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4'
|
21
|
+
DEFAULT_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4'
|
20
22
|
# rubocop:enable Metrics/LineLength
|
21
23
|
|
22
24
|
attr_reader :browser
|
@@ -27,9 +29,11 @@ module Tr4n5l4te
|
|
27
29
|
browser.driver.headers = { 'User-Agent' => DEFAULT_UA }
|
28
30
|
end
|
29
31
|
|
30
|
-
# rubocop:disable Metrics/AbcSize, Lint/AssignmentInCondition
|
31
32
|
def load_cookies(cookie_file)
|
32
|
-
return false unless cookie_hash = YAML.
|
33
|
+
return false unless cookie_hash = YAML.safe_load(
|
34
|
+
File.read(cookie_file), permitted_classes: [Capybara::Poltergeist::Cookie]
|
35
|
+
)
|
36
|
+
|
33
37
|
browser.driver.clear_cookies
|
34
38
|
cookie_hash.each do |key, cookie_obj|
|
35
39
|
browser.driver.set_cookie(
|
@@ -43,7 +47,7 @@ module Tr4n5l4te
|
|
43
47
|
)
|
44
48
|
end
|
45
49
|
end
|
46
|
-
# rubocop:enable
|
50
|
+
# rubocop:enable
|
47
51
|
|
48
52
|
def store_cookies(cookie_file)
|
49
53
|
FileUtils.mkdir_p(File.dirname(cookie_file))
|
data/lib/tr4n5l4te/language.rb
CHANGED
@@ -1,109 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Tr4n5l4te
|
4
|
+
# rubocop:disable Metrics/ClassLength
|
2
5
|
class Language
|
6
|
+
# rubocop:enable Metrics/ClassLength
|
3
7
|
TABLE = {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
8
|
+
'af' => 'Afrikaans',
|
9
|
+
'sq' => 'Albanian',
|
10
|
+
'am' => 'Amharic',
|
11
|
+
'ar' => 'Arabic',
|
12
|
+
'hy' => 'Armenian',
|
13
|
+
'az' => 'Azerbaijani',
|
14
|
+
'eu' => 'Basque',
|
15
|
+
'be' => 'Belarusian',
|
16
|
+
'bn' => 'Bengali',
|
17
|
+
'bs' => 'Bosnian',
|
18
|
+
'bg' => 'Bulgarian',
|
19
|
+
'ca' => 'Catalan',
|
20
|
+
'ceb' => 'Cebuano',
|
21
|
+
'ny' => 'Chichewa',
|
22
|
+
'zh-CN' => 'Chinese',
|
23
|
+
'co' => 'Corsican',
|
24
|
+
'hr' => 'Croatian',
|
25
|
+
'cs' => 'Czech',
|
26
|
+
'da' => 'Danish',
|
27
|
+
'nl' => 'Dutch',
|
28
|
+
'en' => 'English',
|
29
|
+
'eo' => 'Esperanto',
|
30
|
+
'et' => 'Estonian',
|
31
|
+
'tl' => 'Filipino',
|
32
|
+
'fi' => 'Finnish',
|
33
|
+
'fr' => 'French',
|
34
|
+
'fy' => 'Frisian',
|
35
|
+
'gl' => 'Galician',
|
36
|
+
'ka' => 'Georgian',
|
37
|
+
'de' => 'German',
|
38
|
+
'el' => 'Greek',
|
39
|
+
'gu' => 'Gujarati',
|
40
|
+
'ht' => 'Haitian Creole',
|
41
|
+
'ha' => 'Hausa',
|
42
|
+
'haw' => 'Hawaiian',
|
43
|
+
'iw' => 'Hebrew',
|
44
|
+
'hi' => 'Hindi',
|
45
|
+
'hmn' => 'Hmong',
|
46
|
+
'hu' => 'Hungarian',
|
47
|
+
'is' => 'Icelandic',
|
48
|
+
'ig' => 'Igbo',
|
49
|
+
'id' => 'Indonesian',
|
50
|
+
'ga' => 'Irish',
|
51
|
+
'it' => 'Italian',
|
52
|
+
'ja' => 'Japanese',
|
53
|
+
'jw' => 'Javanese',
|
54
|
+
'kn' => 'Kannada',
|
55
|
+
'kk' => 'Kazakh',
|
56
|
+
'km' => 'Khmer',
|
57
|
+
'ko' => 'Korean',
|
58
|
+
'ku' => 'Kurdish (Kurmanji)',
|
59
|
+
'ky' => 'Kyrgyz',
|
60
|
+
'lo' => 'Lao',
|
61
|
+
'la' => 'Latin',
|
62
|
+
'lv' => 'Latvian',
|
63
|
+
'lt' => 'Lithuanian',
|
64
|
+
'lb' => 'Luxembourgish',
|
65
|
+
'mk' => 'Macedonian',
|
66
|
+
'mg' => 'Malagasy',
|
67
|
+
'ms' => 'Malay',
|
68
|
+
'ml' => 'Malayalam',
|
69
|
+
'mt' => 'Maltese',
|
70
|
+
'mi' => 'Maori',
|
71
|
+
'mr' => 'Marathi',
|
72
|
+
'mn' => 'Mongolian',
|
73
|
+
'my' => 'Myanmar (Burmese)',
|
74
|
+
'ne' => 'Nepali',
|
75
|
+
'no' => 'Norwegian',
|
76
|
+
'ps' => 'Pashto',
|
77
|
+
'fa' => 'Persian',
|
78
|
+
'pl' => 'Polish',
|
79
|
+
'pt' => 'Portuguese',
|
80
|
+
'pa' => 'Punjabi',
|
81
|
+
'ro' => 'Romanian',
|
82
|
+
'ru' => 'Russian',
|
83
|
+
'sm' => 'Samoan',
|
84
|
+
'gd' => 'Scots Gaelic',
|
85
|
+
'sr' => 'Serbian',
|
86
|
+
'st' => 'Sesotho',
|
87
|
+
'sn' => 'Shona',
|
88
|
+
'sd' => 'Sindhi',
|
89
|
+
'si' => 'Sinhala',
|
90
|
+
'sk' => 'Slovak',
|
91
|
+
'sl' => 'Slovenian',
|
92
|
+
'so' => 'Somali',
|
93
|
+
'es' => 'Spanish',
|
94
|
+
'su' => 'Sundanese',
|
95
|
+
'sw' => 'Swahili',
|
96
|
+
'sv' => 'Swedish',
|
97
|
+
'tg' => 'Tajik',
|
98
|
+
'ta' => 'Tamil',
|
99
|
+
'te' => 'Telugu',
|
100
|
+
'th' => 'Thai',
|
101
|
+
'tr' => 'Turkish',
|
102
|
+
'uk' => 'Ukrainian',
|
103
|
+
'ur' => 'Urdu',
|
104
|
+
'uz' => 'Uzbek',
|
105
|
+
'vi' => 'Vietnamese',
|
106
|
+
'cy' => 'Welsh',
|
107
|
+
'xh' => 'Xhosa',
|
108
|
+
'yi' => 'Yiddish',
|
109
|
+
'yo' => 'Yoruba',
|
110
|
+
'zu' => 'Zulu'
|
107
111
|
}.freeze
|
108
112
|
|
109
113
|
class << self
|
@@ -113,6 +117,7 @@ module Tr4n5l4te
|
|
113
117
|
|
114
118
|
def ensure_code(string)
|
115
119
|
fail("Invalid language: [#{string}]") unless valid?(string)
|
120
|
+
|
116
121
|
code(string) || string
|
117
122
|
end
|
118
123
|
|
data/lib/tr4n5l4te/runner.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'optimist'
|
2
4
|
require 'colored'
|
3
5
|
require 'fileutils'
|
@@ -55,7 +57,8 @@ module Tr4n5l4te
|
|
55
57
|
|
56
58
|
def from_lang
|
57
59
|
md = File.basename(options[:yaml_file]).match(/^(\w\w)\.yml$/)
|
58
|
-
|
60
|
+
fail "Could not determine language from yaml file: '#{options[:yaml_file]}'" unless md
|
61
|
+
|
59
62
|
md[1]
|
60
63
|
end
|
61
64
|
|
@@ -68,31 +71,39 @@ module Tr4n5l4te
|
|
68
71
|
|
69
72
|
# rubocop:disable Metrics/MethodLength
|
70
73
|
def collect_args
|
74
|
+
# rubocop:disable Metrics/BlockLength
|
71
75
|
Optimist.options do
|
76
|
+
# rubocop:enable Metrics/BlockLength
|
72
77
|
opt(
|
73
78
|
:yaml_file,
|
74
79
|
"A YAML locale file - filename determines source language 'en.yml' - English",
|
75
|
-
type: :string, required: false, short: 'y'
|
80
|
+
type: :string, required: false, short: 'y'
|
81
|
+
)
|
76
82
|
opt(
|
77
83
|
:lang,
|
78
84
|
'Destination language',
|
79
|
-
type: :string, required: false, short: 'l'
|
85
|
+
type: :string, required: false, short: 'l'
|
86
|
+
)
|
80
87
|
opt(
|
81
88
|
:list,
|
82
89
|
'List known languages',
|
83
|
-
type: :boolean, required: false
|
90
|
+
type: :boolean, required: false
|
91
|
+
)
|
84
92
|
opt(
|
85
93
|
:sleep_time,
|
86
94
|
'Sleep time',
|
87
|
-
type: :integer, default: 2, short: 's'
|
95
|
+
type: :integer, default: 2, short: 's'
|
96
|
+
)
|
88
97
|
opt(
|
89
98
|
:timeout,
|
90
99
|
'Poltergeist timeout option - default 30',
|
91
|
-
type: :integer, default: 30, short: 't'
|
100
|
+
type: :integer, default: 30, short: 't'
|
101
|
+
)
|
92
102
|
opt(
|
93
103
|
:verbose,
|
94
104
|
'Be verbose with output',
|
95
|
-
type: :boolean, required: false, short: 'v', default: false
|
105
|
+
type: :boolean, required: false, short: 'v', default: false
|
106
|
+
)
|
96
107
|
end
|
97
108
|
end
|
98
109
|
# rubocop:enable Metrics/MethodLength
|
data/lib/tr4n5l4te/translator.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'open-uri'
|
2
4
|
|
3
5
|
module Tr4n5l4te
|
4
6
|
class Translator
|
5
|
-
START_PAGE = 'https://translate.google.com'
|
7
|
+
START_PAGE = 'https://translate.google.com'
|
6
8
|
|
7
9
|
attr_reader :sleep_time, :agent
|
8
10
|
|
@@ -15,6 +17,7 @@ module Tr4n5l4te
|
|
15
17
|
puts "Translating: #{text}"
|
16
18
|
encoded_text = validate_and_encode(text)
|
17
19
|
return '' if encoded_text == ''
|
20
|
+
|
18
21
|
smart_visit(translator_url(encoded_text, from_lang, to_lang))
|
19
22
|
result_box = browser.find('.tlid-translation')
|
20
23
|
result_box.text
|
@@ -25,8 +28,8 @@ module Tr4n5l4te
|
|
25
28
|
def validate_and_encode(text)
|
26
29
|
return '' if text.nil?
|
27
30
|
fail "Cannot translate a [#{text.class}]: '#{text}'" unless text.respond_to?(:gsub)
|
28
|
-
|
29
|
-
|
31
|
+
|
32
|
+
CGI.escape(text.strip)
|
30
33
|
end
|
31
34
|
|
32
35
|
def smart_visit(url)
|
data/lib/tr4n5l4te/version.rb
CHANGED
data/lib/tr4n5l4te.rb
CHANGED
data/tr4n5l4te.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'tr4n5l4te/version'
|
@@ -22,11 +24,12 @@ Gem::Specification.new do |spec|
|
|
22
24
|
spec.add_development_dependency 'pry-nav'
|
23
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
26
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'rubocop'
|
25
28
|
spec.add_development_dependency 'simplecov', '~> 0.11'
|
26
29
|
|
27
30
|
spec.add_dependency 'capybara', '~> 2.6'
|
28
31
|
spec.add_dependency 'colored', '~> 1'
|
29
32
|
spec.add_dependency 'midwire_common', '~> 0.1'
|
30
|
-
spec.add_dependency 'poltergeist', '~> 1.9'
|
31
33
|
spec.add_dependency 'optimist'
|
34
|
+
spec.add_dependency 'poltergeist', '~> 1.9'
|
32
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tr4n5l4te
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Blackburn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: simplecov
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,33 +137,33 @@ dependencies:
|
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '0.1'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
140
|
+
name: optimist
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
|
-
- - "
|
143
|
+
- - ">="
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
145
|
+
version: '0'
|
132
146
|
type: :runtime
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
|
-
- - "
|
150
|
+
- - ">="
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
154
|
+
name: poltergeist
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
|
-
- - "
|
157
|
+
- - "~>"
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
159
|
+
version: '1.9'
|
146
160
|
type: :runtime
|
147
161
|
prerelease: false
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
149
163
|
requirements:
|
150
|
-
- - "
|
164
|
+
- - "~>"
|
151
165
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
166
|
+
version: '1.9'
|
153
167
|
description: Use Google Translate without an API key.
|
154
168
|
email:
|
155
169
|
- 87a1779b@opayq.com
|