web_translate_it 2.6.3 → 2.7.0

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: 0b4f8260eedb1c889b34365fbb4d5e5f00b4907c52068a5f9ee1271eac7e0aa8
4
- data.tar.gz: b872158814a7a958c873ddb603651b14aab8a2809c5ee42fbc7398d01fe71218
3
+ metadata.gz: 6cef77421b30d347178a38e6fe50300e44d41a2c47fe46736ad79d76bc891374
4
+ data.tar.gz: e3d93cec2762262b06a8eb5aa2f71a901eb5ba77ff09b1e2f85462f765617501
5
5
  SHA512:
6
- metadata.gz: 2e71ac4f5c76fb436583cd10b1f2092528eb5204a4b777a97b611eff2e55600c07f192c4844794d20c8e5dc800af5e0c73d308f074dc643917173efd5a0703e6
7
- data.tar.gz: 5955c786b2a7f69f55e9ac9126d0a4637a4ecb9e286b9d810efdb1a5c58450cf183dee71601eb35454798c244c8d098f8af635e25988a4a1b30935e8eeb5fc11
6
+ metadata.gz: 154b48ea91ca07bc107ff3b551678bf152a791db84432be020d1e3f3444c7f0830f303f5a222947fdbf1178638648df973f1c2ff8755c8db30e22c8916808c75
7
+ data.tar.gz: 1bbf7533a388aeec98f9d0541c1839d95d18ed99d0cf2ccb4bb6400cb0852ddd8d98d04e4d29315b55c05790e70095db5d5a418ac47a1b47234ca84da495cf5b
data/bin/wti CHANGED
@@ -34,93 +34,93 @@ end
34
34
 
35
35
  command = ARGV.shift # get the subcommand
36
36
  command_options = case command
