web_translate_it 3.1.2 → 3.2.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: d4db3eb8623580c53dff0ca3d6e4dea860781436b20c9ff4580bf53e5a7661d0
4
- data.tar.gz: f68c3e3ef4b7ed934a6df20da1c4eb13afaa7c115468595f241efc4bc3f5dea5
3
+ metadata.gz: 62888b8fc7d40d82a556bbe69e049b5f8ca713d79208c1a65540c9fa3893bdad
4
+ data.tar.gz: e3f9e96f09e669f20d2235314842bfc0b2865cf67816b4bc48d2e369c4b13bdf
5
5
  SHA512:
6
- metadata.gz: 2faab2844f1ed735004291f6dc7def7cdb630837c18e4e526ca90dc83cb537379090f825403a5cfb2b758fa7213945419fd47eb45e849b154b20af1cbf54d3a5
7
- data.tar.gz: b1ae273de1459eabe8ad461d0eee5261e2428aff6ad69230ee7af9a1806302efb09fcea4af7f864c0f6fde697ef7558339777717d583a6cdac95e92a5e9c70ae
6
+ metadata.gz: '099f8ebe73c79ad7a57a56beab8e8a2f1aa5688b57fa84c6020439d11fa2e836047cc22ebfcd33363db8ff751dbbffd9c27fe952a3930786acfda715d8bebdfd'
7
+ data.tar.gz: 8f2611c67e384f751d617a863675e66a9c0c4ce0f254516f42a3a7284aa784a9f6938895bb5e3b9d5bb005ccc1831b59b6f8159b5edbd1cb648305f692cae080
data/bin/wti CHANGED
@@ -13,6 +13,7 @@ show_commands = <<~COMMANDS
13
13
  pull Pull target language file(s)
14
14
  push Push master language file(s)
15
15
  match Display matching of local files with File Manager
16
+ diff Display a diff between local and remote files
16
17
  add Create and push a new master language file
17
18
  rm Delete a master language file from a project
18
19
  mv Moves a file both locally and from a project
@@ -26,7 +27,7 @@ show_commands = <<~COMMANDS
26
27
  [options] are:
27
28
  COMMANDS
28
29
 
29
- SUB_COMMANDS = %w[pull push match add rm mv addlocale rmlocale status st init].freeze
30
+ SUB_COMMANDS = %w[pull push match diff add rm mv addlocale rmlocale status st init].freeze
30
31
  global_options = Optimist.options do
31
32
  stop_on SUB_COMMANDS
32
33
  banner show_commands
@@ -65,6 +66,15 @@ when 'push'
65
66
  opt :all, 'DEPRECATED -- See `wti push --target` instead'
66
67
  opt :debug, 'Display debug information'
67
68
  end
69
+ when 'diff'
70
+ Optimist.options do
71
+ banner <<~BANNER
72
+ wti diff [filename] - Display a diff between local and remote files
73
+ [options] are:
74
+ BANNER
75
+ opt :config, 'Path to a configuration file', short: '-c', default: '.wti'
76
+ opt :debug, 'Display debug information'
77
+ end
68
78
  when 'add'
69
79
  Optimist.options do
70
80
  banner 'wti add filename - Create and push a new master language file'
data/history.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## Version 3.2.0 / 2026-01-14
2
+
3
+ * Add `wti diff` command.
4
+
1
5
  ## Version 3.1.2 / 2025-06-06
2
6
 
3
7
  * Fix `wti mv` command. #366
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tempfile'
4
+
3
5
  module WebTranslateIt
4
6
 
5
7
  class CommandLine # rubocop:todo Metrics/ClassLength
@@ -15,6 +17,8 @@ module WebTranslateIt
15
17
  'Pulling files'
16
18
  when 'push'
17
19
  'Pushing files'
20
+ when 'diff'
21
+ 'Diffing files'
18
22
  when 'add'
19
23
  'Creating master files'
20
24
  when 'rm'
@@ -150,6 +154,42 @@ module WebTranslateIt
150
154
  end
151
155
  end
152
156
 
157
+ def diff # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
158
+ complete_success = true
159
+ $stdout.sync = true
160
+ WebTranslateIt::Connection.new(configuration.api_key) do |http|
161
+ files = if parameters.any?
162
+ configuration.files.find_all { |file| parameters.include?(file.file_path) }.sort { |a, b| a.file_path <=> b.file_path }
163
+ else
164
+ configuration.files.find_all { |file| file.locale == configuration.source_locale }.sort { |a, b| a.file_path <=> b.file_path }
165
+ end
166
+ if files.empty?
167
+ puts "Couldn't find any local files registered on WebTranslateIt to diff."
168
+ else
169
+ files.each do |file|
170
+ if File.exist?(file.file_path)
171
+ remote_content = file.fetch_remote_content(http)
172
+ if remote_content
173
+ temp_file = Tempfile.new('wti')
174
+ temp_file.write(remote_content)
175
+ temp_file.close
176
+ puts "Diff for #{file.file_path}:"
177
+ system "diff #{temp_file.path} #{file.file_path}"
178
+ temp_file.unlink
179
+ else
180
+ puts StringUtil.failure("Couldn't fetch remote file #{file.file_path}")
181
+ complete_success = false
182
+ end
183
+ else
184
+ puts StringUtil.failure("Can't diff #{file.file_path}. File doesn't exist locally.")
185
+ complete_success = false
186
+ end
187
+ end
188
+ end
189
+ end
190
+ complete_success
191
+ end
192
+
153
193
  def add # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
