tr4n5l4te 0.1.8 → 0.1.14
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/CHANGELOG +27 -0
- data/Gemfile.lock +49 -44
- data/README.md +6 -6
- data/bin/console +4 -4
- data/lib/tr4n5l4te/agent.rb +3 -1
- data/lib/tr4n5l4te/runner.rb +15 -5
- data/lib/tr4n5l4te/translator.rb +32 -5
- data/lib/tr4n5l4te/version.rb +1 -1
- data/tr4n5l4te.gemspec +3 -3
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2708e83a48fe0953a4907f1bd440e3f5268e28b23cf34c1f3e3ee53a7cb66cd0
|
4
|
+
data.tar.gz: 43c32d754fb454c1e65b2349c71e5db4a2507c967de3feb8f0362e547a3a6bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3bf415df410267cddb4cb1cb9954bbb3bd1e93eff96813dad2b8137830137db8c40d107c7209d29a5fd9148388421a5571bb922251e82d59844f5cf74c5b94a
|
7
|
+
data.tar.gz: 5283f8a67579572b5c32f3ed63ae5b8a9c5b1282e1ca49d24fbc313610d52a7deba8d9919bb4494e291d592b22302a1ce050680fc8b1046acbd56acd5b5a5f91
|
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
*0.1.14* (June 07, 2021)
|
2
|
+
|
3
|
+
* Add workaround for phantomjs SSL handshake problem, issue #24 - SSL handshake failed, by @gahia - see also: "https://github.com/ariya/phantomjs/issues/12440"
|
4
|
+
* Look for and report non-neutral gender translations. Now accepts the "male" translation by default and warns that there are alternatives, by @gahia.
|
5
|
+
* Don't fail if a translation is not found but instead show a warning message and continue, by @gahia.
|
6
|
+
|
7
|
+
*0.1.13* (April 30, 2021)
|
8
|
+
|
9
|
+
* Upgrade rexml from 3.2.4 to 3.2.5 to fix a CVE
|
10
|
+
|
11
|
+
*0.1.12* (March 11, 2021)
|
12
|
+
|
13
|
+
* Dump console message into oblivion, do we don't see stupid warning messages like "Using this console may allow attackers to impersonate you and steal your information using an attack called Self-XSS"
|
14
|
+
|
15
|
+
*0.1.11* (March 09, 2021)
|
16
|
+
|
17
|
+
* Disregard case when using variable interpolation.
|
18
|
+
|
19
|
+
*0.1.10* (March 09, 2021)
|
20
|
+
|
21
|
+
* Accomodate latest changes to the web interface.
|
22
|
+
|
23
|
+
*0.1.9* (March 05, 2020)
|
24
|
+
|
25
|
+
* The top-level primary language key was being propagated from the source .yml file to the translated target .yml file. That is now fixed.
|
26
|
+
* Now keeps the interpolation tags intact.
|
27
|
+
|
1
28
|
*0.1.8* (February 21, 2020)
|
2
29
|
|
3
30
|
* Address ambiguous translations without stopping the run when the exception occurs.
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tr4n5l4te (0.1.
|
4
|
+
tr4n5l4te (0.1.14)
|
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
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
specs:
|
14
14
|
addressable (2.7.0)
|
15
15
|
public_suffix (>= 2.0.2, < 5.0)
|
16
|
-
ast (2.4.
|
16
|
+
ast (2.4.2)
|
17
17
|
capybara (2.18.0)
|
18
18
|
addressable
|
19
19
|
mini_mime (>= 0.1.3)
|
@@ -22,23 +22,20 @@ GEM
|
|
22
22
|
rack-test (>= 0.5.4)
|
23
23
|
xpath (>= 2.0, < 4.0)
|
24
24
|
cliver (0.3.2)
|
25
|
-
coderay (1.1.
|
25
|
+
coderay (1.1.3)
|
26
26
|
colored (1.2)
|
27
|
-
diff-lcs (1.
|
28
|
-
docile (1.3.
|
29
|
-
jaro_winkler (1.5.4)
|
30
|
-
json (2.3.0)
|
27
|
+
diff-lcs (1.4.4)
|
28
|
+
docile (1.3.5)
|
31
29
|
method_source (0.9.2)
|
32
30
|
midwire_common (0.3.0)
|
33
31
|
thor (~> 0.19)
|
34
32
|
mini_mime (1.0.2)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
ast (~> 2.4.0)
|
33
|
+
nokogiri (1.11.5-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)
|
42
39
|
poltergeist (1.18.1)
|
43
40
|
capybara (>= 2.1, < 4)
|
44
41
|
cliver (~> 0.3.1)
|
@@ -48,43 +45,51 @@ GEM
|
|
48
45
|
method_source (~> 0.9.0)
|
49
46
|
pry-nav (0.3.0)
|
50
47
|
pry (>= 0.9.10, < 0.13.0)
|
51
|
-
public_suffix (4.0.
|
52
|
-
|
48
|
+
public_suffix (4.0.6)
|
49
|
+
racc (1.5.2)
|
50
|
+
rack (2.2.3)
|
53
51
|
rack-test (1.1.0)
|
54
52
|
rack (>= 1.0, < 3)
|
55
53
|
rainbow (3.0.0)
|
56
|
-
rake (
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
rspec-
|
61
|
-
|
62
|
-
rspec-
|
63
|
-
rspec-
|
54
|
+
rake (13.0.3)
|
55
|
+
regexp_parser (2.1.1)
|
56
|
+
rexml (3.2.5)
|
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)
|
64
64
|
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
-
rspec-support (~> 3.
|
66
|
-
rspec-mocks (3.
|
65
|
+
rspec-support (~> 3.10.0)
|
66
|
+
rspec-mocks (3.10.2)
|
67
67
|
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
-
rspec-support (~> 3.
|
69
|
-
rspec-support (3.
|
70
|
-
rubocop (
|
71
|
-
jaro_winkler (~> 1.5.1)
|
68
|
+
rspec-support (~> 3.10.0)
|
69
|
+
rspec-support (3.10.2)
|
70
|
+
rubocop (1.11.0)
|
72
71
|
parallel (~> 1.10)
|
73
|
-
parser (>=
|
72
|
+
parser (>= 3.0.0.0)
|
74
73
|
rainbow (>= 2.2.2, < 4.0)
|
74
|
+
regexp_parser (>= 1.8, < 3.0)
|
75
|
+
rexml
|
76
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
75
77
|
ruby-progressbar (~> 1.7)
|
76
|
-
unicode-display_width (>= 1.4.0, <
|
77
|
-
|
78
|
-
|
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)
|
79
83
|
docile (~> 1.1)
|
80
|
-
|
81
|
-
|
82
|
-
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)
|
83
88
|
thor (0.20.3)
|
84
|
-
unicode-display_width (
|
85
|
-
websocket-driver (0.7.
|
89
|
+
unicode-display_width (2.0.0)
|
90
|
+
websocket-driver (0.7.3)
|
86
91
|
websocket-extensions (>= 0.1.0)
|
87
|
-
websocket-extensions (0.1.
|
92
|
+
websocket-extensions (0.1.5)
|
88
93
|
xpath (3.2.0)
|
89
94
|
nokogiri (~> 1.8)
|
90
95
|
|
@@ -92,13 +97,13 @@ PLATFORMS
|
|
92
97
|
ruby
|
93
98
|
|
94
99
|
DEPENDENCIES
|
95
|
-
bundler (~> 2.
|
100
|
+
bundler (~> 2.1)
|
96
101
|
pry-nav
|
97
|
-
rake (~>
|
102
|
+
rake (~> 13.0)
|
98
103
|
rspec (~> 3.0)
|
99
104
|
rubocop
|
100
105
|
simplecov (~> 0.11)
|
101
106
|
tr4n5l4te!
|
102
107
|
|
103
108
|
BUNDLED WITH
|
104
|
-
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.14**
|
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
|
|
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/lib/tr4n5l4te/agent.rb
CHANGED
@@ -10,7 +10,9 @@ module Tr4n5l4te
|
|
10
10
|
app,
|
11
11
|
js_errors: false,
|
12
12
|
timeout: Tr4n5l4te.configuration.timeout,
|
13
|
-
phantomjs_options: ['--load-images=no']
|
13
|
+
phantomjs_options: ['--load-images=no', '--ignore-ssl-errors=yes', '--web-security=false', '--ssl-protocol=any'],
|
14
|
+
phantomjs_logger: StringIO.new,
|
15
|
+
logger: StringIO.new
|
14
16
|
)
|
15
17
|
end
|
16
18
|
Capybara.default_driver = :poltergeist
|
data/lib/tr4n5l4te/runner.rb
CHANGED
@@ -4,6 +4,7 @@ require 'optimist'
|
|
4
4
|
require 'colored'
|
5
5
|
require 'fileutils'
|
6
6
|
require 'midwire_common/string'
|
7
|
+
require 'pry' unless ENV.fetch('GEM_ENV', nil).nil?
|
7
8
|
|
8
9
|
module Tr4n5l4te
|
9
10
|
class Runner
|
@@ -30,7 +31,7 @@ module Tr4n5l4te
|
|
30
31
|
|
31
32
|
hash = YAML.load_file(options[:yaml_file])
|
32
33
|
translated = process(hash)
|
33
|
-
store_translation(translated)
|
34
|
+
store_translation(replace_lang_key(translated))
|
34
35
|
|
35
36
|
puts("Processed #{@count} strings in [#{Time.now - start_time}] seconds.".yellow)
|
36
37
|
end
|
@@ -47,7 +48,7 @@ module Tr4n5l4te
|
|
47
48
|
|
48
49
|
def translate(string)
|
49
50
|
@count += 1
|
50
|
-
puts("[#{string}]") if options[:verbose]
|
51
|
+
puts("Translating [#{string}]") if options[:verbose]
|
51
52
|
translator.translate(string, from_lang, options[:lang])
|
52
53
|
end
|
53
54
|
|
@@ -56,10 +57,19 @@ module Tr4n5l4te
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def from_lang
|
59
|
-
|
60
|
-
|
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
|
61
63
|
|
62
|
-
|
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 }
|
63
73
|
end
|
64
74
|
|
65
75
|
def store_translation(translated)
|
data/lib/tr4n5l4te/translator.rb
CHANGED
@@ -14,27 +14,54 @@ module Tr4n5l4te
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def translate(text, from_lang, to_lang)
|
17
|
-
puts "Translating: #{text}"
|
18
17
|
encoded_text = validate_and_encode(text)
|
19
18
|
return '' if encoded_text == ''
|
20
19
|
|
21
20
|
smart_visit(translator_url(encoded_text, from_lang, to_lang))
|
22
|
-
result_box = browser.find('.
|
23
|
-
result_box.text
|
21
|
+
result_box = browser.find('.JLqJ4b.ChMk0b > span:first-child')
|
22
|
+
postprocess(result_box.text)
|
23
|
+
|
24
24
|
rescue Capybara::Ambiguous
|
25
|
-
all_translations = browser.find_all('.
|
25
|
+
all_translations = browser.find_all('.JLqJ4b.ChMk0b > span:first-child')
|
26
26
|
multiples = all_translations.collect(&:text)
|
27
27
|
puts("WARNING: '#{text}' has multiple translations: [#{multiples.join(', ')}]")
|
28
28
|
text
|
29
|
+
|
30
|
+
rescue Capybara::ElementNotFound
|
31
|
+
all_translations = browser.find_all('.J0lOec > span:first-child')
|
32
|
+
multiples = all_translations.collect(&:text)
|
33
|
+
if multiples.any?
|
34
|
+
puts("WARNING: '#{text}' has gender translations: [#{multiples.join(', ')}]")
|
35
|
+
postprocess(multiples.last) # take the male form
|
36
|
+
else
|
37
|
+
puts("WARNING: Could not find a translation for '#{text}'")
|
38
|
+
end
|
29
39
|
end
|
30
40
|
|
31
41
|
private
|
32
42
|
|
43
|
+
def preprocess(text)
|
44
|
+
@interpolations = text.scan(/(%{.*})/).flatten
|
45
|
+
@interpolations.each_with_index do |var, ndx|
|
46
|
+
stub = "VAR#{ndx}"
|
47
|
+
text.gsub!(%r{#{var}}, stub)
|
48
|
+
end
|
49
|
+
text
|
50
|
+
end
|
51
|
+
|
52
|
+
def postprocess(text)
|
53
|
+
@interpolations.each_with_index do |interp, ndx|
|
54
|
+
stub = /VAR#{ndx}/i
|
55
|
+
text.gsub!(stub, interp)
|
56
|
+
end
|
57
|
+
text
|
58
|
+
end
|
59
|
+
|
33
60
|
def validate_and_encode(text)
|
34
61
|
return '' if text.nil?
|
35
62
|
fail "Cannot translate a [#{text.class}]: '#{text}'" unless text.respond_to?(:gsub)
|
36
63
|
|
37
|
-
CGI.escape(text.strip)
|
64
|
+
CGI.escape(preprocess(text.strip))
|
38
65
|
end
|
39
66
|
|
40
67
|
def smart_visit(url)
|
data/lib/tr4n5l4te/version.rb
CHANGED
data/tr4n5l4te.gemspec
CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_development_dependency 'bundler', '~> 2.
|
23
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
24
24
|
spec.add_development_dependency 'pry-nav'
|
25
|
-
spec.add_development_dependency 'rake', '~>
|
25
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
26
26
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
27
|
spec.add_development_dependency 'rubocop'
|
28
28
|
spec.add_development_dependency 'simplecov', '~> 0.11'
|
@@ -30,6 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_dependency 'capybara', '~> 2.6'
|
31
31
|
spec.add_dependency 'colored', '~> 1'
|
32
32
|
spec.add_dependency 'midwire_common', '~> 0.1'
|
33
|
-
spec.add_dependency 'optimist'
|
33
|
+
spec.add_dependency 'optimist', '~> 3.0'
|
34
34
|
spec.add_dependency 'poltergeist', '~> 1.9'
|
35
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.14
|
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-06-07 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
|
@@ -140,16 +140,16 @@ dependencies:
|
|
140
140
|
name: optimist
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
145
|
+
version: '3.0'
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - "
|
150
|
+
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
152
|
+
version: '3.0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: poltergeist
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,7 +203,7 @@ homepage: https://github.com/midwire/tr4n5l4te
|
|
203
203
|
licenses:
|
204
204
|
- MIT
|
205
205
|
metadata: {}
|
206
|
-
post_install_message:
|
206
|
+
post_install_message:
|
207
207
|
rdoc_options: []
|
208
208
|
require_paths:
|
209
209
|
- lib
|
@@ -218,8 +218,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
- !ruby/object:Gem::Version
|
219
219
|
version: '0'
|
220
220
|
requirements: []
|
221
|
-
rubygems_version: 3.
|
222
|
-
signing_key:
|
221
|
+
rubygems_version: 3.1.4
|
222
|
+
signing_key:
|
223
223
|
specification_version: 4
|
224
224
|
summary: Use Google Translate without an API key.
|
225
225
|
test_files: []
|