37
- when 'pull'
38
- Optimist.options do
39
- banner <<~BANNER
40
- wti pull [filename] - Pull target language file(s)
41
- [options] are:
42
- BANNER
43
- opt :locale, 'ISO code of locale(s) to pull, space-separated', type: :string
44
- opt :all, 'Pull all files'
45
- opt :force, 'Force pull (bypass conditional requests to WTI)'
46
- opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
47
- opt :debug, 'Display debug information'
48
- end
49
- when 'push'
50
- Optimist.options do
51
- banner <<~BANNER
52
- wti push [filename] - Push master language file(s)
53
- [options] are:
54
- BANNER
55
- opt :locale, 'ISO code of locale(s) to push, space-separated', type: :string
56
- opt :target, 'Upload all target files'
57
- opt :force, 'Force push (bypass conditional requests to WTI)'
58
- opt :low_priority, 'WTI will process this file with a low priority'
59
- opt :merge, 'Force WTI to merge this file'
60
- opt :ignore_missing, 'Force WTI to not obsolete missing strings'
61
- opt :minor, 'Minor Changes. When pushing a master file, prevents target translations to be flagged as `to_verify`.'
62
- opt :label, 'Apply a label to the changes', type: :string
63
- opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
64
- opt :all, 'DEPRECATED -- See `wti push --target` instead'
65
- opt :debug, 'Display debug information'
66
- end
67
- when 'add'
68
- Optimist.options do
69
- banner 'wti add filename - Create and push a new master language file'
70
- opt :low_priority, 'WTI will process this file with a low priority'
71
- opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
72
- opt :debug, 'Display debug information'
73
- end
74
- when 'rm'
75
- Optimist.options do
76
- banner 'wti rm filename - Delete a master language file'
77
- opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
78
- opt :debug, 'Display debug information'
79
- end
80
- when 'mv'
81
- Optimist.options do
82
- banner 'wti mv filename - Moves a master language file and its target files'
83
- opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
84
- opt :debug, 'Display debug information'
85
- end
86
- when 'addlocale'
87
- Optimist.options do
88
- banner 'wti addlocale localename - Add a new locale to the project'
89
- opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
90
- opt :debug, 'Display debug information'
91
- end
92
- when 'rmlocale'
93
- Optimist.options do
94
- banner 'wti rmlocale localename Delete a locale from the project'
95
- opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
96
- opt :debug, 'Display debug information'
97
- end
98
- when 'status'
99
- Optimist.options do
100
- banner "wti status - Fetch and display project statistics.\nReturns 100 if untranslated segments exist in project\nReturns 101 if unproofread segments exist in project."
101
- opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
102
- opt :debug, 'Display debug information'
103
- end
104
- when 'init'
105
- Optimist.options do
106
- banner 'wti init [api_token] - Configure your project to sync'
107
- opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
108
- opt :debug, 'Display debug information'
109
- end
110
- when 'match'
111
- Optimist.options do
112
- banner 'wti match - Display matching of local files with File Manager'
113
- opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
114
- opt :debug, 'Display debug information'
115
- end
116
- else
117
- if command.nil?
118
- puts show_commands
119
- exit
120
- else
121
- Optimist.die "Unknown subcommand #{command.inspect}"
122
- end
123
- end
37
+ when 'pull'
38
+ Optimist.options do
39
+ banner <<~BANNER
40
+ wti pull [filename] - Pull target language file(s)
41
+ [options] are:
42
+ BANNER
43
+ opt :locale, 'ISO code of locale(s) to pull, space-separated', type: :string
44
+ opt :all, 'Pull all files'
45
+ opt :force, 'Force pull (bypass conditional requests to WTI)'
46
+ opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
47
+ opt :debug, 'Display debug information'
48
+ end
49
+ when 'push'
50
+ Optimist.options do
51
+ banner <<~BANNER
52
+ wti push [filename] - Push master language file(s)
53
+ [options] are:
54
+ BANNER
55
+ opt :locale, 'ISO code of locale(s) to push, space-separated', type: :string
56
+ opt :target, 'Upload all target files'
57
+ opt :force, 'Force push (bypass conditional requests to WTI)'
58
+ opt :low_priority, 'WTI will process this file with a low priority'
59
+ opt :merge, 'Force WTI to merge this file'
60
+ opt :ignore_missing, 'Force WTI to not obsolete missing strings'
61
+ opt :minor, 'Minor Changes. When pushing a master file, prevents target translations to be flagged as `to_verify`.'
62
+ opt :label, 'Apply a label to the changes', type: :string
63
+ opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
64
+ opt :all, 'DEPRECATED -- See `wti push --target` instead'
65
+ opt :debug, 'Display debug information'
66
+ end
67
+ when 'add'
68
+ Optimist.options do
69
+ banner 'wti add filename - Create and push a new master language file'
70
+ opt :low_priority, 'WTI will process this file with a low priority'
71
+ opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
72
+ opt :debug, 'Display debug information'
73
+ end
74
+ when 'rm'
75
+ Optimist.options do
76
+ banner 'wti rm filename - Delete a master language file'
77
+ opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
78
+ opt :debug, 'Display debug information'
79
+ end
80
+ when 'mv'
81
+ Optimist.options do
82
+ banner 'wti mv filename - Moves a master language file and its target files'
83
+ opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
84
+ opt :debug, 'Display debug information'
85
+ end
86
+ when 'addlocale'
87
+ Optimist.options do
88
+ banner 'wti addlocale localename - Add a new locale to the project'
89
+ opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
90
+ opt :debug, 'Display debug information'
91
+ end
92
+ when 'rmlocale'
93
+ Optimist.options do
94
+ banner 'wti rmlocale localename Delete a locale from the project'
95
+ opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
96
+ opt :debug, 'Display debug information'
97
+ end
98
+ when 'status'
99
+ Optimist.options do
100
+ banner "wti status [filename] - Fetch and display project statistics.\nReturns 100 if untranslated segments exist in project\nReturns 101 if unproofread segments exist in project."
101
+ opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
102
+ opt :debug, 'Display debug information'
103
+ end
104
+ when 'init'
105
+ Optimist.options do
106
+ banner 'wti init [api_token] - Configure your project to sync'
107
+ opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
108
+ opt :debug, 'Display debug information'
109
+ end
110
+ when 'match'
111
+ Optimist.options do
112
+ banner 'wti match - Display matching of local files with File Manager'
113
+ opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
114
+ opt :debug, 'Display debug information'
115
+ end
116
+ else
117
+ if command.nil?
118
+ puts show_commands
119
+ exit
120
+ else
121
+ Optimist.die "Unknown subcommand #{command.inspect}"
122
+ end
123
+ end
124
124
 
125
125
  begin
126
126
  WebTranslateIt::Connection.turn_debug_on if command_options.debug
data/examples/locale.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  class Locale
2
+
2
3
  def initialize(app)
3
4
  @app = app
4
5
  end
@@ -9,4 +10,5 @@ class Locale
9
10
  status, headers, response = @app.call(env)
