web_translate_it 2.6.4 → 2.7.1

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: 186304899ba3932f5c4152b0a02bc34fbdb47d0392c88d8931e30976e66ea916
4
- data.tar.gz: 90cdef9f2d193d4d00a34a2362a7af85e2f7fb010d0455f47c1991935d7e0b85
3
+ metadata.gz: 269b89b988031ffdaa8bb761411e0e93f12be4e415b48c4b6877d104ee241f06
4
+ data.tar.gz: 51706b4f7ed1d249d67050f32fd81de7c6ede08cf763ab7faaa33b5619aa9c9e
5
5
  SHA512:
6
- metadata.gz: 9d78a7788bec607b0722bce91668ea89bfb6c05c6c2c5a1baaeb34fbfbc446f16817ac84f5a902c7edb6860fe626f6de2fd03dde9dd6cb96076c3f703fccb1a0
7
- data.tar.gz: 22ae36a655963dfc12092951c2aee41fa29612e1a69ae05ce0bb79b9361ce1eb81755cdaf3a7b53152e46971d5af322989424f22ff6eb9428f7b961fb1dcbcd0
6
+ metadata.gz: d36a9194b73e6b9fe21c720874c2e86308944b909901cdcbb72e2dd7978dd05f42d40bfa2a0dfbdd11439781b0bed0b069a72b72eb4f7089fd42398e1151c7a3
7
+ data.tar.gz: aa9e14cace635cc65b209be7d3e25a969d303ee79b47f64aebfd2572ba47a3531190f70286ca046e90c6210f20ecd7bca45c8c41a47a390dfcb2fd937d1a36bb
data/bin/wti CHANGED
@@ -97,7 +97,7 @@ when 'rmlocale'
97
97
  end
98
98
  when 'status'
99
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."
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
101
  opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
102
102
  opt :debug, 'Display debug information'
103
103
  end
data/history.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## Version 2.7.1 / 2022-10-14
2
+
3
+ * Potential fix potential for issue `uninitialized constant WebTranslateIt::TranslationFile::Multipart`.
4
+ * Code refactoring.
5
+
6
+ ## Version 2.7.0 / 2022-10-10
7
+
8
+ * New: Ability to see translation statistics per file.
9
+ - `wti status` gives the whole translation project statistics.
10
+ - `wti status path/to/file` gives the file translation statistics.
11
+ * Update readme file (installation instructions and add link to Docker package).
12
+ * Fix Rspec ExampleWording offences.
13
+
1
14
  ## Version 2.6.4 / 2022-09-22
2
15
 
3
16
  * Move development dependencies to Gemfile and commit Gemfile.lock to version control.
@@ -2,8 +2,6 @@ module WebTranslateIt
2
2
 
3
3
  class CommandLine # rubocop:todo Metrics/ClassLength
4
4
 
5
- require 'fileutils'
6
- require 'set'
7
5
  attr_accessor :configuration, :global_options, :command_options, :parameters
8
6
 
9
7
  def initialize(command, command_options, _global_options, parameters, project_path) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/MethodLength
@@ -353,8 +351,15 @@ module WebTranslateIt
353
351
  true
354
352
  end
355
353
 
356
- def status # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
357
- stats = YAML.load(Project.fetch_stats(configuration.api_key))
354
+ def status # rubocop:todo Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
355
+ if parameters.any?
356
+ file = configuration.files.find { |f| parameters.first.strip == f.file_path }
357
+ abort "File '#{parameters.first}' not found." unless file
358
+
359
+ file_id = file.master_id || file.id
360
+ puts "Statistics for '#{parameters.first}':"
361
+ end
362
+ stats = YAML.load(Project.fetch_stats(configuration.api_key, file_id))
358
363
  completely_translated = true
359
364
  completely_proofread = true
360
365
  stats.each do |locale, values|
@@ -411,7 +416,6 @@ module WebTranslateIt
411
416
  puts 'Warning: `config/translation.yml` is deprecated in favour of a `.wti` file.'
412
417
  return 'config/translation.yml' unless Util.ask_yes_no('Would you like to migrate your configuration now?', true)
413
418
 
414
- require 'fileutils'
415
419
  return '.wti' if FileUtils.mv('config/translation.yml', '.wti')
416
420
 
417
421
  puts 'Couldn’t move `config/translation.yml`.'
@@ -8,9 +8,6 @@ module WebTranslateIt
8
8
  #
9
9
  class Configuration
10
10
 
11
- require 'yaml'
12
- require 'fileutils'
13
- require 'erb'
14
11
  attr_accessor :path, :api_key, :source_locale, :target_locales, :files, :ignore_locales, :needed_locales, :logger, :before_pull, :after_pull, :before_push, :after_push, :project_name, :path_to_config_file, :ignore_files
15
12
 
