tr4n5l4te 0.1.5 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +86 -19
- data/CHANGELOG +25 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +57 -36
- data/README.md +12 -6
- data/Rakefile +2 -0
- data/bin/console +4 -4
- data/exe/translate +1 -0
- data/lib/tr4n5l4te.rb +3 -2
- 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 +32 -11
- data/lib/tr4n5l4te/translator.rb +30 -6
- data/lib/tr4n5l4te/version.rb +3 -1
- data/tr4n5l4te.gemspec +6 -3
- metadata +31 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5628a5c8a6bdbe6d6ace4af5ae7219aca724ab217578bda9266381cedc7b5359
|
4
|
+
data.tar.gz: fce1e1f205dfaf0054eadcc79b9c6add8607e84d384b94247305806ae8e757bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7884c55e6723c27eb2cb74107bec48b1dbbeca9a2386562ae94052f798d53d4315d73356002353259ed7c48497a481cb62b4888088992ac86723ab1e4e3042f
|
7
|
+
data.tar.gz: 9878365b79bb5c5c4c680e2077fb2c0a967d5ac708ba4e031f03f16fc712d6c099e55122beb3003ed6e1f9d803223d9311d969a65d2b93c030e6f03f66eef3ba
|
data/.gitignore
CHANGED
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,28 @@
|
|
1
|
+
*0.1.10* (March 09, 2021)
|
2
|
+
|
3
|
+
* Accomodate latest changes to the web interface.
|
4
|
+
|
5
|
+
*0.1.9* (March 05, 2020)
|
6
|
+
|
7
|
+
* The top-level primary language key was being propagated from the source .yml file to the translated target .yml file. That is now fixed.
|
8
|
+
* Now keeps the interpolation tags intact.
|
9
|
+
|
10
|
+
*0.1.8* (February 21, 2020)
|
11
|
+
|
12
|
+
* Address ambiguous translations without stopping the run when the exception occurs.
|
13
|
+
* Fixes issue #9
|
14
|
+
|
15
|
+
*0.1.7* (January 14, 2020)
|
16
|
+
|
17
|
+
* Remove midwire common String usage
|
18
|
+
* Fixes issue #7
|
19
|
+
|
20
|
+
*0.1.6* (January 14, 2020)
|
21
|
+
|
22
|
+
* Fix rubocop violations
|
23
|
+
* Upgrade gems to address CVEs
|
24
|
+
* Pass `permitted_classes` array to allow new YAML.safe_load to work properly
|
25
|
+
|
1
26
|
*0.1.5* (May 06, 2019)
|
2
27
|
|
3
28
|
* Fixed phantomjs selector, migration to Optimist gem - Thanks @kirylpl
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tr4n5l4te (0.1.
|
4
|
+
tr4n5l4te (0.1.10)
|
5
5
|
capybara (~> 2.6)
|
6
6
|
colored (~> 1)
|
7
7
|
midwire_common (~> 0.1)
|
8
|
-
optimist
|
8
|
+
optimist (~> 3.0)
|
9
9
|
poltergeist (~> 1.9)
|
10
10
|
|
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.2)
|
16
17
|
capybara (2.18.0)
|
17
18
|
addressable
|
18
19
|
mini_mime (>= 0.1.3)
|
@@ -21,19 +22,20 @@ GEM
|
|
21
22
|
rack-test (>= 0.5.4)
|
22
23
|
xpath (>= 2.0, < 4.0)
|
23
24
|
cliver (0.3.2)
|
24
|
-
coderay (1.1.
|
25
|
+
coderay (1.1.3)
|
25
26
|
colored (1.2)
|
26
|
-
diff-lcs (1.
|
27
|
-
docile (1.3.
|
28
|
-
json (2.2.0)
|
27
|
+
diff-lcs (1.4.4)
|
28
|
+
docile (1.3.5)
|
29
29
|
method_source (0.9.2)
|
30
30
|
midwire_common (0.3.0)
|
31
31
|
thor (~> 0.19)
|
32
|
-
mini_mime (1.0.
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
mini_mime (1.0.2)
|
33
|
+
nokogiri (1.11.1-x86_64-darwin)
|
34
|
+
racc (~> 1.4)
|
35
|
+
optimist (3.0.1)
|
36
|
+
parallel (1.20.1)
|
37
|
+
parser (3.0.0.0)
|
38
|
+
ast (~> 2.4.1)
|
37
39
|
poltergeist (1.18.1)
|
38
40
|
capybara (>= 2.1, < 4)
|
39
41
|
cliver (~> 0.3.1)
|
@@ -43,33 +45,51 @@ GEM
|
|
43
45
|
method_source (~> 0.9.0)
|
44
46
|
pry-nav (0.3.0)
|
45
47
|
pry (>= 0.9.10, < 0.13.0)
|
46
|
-
public_suffix (
|
47
|
-
|
48
|
+
public_suffix (4.0.6)
|
49
|
+
racc (1.5.2)
|
50
|
+
rack (2.2.3)
|
48
51
|
rack-test (1.1.0)
|
49
52
|
rack (>= 1.0, < 3)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
rspec-
|
57
|
-
|
53
|
+
rainbow (3.0.0)
|
54
|
+
rake (13.0.3)
|
55
|
+
regexp_parser (2.1.1)
|
56
|
+
rexml (3.2.4)
|
57
|
+
rspec (3.10.0)
|
58
|
+
rspec-core (~> 3.10.0)
|
59
|
+
rspec-expectations (~> 3.10.0)
|
60
|
+
rspec-mocks (~> 3.10.0)
|
61
|
+
rspec-core (3.10.1)
|
62
|
+
rspec-support (~> 3.10.0)
|
63
|
+
rspec-expectations (3.10.1)
|
58
64
|
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
-
rspec-support (~> 3.
|
60
|
-
rspec-mocks (3.
|
65
|
+
rspec-support (~> 3.10.0)
|
66
|
+
rspec-mocks (3.10.2)
|
61
67
|
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
-
rspec-support (~> 3.
|
63
|
-
rspec-support (3.
|
64
|
-
|
68
|
+
rspec-support (~> 3.10.0)
|
69
|
+
rspec-support (3.10.2)
|
70
|
+
rubocop (1.11.0)
|
71
|
+
parallel (~> 1.10)
|
72
|
+
parser (>= 3.0.0.0)
|
73
|
+
rainbow (>= 2.2.2, < 4.0)
|
74
|
+
regexp_parser (>= 1.8, < 3.0)
|
75
|
+
rexml
|
76
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
77
|
+
ruby-progressbar (~> 1.7)
|
78
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
79
|
+
rubocop-ast (1.4.1)
|
80
|
+
parser (>= 2.7.1.5)
|
81
|
+
ruby-progressbar (1.11.0)
|
82
|
+
simplecov (0.21.2)
|
65
83
|
docile (~> 1.1)
|
66
|
-
|
67
|
-
|
68
|
-
simplecov-html (0.
|
84
|
+
simplecov-html (~> 0.11)
|
85
|
+
simplecov_json_formatter (~> 0.1)
|
86
|
+
simplecov-html (0.12.3)
|
87
|
+
simplecov_json_formatter (0.1.2)
|
69
88
|
thor (0.20.3)
|
70
|
-
|
89
|
+
unicode-display_width (2.0.0)
|
90
|
+
websocket-driver (0.7.3)
|
71
91
|
websocket-extensions (>= 0.1.0)
|
72
|
-
websocket-extensions (0.1.
|
92
|
+
websocket-extensions (0.1.5)
|
73
93
|
xpath (3.2.0)
|
74
94
|
nokogiri (~> 1.8)
|
75
95
|
|
@@ -77,12 +97,13 @@ PLATFORMS
|
|
77
97
|
ruby
|
78
98
|
|
79
99
|
DEPENDENCIES
|
80
|
-
bundler (~> 2.
|
100
|
+
bundler (~> 2.1)
|
81
101
|
pry-nav
|
82
|
-
rake (~>
|
102
|
+
rake (~> 13.0)
|
83
103
|
rspec (~> 3.0)
|
104
|
+
rubocop
|
84
105
|
simplecov (~> 0.11)
|
85
106
|
tr4n5l4te!
|
86
107
|
|
87
108
|
BUNDLED WITH
|
88
|
-
2.
|
109
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Tr4n5l4te
|
2
2
|
|
3
|
-
**Version: 0.1.
|
3
|
+
**Version: 0.1.10**
|
4
4
|
|
5
5
|
Use Google Translate without an API key.
|
6
6
|
|
@@ -30,10 +30,10 @@ In your code:
|
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
translator = Tr4n5l4te::Translator.new
|
33
|
-
english_strings =
|
34
|
-
hello
|
35
|
-
how are you
|
36
|
-
|
33
|
+
english_strings = [
|
34
|
+
'hello'
|
35
|
+
'how are you'
|
36
|
+
]
|
37
37
|
english_strings.each do |text|
|
38
38
|
puts translator.translate(text, :en, :es)
|
39
39
|
end
|
@@ -65,7 +65,7 @@ Warning: If you pass in '0' and translate a large file, it is very likely that G
|
|
65
65
|
|
66
66
|
To list all known languages
|
67
67
|
|
68
|
-
$ ./exe/translate
|
68
|
+
$ ./exe/translate --list
|
69
69
|
|
70
70
|
## Development
|
71
71
|
|
@@ -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/bin/console
CHANGED
@@ -7,8 +7,8 @@ require 'tr4n5l4te'
|
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
|
11
|
-
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
12
12
|
|
13
|
-
require 'irb'
|
14
|
-
IRB.start
|
13
|
+
# require 'irb'
|
14
|
+
# IRB.start
|
data/exe/translate
CHANGED
data/lib/tr4n5l4te.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'tr4n5l4te/version'
|
2
4
|
|
3
|
-
require 'midwire_common/string'
|
4
5
|
require 'midwire_common/yaml_setting'
|
5
6
|
require 'midwire_common/hash'
|
6
7
|
|
@@ -13,7 +14,7 @@ module Tr4n5l4te
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def string_id
|
16
|
-
|
17
|
+
'tr4n5l4te'
|
17
18
|
end
|
18
19
|
|
19
20
|
def default_config_directory
|
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,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'optimist'
|
2
4
|
require 'colored'
|
3
5
|
require 'fileutils'
|
4
6
|
require 'midwire_common/string'
|
7
|
+
require 'pry' unless ENV.fetch('GEM_ENV', nil).nil?
|
5
8
|
|
6
9
|
module Tr4n5l4te
|
7
10
|
class Runner
|
@@ -28,7 +31,7 @@ module Tr4n5l4te
|
|
28
31
|
|
29
32
|
hash = YAML.load_file(options[:yaml_file])
|
30
33
|
translated = process(hash)
|
31
|
-
store_translation(translated)
|
34
|
+
store_translation(replace_lang_key(translated))
|
32
35
|
|
33
36
|
puts("Processed #{@count} strings in [#{Time.now - start_time}] seconds.".yellow)
|
34
37
|
end
|
@@ -45,7 +48,7 @@ module Tr4n5l4te
|
|
45
48
|
|
46
49
|
def translate(string)
|
47
50
|
@count += 1
|
48
|
-
puts("[#{string}]") if options[:verbose]
|
51
|
+
puts("Translating [#{string}]") if options[:verbose]
|
49
52
|
translator.translate(string, from_lang, options[:lang])
|
50
53
|
end
|
51
54
|
|
@@ -54,9 +57,19 @@ module Tr4n5l4te
|
|
54
57
|
end
|
55
58
|
|
56
59
|
def from_lang
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
@from_lang ||= begin
|
61
|
+
md = File.basename(options[:yaml_file]).match(/^(\w\w)\.yml$/)
|
62
|
+
fail "Could not determine language from yaml file: '#{options[:yaml_file]}'" unless md
|
63
|
+
|
64
|
+
md[1]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def replace_lang_key(translated)
|
69
|
+
assumed_source_lang = translated.keys.first
|
70
|
+
return translated unless assumed_source_lang == from_lang
|
71
|
+
|
72
|
+
{ options[:lang] => translated.values.first }
|
60
73
|
end
|
61
74
|
|
62
75
|
def store_translation(translated)
|
@@ -68,31 +81,39 @@ module Tr4n5l4te
|
|
68
81
|
|
69
82
|
# rubocop:disable Metrics/MethodLength
|
70
83
|
def collect_args
|
84
|
+
# rubocop:disable Metrics/BlockLength
|
71
85
|
Optimist.options do
|
86
|
+
# rubocop:enable Metrics/BlockLength
|
72
87
|
opt(
|
73
88
|
:yaml_file,
|
74
89
|
"A YAML locale file - filename determines source language 'en.yml' - English",
|
75
|
-
type: :string, required: false, short: 'y'
|
90
|
+
type: :string, required: false, short: 'y'
|
91
|
+
)
|
76
92
|
opt(
|
77
93
|
:lang,
|
78
94
|
'Destination language',
|
79
|
-
type: :string, required: false, short: 'l'
|
95
|
+
type: :string, required: false, short: 'l'
|
96
|
+
)
|
80
97
|
opt(
|
81
98
|
:list,
|
82
99
|
'List known languages',
|
83
|
-
type: :boolean, required: false
|
100
|
+
type: :boolean, required: false
|
101
|
+
)
|
84
102
|
opt(
|
85
103
|
:sleep_time,
|
86
104
|
'Sleep time',
|
87
|
-
type: :integer, default: 2, short: 's'
|
105
|
+
type: :integer, default: 2, short: 's'
|
106
|
+
)
|
88
107
|
opt(
|
89
108
|
:timeout,
|
90
109
|
'Poltergeist timeout option - default 30',
|
91
|
-
type: :integer, default: 30, short: 't'
|
110
|
+
type: :integer, default: 30, short: 't'
|
111
|
+
)
|
92
112
|
opt(
|
93
113
|
:verbose,
|
94
114
|
'Be verbose with output',
|
95
|
-
type: :boolean, required: false, short: 'v', default: false
|
115
|
+
type: :boolean, required: false, short: 'v', default: false
|
116
|
+
)
|
96
117
|
end
|
97
118
|
end
|
98
119
|
# 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
|
|
@@ -12,21 +14,43 @@ module Tr4n5l4te
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def translate(text, from_lang, to_lang)
|
15
|
-
puts "Translating: #{text}"
|
16
17
|
encoded_text = validate_and_encode(text)
|
17
18
|
return '' if encoded_text == ''
|
19
|
+
|
18
20
|
smart_visit(translator_url(encoded_text, from_lang, to_lang))
|
19
|
-
result_box = browser.find('.
|
20
|
-
result_box.text
|
21
|
+
result_box = browser.find('.JLqJ4b.ChMk0b > span:first-child')
|
22
|
+
postprocess(result_box.text)
|
23
|
+
rescue Capybara::Ambiguous
|
24
|
+
all_translations = browser.find_all('.JLqJ4b.ChMk0b > span:first-child')
|
25
|
+
multiples = all_translations.collect(&:text)
|
26
|
+
puts("WARNING: '#{text}' has multiple translations: [#{multiples.join(', ')}]")
|
27
|
+
text
|
21
28
|
end
|
22
29
|
|
23
30
|
private
|
24
31
|
|
32
|
+
def preprocess(text)
|
33
|
+
@interpolations = text.scan(/(%{.*})/).flatten
|
34
|
+
@interpolations.each_with_index do |var, ndx|
|
35
|
+
stub = "VAR#{ndx}"
|
36
|
+
text.gsub!(%r{#{var}}, stub)
|
37
|
+
end
|
38
|
+
text
|
39
|
+
end
|
40
|
+
|
41
|
+
def postprocess(text)
|
42
|
+
@interpolations.each_with_index do |interp, ndx|
|
43
|
+
stub = /VAR#{ndx}/
|
44
|
+
text.gsub!(stub, interp)
|
45
|
+
end
|
46
|
+
text
|
47
|
+
end
|
48
|
+
|
25
49
|
def validate_and_encode(text)
|
26
50
|
return '' if text.nil?
|
27
51
|
fail "Cannot translate a [#{text.class}]: '#{text}'" unless text.respond_to?(:gsub)
|
28
|
-
|
29
|
-
|
52
|
+
|
53
|
+
CGI.escape(preprocess(text.strip))
|
30
54
|
end
|
31
55
|
|
32
56
|
def smart_visit(url)
|
data/lib/tr4n5l4te/version.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'
|
@@ -18,15 +20,16 @@ Gem::Specification.new do |spec|
|
|
18
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
21
|
spec.require_paths = ['lib']
|
20
22
|
|
21
|
-
spec.add_development_dependency 'bundler', '~> 2.
|
23
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
22
24
|
spec.add_development_dependency 'pry-nav'
|
23
|
-
spec.add_development_dependency 'rake', '~>
|
25
|
+
spec.add_development_dependency 'rake', '~> 13.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'
|
33
|
+
spec.add_dependency 'optimist', '~> 3.0'
|
30
34
|
spec.add_dependency 'poltergeist', '~> 1.9'
|
31
|
-
spec.add_dependency 'optimist'
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Blackburn
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry-nav
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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: '3.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: '3.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
|
@@ -189,7 +203,7 @@ homepage: https://github.com/midwire/tr4n5l4te
|
|
189
203
|
licenses:
|
190
204
|
- MIT
|
191
205
|
metadata: {}
|
192
|
-
post_install_message:
|
206
|
+
post_install_message:
|
193
207
|
rdoc_options: []
|
194
208
|
require_paths:
|
195
209
|
- lib
|
@@ -205,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
219
|
version: '0'
|
206
220
|
requirements: []
|
207
221
|
rubygems_version: 3.0.3
|
208
|
-
signing_key:
|
222
|
+
signing_key:
|
209
223
|
specification_version: 4
|
210
224
|
summary: Use Google Translate without an API key.
|
211
225
|
test_files: []
|