web_translate_it 2.4.7 → 2.4.12

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
- SHA1:
3
- metadata.gz: 37656492f7a6e8dc4217d6f84799a141f9bc30c2
4
- data.tar.gz: 9590f016fa7a25b0453435b06e379566331ae315
2
+ SHA256:
3
+ metadata.gz: '088a8a2578209bdefd6abbdc9989c29c27da69df2a4ebf57ff7e89aeddc454fe'
4
+ data.tar.gz: 45428f99e5b9aef34759d7c3c0089cbb843cb6fe298102855823156d8501b4b1
5
5
  SHA512:
6
- metadata.gz: e9a52a91a082f0ef0906319993b13926e47df20997cfc1aa9775032c4a3d21a2f95d1f784c660b2b3fcbf97448b4e24b2c32ab9b6af3a1794c1070e2a298b9d7
7
- data.tar.gz: adcd82f7ce617746a63b6c3dbf838a890c76cbb300b6a205b6a96188a4fca96671d147f49c92f564680ae0ceb74c3e55099a1724fdcd31b2d12f761305e510ba
6
+ metadata.gz: 15e13a2794cee9a705ad276b8c4d04452fdff2db386b1ec1766c69e3044df1c5258e7e682b981c6c0ce568d83e91af9125ca35b10eb7aedee191744f60b176e2
7
+ data.tar.gz: 626bda04b619653a15122cd0d41214f2d4cdf7612680c8f378906447c0ce9c6017ec6472189ac12dbcc314b1a370efb8c7f50081a906131a2ec146211b62a783
data/bin/wti CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  $PROGRAM_NAME = 'wti'
4
4
 
5
- require 'trollop'
5
+ require 'optimist'
6
6
  require 'web_translate_it'
7
7
 
8
8
  show_commands = <<-EOS
@@ -14,6 +14,7 @@ The most commonly used wti commands are:
14
14
  match Display matching of local files with File Manager
15
15
  add Create and push a new master language file
16
16
  rm Delete a master language file from a project
17
+ mv Moves a file both locally and from a project
17
18
  addlocale Add a new locale to the project
18
19
  rmlocale Delete a locale from a project
19
20
  status Fetch and display project statistics
@@ -24,8 +25,8 @@ See `wti <command> --help` for more information on a specific command.
24
25
  [options] are:
25
26
  EOS
26
27
 
27
- SUB_COMMANDS = %w(pull push match add addlocale status st init)
28
- global_options = Trollop::options do
28
+ SUB_COMMANDS = %w(pull push match add rm mv addlocale rmlocale status st init)
29
+ global_options = Optimist::options do
29
30
  stop_on SUB_COMMANDS
30
31
  banner show_commands
31
32
  version "wti version #{WebTranslateIt::Util.version}"
@@ -34,76 +35,82 @@ end
34
35
  command = ARGV.shift # get the subcommand
35
36
  command_options = case command
36
37
  when "pull"
37
- Trollop::options do
38
+ Optimist::options do
38
39
  banner <<-EOS
39
40
  wti pull [filename] - Pull target language file(s)
40
41
  [options] are:
41
42
  EOS
42
- opt :locale, "ISO code of locale(s) to pull", :type => :string
43
+ opt :locale, "ISO code of locale(s) to pull", type: :string
43
44
  opt :all, "Pull all files"
44
45
  opt :force, "Force pull (bypass conditional requests to WTI)"
45
- opt :config, "Path to a configuration file", :short => "-c", :default => ".wti"
46
+ opt :config, "Path to a configuration file", short: "-c", default: ".wti"
46
47
  opt :debug, "Display debug information"
47
48
  end
48
49
  when "push"
49
- Trollop::options do
50
+ Optimist::options do
50
51
  banner <<-EOS
51
52
  wti push [filename] - Push master language file(s)
52
53
  [options] are:
53
54
  EOS
54
- opt :locale, "ISO code of locale(s) to push", :type => :string
55
+ opt :locale, "ISO code of locale(s) to push", type: :string
55
56
  opt :target, "Upload all target files"
56
57
  opt :force, "Force push (bypass conditional requests to WTI)"
57
58
  opt :low_priority, "WTI will process this file with a low priority"
58
59
  opt :merge, "Force WTI to merge this file"
59
60
  opt :ignore_missing, "Force WTI to not obsolete missing strings"
60
61
  opt :minor, "Minor Changes. When pushing a master file, prevents target translations to be flagged as `to_verify`."