10
11
  [status, headers, response]
11
12
  end
13
+
12
14
  end
@@ -1,6 +1,7 @@
1
1
  require File.expand_path("#{File.dirname(__FILE__)}/lib/insert_commands.rb")
2
2
 
3
3
  class WebtranslateitGenerator < Rails::Generator::Base
4
+
4
5
  def add_options!(opt)
5
6
  opt.on('-k', '--api-key=key', String, 'Your Web Translate It API key') { |v| options[:api_key] = v }
6
7
  end
@@ -14,7 +15,7 @@ class WebtranslateitGenerator < Rails::Generator::Base
14
15
  if options[:api_key]
15
16
  project_details = YAML.load WebTranslateIt::Project.fetch_info(options[:api_key])
16
17
  m.template '.wti', '.wti',
17
- assigns: { api_key: options[:api_key], project: project_details['project'] }
18
+ assigns: {api_key: options[:api_key], project: project_details['project']}
18
19
  m.append_to 'Rakefile', "require 'web_translate_it' rescue LoadError"
19
20
  end
20
21
  end
@@ -23,4 +24,5 @@ class WebtranslateitGenerator < Rails::Generator::Base
23
24
  def api_key_configured?
24
25
  File.exist?('config/translations.yml')
25
26
  end
27
+
26
28
  end
data/history.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## Version 2.7.0 / 2022-10-10
2
+
3
+ * New: Ability to see translation statistics per file.
4
+ - `wti status` gives the whole translation project statistics.
5
+ - `wti status path/to/file` gives the file translation statistics.
6
+ * Update readme file (installation instructions and add link to Docker package).
7
+ * Fix Rspec ExampleWording offences.
8
+
9
+ ## Version 2.6.4 / 2022-09-22
10
+
11
+ * Move development dependencies to Gemfile and commit Gemfile.lock to version control.
12
+ * wti now sends a `User-Agent` header.
13
+
1
14
  ## Version 2.6.3 / 2022-06-14
2
15
 
3
16
  * Fix deprecation warning. #181
@@ -1,4 +1,5 @@
1
1
  module WebTranslateIt
2
+
2
3
  # Class to automatically fetch the last translations from Web Translate It
3
4
  # for every page requested.
4
5
  # This can be used as a rack middleware.
@@ -8,6 +9,7 @@ module WebTranslateIt
8
9
  # config.middleware.use "WebTranslateIt::AutoFetch"
9
10
  #
10
11
  class AutoFetch
12
+
11
13
  def initialize(app)
12
14
  @app = app
13
15
  end
@@ -27,5 +29,7 @@ module WebTranslateIt
27
29
  def valid_request?(env)
28
30
  env['PATH_INFO'] !~ /\.(js|css|jpeg|jpg|gif|png|woff)$/
29
31
  end
32
+
30
33
  end
34
+
31
35
  end
@@ -1,31 +1,33 @@
1
1
  module WebTranslateIt
2
+
2
3
  class CommandLine # rubocop:todo Metrics/ClassLength
4
+
3
5
  require 'fileutils'
4
6
  require 'set'
5
7
  attr_accessor :configuration, :global_options, :command_options, :parameters
6
8
 
7
- def initialize(command, command_options, global_options, parameters, project_path) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/MethodLength
9
+ def initialize(command, command_options, _global_options, parameters, project_path) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/MethodLength
8
10
  self.command_options = command_options
9
11
  self.parameters = parameters
10
12
  unless command == 'init'
11
13
  message = case command
12
- when 'pull'
13
- 'Pulling files'
14
- when 'push'
15
- 'Pushing files'
16
- when 'add'
17
- 'Creating master files'
18
- when 'rm'
19
- 'Deleting files'
20
- when 'mv'
21
- 'Moving files'
22
- when 'addlocale'
23
- 'Adding locale'
24
- when 'rmlocale'
25
- 'Deleting locale'
26
- else
27
- 'Gathering information'
28
- end
14
+ when 'pull'
15
+ 'Pulling files'
16
+ when 'push'
17
+ 'Pushing files'
18
+ when 'add'
19
+ 'Creating master files'
20
+ when 'rm'
21
+ 'Deleting files'
22
+ when 'mv'
23
+ 'Moving files'
24
+ when 'addlocale'
25
+ 'Adding locale'
26
+ when 'rmlocale'
27
+ 'Deleting locale'
28
+ else
29
+ 'Gathering information'
30
+ end
29
31
  throb do
