web_translate_it 2.8.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1667be9e5fab89fe2ab18228ab94666225ebd108a6c234bed49c2df9fe5ae31
4
- data.tar.gz: 6163b2dc6e981cde12a4a64d2e28f9220d9e2983818dc70d922d60c56993f1f0
3
+ metadata.gz: 1bc4b7dbcd64e3579d7c3e2e387318a225ec4ea022ffff11d5b0e75cd2e7d02c
4
+ data.tar.gz: 7a8d7a94642bbdb7445b94960da05584e8f0c2f3c7a10fbb13ee44e60e727235
5
5
  SHA512:
6
- metadata.gz: 24a36fbb86cca9fb0abfb2f9c7936a3ef023975ab714080a561966d340b4e9b6f7d27850cf9dacd1bc23ede523d16a8133781f0901e3a325c2ca51f891b943b8
7
- data.tar.gz: 191cc4fa792d0026d30a1366f85ecf7ad047dbdcba17e16ed83b4e6c68651883c420fc4870f20e189505b26c253cc94cc524233054cd8865b0435d66c041c97a
6
+ metadata.gz: cc10adf1aff74638ec4e8109c5524d0f445b84eddded635fbd06ff03ecd262bcdbd2b519357bc4eb275eb7a92a62573c03eb48365ee3a2c1f3e6ba4989a1804c
7
+ data.tar.gz: 9fae2edb938c720297b251ebe512442dfb75a06d04dcdc7012cc1989ea510ef9560453380a0eda9cd0590a366481515b8cbf5b95b03e9d6bcc4b9c65e5e6dc11
data/bin/wti CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  $PROGRAM_NAME = 'wti'
4
5
 
data/examples/locale.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Locale
2
4
 
3
5
  def initialize(app)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
2
4
 
3
5
  Rails::Generator::Commands::Base.class_eval do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.expand_path("#{File.dirname(__FILE__)}/lib/insert_commands.rb")
2
4
 
3
5
  class WebtranslateitGenerator < Rails::Generator::Base
data/history.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## Version 3.0.0 / 2023-09-20
2
+
3
+ * Remove dependency on `multipart_post`. #255
4
+ * Add frozen string litteral comments. #251
5
+ * Bump minimum ruby version to ruby 2.7.
6
+ * Don’t rescue SSL errors. #257
7
+
1
8
  ## Version 2.8.3 / 2023-04-19
2
9
 
3
10
  * Fix `wti addlocale` and `wti rmlocale` commands. #253
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  # Class to automatically fetch the last translations from Web Translate It
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  class CommandLine # rubocop:todo Metrics/ClassLength
@@ -58,7 +60,7 @@ module WebTranslateIt
58
60
  time = Time.now
59
61
  threads = []
60
62
  n_threads = [(files.size.to_f / 3).ceil, 10].min
61
- ArrayUtil.chunk(files, n_threads).each do |file_array|
63
+ files.each_slice(n_threads).each do |file_array|
62
64
  next if file_array.empty?
63
65
 
64
66
  threads << Thread.new(file_array) do |f_array|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  # Handles the configuration of your project, both via the the configuration file
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  class Connection
@@ -33,14 +35,8 @@ module WebTranslateIt
33
35
  @@http_connection = http.start
34
36
  yield @@http_connection if block_given?
35
37
  rescue OpenSSL::SSL::SSLError
36
- puts 'Unable to verify SSL certificate.'
37
- http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new('webtranslateit.com', 443)
38
- http.set_debug_output($stderr) if @@debug
39
- http.use_ssl = true
40
- http.open_timeout = http.read_timeout = 60
41
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
42
- @@http_connection = http.start
43
- yield @@http_connection if block_given?
38
+ puts 'Error: Unable to verify SSL certificate.'
39
+ exit 1
44
40
  rescue StandardError
45
41
  puts $ERROR_INFO
46
42
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  class Project
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  class String # rubocop:todo Metrics/ClassLength
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  class Term # rubocop:todo Metrics/ClassLength
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  class TermTranslation
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  class Translation
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  # A TranslationFile is the representation of a master language file
@@ -68,7 +70,7 @@ module WebTranslateIt
68
70
  else