16
13
  # Load configuration file from the path.
@@ -30,10 +27,11 @@ module WebTranslateIt
30
27
  else
31
28
  YAML.load WebTranslateIt::Project.fetch_info(api_key)
32
29
  end
33
- set_locales_to_ignore(configuration)
34
- set_locales_needed(configuration)
35
- set_files(project_info['project'])
36
- set_locales(project_info['project'])
30
+ self.ignore_locales = locales_to_ignore(configuration)
31
+ self.needed_locales = locales_needed(configuration)
32
+ self.files = files_from_project(project_info['project'])
33
+ self.source_locale = source_locale_from_project(project_info['project'])
34
+ self.target_locales = target_locales_from_project(project_info['project'])
37
35
  self.project_name = project_info['project']['name']
38
36
  else
39
37
  puts StringUtil.failure("\nNo configuration file found in #{File.expand_path(path_to_config_file, path)}")
@@ -43,23 +41,24 @@ module WebTranslateIt
43
41
 
44
42
  # Reload project data
45
43
  #
46
- def reload
44
+ def reload # rubocop:todo Metrics/AbcSize
47
45
  project_info = YAML.load WebTranslateIt::Project.fetch_info(api_key)
48
- set_locales_to_ignore(configuration)
49
- set_locales_needed(configuration)
50
- set_files(project_info['project'])
51
- set_locales(project_info['project'])
46
+ self.ignore_locales = locales_to_ignore(configuration)
47
+ self.needed_locales = locales_needed(configuration)
48
+ self.files = files_from_project(project_info['project'])
49
+ self.source_locale = source_locale_from_project(project_info['project'])
50
+ self.target_locales = target_locales_from_project(project_info['project'])
52
51
  self.project_name = project_info['project']['name']
53
52
  end
54
53
 
55
- # Set the project locales from the Project API.
56
- # Implementation example:
57
- #
58
- # configuration = WebTranslateIt::Configuration.new
59
- # locales = configuration.locales # returns an array of locales: ['en', 'fr', 'es', ...]
60
- def set_locales(project)
61
- self.source_locale = project['source_locale']['code']
62
- self.target_locales = project['target_locales'].map { |locale| locale['code'] }
54
+ # Returns the source locale from the Project API.
55
+ def source_locale_from_project(project)
56
+ project['source_locale']['code']
57
+ end
58
+
59
+ # Returns the target locales from the Project API.
60
+ def target_locales_from_project(project)
61
+ project['target_locales'].map { |locale| locale['code'] }
63
62
  end
64
63
 
65
64
  # Set the project files from the Project API.
@@ -67,33 +66,34 @@ module WebTranslateIt
67
66
  #
68
67
  # configuration = WebTranslateIt::Configuration.new
69
68
  # files = configuration.files # returns an array of TranslationFile
70
- def set_files(project) # rubocop:todo Metrics/AbcSize
71
- self.files = []
69
+ def files_from_project(project) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
70
+ array_files = []
72
71
  project['project_files'].each do |project_file|
73
72
  if project_file['name'].nil? || (project_file['name'].strip == '')
74
73
  puts "File #{project_file['id']} not set up"
75
74
  elsif ignore_files&.any? { |glob| File.fnmatch(glob, project_file['name']) }
76
75
  puts "Ignoring #{project_file['name']}"
77
76
  else
78
- files.push TranslationFile.new(project_file['id'], project_file['name'], project_file['locale_code'], api_key, project_file['updated_at'], project_file['hash_file'], project_file['master_project_file_id'], project_file['fresh'])
77
+ array_files.push TranslationFile.new(project_file['id'], project_file['name'], project_file['locale_code'], api_key, project_file['updated_at'], project_file['hash_file'], project_file['master_project_file_id'], project_file['fresh'])
79
78
  end
80
79
  end
80
+ array_files
81
81
  end
82
82
 
83
- # Set locales to ignore from the configuration file, if set.
84
- def set_locales_to_ignore(configuration)
85
- self.ignore_locales = Array(configuration['ignore_locales']).map(&:to_s)
83
+ # Returns an array of locales to ignore from the configuration file, if set.
84
+ def locales_to_ignore(configuration)
85
+ Array(configuration['ignore_locales']).map(&:to_s)
86
86
  end
87
87
 
88
- # Set locales to specifically pull from the configuration file, if set
89
- def set_locales_needed(configuration)
90
- self.needed_locales = Array(configuration['needed_locales']).map(&:to_s)
88
+ # Returns an array of locales to specifically pull from the configuration file, if set
89
+ def locales_needed(configuration)
90
+ Array(configuration['needed_locales']).map(&:to_s)
91
91
  end
92
92
 