30
32
  print " #{message}"
31
33
  self.configuration = WebTranslateIt::Configuration.new(project_path, configuration_file_path)
@@ -107,10 +109,10 @@ module WebTranslateIt
107
109
  WebTranslateIt::Connection.new(configuration.api_key) do |http|
108
110
  fetch_locales_to_push(configuration).each do |locale|
109
111
  files = if parameters.any?
110
- configuration.files.find_all { |file| parameters.include?(file.file_path) }.sort { |a, b| a.file_path <=> b.file_path }
111
- else
112
- configuration.files.find_all { |file| file.locale == locale }.sort { |a, b| a.file_path <=> b.file_path }
113
- end
112
+ configuration.files.find_all { |file| parameters.include?(file.file_path) }.sort { |a, b| a.file_path <=> b.file_path }
113
+ else
114
+ configuration.files.find_all { |file| file.locale == locale }.sort { |a, b| a.file_path <=> b.file_path }
115
+ end
114
116
  if files.empty?
115
117
  puts "Couldn't find any local files registered on WebTranslateIt to push."
116
118
  else
@@ -295,10 +297,10 @@ module WebTranslateIt
295
297
  end
296
298
  FileUtils.mkpath(path.split('/')[0..path.split('/').size - 2].join('/')) unless path.split('/').size == 1
297
299
  project = if RUBY_VERSION >= '3.1'
298
- YAML.safe_load WebTranslateIt::Project.fetch_info(api_key), permitted_classes: [Time]
299
- else
300
- YAML.load WebTranslateIt::Project.fetch_info(api_key)
301
- end
300
+ YAML.safe_load WebTranslateIt::Project.fetch_info(api_key), permitted_classes: [Time]
301
+ else
302
+ YAML.load WebTranslateIt::Project.fetch_info(api_key)
303
+ end
302
304
  project_info = project['project']
303
305
  if File.exist?(path) && !File.writable?(path)
304
306
  puts StringUtil.failure("Error: `#{path}` file is not writable.")
@@ -351,8 +353,15 @@ module WebTranslateIt
351
353
  true
352
354
  end
353
355
 
354
- def status # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
355
- stats = YAML.load(Project.fetch_stats(configuration.api_key))
356
+ def status # rubocop:todo Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
357
+ if parameters.any?
358
+ file = configuration.files.find { |f| parameters.first.strip == f.file_path }
359
+ abort "File '#{parameters.first}' not found." unless file
360
+
361
+ file_id = file.master_id || file.id
362
+ puts "Statistics for '#{parameters.first}':"
363
+ end
364
+ stats = YAML.load(Project.fetch_stats(configuration.api_key, file_id))
356
365
  completely_translated = true
357
366
  completely_proofread = true
358
367
  stats.each do |locale, values|
@@ -470,5 +479,7 @@ module WebTranslateIt
470
479
  puts "\r\e[0G#\e[?25h"
471
480
  end
472
481
  end
482
+
473
483
  end
484
+
474
485
  end
@@ -1,4 +1,5 @@
1
1
  module WebTranslateIt
2
+
2
3
  # Handles the configuration of your project, both via the the configuration file
3
4
  # and via the API.
4
5
  # Implementation example, assuming you have a valid .wti file:
@@ -6,6 +7,7 @@ module WebTranslateIt
6
7
  # configuration = WebTranslateIt::Configuration.new
7
8
  #
8
9
  class Configuration
10
+
9
11
  require 'yaml'
10
12
  require 'fileutils'
11
13
  require 'erb'
@@ -24,10 +26,10 @@ module WebTranslateIt
24
26
  self.after_push = configuration['after_push']
25
27
  self.ignore_files = configuration['ignore_files']
26
28
  project_info = if RUBY_VERSION >= '3.1.0'
27
- YAML.safe_load WebTranslateIt::Project.fetch_info(api_key), permitted_classes: [Time]
28
- else
29
- YAML.load WebTranslateIt::Project.fetch_info(api_key)
30
- end
29
+ YAML.safe_load WebTranslateIt::Project.fetch_info(api_key), permitted_classes: [Time]
30
+ else
31
+ YAML.load WebTranslateIt::Project.fetch_info(api_key)
32
+ end
31
33
  set_locales_to_ignore(configuration)
32
34
  set_locales_needed(configuration)
33
35
  set_files(project_info['project'])