154
194
  complete_success = true
155
195
  $stdout.sync = true
@@ -296,7 +336,7 @@ module WebTranslateIt
296
336
  api_key = Util.ask(' Project API Key:')
297
337
  path = Util.ask(' Path to configuration file:', '.wti')
298
338
  end
299
- FileUtils.mkpath(path.split('/')[0..path.split('/').size - 2].join('/')) unless path.split('/').size == 1
339
+ FileUtils.mkpath(path.split('/')[0..(path.split('/').size - 2)].join('/')) unless path.split('/').size == 1
300
340
  project = JSON.parse WebTranslateIt::Project.fetch_info(api_key)
301
341
  project_info = project['project']
302
342
  if File.exist?(path) && !File.writable?(path)
@@ -46,27 +46,27 @@ module WebTranslateIt
46
46
  end
47
47
  display.push "#{StringUtil.checksumify(local_checksum.to_s)}..#{StringUtil.checksumify(remote_checksum.to_s)}"
48
48
  if !File.exist?(file_path) || force || (remote_checksum != local_checksum)
49
+
50
+ request = Net::HTTP::Get.new(api_url)
51
+ WebTranslateIt::Util.add_fields(request)
52
+ FileUtils.mkpath(file_path.split('/')[0..-2].join('/')) unless File.exist?(file_path) || (file_path.split('/')[0..-2].join('/') == '')
49
53
  begin
50
- request = Net::HTTP::Get.new(api_url)
51
- WebTranslateIt::Util.add_fields(request)
52
- FileUtils.mkpath(file_path.split('/')[0..-2].join('/')) unless File.exist?(file_path) || (file_path.split('/')[0..-2].join('/') == '')
53
- begin
54
- response = http_connection.request(request)
55
- File.open(file_path, 'wb') { |file| file << response.body } if response.code.to_i == 200
56
- display.push Util.handle_response(response)
57
- rescue Timeout::Error
58
- puts StringUtil.failure('Request timeout. Will retry in 5 seconds.')
59
- if (tries -= 1).positive?
60
- sleep(5)
61
- retry
62
- else
63
- success = false
64
- end
65
- rescue StandardError
66
- display.push StringUtil.failure("An error occured: #{$ERROR_INFO}")
54
+ response = http_connection.request(request)
55
+ File.open(file_path, 'wb') { |file| file << response.body } if response.code.to_i == 200
56
+ display.push Util.handle_response(response)
57
+ rescue Timeout::Error
58
+ puts StringUtil.failure('Request timeout. Will retry in 5 seconds.')
59
+ if (tries -= 1).positive?
60
+ sleep(5)
61
+ retry
62
+ else
67
63
  success = false
68
64
  end
65
+ rescue StandardError
66
+ display.push StringUtil.failure("An error occured: #{$ERROR_INFO}")
67
+ success = false
69
68
  end
69
+
70
70
  else
71
71
  display.push StringUtil.success('Skipped')
72
72
  end
@@ -74,6 +74,13 @@ module WebTranslateIt
74
74
  success
75
75
  end
76
76
 
77
+ def fetch_remote_content(http_connection)
78
+ request = Net::HTTP::Get.new(api_url)
79
+ WebTranslateIt::Util.add_fields(request)
80
+ response = http_connection.request(request)
81
+ response.body if response.code.to_i == 200
82
+ end
83
+
77
84
  # Update a language file to Web Translate It by performing a PUT Request.
78
85
  #
79
86
  # Example of implementation:
@@ -3,7 +3,7 @@
3
3
  class StringUtil
4
4
 
5
5
  def self.backward_truncate(str)
6
- return "...#{str[str.length - 50 + 3..str.length]}" if str.length > 50
6
+ return "...#{str[(str.length - 50 + 3)..str.length]}" if str.length > 50
7
7
 
8
8
  spaces = ''
9
9
  (50 - str.length).times { spaces += ' ' }
data/man/wti.1 CHANGED
@@ -15,6 +15,9 @@
15
15
  .P
16
16
  \fBwti pull\fR [\fB\-l\fR] \fIOPTIONS\fR
17
17
  .
18
+ .P
19
+ \fBwti diff\fR \fIOPTIONS\fR
20
+ .
18
21
  .SH "DESCRIPTION"