61
- opt :label, "Apply a label to the changes", :type => :string
62
- opt :config, "Path to a configuration file", :short => "-c", :default => ".wti"
62
+ opt :label, "Apply a label to the changes", type: :string
63
+ opt :config, "Path to a configuration file", short: "-c", default: ".wti"
63
64
  opt :all, "DEPRECATED -- See `wti push --target` instead"
64
65
  opt :debug, "Display debug information"
65
66
  end
66
67
  when "add"
67
- Trollop::options do
68
+ Optimist::options do
68
69
  banner "wti add filename - Create and push a new master language file"
69
70
  opt :low_priority, "WTI will process this file with a low priority"
70
- opt :config, "Path to a configuration file", :short => "-c", :default => ".wti"
71
+ opt :config, "Path to a configuration file", short: "-c", default: ".wti"
71
72
  opt :debug, "Display debug information"
72
73
  end
73
74
  when "rm"
74
- Trollop::options do
75
+ Optimist::options do
75
76
  banner "wti rm filename - Delete a master language file"
76
- opt :config, "Path to a configuration file", :short => "-c", :default => ".wti"
77
+ opt :config, "Path to a configuration file", short: "-c", default: ".wti"
77
78
  opt :debug, "Display debug information"
78
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
79
86
  when "addlocale"
80
- Trollop::options do
87
+ Optimist::options do
81
88
  banner "wti addlocale localename - Add a new locale to the project"
82
- opt :config, "Path to a configuration file", :short => "-c", :default => ".wti"
89
+ opt :config, "Path to a configuration file", short: "-c", default: ".wti"
83
90
  opt :debug, "Display debug information"
84
91
  end
85
92
  when "rmlocale"
86
- Trollop::options do
93
+ Optimist::options do
87
94
  banner "wti rmlocale localename Delete a locale from the project"
88
- opt :config, "Path to a configuration file", :short => "-c", :default => ".wti"
95
+ opt :config, "Path to a configuration file", short: "-c", default: ".wti"
89
96
  opt :debug, "Display debug information"
90
97
  end
91
98
  when "status"
92
- Trollop::options do
99
+ Optimist::options do
93
100
  banner "wti status - Fetch and display project statistics"
94
- opt :config, "Path to a configuration file", :short => "-c", :default => ".wti"
101
+ opt :config, "Path to a configuration file", short: "-c", default: ".wti"
95
102
  opt :debug, "Display debug information"
96
103
  end
97
104
  when "init"
98
- Trollop::options do
105
+ Optimist::options do
99
106
  banner "wti init [api_token] - Configure your project to sync"
100
- opt :config, "Path to a configuration file", :short => "-c", :default => ".wti"
107
+ opt :config, "Path to a configuration file", short: "-c", default: ".wti"
101
108
  opt :debug, "Display debug information"
102
109
  end
103
110
  when "match"
104
- Trollop::options do
111
+ Optimist::options do
105
112
  banner "wti match - Display matching of local files with File Manager"
106
- opt :config, "Path to a configuration file", :short => "-c", :default => ".wti"
113
+ opt :config, "Path to a configuration file", short: "-c", default: ".wti"
107
114
  opt :debug, "Display debug information"
108
115
  end
109
116
  else
@@ -111,7 +118,7 @@ EOS
111
118
  puts show_commands
112
119
  exit
113
120
  else
114
- Trollop::die "Unknown subcommand #{command.inspect}"
121
+ Optimist::die "Unknown subcommand #{command.inspect}"
115
122
  end
116
123
  end
117
124
 
@@ -122,4 +129,3 @@ rescue Interrupt => e
122
129
  puts StringUtil.failure("\nQuitting...")
123
130
  exit 1
124
131
  end
125
-
data/history.md CHANGED
@@ -1,3 +1,28 @@
1
+ ## Version 2.4.12 / 2021-06-30
2
+
3
+ * Add ability to pass project API token as an ENV variable. You can run:
4
+ `export WTI_PROJECT_API_KEY=[my_api_token]`
5
+ `wti pull`
6
+
7
+ ## Version 2.4.11 / 2019-10-22
8
+
9
+ * Fix for `wti pull` without parameters.
10
+
11
+ ## Version 2.4.10 / 2019-10-21
12
+
13
+ * New command: `wti mv path/to/file.po newpath/to/file.po` to move a language file
14
+ both on your local working directory and on your WebTranslateIt project.
15
+ * Fix: `wti pull something` now doesn’t pull anything if no files match what needs to be pulled. Close #151.
16
+
17
+ ## Version 2.4.9 / 2019-08-07
18
+
19
+ * Fix issue referencing old `Trollop` library. #149
20
+ * Fix issue with SSL certificates. If you encounter any issues you will need to update your CA certificates: https://github.com/AtelierConvivialite/webtranslateit/wiki/Update-CA-certificates
21
+
22
+ ## Version 2.4.8 / 2018-09-06
23
+
24
+ * Update deprecated gem `Trollop` to `Optimist`.
25
+
1
26
  ## Version 2.4.7 / 2018-03-28