93
- # Set files to ignore from the configuration file, if set.
94
- def set_ignore_files(configuration)
95
- self.ignore_files = Array(configuration['ignore_files']).map(&:to_s)
96
- end
93
+ # # Set files to ignore from the configuration file, if set.
94
+ # def ignore_files(configuration)
95
+ # Array(configuration['ignore_files']).map(&:to_s)
96
+ # end
97
97
 
98
98
  # Convenience method which returns the endpoint for fetching a list of locales for a project.
99
99
  def api_url
@@ -1,15 +1,9 @@
1
- require 'English'
2
1
  module WebTranslateIt
3
2
 
4
3
  class Connection
5
4
 
6
5
  attr_reader :api_key, :http_connection
7
6
 
8
- require 'net/http'
9
- require 'net/https'
10
- require 'openssl'
11
- require 'uri'
12
-
13
7
  @api_key = nil
14
8
  @http_connection = nil
15
9
  @debug = false
@@ -49,7 +43,7 @@ module WebTranslateIt
49
43
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
50
44
  @http_connection = http.start
51
45
  yield @http_connection if block_given?
52
- rescue
46
+ rescue StandardError
53
47
  puts $ERROR_INFO
54
48
  end
55
49
  end
@@ -1,4 +1,3 @@
1
- require 'English'
2
1
  module WebTranslateIt
3
2
 
4
3
  class Project
@@ -25,18 +24,19 @@ module WebTranslateIt
25
24
  else
26
25
  success = false
27
26
  end
28
- rescue
27
+ rescue StandardError
29
28
  puts $ERROR_INFO.inspect
30
29
  end
31
30
  success
32
31
  end
33
32
 
34
- def self.fetch_stats(api_key) # rubocop:todo Metrics/MethodLength
33
+ def self.fetch_stats(api_key, file_id = nil) # rubocop:todo Metrics/MethodLength
34
+ url = file_id.nil? ? "/api/projects/#{api_key}/stats.yaml" : "/api/projects/#{api_key}/stats.yaml?file=#{file_id}"
35
35
  success = true
36
36
  tries ||= 3
37
37
  begin
38
38
  WebTranslateIt::Connection.new(api_key) do |http|
39
- request = Net::HTTP::Get.new("/api/projects/#{api_key}/stats.yaml")
39
+ request = Net::HTTP::Get.new(url)
40
40
  WebTranslateIt::Util.add_fields(request)
41
41
  return Util.handle_response(http.request(request), true)
42
42
  end
@@ -2,8 +2,6 @@ module WebTranslateIt
2
2
 
3
3
  class String # rubocop:todo Metrics/ClassLength
4
4
 
5
- require 'multi_json'
6
-
7
5
  attr_accessor :id, :key, :plural, :type, :dev_comment, :word_count, :status, :category, :labels, :file,
8
6
  :created_at, :updated_at, :translations, :new_record
9
7
 
@@ -2,9 +2,6 @@ module WebTranslateIt
2
2
 
3
3
  class Term # rubocop:todo Metrics/ClassLength
4
4
 
5
- require 'net/https'
6
- require 'multi_json'
7
-
8
5
  attr_accessor :id, :text, :description, :created_at, :updated_at, :translations, :new_record
9
6
 
10
7
  # Initialize a new WebTranslateIt::Term
@@ -2,9 +2,6 @@ module WebTranslateIt
2
2
 
3
3
  class TermTranslation
4
4
 
5
- require 'net/https'
6
- require 'multi_json'
7
-
8
5
  attr_accessor :id, :locale, :text, :description, :status, :new_record, :term_id
9
6
 
10
7
  # Initialize a new WebTranslateIt::TermTranslation
@@ -2,9 +2,6 @@ module WebTranslateIt
2
2
 
3
3
  class Translation
4
4
 
5
- require 'net/https'
6
- require 'multi_json'
7
-
8
5
  attr_accessor :id, :locale, :text, :status, :created_at, :updated_at, :version, :string_id
9
6
 
10
7
  # Initialize a new WebTranslateIt::Translation
@@ -8,11 +8,6 @@ module WebTranslateIt
8
8
  # manipulate a _target_ language file.
9
9
  class TranslationFile # rubocop:todo Metrics/ClassLength
10
10
 
11
- require 'net/https'
12
- require 'net/http/post/multipart'
13
- require 'time'
14
- require 'fileutils'
15
-
16
11
  attr_accessor :id, :file_path, :locale, :api_key, :updated_at, :remote_checksum, :master_id, :fresh
17
12
 
18
13
  def initialize(id, file_path, locale, api_key, updated_at = nil, remote_checksum = '', master_id = nil, fresh = nil) # rubocop:todo Metrics/ParameterLists
@@ -65,7 +60,7 @@ module WebTranslateIt
65
60
  else
66
61
  success = false
67
62
  end