19
22
  \fBwti\fR is an utility to help you sync language files between the WebTranslateIt\.com service and your computer/server\.
20
23
  .
@@ -25,6 +28,9 @@
25
28
  \fBwti pull\fR will pull the target language files from Web Translate It\. It will download and update your file with the latest translations from Web Translate It\.
26
29
  .
27
30
  .P
31
+ \fBwti diff\fR will show a difference between your local file and the file hosted at Web Translate It\.
32
+ .
33
+ .P
28
34
  \fBwti status\fR fetch and display translation statistics from Web Translate It\.
29
35
  .
30
36
  .SH "OPTIONS"
data/man/wti.1.html CHANGED
@@ -93,6 +93,8 @@ update the strings hosted at Web Translate It by the strings from the file you p
93
93
  <p><code>wti pull</code> will pull the target language files from Web Translate It. It will download
94
94
  and update your file with the latest translations from Web Translate It.</p>
95
95
 
96
+ <p><code>wti diff</code> will display a diff between local and remote language files.</p>
97
+
96
98
  <p><code>wti status</code> fetch and display translation statistics from Web Translate It.</p>
97
99
 
98
100
  <h2 id="OPTIONS">OPTIONS</h2>
data/man/wti.1.ron CHANGED
@@ -9,6 +9,8 @@ wti(1) -- WebTranslateIt.com from the command line
9
9
 
10
10
  `wti pull` [`-l`] <OPTIONS>
11
11
 
12
+ `wti diff` <OPTIONS>
13
+
12
14
  ## DESCRIPTION
13
15
 
14
16
  `wti` is an utility to help you sync language files between the
@@ -20,6 +22,8 @@ update the strings hosted at Web Translate It by the strings from the file you p
20
22
  `wti pull` will pull the target language files from Web Translate It. It will download
21
23
  and update your file with the latest translations from Web Translate It.
22
24
 
25
+ `wti diff` will show a difference between your local file and the file hosted at Web Translate It.
26
+
23
27
  `wti status` fetch and display translation statistics from Web Translate It.
24
28
 
25
29
  ## OPTIONS
data/readme.md CHANGED
@@ -12,7 +12,7 @@ wti lets you easily sync your language files with [WebTranslateIt.com](https://w
12
12
 
13
13
  ### wti...
14
14
 
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
+ * wti is a **command-line tool**. It works on all operating systems: Windows, Linux, macOS, ... It is also available as a [Docker package](https://github.com/webtranslateit/wti-docker/pkgs/container/wti-docker).
16
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.
17
17
 
18
18
  ### Optionally, wti does...
@@ -29,8 +29,8 @@ You will also need ruby to run `wti`. We require ruby version 3.0 or newer. On L
29
29
 
30
30
  ``` bash
31
31
  $ gem install web_translate_it
32
- Fetching: web_translate_it-3.0.2.gem (100%)
33
- Successfully installed web_translate_it-3.0.2
32
+ Fetching: web_translate_it-3.2.0.gem (100%)
33
+ Successfully installed web_translate_it-3.2.0
34
34
  1 gem installed
35
35
  ```
36
36
 
@@ -38,7 +38,7 @@ At this point you should have the `wti` executable working:
38
38
 
39
39
  ``` bash
40
40
  $ wti -v
41
- wti version 3.0.2
41
+ wti version 3.2.0
42
42
  ```
43
43
 
44
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).
@@ -78,6 +78,7 @@ Execute `wti --help` to see the usage:
78
78
  pull Pull target language file(s)
79
79
  push Push master language file(s)
80
80
  match Display matching of local files with File Manager
81
+ diff Display a diff between local and remote files
81
82
  add Create and push a new master language file
82
83
  addlocale Add a new locale to the project
83
84
  server Start a synchronisation server
@@ -196,6 +197,10 @@ Append `--help` for each command for more information. For instance:
196
197
  <td>wti match</td>
197
198
  <td>Show matching between files on local computer and the ones in WebTranslateIt’s File Manager</td>
198
199
  </tr>
200
+ <tr>
201
+ <td>wti diff config/locales/app/en.yml</td>
202
+ <td>View diff between local and remote file config/locales/app/en.yml</td>
203
+ </tr>
199
204
  </table>
200
205
 
201
206
  ## Hooks
@@ -272,4 +277,4 @@ fr: 100% translated, 100% completed.
272
277
 
273
278
  # License
274
279
 
275
- Copyright (c) 2009-2024 [WebTranslateIt Software S.L](https://webtranslateit.com), released under the MIT License.
280
+ Copyright (c) 2009-2026 [WebTranslateIt Software S.L](https://webtranslateit.com), released under the MIT License.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_translate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edouard Briere
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-06-06 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: multi_json
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.6.2
98
+ rubygems_version: 3.6.9
99
99
  specification_version: 4
100
100
  summary: A CLI tool to sync locale files with WebTranslateIt.com.
101
101
  test_files: []