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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 204b74b356e859f4e2eb6495d225307ee7344267785d0e961d7608beb99fdf5e
4
- data.tar.gz: c934a59f87142a43fa9ddc40d4c26e04e73c088a04f916f90e97ce18d2cd2e39
3
+ metadata.gz: 5628a5c8a6bdbe6d6ace4af5ae7219aca724ab217578bda9266381cedc7b5359
4
+ data.tar.gz: fce1e1f205dfaf0054eadcc79b9c6add8607e84d384b94247305806ae8e757bc
5
5
  SHA512:
6
- metadata.gz: b8b01237723dec2ef19e1570f59792701503c769c324dda07da9d950fc85c74897adca11e57507fc5e0531ad9a1202c57814e95f3adc6dd90f66ccd582fe4628
7
- data.tar.gz: 29d9b1c7c921741e2531029f18b1220fe84ad217f52b9f3ab547edfcfbcf97b4936abdc1f130069e4d329f184b91e04089b4cc85141125a0de4e766ad9fd9683
6
+ metadata.gz: c7884c55e6723c27eb2cb74107bec48b1dbbeca9a2386562ae94052f798d53d4315d73356002353259ed7c48497a481cb62b4888088992ac86723ab1e4e3042f
7
+ data.tar.gz: 9878365b79bb5c5c4c680e2077fb2c0a967d5ac708ba4e031f03f16fc712d6c099e55122beb3003ed6e1f9d803223d9311d969a65d2b93c030e6f03f66eef3ba
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
  test.html
10
10
  /vendor
11
11
  /stubs
12
+ /node_modules/
13
+ yarn.lock
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
- # Include gemspec and Rakefile
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/MultilineMethodCallIndentation:
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
- Style/CaseIndentation:
109
+ Layout/CaseIndentation:
63
110
  Enabled: false
64
111
 
65
- Style/TrivialAccessors:
112
+ Layout/ElseAlignment:
66
113
  Enabled: false
67
114
 
68
- Style/NumericLiterals:
115
+ Layout/EndAlignment:
116
+ EnforcedStyleAlignWith: variable
117
+
118
+ ########################################
119
+ # Naming Cops
120
+
121
+ Naming/FileName:
69
122
  Enabled: false
70
123
 
71
124
  ########################################
72
- # Lint Cops
125
+ # Security Cops
73
126
 
74
- Lint/Eval:
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in tr4n5l4te.gemspec
data/Gemfile.lock CHANGED
@@ -1,18 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tr4n5l4te (0.1.5)
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.6.0)
15
- public_suffix (>= 2.0.2, < 4.0)
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.2)
25
+ coderay (1.1.3)
25
26
  colored (1.2)
26
- diff-lcs (1.3)
27
- docile (1.3.1)
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.1)
33
- mini_portile2 (2.4.0)
34
- nokogiri (1.10.3)
35
- mini_portile2 (~> 2.4.0)
36
- optimist (3.0.0)
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 (3.0.3)
47
- rack (2.0.7)
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
- rake (10.5.0)
51
- rspec (3.8.0)
52
- rspec-core (~> 3.8.0)
53
- rspec-expectations (~> 3.8.0)
54
- rspec-mocks (~> 3.8.0)
55
- rspec-core (3.8.0)
56
- rspec-support (~> 3.8.0)
57
- rspec-expectations (3.8.3)
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.8.0)
60
- rspec-mocks (3.8.0)
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.8.0)
63
- rspec-support (3.8.0)
64
- simplecov (0.16.1)
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
- json (>= 1.8, < 3)
67
- simplecov-html (~> 0.10.0)
68
- simplecov-html (0.10.2)
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
- websocket-driver (0.7.0)
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.3)
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.0.1)
100
+ bundler (~> 2.1)
81
101
  pry-nav
82
- rake (~> 10.0)
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.0.1
109
+ 2.1.4
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tr4n5l4te
2
2
 