69
71
  display.push StringUtil.success('Skipped')
70
72
  end
71
- print ArrayUtil.to_columns(display)
73
+ print StringUtil.array_to_columns(display)
72
74
  success
73
75
  end
74
76
 
@@ -96,11 +98,18 @@ module WebTranslateIt
96
98
  if File.exist?(file_path)
97
99
  if force || (remote_checksum != local_checksum)
98
100
  File.open(file_path) do |file|
99
- params = {'file' => UploadIO.new(file, 'text/plain', file.path), 'merge' => merge, 'ignore_missing' => ignore_missing, 'label' => label, 'minor_changes' => minor_changes}
100
- params['name'] = destination_path unless destination_path.nil?
101
- params['rename_others'] = rename_others
102
- request = Net::HTTP::Put::Multipart.new(api_url, params)
101
+ params = [
102
+ ['merge', merge.to_s],
103
+ ['ignore_missing', ignore_missing.to_s],
104
+ ['label', label.to_s],
105
+ ['minor_changes', minor_changes.to_s],
106
+ ['rename_others', rename_others.to_s],
107
+ ['file', file]
108
+ ]
109
+ params += [['name', destination_path]] unless destination_path.nil?
110
+ request = Net::HTTP::Put.new(api_url)
103
111
  WebTranslateIt::Util.add_fields(request)
112
+ request.set_form params, 'multipart/form-data'
104
113
  display.push Util.handle_response(http_connection.request(request))
105
114
  rescue Timeout::Error
106
115
  puts StringUtil.failure('Request timeout. Will retry in 5 seconds.')
@@ -117,7 +126,7 @@ module WebTranslateIt
117
126
  else
118
127
  display.push StringUtil.success('Skipped')
119
128
  end
120
- puts ArrayUtil.to_columns(display)
129
+ puts StringUtil.array_to_columns(display)
121
130
  else
122
131
  puts StringUtil.failure("Can't push #{file_path}. File doesn't exist locally.")
123
132
  end
@@ -147,10 +156,13 @@ module WebTranslateIt
147
156
  display.push "#{StringUtil.checksumify(local_checksum.to_s)}..[ ]"
148
157
  if File.exist?(file_path)
149
158
  File.open(file_path) do |file|
150
- request = Net::HTTP::Post::Multipart.new(api_url_for_create, {'name' => file_path, 'file' => UploadIO.new(file, 'text/plain', file.path)})
159
+ params = [['name', file_path]]
160
+ params += [['file', file]]
161
+ request = Net::HTTP::Post.new(api_url_for_create)
151
162
  WebTranslateIt::Util.add_fields(request)
163
+ request.set_form params, 'multipart/form-data'
152
164
  display.push Util.handle_response(http_connection.request(request))
153
- puts ArrayUtil.to_columns(display)
165
+ puts StringUtil.array_to_columns(display)
154
166
  rescue Timeout::Error
155
167
  puts StringUtil.failure('Request timeout. Will retry in 5 seconds.')
156
168
  if (tries -= 1).positive?
@@ -181,7 +193,7 @@ module WebTranslateIt
181
193
  request = Net::HTTP::Delete.new(api_url_for_delete)
182
194
  WebTranslateIt::Util.add_fields(request)
183
195
  display.push Util.handle_response(http_connection.request(request))
184
- puts ArrayUtil.to_columns(display)
196
+ puts StringUtil.array_to_columns(display)
185
197
  rescue Timeout::Error
186
198
  puts StringUtil.failure('Request timeout. Will retry in 5 seconds.')
187
199
  if (tries -= 1).positive?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class HashUtil
2
4
 
3
5
  def self.to_params(hash) # rubocop:todo Metrics/MethodLength
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class StringUtil
2
4
 
3
5
  def self.backward_truncate(str)
4
6
  return '...' << str[str.length - 50 + 3..str.length] if str.length > 50
5
7
 
6
8
  spaces = ''
7
- (50 - str.length).times { spaces << ' ' }
8
- str.dup << spaces
9
+ (50 - str.length).times { spaces += ' ' }
10
+ str + spaces
9
11
  end