2
27
 
3
28
  * Add an option to .wti file to silence SSL errors.
@@ -18,6 +18,8 @@ module WebTranslateIt
18
18
  message = "Creating master files"
19
19
  when 'rm'
20
20
  message = "Deleting files"
21
+ when 'mv'
22
+ message = "Moving files"
21
23
  when 'addlocale'
22
24
  message = "Adding locale"
23
25
  when 'rmlocale'
@@ -44,7 +46,7 @@ module WebTranslateIt
44
46
  parameters.each do |parameter|
45
47
  found_files += files.find_all{ |file| File.fnmatch(parameter, file.file_path) }
46
48
  end
47
- files = found_files if found_files.any?
49
+ files = found_files if parameters.any?
48
50
  files = files.uniq.sort{ |a,b| a.file_path <=> b.file_path }
49
51
  if files.size == 0
50
52
  puts "No files to pull."
@@ -111,7 +113,7 @@ module WebTranslateIt
111
113
  to_add = parameters.reject{ |param| added.include?(File.expand_path(param))}
112
114
  if to_add.any?
113
115
  to_add.each do |param|
114
- file = TranslationFile.new(nil, param, nil, configuration.api_key)
116
+ file = TranslationFile.new(nil, param.gsub(/ /, "\\ "), nil, configuration.api_key)
115
117
  success = file.create(http, command_options.low_priority)
116
118
  complete_success = false if !success
117
119
  end
@@ -127,26 +129,77 @@ module WebTranslateIt
127
129
  STDOUT.sync = true
128
130
  if parameters == []
129
131
  puts StringUtil.failure("Error: You must provide the path to the master file to remove.")
130
- puts "Usage: wti path/to/rm master_file_1 path/to/master_file_2 ..."
132
+ puts "Usage: wti rm path/to/master_file_1 path/to/master_file_2 ..."
131
133
  exit
132
134
  end
133
135
  WebTranslateIt::Connection.new(configuration.api_key) do |http|
134
136
  parameters.each do |param|
135
137
  if Util.ask_yes_no("Are you sure you want to delete the master file #{param}?\nThis will also delete its target files and translations.", false)
136
- configuration.files.find_all{ |file| file.file_path == param }.each do |master_file|
137
- master_file.delete(http)
138
- # delete files
139
- success = File.delete(master_file.file_path) if File.exists?(master_file.file_path)
140
- complete_success = false if !success
141
- configuration.files.find_all{ |file| file.master_id == master_file.id }.each do |target_file|
142
- success = File.delete(target_file.file_path) if File.exists?(target_file.file_path)
138
+ files = configuration.files.find_all{ |file| file.file_path == param }
139
+ if files.any?
140
+ files.each do |master_file|
141
+ master_file.delete(http)
142
+ # delete files
143
+ if File.exists?(master_file.file_path)
144
+ success = File.delete(master_file.file_path)
145
+ puts StringUtil.success("Deleted master file #{master_file.file_path}.") if success
146
+ end
143
147
  complete_success = false if !success
148
+ configuration.files.find_all{ |file| file.master_id == master_file.id }.each do |target_file|
149
+ if File.exists?(target_file.file_path)
150
+ success = File.delete(target_file.file_path)
151
+ puts StringUtil.success("Deleted target file #{target_file.file_path}.") if success
152
+ else
153
+ puts StringUtil.failure("Target file #{target_file.file_path} doesn’t exist locally")
154
+ end
155
+ complete_success = false if !success
156
+ end
144
157
  end