@@ -116,5 +118,7 @@ module WebTranslateIt
116
118
  def parse_erb_in_configuration
117
119
  ERB.new(File.read(File.expand_path(path_to_config_file, path))).result
118
120
  end
121
+
119
122
  end
123
+
120
124
  end
@@ -1,6 +1,8 @@
1
1
  require 'English'
2
2
  module WebTranslateIt
3
+
3
4
  class Connection
5
+
4
6
  attr_reader :api_key, :http_connection
5
7
 
6
8
  require 'net/http'
@@ -55,5 +57,7 @@ module WebTranslateIt
55
57
  def self.turn_debug_on
56
58
  @debug = true
57
59
  end
60
+
58
61
  end
62
+
59
63
  end
@@ -1,6 +1,8 @@
1
1
  require 'English'
2
2
  module WebTranslateIt
3
+
3
4
  class Project
5
+
4
6
  def self.fetch_info(api_key) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
5
7
  success = true
6
8
  tries ||= 3
@@ -29,12 +31,13 @@ module WebTranslateIt
29
31
  success
30
32
  end
31
33
 
32
- def self.fetch_stats(api_key) # rubocop:todo Metrics/MethodLength
34
+ def self.fetch_stats(api_key, file_id = nil) # rubocop:todo Metrics/MethodLength
35
+ url = file_id.nil? ? "/api/projects/#{api_key}/stats.yaml" : "/api/projects/#{api_key}/stats.yaml?file=#{file_id}"
33
36
  success = true
34
37
  tries ||= 3
35
38
  begin
36
39
  WebTranslateIt::Connection.new(api_key) do |http|
37
- request = Net::HTTP::Get.new("/api/projects/#{api_key}/stats.yaml")
40
+ request = Net::HTTP::Get.new(url)
38
41
  WebTranslateIt::Util.add_fields(request)
39
42
  return Util.handle_response(http.request(request), true)
40
43
  end
@@ -56,7 +59,7 @@ module WebTranslateIt
56
59
  begin
57
60
  request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/locales")
58
61
  WebTranslateIt::Util.add_fields(request)
59
- request.set_form_data({ 'id' => locale_code }, ';')
62
+ request.set_form_data({'id' => locale_code}, ';')
60
63
  Util.handle_response(Connection.http_connection.request(request), true)
61
64
  rescue Timeout::Error
62
65
  puts 'Request timeout. Will retry in 5 seconds.'
@@ -88,5 +91,7 @@ module WebTranslateIt
88
91
  end
89
92
  success
90
93
  end
94
+
91
95
  end
96
+
92
97
  end
@@ -1,5 +1,7 @@
1
1
  module WebTranslateIt
2
+
2
3
  class String # rubocop:todo Metrics/ClassLength
4
+
3
5
  require 'multi_json'
4
6
 
5
7
  attr_accessor :id, :key, :plural, :type, :dev_comment, :word_count, :status, :category, :labels, :file,
@@ -265,7 +267,7 @@ module WebTranslateIt
265
267
  success
266
268
  end
267
269
 
268
- def to_json(with_translations = false) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
270
+ def to_json(with_translations = false) # rubocop:todo Metrics/AbcSize
269
271
  hash = {
270
272
  'id' => id,
271
273
  'key' => key,
@@ -278,12 +280,14 @@ module WebTranslateIt
278
280
  'file' => file
279
281
  }
280
282
  if translations.any? && with_translations
281
- hash.update({ 'translations' => [] })
283
+ hash.update({'translations' => []})
282
284
  translations.each do |translation|
283
285
  hash['translations'].push(translation.to_hash)
284
286
  end
285
287
  end
286
288
  MultiJson.dump(hash)
287
289
  end
290
+
288
291
  end
292
+
289
293
  end
@@ -1,5 +1,7 @@
1
1
  module WebTranslateIt
2
+
2
3
  class Term # rubocop:todo Metrics/ClassLength
4
+
3
5
  require 'net/https'
4
6
  require 'multi_json'
5
7
 
@@ -255,19 +257,21 @@ module WebTranslateIt
255
257
  success
256
258
  end
257
259
 
258
- def to_json(with_translations = false) # rubocop:todo Metrics/MethodLength
260
+ def to_json(with_translations = false)
259
261
  hash = {
260
262
  'id' => id,
261
263
  'text' => text,
262
264
  'description' => description
263
265
  }
264
266
  if translations.any? && with_translations