3
- **Version: 0.1.5**
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 = %w(
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 -t
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
5
  require 'rspec/core/rake_task'
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
- # require "pry"
11
- # Pry.start
10
+ require 'pry'
11
+ Pry.start
12
12
 
13
- require 'irb'
14
- IRB.start
13
+ # require 'irb'
14
+ # IRB.start
data/exe/translate CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'rubygems'
4
5
  require 'bundler/setup'
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
- to_s.snakerize
17
+ 'tr4n5l4te'
17
18
  end
18
19
 
19
20
  def default_config_directory
@@ -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'.freeze
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.load(File.read(cookie_file))
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 Metrics/AbcSize, Lint/AssignmentInCondition
50
+ # rubocop:enable
47
51
 
48
52
  def store_cookies(cookie_file)
49
53
  FileUtils.mkdir_p(File.dirname(cookie_file))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tr4n5l4te
2
4
  class Configuration
3
5
  attr_accessor :timeout
@@ -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
- "af" => "Afrikaans",
5
- "sq" => "Albanian",
6
- "am" => "Amharic",
7
- "ar" => "Arabic",
8
- "hy" => "Armenian",
9
- "az" => "Azerbaijani",
10
- "eu" => "Basque",
11
- "be" => "Belarusian",
12
- "bn" => "Bengali",
13
- "bs" => "Bosnian",
14
- "bg" => "Bulgarian",
15
- "ca" => "Catalan",
16
- "ceb" => "Cebuano",
17
- "ny" => "Chichewa",
18
- "zh-CN" => "Chinese",
19
- "co" => "Corsican",
20
- "hr" => "Croatian",
21
- "cs" => "Czech",
22
- "da" => "Danish",
23
- "nl" => "Dutch",
24
- "en" => "English",
25
- "eo" => "Esperanto",
26
- "et" => "Estonian",
27
- "tl" => "Filipino",
28
- "fi" => "Finnish",
29
- "fr" => "French",
30
- "fy" => "Frisian",
31
- "gl" => "Galician",
32
- "ka" => "Georgian",
33
- "de" => "German",
34
- "el" => "Greek",
35
- "gu" => "Gujarati",
36
- "ht" => "Haitian Creole",
37
- "ha" => "Hausa",
38
- "haw" => "Hawaiian",
39
- "iw" => "Hebrew",
40
- "hi" => "Hindi",
41
- "hmn" => "Hmong",
42
- "hu" => "Hungarian",
43
- "is" => "Icelandic",
44
- "ig" => "Igbo",
45
- "id" => "Indonesian",
46
- "ga" => "Irish",
47
- "it" => "Italian",
48
- "ja" => "Japanese",
49
- "jw" => "Javanese",
50
- "kn" => "Kannada",
51
- "kk" => "Kazakh",
52
- "km" => "Khmer",
53
- "ko" => "Korean",
54
- "ku" => "Kurdish (Kurmanji)",
55
- "ky" => "Kyrgyz",
56
- "lo" => "Lao",
57
- "la" => "Latin",
58
- "lv" => "Latvian",
59
- "lt" => "Lithuanian",
60
- "lb" => "Luxembourgish",
61
- "mk" => "Macedonian",
62
- "mg" => "Malagasy",
63
- "ms" => "Malay",
64
- "ml" => "Malayalam",
65
- "mt" => "Maltese",
66
- "mi" => "Maori",
67
- "mr" => "Marathi",
68
- "mn" => "Mongolian",
69
- "my" => "Myanmar (Burmese)",
70
- "ne" => "Nepali",
71
- "no" => "Norwegian",
72
- "ps" => "Pashto",
73
- "fa" => "Persian",
74
- "pl" => "Polish",
75
- "pt" => "Portuguese",
76
- "pa" => "Punjabi",
77
- "ro" => "Romanian",
78
- "ru" => "Russian",
79
- "sm" => "Samoan",
80
- "gd" => "Scots Gaelic",
81
- "sr" => "Serbian",
82
- "st" => "Sesotho",
83
- "sn" => "Shona",
84
- "sd" => "Sindhi",
85
- "si" => "Sinhala",
86
- "sk" => "Slovak",
87
- "sl" => "Slovenian",
88
- "so" => "Somali",
89
- "es" => "Spanish",
90
- "su" => "Sundanese",
91
- "sw" => "Swahili",
92
- "sv" => "Swedish",
93
- "tg" => "Tajik",
94
- "ta" => "Tamil",
95
- "te" => "Telugu",
96
- "th" => "Thai",
97
- "tr" => "Turkish",
98
- "uk" => "Ukrainian",
99
- "ur" => "Urdu",
100
- "uz" => "Uzbek",
101
- "vi" => "Vietnamese",
102
- "cy" => "Welsh",
103
- "xh" => "Xhosa",
104
- "yi" => "Yiddish",
105
- "yo" => "Yoruba",
106
- "zu" => "Zulu"
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
 
@@ -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
- md = File.basename(options[:yaml_file]).match(/^(\w\w)\.yml$/)
58
- raise "Could not determine language from yaml file: '#{options[:yaml_file]}'" unless md
59
- md[1]
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
@@ -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'.freeze
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('.tlid-translation')
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
- text.strip!
29
- URI.encode(text)
52
+
53
+ CGI.escape(preprocess(text.strip))
30
54
  end
31
55
 
32
56
  def smart_visit(url)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tr4n5l4te
2
- VERSION = '0.1.5'.freeze
4
+ VERSION = '0.1.10'.freeze
3
5
  end
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.0.1'
23
+ spec.add_development_dependency 'bundler', '~> 2.1'
22
24
  spec.add_development_dependency 'pry-nav'
23
- spec.add_development_dependency 'rake', '~> 10.0'
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.5
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: 2019-05-06 00:00:00.000000000 Z
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.0.1
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.0.1
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: '10.0'
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: '10.0'
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: poltergeist
140
+ name: optimist
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '1.9'
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: '1.9'
152
+ version: '3.0'
139
153
  - !ruby/object:Gem::Dependency
140
- name: optimist
154
+ name: poltergeist
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ">="
157
+ - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '0'
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: '0'
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: []