158
+ puts StringUtil.success("All done.") if complete_success
159
+ else
160
+ puts StringUtil.failure("#{param}: File doesn’t exist on project.")
161
+ end
162
+ end
163
+ end
164
+ end
165
+ complete_success
166
+ end
167
+
168
+ def mv
169
+ complete_success = true
170
+ STDOUT.sync = true
171
+ if parameters.count != 2
172
+ puts StringUtil.failure("Error: You must provide the source path and destination path of the master file to move.")
173
+ puts "Usage: wti mv path/to/master_file_old_path path/to/master_file_new_path ..."
174
+ exit
175
+ end
176
+ source = parameters[0]
177
+ destination = parameters[1]
178
+ WebTranslateIt::Connection.new(configuration.api_key) do |http|
179
+ if Util.ask_yes_no("Are you sure you want to move the master file #{source} and its target files?", true)
180
+ configuration.files.find_all{ |file| file.file_path == source }.each do |master_file|
181
+ master_file.upload(http, false, false, nil, false, false, true, true, destination)
182
+ # move master file
183
+ if File.exists?(source)
184
+ success = File.rename(source, destination) if File.exists?(source)
185
+ puts StringUtil.success("Moved master file #{master_file.file_path}.") if success
186
+ end
187
+ complete_success = false if !success
188
+ configuration.files.find_all{ |file| file.master_id == master_file.id }.each do |target_file|
189
+ if File.exists?(target_file.file_path)
190
+ success = File.delete(target_file.file_path)
191
+ complete_success = false if !success
192
+ end
193
+ end
194
+ configuration.reload
195
+ configuration.files.find_all{ |file| file.master_id == master_file.id }.each do |target_file|
196
+ success = target_file.fetch(http)
197
+ complete_success = false if !success
145
198
  end
199
+ puts StringUtil.success("All done.") if complete_success
146
200
  end
147
201
  end
148
202
  end
149
- puts StringUtil.success("Master file deleted.")
150
203
  complete_success
151
204
  end
152
205
 
@@ -20,7 +20,7 @@ module WebTranslateIt
20
20
  self.path = root_path
21
21
  self.logger = logger
22
22
  if File.exists?(File.expand_path(path_to_config_file, self.path))
23
- self.api_key = configuration['api_key']
23
+ self.api_key = ENV["WTI_PROJECT_API_KEY"] || configuration['api_key']
24
24
  self.before_pull = configuration['before_pull']
25
25
  self.after_pull = configuration['after_pull']
26
26
  self.before_push = configuration['before_push']
@@ -33,11 +33,23 @@ module WebTranslateIt
33
33
  WebTranslateIt::Connection.turn_silent_on if configuration['silence_errors']
34
34
  self.project_name = project_info['project']['name']
35
35
  else
36
- puts StringUtil.failure("\nCan't find a configuration file in #{File.expand_path(path_to_config_file, self.path)}")
36
+ puts StringUtil.failure("\nNo configuration file found in #{File.expand_path(path_to_config_file, self.path)}")
37
37
  exit(1)
38
38
  end
39
39
  end
40
40
 
41
+ # Reload project data
42
+ #
43
+ def reload
44
+ project_info = YAML.load WebTranslateIt::Project.fetch_info(self.api_key)
45
+ set_locales_to_ignore(configuration)
46
+ set_locales_needed(configuration)
47
+ set_files(project_info['project'])
48
+ set_locales(project_info['project'])
49
+ WebTranslateIt::Connection.turn_silent_on if configuration['silence_errors']
50
+ self.project_name = project_info['project']['name']
51
+ end
52
+
41
53
  # Set the project locales from the Project API.
42
54
  # Implementation example:
43
55
  #
@@ -36,11 +36,6 @@ module WebTranslateIt
36
36
  http.set_debug_output($stderr) if @@debug
37
37
  begin
38
38
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
39
- if File.exists?('/etc/ssl/certs') # Ubuntu
40
- http.ca_path = '/etc/ssl/certs'
41
- else
42
- http.ca_file = File.expand_path('../cacert.pem', __FILE__)
43
- end
44
39
  @@http_connection = http.start
45
40
  yield @@http_connection if block_given?
46
41
  rescue OpenSSL::SSL::SSLError
@@ -74,4 +69,3 @@ module WebTranslateIt
74
69
  end
75
70
  end
76
71
  end
77
-
@@ -8,8 +8,7 @@ module WebTranslateIt
8
8
  begin
9
9
  WebTranslateIt::Connection.new(api_key) do |http|
10
10
  request = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml")
11
- request.add_field("X-Client-Name", "web_translate_it")
12
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
11
+ WebTranslateIt::Util.add_fields(request)
13
12
  response = http.request(request)
14
13
  if response.is_a?(Net::HTTPSuccess)
15
14
  return response.body
@@ -39,8 +38,7 @@ module WebTranslateIt
39
38
  begin
40
39
  WebTranslateIt::Connection.new(api_key) do |http|
41
40
  request = Net::HTTP::Get.new("/api/projects/#{api_key}/stats.yaml")
42
- request.add_field("X-Client-Name", "web_translate_it")
43
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
41
+ WebTranslateIt::Util.add_fields(request)
44
42
  return Util.handle_response(http.request(request), true)
45
43
  end
46
44
  rescue Timeout::Error
@@ -60,8 +58,7 @@ module WebTranslateIt
60
58
  tries ||= 3
61
59
  begin