265
- hash.update({ 'translations' => [] })
267
+ hash.update({'translations' => []})
266
268
  translations.each do |translation|
267
269
  hash['translations'].push(translation.to_hash)
268
270
  end
269
271
  end
270
272
  MultiJson.dump(hash)
271
273
  end
274
+
272
275
  end
276
+
273
277
  end
@@ -1,5 +1,7 @@
1
1
  module WebTranslateIt
2
+
2
3
  class TermTranslation
4
+
3
5
  require 'net/https'
4
6
  require 'multi_json'
5
7
 
@@ -98,5 +100,7 @@ module WebTranslateIt
98
100
  end
99
101
  success
100
102
  end
103
+
101
104
  end
105
+
102
106
  end
@@ -1,5 +1,7 @@
1
1
  module WebTranslateIt
2
+
2
3
  class Translation
4
+
3
5
  require 'net/https'
4
6
  require 'multi_json'
5
7
 
@@ -63,5 +65,7 @@ module WebTranslateIt
63
65
  def to_json(*_args)
64
66
  MultiJson.dump(to_hash)
65
67
  end
68
+
66
69
  end
70
+
67
71
  end
@@ -1,4 +1,5 @@
1
1
  module WebTranslateIt
2
+
2
3
  # A TranslationFile is the representation of a master language file
3
4
  # on Web Translate It.
4
5
  #
@@ -6,6 +7,7 @@ module WebTranslateIt
6
7
  # If you pass a Locale to the master language file you will be able to
7
8
  # manipulate a _target_ language file.
8
9
  class TranslationFile # rubocop:todo Metrics/ClassLength
10
+
9
11
  require 'net/https'
10
12
  require 'net/http/post/multipart'
11
13
  require 'time'
@@ -99,7 +101,7 @@ module WebTranslateIt
99
101
  if File.exist?(file_path)
100
102
  if force || (remote_checksum != local_checksum)
101
103
  File.open(file_path) do |file|
102
- params = { 'file' => Multipart::Post::UploadIO.new(file, 'text/plain', file.path), 'merge' => merge, 'ignore_missing' => ignore_missing, 'label' => label, 'low_priority' => low_priority, 'minor_changes' => minor_changes }
104
+ params = {'file' => Multipart::Post::UploadIO.new(file, 'text/plain', file.path), 'merge' => merge, 'ignore_missing' => ignore_missing, 'label' => label, 'low_priority' => low_priority, 'minor_changes' => minor_changes}
103
105
  params['name'] = destination_path unless destination_path.nil?
104
106
  params['rename_others'] = rename_others
105
107
  request = Net::HTTP::Put::Multipart.new(api_url, params)
@@ -150,7 +152,7 @@ module WebTranslateIt
150
152
  display.push "#{StringUtil.checksumify(local_checksum.to_s)}..[ ]"
151
153
  if File.exist?(file_path)
152
154
  File.open(file_path) do |file|
153
- request = Net::HTTP::Post::Multipart.new(api_url_for_create, { 'name' => file_path, 'file' => Multipart::Post::UploadIO.new(file, 'text/plain', file.path), 'low_priority' => low_priority })
155
+ request = Net::HTTP::Post::Multipart.new(api_url_for_create, {'name' => file_path, 'file' => Multipart::Post::UploadIO.new(file, 'text/plain', file.path), 'low_priority' => low_priority})
154
156
  WebTranslateIt::Util.add_fields(request)
155
157
  display.push Util.handle_response(http_connection.request(request))
156
158
  puts ArrayUtil.to_columns(display)
@@ -239,5 +241,7 @@ module WebTranslateIt
239
241
  ''
240
242
  end
241
243
  end
244
+
242
245
  end
246
+
243
247
  end
@@ -1,4 +1,5 @@
1
1
  class ArrayUtil
2
+
2
3
  def self.to_columns(arr)
3
4
  if arr[0][0] == '*'
4
5
  "*#{StringUtil.backward_truncate(arr[0][1..])} | #{arr[1]} #{arr[2]}\n"
@@ -20,4 +21,5 @@ class ArrayUtil
20
21
  end
21
22
  chunks
22
23
  end
24
+
23
25
  end
@@ -1,4 +1,5 @@
1
1
  class HashUtil
2
+
2
3
  def self.to_params(hash) # rubocop:todo Metrics/MethodLength
3
4
  params = ''
4
5
  stack = []
@@ -24,9 +25,11 @@ class HashUtil
24
25
  params.chop! # trailing &