68
- rescue
63
+ rescue StandardError
69
64
  display.push StringUtil.failure("An error occured: #{$ERROR_INFO}")
70
65
  success = false
71
66
  end
@@ -115,7 +110,7 @@ module WebTranslateIt
115
110
  else
116
111
  success = false
117
112
  end
118
- rescue
113
+ rescue StandardError
119
114
  display.push StringUtil.failure("An error occured: #{$ERROR_INFO}")
120
115
  success = false
121
116
  end
@@ -164,7 +159,7 @@ module WebTranslateIt
164
159
  else
165
160
  success = false
166
161
  end
167
- rescue
162
+ rescue StandardError
168
163
  display.push StringUtil.failure("An error occured: #{$ERROR_INFO}")
169
164
  success = false
170
165
  end
@@ -195,7 +190,7 @@ module WebTranslateIt
195
190
  else
196
191
  success = false
197
192
  end
198
- rescue
193
+ rescue StandardError
199
194
  display.push StringUtil.failure("An error occured: #{$ERROR_INFO}")
200
195
  success = false
201
196
  end
@@ -234,12 +229,9 @@ module WebTranslateIt
234
229
  end
235
230
 
236
231
  def local_checksum
237
- require 'digest/sha1'
238
- begin
239
- Digest::SHA1.hexdigest(File.read(file_path))
240
- rescue
241
- ''
242
- end
232
+ Digest::SHA1.hexdigest(File.read(file_path))
233
+ rescue StandardError
234
+ ''
243
235
  end
244
236
 
245
237
  end
@@ -3,8 +3,6 @@ module WebTranslateIt
3
3
  # A few useful functions
4
4
  class Util
5
5
 
6
- require 'multi_json'
7
-
8
6
  # Return a string representing the gem version
9
7
  # For example "1.8.3"
10
8
  def self.version
@@ -1,3 +1,15 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+ require 'erb'
4
+ require 'net/http'
5
+ require 'net/https'
6
+ require 'net/http/post/multipart'
7
+ require 'openssl'
8
+ require 'uri'
9
+ require 'multi_json'
10
+ require 'digest/sha1'
11
+ require 'English'
12
+
1
13
  require 'web_translate_it/connection'
2
14
  require 'web_translate_it/util'
3
15
  require 'web_translate_it/util/array_util'
@@ -13,8 +25,6 @@ require 'web_translate_it/auto_fetch'
13
25
  require 'web_translate_it/command_line'
14
26
  require 'web_translate_it/project'
15
27
 
16
- require 'English'
17
-
18
28
  module WebTranslateIt
19
29
 
20
30
  def self.fetch_translations # rubocop:todo Metrics/AbcSize
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
@@ -198,7 +187,11 @@ Append `--help` for each command for more information. For instance:
198
187
  </tr>
199
188
  <tr>
200
189
  <td>wti status</td>
201
- <td>View project statistics</td>
190
+ <td>View project translation statistics</td>
191
+ </tr>
192
+ <tr>
193
+ <td>wti status config/locales/app/en.yml</td>
194
+ <td>View translation statistics on file config/locales/app/en.yml</td>
202
195
  </tr>
203
196
  <tr>
204
197
  <td>wti match</td>
@@ -221,7 +214,7 @@ Check the [sample `.wti`](https://github.com/webtranslateit/webtranslateit/blob/
221
214
 
222
215
  ## Exit codes
223
216
 
224
- Since version 1.4.0 `wti` returns exit codes on failure. The exit code is `0` if the command executed successfully and `1` if the command executed but encountered at least one error. This is useful to act upon errors if you use `wti` to pull files in an automated build process.
217
+ `wti` returns exit codes on failure. The exit code is `0` if the command executed successfully and `1` if the command executed but encountered at least one error. This is useful to act upon errors if you use `wti` to pull files in an automated build process.
225
218
 
226
219
  ``` zsh
227
220
  ~/code/webtranslateit.com[master]% wti pull
@@ -250,7 +243,7 @@ Pulled 3 files at 3 files/sec, using 3 threads.
250
243
  1
251
244
  ```
252
245
 
253
- Since version 2.4.1 the `wti status` command also returns meaningful codes. It will exit with `0` if the project is 100% translated and proofread, `100` if the project is not 100% translated and `101` if the project is not 100% proofread. This could allow you to check if a project is 100% translated or completed before deploying a project.
246
+ `wti status` command also returns meaningful codes. It will exit with `0` if the project is 100% translated and proofread, `100` if the project is not 100% translated and `101` if the project is not 100% proofread. This could allow you to check if a project is 100% translated or completed before deploying a project.
254
247
 
255
248
  ``` zsh
256
249
  ~/Desktop/test% wti status
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.4
4
+ version: 2.7.1
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-09-22 00:00:00.000000000 Z
11
+ date: 2022-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json