62
60
  request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/locales")
63
- request.add_field("X-Client-Name", "web_translate_it")
64
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
61
+ WebTranslateIt::Util.add_fields(request)
65
62
  request.set_form_data({ 'id' => locale_code }, ';')
66
63
  Util.handle_response(Connection.http_connection.request(request), true)
67
64
  rescue Timeout::Error
@@ -81,8 +78,7 @@ module WebTranslateIt
81
78
  tries ||= 3
82
79
  begin
83
80
  request = Net::HTTP::Delete.new("/api/projects/#{Connection.api_key}/locales/#{locale_code}")
84
- request.add_field("X-Client-Name", "web_translate_it")
85
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
81
+ WebTranslateIt::Util.add_fields(request)
86
82
  Util.handle_response(Connection.http_connection.request(request), true)
87
83
  rescue Timeout::Error
88
84
  puts "Request timeout. Will retry in 5 seconds."
@@ -58,9 +58,7 @@ module WebTranslateIt
58
58
  url += '?' + HashUtil.to_params("filters" => params) unless params.empty?
59
59
 
60
60
  request = Net::HTTP::Get.new(url)
61
- request.add_field("X-Client-Name", "web_translate_it")
62
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
63
-
61
+ WebTranslateIt::Util.add_fields(request)
64
62
  begin
65
63
  strings = []
66
64
  while(request) do
@@ -73,8 +71,7 @@ module WebTranslateIt
73
71
  if response["Link"] && response["Link"].include?("rel=\"next\"")
74
72
  url = response["Link"].match(/<(.*)>; rel="next"/)[1]
75
73
  request = Net::HTTP::Get.new(url)
76
- request.add_field("X-Client-Name", "web_translate_it")
77
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
74
+ WebTranslateIt::Util.add_fields(request)
78
75
  else
79
76
  request = nil
80
77
  end
@@ -110,9 +107,7 @@ module WebTranslateIt
110
107
  success = true
111
108
  tries ||= 3
112
109
  request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/strings/#{id}.yaml")
113
- request.add_field("X-Client-Name", "web_translate_it")
114
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
115
-
110
+ WebTranslateIt::Util.add_fields(request)
116
111
  begin
117
112
  response = Connection.http_connection.request(request)
118
113
  return nil if response.code.to_i == 404
@@ -160,9 +155,7 @@ module WebTranslateIt
160
155
  success = true
161
156
  tries ||= 3
162
157
  request = Net::HTTP::Delete.new("/api/projects/#{Connection.api_key}/strings/#{self.id}")
163
- request.add_field("X-Client-Name", "web_translate_it")
164
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
165
-
158
+ WebTranslateIt::Util.add_fields(request)
166
159
  begin
167
160
  Util.handle_response(Connection.http_connection.request(request), true, true)
168
161
  rescue Timeout::Error
@@ -194,9 +187,7 @@ module WebTranslateIt
194
187
  return translation if translation
195
188
  return nil if self.new_record
196
189
  request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/strings/#{self.id}/locales/#{locale}/translations.yaml")
197
- request.add_field("X-Client-Name", "web_translate_it")
198
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
199
-
190
+ WebTranslateIt::Util.add_fields(request)
200
191
  begin
201
192
  response = Util.handle_response(Connection.http_connection.request(request), true, true)
202
193
  hash = YAML.load(response)
@@ -225,9 +216,7 @@ module WebTranslateIt
225
216
  success = true
226
217
  tries ||= 3
227
218
  request = Net::HTTP::Put.new("/api/projects/#{Connection.api_key}/strings/#{self.id}.yaml")
228
- request.add_field("X-Client-Name", "web_translate_it")
229
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
230
- request.add_field("Content-Type", "application/json")
219
+ WebTranslateIt::Util.add_fields(request)
231
220
  request.body = self.to_json
232
221
 
233
222
  self.translations.each do |translation|
@@ -256,11 +245,8 @@ module WebTranslateIt
256
245
  success = true
257
246
  tries ||= 3
258
247
  request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/strings")
259
- request.add_field("X-Client-Name", "web_translate_it")
260
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
261
- request.add_field("Content-Type", "application/json")
248
+ WebTranslateIt::Util.add_fields(request)
262
249
  request.body = self.to_json(true)
263
-
264
250
  begin
265
251
  response = YAML.load(Util.handle_response(Connection.http_connection.request(request), true, true))
266
252
  self.id = response["id"]
@@ -49,9 +49,7 @@ module WebTranslateIt
49
49
  url += '?' + HashUtil.to_params(params) unless params.empty?
50
50
 
51
51
  request = Net::HTTP::Get.new(url)