25
26
  params
26
27
  end
28
+
27
29
  end
28
30
 
29
31
  class Hash
32
+
30
33
  # Destructively convert all keys to strings.
31
34
  def stringify_keys!
32
35
  keys.each do |key|
@@ -34,4 +37,5 @@ class Hash
34
37
  end
35
38
  self
36
39
  end
40
+
37
41
  end
@@ -1,4 +1,5 @@
1
1
  class StringUtil
2
+
2
3
  def self.backward_truncate(str)
3
4
  return '...' << str[str.length - 50 + 3..str.length] if str.length > 50
4
5
 
@@ -26,4 +27,5 @@ class StringUtil
26
27
  def self.important(str)
27
28
  WebTranslateIt::Util.can_display_colors? ? "\e[1m#{str}\e[0m" : str
28
29
  end
30
+
29
31
  end
@@ -1,6 +1,8 @@
1
1
  module WebTranslateIt
2
+
2
3
  # A few useful functions
3
4
  class Util
5
+
4
6
  require 'multi_json'
5
7
 
6
8
  # Return a string representing the gem version
@@ -41,8 +43,7 @@ module WebTranslateIt
41
43
  # rubocop:enable Metrics/PerceivedComplexity
42
44
 
43
45
  def self.add_fields(request)
44
- request.add_field('X-Client-Name', 'web_translate_it')
45
- request.add_field('X-Client-Version', version)
46
+ request.add_field('User-Agent', "wti v#{version}")
46
47
  request.add_field('Content-Type', 'application/json')
47
48
  end
48
49
 
@@ -51,26 +52,26 @@ module WebTranslateIt
51
52
 
52
53
  def self.ask_yes_no(question, default = nil) # rubocop:todo Metrics/MethodLength
53
54
  qstr = case default
54
- when nil
55
- 'yn'
56
- when true
57
- 'Yn'
58
- else
59
- 'yN'
60
- end
55
+ when nil
56
+ 'yn'
57
+ when true
58
+ 'Yn'
59
+ else
60
+ 'yN'
61
+ end
61
62
 
62
63
  result = nil
63
64
 
64
65
  while result.nil?
65
66
  result = ask("#{question} [#{qstr}]")
66
67
  result = case result
67
- when /^[Yy].*/
68
- true
69
- when /^[Nn].*/
70
- false
71
- when '', nil
72
- default
73
- end
68
+ when /^[Yy].*/
69
+ true
70
+ when /^[Nn].*/
71
+ false
72
+ when '', nil
73
+ default
74
+ end
74
75
  end
75
76
 
76
77
  result
@@ -96,5 +97,7 @@ module WebTranslateIt
96
97
  def self.can_display_colors?
97
98
  !RUBY_PLATFORM.downcase.include?('mingw32')
98
99
  end
100
+
99
101
  end
102
+
100
103
  end
@@ -16,6 +16,7 @@ require 'web_translate_it/project'
16
16
  require 'English'
17
17
 
18
18
  module WebTranslateIt
19
+
19
20
  def self.fetch_translations # rubocop:todo Metrics/AbcSize
20
21
  config = Configuration.new
21
22
  locale = I18n.locale.to_s
@@ -28,4 +29,5 @@ module WebTranslateIt
28
29
  end
29
30
  end
30
31
  end
32
+
31
33
  end