10
12
 
11
13
  def self.success(str)
@@ -28,4 +30,12 @@ class StringUtil
28
30
  WebTranslateIt::Util.can_display_colors? ? "\e[1m#{str}\e[0m" : str
29
31
  end
30
32
 
33
+ def self.array_to_columns(array)
34
+ if array[0][0] == '*'
35
+ "*#{backward_truncate(array[0][1..])} | #{array[1]} #{array[2]}\n"
36
+ else
37
+ " #{backward_truncate(array[0])} | #{array[1]} #{array[2]}\n"
38
+ end
39
+ end
40
+
31
41
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  # A few useful functions
@@ -33,7 +35,8 @@ module WebTranslateIt
33
35
  return StringUtil.success('Created') if response.code.to_i == 201
34
36
  return StringUtil.success('Accepted') if response.code.to_i == 202
35
37
  return StringUtil.success('Not Modified') if response.code.to_i == 304
36
- return StringUtil.failure("Locked\n (another import in progress)") if response.code.to_i == 503
38
+
39
+ StringUtil.failure("Locked\n (another import in progress)") if response.code.to_i == 503
37
40
  end
38
41
  end
39
42
  # rubocop:enable Metrics/AbcSize
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
  require 'json'
3
5
  require 'yaml'
4
6
  require 'erb'
5
7
  require 'net/http'
6
8
  require 'net/https'
7
- require 'net/http/post/multipart'
8
9
  require 'openssl'
9
10
  require 'uri'
10
11
  require 'multi_json'
@@ -13,7 +14,6 @@ require 'English'
13
14
 
14
15
  require 'web_translate_it/connection'
15
16
  require 'web_translate_it/util'
16
- require 'web_translate_it/util/array_util'
17
17
  require 'web_translate_it/util/string_util'
18
18
  require 'web_translate_it/util/hash_util'
19
19
  require 'web_translate_it/configuration'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_translate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edouard Briere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-19 00:00:00.000000000 Z
11
+ date: 2023-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: multipart-post
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '2.0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '2.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: optimist
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -78,7 +64,6 @@ files:
78
64
  - lib/web_translate_it/translation.rb
79
65
  - lib/web_translate_it/translation_file.rb
80
66
  - lib/web_translate_it/util.rb
81
- - lib/web_translate_it/util/array_util.rb
82
67
  - lib/web_translate_it/util/hash_util.rb
83
68
  - lib/web_translate_it/util/string_util.rb
84
69
  - license
@@ -107,14 +92,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
92
  requirements:
108
93
  - - ">="
109
94
  - !ruby/object:Gem::Version
110
- version: '2.6'
95
+ version: '2.7'
111
96
  required_rubygems_version: !ruby/object:Gem::Requirement
112
97
  requirements:
113
98
  - - ">="
114
99
  - !ruby/object:Gem::Version
115
100
  version: '0'
116
101
  requirements: []
117
- rubygems_version: 3.4.10
102
+ rubygems_version: 3.4.19
118
103
  signing_key:
119
104
  specification_version: 4
120
105
  summary: A CLI tool to sync locale files with WebTranslateIt.com.
@@ -1,25 +0,0 @@
1
- class ArrayUtil
2
-
3
- def self.to_columns(arr)
4
- if arr[0][0] == '*'
5
- "*#{StringUtil.backward_truncate(arr[0][1..])} | #{arr[1]} #{arr[2]}\n"
6
- else
7
- " #{StringUtil.backward_truncate(arr[0])} | #{arr[1]} #{arr[2]}\n"
8
- end
9
- end
10
-
11
- def self.chunk(arr, pieces = 2) # rubocop:todo Metrics/MethodLength
12
- len = arr.length
13
- mid = (len / pieces)
14
- chunks = []
15
- start = 0
16
- 1.upto(pieces) do |i|
17
- last = start + mid
18
- last -= 1 unless len % pieces >= i
19
- chunks << (arr[start..last] || [])
20
- start = last + 1
21
- end
22
- chunks
23
- end
24
-
25
- end