52
- request.add_field("X-Client-Name", "web_translate_it")
53
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
54
-
52
+ WebTranslateIt::Util.add_fields(request)
55
53
  begin
56
54
  terms = []
57
55
  while(request) do
@@ -64,8 +62,7 @@ module WebTranslateIt
64
62
  if response["Link"] && response["Link"].include?("rel=\"next\"")
65
63
  url = response["Link"].match(/<(.*)>; rel="next"/)[1]
66
64
  request = Net::HTTP::Get.new(url)
67
- request.add_field("X-Client-Name", "web_translate_it")
68
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
65
+ WebTranslateIt::Util.add_fields(request)
69
66
  else
70
67
  request = nil
71
68
  end
@@ -101,9 +98,7 @@ module WebTranslateIt
101
98
  success = true
102
99
  tries ||= 3
103
100
  request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/terms/#{term_id}.yaml")
104
- request.add_field("X-Client-Name", "web_translate_it")
105
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
106
-
101
+ WebTranslateIt::Util.add_fields(request)
107
102
  begin
108
103
  response = Connection.http_connection.request(request)
109
104
  return nil if response.code.to_i == 404
@@ -151,9 +146,7 @@ module WebTranslateIt
151
146
  success = true
152
147
  tries ||= 3
153
148
  request = Net::HTTP::Delete.new("/api/projects/#{Connection.api_key}/terms/#{self.id}")
154
- request.add_field("X-Client-Name", "web_translate_it")
155
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
156
-
149
+ WebTranslateIt::Util.add_fields(request)
157
150
  begin
158
151
  Util.handle_response(Connection.http_connection.request(request), true, true)
159
152
  rescue Timeout::Error
@@ -185,9 +178,7 @@ module WebTranslateIt
185
178
  return translation if translation
186
179
  return nil if self.new_record
187
180
  request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/terms/#{self.id}/locales/#{locale}/translations.yaml")
188
- request.add_field("X-Client-Name", "web_translate_it")
189
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
190
-
181
+ WebTranslateIt::Util.add_fields(request)
191
182
  begin
192
183
  response = Util.handle_response(Connection.http_connection.request(request), true, true)
193
184
  array = YAML.load(response)
@@ -217,10 +208,7 @@ module WebTranslateIt
217
208
  success = true
218
209
  tries ||= 3
219
210
  request = Net::HTTP::Put.new("/api/projects/#{Connection.api_key}/terms/#{self.id}.yaml")
220
- request.add_field("X-Client-Name", "web_translate_it")
221
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
222
- request.add_field("Content-Type", "application/json")
223
-
211
+ WebTranslateIt::Util.add_fields(request)
224
212
  request.body = self.to_json
225
213
 
226
214
  self.translations.each do |translation|
@@ -246,10 +234,7 @@ module WebTranslateIt
246
234
  success = true
247
235
  tries ||= 3
248
236
  request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/terms")
249
- request.add_field("X-Client-Name", "web_translate_it")
250
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
251
- request.add_field("Content-Type", "application/json")
252
-
237
+ WebTranslateIt::Util.add_fields(request)
253
238
  request.body = self.to_json(true)
254
239
 
255
240
  begin
@@ -60,10 +60,7 @@ module WebTranslateIt
60
60
  success = true
61
61
  tries ||= 3
62
62
  request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/terms/#{self.term_id}/locales/#{self.locale}/translations")
63
- request.add_field("X-Client-Name", "web_translate_it")
64
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
65
- request.add_field("Content-Type", "application/json")
66
-
63
+ WebTranslateIt::Util.add_fields(request)
67
64
  request.body = self.to_json
68
65
 
69
66
  begin
@@ -88,12 +85,8 @@ module WebTranslateIt
88
85
  success = true
89
86
  tries ||= 3
90
87
  request = Net::HTTP::Put.new("/api/projects/#{Connection.api_key}/terms/#{self.id}/locales/#{self.locale}/translations/#{self.id}")
91
- request.add_field("X-Client-Name", "web_translate_it")
92
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
93
- request.add_field("Content-Type", "application/json")
94
-
88
+ WebTranslateIt::Util.add_fields(request)
95
89
  request.body = self.to_json
96
-
97
90
  begin
98
91
  Util.handle_response(Connection.http_connection.request(request), true, true)
99
92
  rescue Timeout::Error
@@ -44,11 +44,8 @@ module WebTranslateIt
44
44
  def save
45
45
  tries ||= 3
46
46
  request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/strings/#{self.string_id}/locales/#{self.locale}/translations")
