web_translate_it 2.8.2 → 3.0.0.beta1

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: 90f545288c55ba7994137a77fe9c33a1f5ad9a0a9ef0e7e1fb55adabef34db04
4
- data.tar.gz: 276e1a44adfb1dead4c72f7d3f66c520a2e75e64621b378756ca9e05f4924a91
3
+ metadata.gz: 34ec034f6bb1b51c1acbe92a15edaf0e7d280bcb659af2264362d62d93c1b357
4
+ data.tar.gz: e56a0518f643f2732dd03d20c6d6b21aaa1ce113ee53ef8f80a48e4f2fe525d5
5
5
  SHA512:
6
- metadata.gz: 2cfc4cd709ec351d3581c896b5657144b94859519bb14a6d61f4873f11db880d199af20dcb733c460a90fe33456a57878ffa040c221f0e44735b15c143b92630
7
- data.tar.gz: 2aea23da596406f7536d4b1c9e62005a1891fffd3ff89a5010a79efde5aee38adc84b3c0c38b203cc8d78aaa1c763c87c1f9779dc48a1b1417fe275fd8e2e6df
6
+ metadata.gz: 106bf20797262e6a5fc4d55e4c6799cce2f406242e14320324c53943940012d7dfbef4dd5c22437414236e27826806011011b4b0c478bb7189bc27ce17174876
7
+ data.tar.gz: 7e89486b8fdf46a4c971b08112cd466d91573ad5b56c5f057320cd7ff9171d96c343c080938eca4d170e00b0afb0156a6275fc7b3384a9cca77b6451c2d89a1e
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,14 @@
1
+ ## Version 3.0.0.beta1 / 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
+
8
+ ## Version 2.8.3 / 2023-04-19
9
+
10
+ * Fix `wti addlocale` and `wti rmlocale` commands. #253
11
+
1
12
  ## Version 2.8.2 / 2023-04-18
2
13
 
3
14
  * Fix crash caused by use of API from older Multipart versions. #246 (@rogerluan)
@@ -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,12 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebTranslateIt
2
4
 
3
5
  class Connection
4
6
 
5
- attr_reader :api_key, :http_connection
6
-
7
- @api_key = nil
8
- @http_connection = nil
9
- @debug = false
7
+ @@api_key = nil
8
+ @@http_connection = nil
9
+ @@debug = false
10
10
 
11
11
  #
12
12
  # Initialize and yield a HTTPS Keep-Alive connection to WebTranslateIt.com
@@ -23,33 +23,35 @@ module WebTranslateIt
23
23
  # http_connection.request(request)
24
24
  # end
25
25
  #
26
- def initialize(api_key) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
27
- @api_key = api_key
26
+ def initialize(api_key) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
27
+ @@api_key = api_key
28
28
  proxy = ENV['http_proxy'] ? URI.parse(ENV['http_proxy']) : Struct.new(:host, :port, :user, :password).new
29
29
  http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new('webtranslateit.com', 443)
30
30
  http.use_ssl = true
31
31
  http.open_timeout = http.read_timeout = 60
32
- http.set_debug_output($stderr) if @debug
32
+ http.set_debug_output($stderr) if @@debug
33
33
  begin
34
34
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
35
- @http_connection = http.start
36
- yield @http_connection if block_given?
35
+ @@http_connection = http.start
36
+ yield @@http_connection if block_given?
37
37
  rescue OpenSSL::SSL::SSLError
38
- puts 'Unable to verify SSL certificate.' unless @silent
39
- http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new('webtranslateit.com', 443)
40
- http.set_debug_output($stderr) if @debug
41
- http.use_ssl = true
42
- http.open_timeout = http.read_timeout = 60
43
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
44
- @http_connection = http.start
45
- yield @http_connection if block_given?
38
+ puts 'Error: Unable to verify SSL certificate.'
39
+ exit 1
46
40
  rescue StandardError
47
41
  puts $ERROR_INFO
48
42
  end
49
43
  end
50
44
 
51
45
  def self.turn_debug_on
52
- @debug = true
46
+ @@debug = true
47
+ end
48
+
49
+ def self.api_key
50
+ @@api_key
51
+ end
52
+
53
+ def self.http_connection
54
+ @@http_connection
53
55
  end
54
56
 
55
57
  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.2
4
+ version: 3.0.0.beta1
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-18 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
- version: '0'
100
+ version: 1.3.1
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