data/readme.md CHANGED
@@ -3,7 +3,8 @@
3
3
  [RubyDoc](https://www.rubydoc.info/gems/web_translate_it/) |
4
4
  [Report a bug](https://github.com/webtranslateit/webtranslateit/issues) |
5
5
  [Support](https://webtranslateit.com/support) |
6
- [WebTranslateIt.com Homepage](https://webtranslateit.com)
6
+ [WebTranslateIt.com Homepage](https://webtranslateit.com) |
7
+ [Docker Package](https://github.com/webtranslateit/wti-docker/pkgs/container/wti-docker)
7
8
 
8
9
  wti lets you easily sync your language files with [WebTranslateIt.com](https://webtranslateit.com), a web-based tool to translation software.
9
10
 
@@ -11,7 +12,7 @@ wti lets you easily sync your language files with [WebTranslateIt.com](https://w
11
12
 
12
13
  ### wti...
13
14
 
14
- * wti is a **command-line tool**. It works on all operating systems: Windows, Linux, MacOS X...
15
+ * wti is a **command-line tool**. It works on all operating systems: Windows, Linux, MacOS X, ... It is also available as a [Docker package](https://github.com/webtranslateit/wti-docker/pkgs/container/wti-docker).
15
16
  * wti is really easy to use. It was inspired by git. Use `wti push` and `wti pull` to sync your language files with WebTranslateIt.com.
16
17
 
17
18
  ### Optionally, wti does...
@@ -24,12 +25,12 @@ wti lets you easily sync your language files with [WebTranslateIt.com](https://w
24
25
 
25
26
  ## Installation
26
27
 
27
- You will also need ruby to run `wti`. On Linux or a Mac, it’s already installed. Install [RubyInstaller](http://rubyinstaller.org/) if you’re using Windows. [See detailed installation instructions for Windows users](https://github.com/webtranslateit/webtranslateit/wiki/Install-wti-on-Windows).
28
+ You will also need ruby to run `wti`. We require ruby version 2.6 or newer. On Linux or a Mac, it’s already installed. Install [RubyInstaller](http://rubyinstaller.org/) if you’re using Windows. [See detailed installation instructions for Windows users](https://github.com/webtranslateit/webtranslateit/wiki/Install-wti-on-Windows).
28
29
 
29
30
  ``` bash
30
31
  $ gem install web_translate_it
31
- Fetching: web_translate_it-2.1.3.gem (100%)
32
- Successfully installed web_translate_it-2.1.3
32
+ Fetching: web_translate_it-2.6.4.gem (100%)
33
+ Successfully installed web_translate_it-2.6.4
33
34
  1 gem installed
34
35
  ```
35
36
 
@@ -37,26 +38,14 @@ At this point you should have the `wti` executable working:
37
38
 
38
39
  ``` bash
39
40
  $ wti -v
40
- wti version 2.2.1
41
+ wti version 2.6.4
41
42
  ```
42
43
 
43
- On some Linux distributions you may get the following error:
44
-
45
- ``` bash
46
- $ wti
47
- If 'wti' is not a typo you can use command-not-found to lookup the package that contains it, like this:
48
- cnf wti
49
- ```
50
-
51
- The reason is that the wti file is named in another way: `/usr/bin/wti.ruby2.1` so you will have to create a symlink to make wti run.
52
-
53
- ``` bash
54
- # ln -s /usr/bin/wti.ruby2.1 /usr/bin/wti
55
- ```
44
+ We also provide `wti` as a Docker packages. [See our packages and instructions to install](https://github.com/webtranslateit/wti-docker/pkgs/container/wti-docker).
56
45
 
57
46
  ## Configuration
58
47
 
59
- Now that the tool is installed, you’ll have to configure your project. Basically, `wti` is to be run on a project root directory, and looks for a `.wti` file containing your project information. The command `wti init` lets your create your `.wti` file.
48
+ Now that `wti` is installed, you’ll have to configure your project. Basically, `wti` is to be run on a project root directory, and looks for a `.wti` file containing your project information. The command `wti init` lets your create your `.wti` file.
60
49
 
61
50
  ``` bash
62
51
  $ wti init proj_pvt_V8skdjsdDDA4
@@ -217,7 +206,7 @@ There are 4 hooks:
217
206
  * `before_push`
218
207
  * `after_push`
219
208
 
220
- Check the [sample `.wti`](https://github.com/webtranslateit/webtranslateit/blob/master/examples/.wti#L16-L21) file for implementation.
209
+ Check the [sample `.wti`](https://github.com/webtranslateit/webtranslateit/blob/main/examples/.wti#L21-L28) file for implementation.
221
210
 
222
211
  ## Exit codes
223
212
 
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.6.3
4
+ version: 2.7.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: 2022-06-14 00:00:00.000000000 Z
11
+ date: 2022-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -52,76 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- - !ruby/object:Gem::Dependency
56
- name: guard-rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard-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'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: 2.6.0
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 2.6.0
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: simplecov
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
55
  description: A Command Line Interface tool to push and pull language files to WebTranslateIt.com.
126
56
  email: support@webtranslateit.com
127
57
  executables:
@@ -184,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
114
  - !ruby/object:Gem::Version
185
115
  version: '0'
186
116
  requirements: []
187
- rubygems_version: 3.2.33
117
+ rubygems_version: 3.3.21
188
118
  signing_key:
189
119
  specification_version: 4
190
120
  summary: A CLI tool to sync locale files with WebTranslateIt.com.