47
- request.add_field("X-Client-Name", "web_translate_it")
48
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
49
- request.add_field("Content-Type", "application/json")
47
+ WebTranslateIt::Util.add_fields(request)
50
48
  request.body = self.to_json
51
-
52
49
  begin
53
50
  Util.handle_response(Connection.http_connection.request(request), true, true)
54
51
  rescue Timeout::Error
@@ -45,8 +45,7 @@ module WebTranslateIt
45
45
  if !File.exist?(self.file_path) or force or self.remote_checksum != self.local_checksum
46
46
  begin
47
47
  request = Net::HTTP::Get.new(api_url)
48
- request.add_field("X-Client-Name", "web_translate_it")
49
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
48
+ WebTranslateIt::Util.add_fields(request)
50
49
  FileUtils.mkpath(self.file_path.split('/')[0..-2].join('/')) unless File.exist?(self.file_path) or self.file_path.split('/')[0..-2].join('/') == ""
51
50
  begin
52
51
  response = http_connection.request(request)
@@ -83,7 +82,7 @@ module WebTranslateIt
83
82
  #
84
83
  # Note that the request might or might not eventually be acted upon, as it might be disallowed when processing
85
84
  # actually takes place. This is due to the fact that language file imports are handled by background processing.
86
- def upload(http_connection, merge=false, ignore_missing=false, label=nil, low_priority=false, minor_changes=false, force=false)
85
+ def upload(http_connection, merge=false, ignore_missing=false, label=nil, low_priority=false, minor_changes=false, force=false, rename_others=false, destination_path=nil)
87
86
  success = true
88
87
  tries ||= 3
89
88
  display = []
@@ -93,9 +92,11 @@ module WebTranslateIt
93
92
  if force or self.remote_checksum != self.local_checksum
94
93
  File.open(self.file_path) do |file|
95
94
  begin
96
- request = Net::HTTP::Put::Multipart.new(api_url, {"file" => UploadIO.new(file, "text/plain", file.path), "merge" => merge, "ignore_missing" => ignore_missing, "label" => label, "low_priority" => low_priority, "minor_changes" => minor_changes })
97
- request.add_field("X-Client-Name", "web_translate_it")
98
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
95
+ params = {"file" => UploadIO.new(file, "text/plain", file.path), "merge" => merge, "ignore_missing" => ignore_missing, "label" => label, "low_priority" => low_priority, "minor_changes" => minor_changes }
96
+ params["name"] = destination_path unless destination_path.nil?
97
+ params["rename_others"] = rename_others
98
+ request = Net::HTTP::Put::Multipart.new(api_url, params)
99
+ WebTranslateIt::Util.add_fields(request)
99
100
  display.push Util.handle_response(http_connection.request(request))
100
101
  rescue Timeout::Error
101
102
  puts StringUtil.failure("Request timeout. Will retry in 5 seconds.")
@@ -115,7 +116,7 @@ module WebTranslateIt
115
116
  end
116
117
  puts ArrayUtil.to_columns(display)
117
118
  else
118
- puts StringUtil.failure("Can't push #{self.file_path}. File doesn't exist.")
119
+ puts StringUtil.failure("Can't push #{self.file_path}. File doesn't exist locally.")
119
120
  end
120
121
  return success
121
122
  end
@@ -141,8 +142,7 @@ module WebTranslateIt
141
142
  File.open(self.file_path) do |file|
142
143
  begin
143
144
  request = Net::HTTP::Post::Multipart.new(api_url_for_create, { "name" => self.file_path, "file" => UploadIO.new(file, "text/plain", file.path), "low_priority" => low_priority })
144
- request.add_field("X-Client-Name", "web_translate_it")
145
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
145
+ WebTranslateIt::Util.add_fields(request)
146
146
  display.push Util.handle_response(http_connection.request(request))
147
147
  puts ArrayUtil.to_columns(display)
148
148
  rescue Timeout::Error
@@ -159,7 +159,7 @@ module WebTranslateIt
159
159
  end
160
160
  end
161
161
  else
162
- puts StringUtil.failure("\nFile #{self.file_path} doesn't exist!")
162
+ puts StringUtil.failure("\nFile #{self.file_path} doesn't exist locally!")
163
163
  end
164
164
  return success
165
165
  end
@@ -172,28 +172,25 @@ module WebTranslateIt
172
172
  display = []
173
173
  display.push file_path
174
174
  if File.exists?(self.file_path)
175
- File.open(self.file_path) do |file|
176
- begin
177
- request = Net::HTTP::Delete.new(api_url_for_delete)
178
- request.add_field("X-Client-Name", "web_translate_it")
179
- request.add_field("X-Client-Version", WebTranslateIt::Util.version)
180
- display.push Util.handle_response(http_connection.request(request))
181
- puts ArrayUtil.to_columns(display)
182
- rescue Timeout::Error
183
- puts StringUtil.failure("Request timeout. Will retry in 5 seconds.")
184
- if (tries -= 1) > 0
185
- sleep(5)
186
- retry
187
- else
188
- success = false
189
- end
190
- rescue
191
- display.push StringUtil.failure("An error occured: #{$!}")
175
+ begin
176
+ request = Net::HTTP::Delete.new(api_url_for_delete)
177
+ WebTranslateIt::Util.add_fields(request)
178
+ display.push Util.handle_response(http_connection.request(request))
179
+ puts ArrayUtil.to_columns(display)
180
+ rescue Timeout::Error
181
+ puts StringUtil.failure("Request timeout. Will retry in 5 seconds.")
182
+ if (tries -= 1) > 0
183
+ sleep(5)
184
+ retry
185
+ else
192
186
  success = false
193
187
  end
188
+ rescue
189
+ display.push StringUtil.failure("An error occured: #{$!}")
190
+ success = false
194
191
  end
195
192
  else
196
- puts StringUtil.failure("\nFile #{self.file_path} doesn't exist!")
193
+ puts StringUtil.failure("\nMaster file #{self.file_path} doesn't exist locally!")
197
194
  end
198
195
  return success
199
196
  end
@@ -40,6 +40,12 @@ module WebTranslateIt
40
40
  end
41
41
  end
42
42
 
43
+ 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("Content-Type", "application/json")
47
+ end
48
+
43
49
  ##
44
50
  # Ask a question. Returns a true for yes, false for no, default for nil.
45
51
 
data/license CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2009-2014 Atelier Convivialite
3
+ Copyright (c) 2009-2019 WebTranslateIt Software S.L
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/readme.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  wti lets you easily sync your language files with [WebTranslateIt.com](https://webtranslateit.com), a web-based tool to translation software.
9
9
 
10
- <img src="https://s3.amazonaws.com/f.cl.ly/items/27192V1K263K2O433h2g/webtranslateit_com_%E2%80%94_edouard_Edouards-MacBook-Pro-2____code_webtranslateit_com_%E2%80%94___anslateit_com_%E2%80%94_zsh_%E2%80%94_80%C3%9740.png" alt="WebTranslateIt Synchronization Tool" width="500px">
10
+ <img src="http://edouard.baconfile.com.s3.us-east-1.amazonaws.com/web_translate_it/wti4.png" alt="WebTranslateIt Synchronization Tool" width="500px">
11
11
 
12
12
  ### wti...
13
13
 
@@ -276,4 +276,4 @@ fr: 100% translated, 100% completed.
276
276
 
277
277
  # License
278
278
 
279
- Copyright (c) 2009-2018 Atelier Convivialité, released under the MIT License.
279
+ Copyright (c) 2009-2021 WebTranslateIt Software S.L, released under the MIT License.
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.4.7
4
+ version: 2.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edouard Briere
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-28 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: trollop
28
+ name: optimist
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: multi_json
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -96,7 +96,6 @@ files:
96
96
  - history.md
97
97
  - lib/web_translate_it.rb
98
98
  - lib/web_translate_it/auto_fetch.rb
99
- - lib/web_translate_it/cacert.pem
100
99
  - lib/web_translate_it/command_line.rb
101
100
  - lib/web_translate_it/configuration.rb
102
101
  - lib/web_translate_it/connection.rb
@@ -125,7 +124,7 @@ homepage: https://webtranslateit.com
125
124
  licenses:
126
125
  - MIT
127
126
  metadata: {}
128
- post_install_message:
127
+ post_install_message:
129
128
  rdoc_options:
130
129
  - "--main"
131
130
  - readme.md
@@ -142,9 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
141
  - !ruby/object:Gem::Version
143
142
  version: '0'
144
143
  requirements: []
145
- rubyforge_project:
146
- rubygems_version: 2.6.14
147
- signing_key:
144
+ rubygems_version: 3.0.6
145
+ signing_key:
148
146
  specification_version: 4
149
147
  summary: A CLI to sync locale files with WebTranslateIt.com.
150
148
  test_files:
@@ -1,22 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
3
- MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
4
- d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
5
- QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
6
- MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
7
- b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
8
- 9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
9
- CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
10
- nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
11
- 43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
12
- T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
13
- gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
14
- BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
15
- TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
16
- DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
17
- hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
18
- 06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
19
- PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
20
- YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
21
- CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
22
- -----END CERTIFICATE-----