web_translate_it 1.8.2.0 → 1.8.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/wti CHANGED
@@ -80,7 +80,7 @@ EOS
80
80
  begin
81
81
  WebTranslateIt::CommandLine.new(command, command_options, global_options, ARGV, File.expand_path("."))
82
82
  rescue Interrupt => e
83
- puts "\nQuitting...".failure
83
+ puts StringUtil.failure("\nQuitting...")
84
84
  exit 1
85
85
  end
86
86
 
data/history.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## Version 1.8.2.1 / 2011-10-14
2
+
3
+ * Fix frozen string bug on ruby 1.9.3 (thanks @mikian for the patch).
4
+ * Fix: arrays of symbols `ignore_locales: [:en, :fr]` are not being parsed by Psych.
5
+ People should use an array of strings (`ignore_locales: ['en', 'fr']`) or the longer version instead:
6
+ ``` yaml
7
+ ignore_locales:
8
+ - :en
9
+ - :fr
10
+ ```
11
+
1
12
  ## Version 1.8.2.0 / 2011-09-12
2
13
 
3
14
  * `wti pull` downloads files in parallel, using up to 20 threads.
@@ -1,6 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'web_translate_it/util'
4
+ require 'web_translate_it/util/array_util'
5
+ require 'web_translate_it/util/string_util'
4
6
  require 'web_translate_it/configuration'
5
7
  require 'web_translate_it/translation_file'
6
8
  require 'web_translate_it/auto_fetch'
@@ -16,7 +16,7 @@ module WebTranslateIt
16
16
  def pull
17
17
  STDOUT.sync = true
18
18
  `#{configuration.before_pull}` if configuration.before_pull
19
- puts "Pulling files".titleize
19
+ puts StringUtil.titleize("Pulling files")
20
20
 
21
21
  # Selecting files to pull
22
22
  files = []
@@ -28,7 +28,7 @@ module WebTranslateIt
28
28
  threads = []
29
29
  n_threads = (files.count.to_f/3).ceil >= 20 ? 20 : (files.count.to_f/3).ceil
30
30
  puts "Using up to #{n_threads} threads"
31
- files.chunk(n_threads).each do |file_array|
31
+ ArrayUtil.chunk(files, n_threads).each do |file_array|
32
32
  unless file_array.empty?
33
33
  threads << Thread.new(file_array) do |file_array|
34
34
  WebTranslateIt::Util.http_connection do |http|
@@ -48,7 +48,7 @@ module WebTranslateIt
48
48
  def push
49
49
  STDOUT.sync = true
50
50
  `#{configuration.before_push}` if configuration.before_push
51
- puts "Pushing files".titleize
51
+ puts StringUtil.titleize("Pushing files")
52
52
  WebTranslateIt::Util.http_connection do |http|
53
53
  fetch_locales_to_push(configuration).each do |locale|
54
54
  configuration.files.find_all{ |file| file.locale == locale }.each do |file|
@@ -62,7 +62,7 @@ module WebTranslateIt
62
62
  def add
63
63
  STDOUT.sync = true
64
64
  if parameters == []
65
- puts "No master file given.".failure
65
+ puts StringUtil.failure("No master file given.")
66
66
  puts "Usage: wti add master_file1 master_file2 ..."
67
67
  exit
68
68
  end
@@ -72,18 +72,18 @@ module WebTranslateIt
72
72
  file.create(http)
73
73
  end
74
74
  end
75
- puts "Master file added.".success
75
+ puts StringUtil.success("Master file added.")
76
76
  end
77
77
 
78
78
  def addlocale
79
79
  STDOUT.sync = true
80
80
  if parameters == []
81
- puts "No locale code given.".failure
81
+ puts StringUtil.failure("No locale code given.")
82
82
  puts "Usage: wti addlocale locale1 locale2 ..."
83
83
  exit
84
84
  end
85
85
  parameters.each do |param|
86
- print "Adding locale #{param}... ".success
86
+ print StringUtil.success("Adding locale #{param}... ")
87
87
  puts WebTranslateIt::Project.create_locale(configuration.api_key, param)
88
88
  end
89
89
  puts "Done!"
@@ -94,7 +94,7 @@ module WebTranslateIt
94
94
  project = YAML.load WebTranslateIt::Project.fetch_info(api_key)
95
95
  project_info = project['project']
96
96
  if File.exists?('.wti') && !File.writable?('.wti')
97
- puts "Error: `.wti` file is not writable.".failure
97
+ puts StringUtil.failure("Error: `.wti` file is not writable.")
98
98
  exit
99
99
  end
100
100
  File.open('.wti', 'w'){ |file| file << generate_configuration(api_key, project_info) }
@@ -104,16 +104,16 @@ module WebTranslateIt
104
104
  end
105
105
 
106
106
  def match
107
- puts "Matching local files with File Manager".titleize
107
+ puts StringUtil.titleize("Matching local files with File Manager")
108
108
  configuration.files.find_all{ |mf| mf.locale == configuration.source_locale }.each do |master_file|
109
109
  if !File.exists?(master_file.file_path)
110
- puts master_file.file_path.failure + " (#{master_file.locale})"
110
+ puts StringUtil.failure(master_file.file_path) + " (#{master_file.locale})"
111
111
  else
112
- puts master_file.file_path.important + " (#{master_file.locale})"
112
+ puts StringUtil.important(master_file.file_path) + " (#{master_file.locale})"
113
113
  end
114
114
  configuration.files.find_all{ |f| f.master_id == master_file.id }.each do |file|
115
115
  if !File.exists?(file.file_path)
116
- puts "- #{file.file_path}".failure + " (#{file.locale})"
116
+ puts StringUtil.failure("- #{file.file_path}") + " (#{file.locale})"
117
117
  else
118
118
  puts "- #{file.file_path}" + " (#{file.locale})"
119
119
  end
@@ -190,7 +190,8 @@ module WebTranslateIt
190
190
  api_key: #{api_key}
191
191
 
192
192
  # Optional: locales not to sync with Web Translate It.
193
- # eg. [:en, :fr] or just 'en'
193
+ # Takes a string, a symbol, or an array of string or symbol.
194
+ # More information here: https://github.com/AtelierConvivialite/webtranslateit/wiki
194
195
  # ignore_locales: '#{project_info["source_locale"]["code"]}'
195
196
 
196
197
  # Optional
@@ -39,7 +39,7 @@ module WebTranslateIt
39
39
  def fetch(http_connection, force = false)
40
40
  display = []
41
41
  display.push(self.file_path)
42
- display.push "#{self.local_checksum.to_s.checksumify}..#{self.remote_checksum.to_s.checksumify}"
42
+ display.push "#{StringUtil.checksumify(self.local_checksum.to_s)}..#{StringUtil.checksumify(self.remote_checksum.to_s)}"
43
43
  if !File.exist?(self.file_path) or force or self.remote_checksum != self.local_checksum
44
44
  begin
45
45
  response = http_connection.get(api_url)
@@ -48,17 +48,17 @@ module WebTranslateIt
48
48
  File.open(self.file_path, 'wb'){ |file| file << response.body } if response.code.to_i == 200 and response.body != ''
49
49
  display.push Util.handle_response(response)
50
50
  rescue
51
- display.push "An error occured: #{$!}".failure
51
+ display.push StringUtil.failure("An error occured: #{$!}")
52
52
  end
53
53
  rescue Timeout::Error
54
- puts "Request timeout. Will retry in 5 seconds.".failure
54
+ puts StringUtil.failure("Request timeout. Will retry in 5 seconds.")
55
55
  sleep(5)
56
56
  fetch(http_connection, force)
57
57
  end
58
58
  else
59
- display.push "Skipped".success
59
+ display.push StringUtil.success("Skipped")
60
60
  end
61
- puts display.to_columns
61
+ puts ArrayUtil.to_columns(display)
62
62
  end
63
63
 
64
64
  # Update a language file to Web Translate It by performing a PUT Request.
@@ -75,21 +75,21 @@ module WebTranslateIt
75
75
  def upload(http_connection, merge=false, ignore_missing=false, label=nil, low_priority=false)
76
76
  display = []
77
77
  display.push(self.file_path)
78
- display.push "#{self.local_checksum.to_s.checksumify}..#{self.remote_checksum.to_s.checksumify}"
78
+ display.push "#{StringUtil.checksumify(self.local_checksum.to_s)}..#{StringUtil.checksumify(self.remote_checksum.to_s)}"
79
79
  if File.exists?(self.file_path)
80
80
  File.open(self.file_path) do |file|
81
81
  begin
82
82
  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 })
83
83
  display.push Util.handle_response(http_connection.request(request))
84
- puts display.to_columns
84
+ puts ArrayUtil.to_columns(display)
85
85
  rescue Timeout::Error
86
- puts "Request timeout. Will retry in 5 seconds.".failure
86
+ puts StringUtil.failure("Request timeout. Will retry in 5 seconds.")
87
87
  sleep(5)
88
88
  upload(merge, ignore_missing, label, low_priority)
89
89
  end
90
90
  end
91
91
  else
92
- puts "Can't push #{self.file_path}. File doesn't exist.".failure
92
+ puts StringUtil.failure("Can't push #{self.file_path}. File doesn't exist.")
93
93
  end
94
94
  end
95
95
 
@@ -107,21 +107,21 @@ module WebTranslateIt
107
107
  def create(http_connection)
108
108
  display = []
109
109
  display.push file_path
110
- display.push "#{self.local_checksum.to_s.checksumify}..[ ]"
110
+ display.push "#{StringUtil.checksumify(self.local_checksum.to_s)}..[ ]"
111
111
  if File.exists?(self.file_path)
112
112
  File.open(self.file_path) do |file|
113
113
  begin
114
114
  request = Net::HTTP::Post::Multipart.new(api_url_for_create, { "name" => self.file_path, "file" => UploadIO.new(file, "text/plain", file.path) })
115
115
  display.push Util.handle_response(http_connection.request(request))
116
- puts display.to_columns
116
+ puts ArrayUtil.to_columns(display)
117
117
  rescue Timeout::Error
118
- puts "Request timeout. Will retry in 5 seconds.".failure
118
+ puts StringUtil.failure("Request timeout. Will retry in 5 seconds.")
119
119
  sleep(5)
120
120
  create
121
121
  end
122
122
  end
123
123
  else
124
- puts "\nFile #{self.file_path} doesn't exist!".failure
124
+ puts StringUtil.failure("\nFile #{self.file_path} doesn't exist!")
125
125
  end
126
126
  end
127
127
 
@@ -56,16 +56,16 @@ module WebTranslateIt
56
56
 
57
57
  def self.handle_response(response, return_response = false)
58
58
  if response.code.to_i >= 400 and response.code.to_i < 500
59
- "Error: Can't find project for this API key.".failure
59
+ StringUtil.failure("Error: Can't find project for this API key.")
60
60
  elsif response.code.to_i >= 500
61
- "Error: Server temporarily unavailable. Please try again shortly.".failure
61
+ StringUtil.failure("Error: Server temporarily unavailable. Please try again shortly.")
62
62
  else
63
63
  return response.body if return_response
64
- return "Server currently processing file. Please retry later.".failure if response.code.to_i == 102
65
- return "OK".success if response.code.to_i == 200
66
- return "Created".success if response.code.to_i == 201
67
- return "Accepted".success if response.code.to_i == 202
68
- return "Not Modified".success if response.code.to_i == 304
64
+ return StringUtil.failure("Server currently processing file. Please retry later.") if response.code.to_i == 102
65
+ return StringUtil.success("OK") if response.code.to_i == 200
66
+ return StringUtil.success("Created") if response.code.to_i == 201
67
+ return StringUtil.success("Accepted") if response.code.to_i == 202
68
+ return StringUtil.success("Not Modified") if response.code.to_i == 304
69
69
  end
70
70
  end
71
71
 
@@ -131,58 +131,4 @@ module WebTranslateIt
131
131
  !RUBY_PLATFORM.downcase.include?("mingw32")
132
132
  end
133
133
  end
134
- end
135
-
136
- class Array
137
- def to_columns
138
- " #{self[0].backward_truncate} | #{self[1]} #{self[2]}"
139
- end
140
-
141
- def chunk(pieces=2)
142
- len = self.length;
143
- mid = (len/pieces)
144
- chunks = []
145
- start = 0
146
- 1.upto(pieces) do |i|
147
- last = start+mid
148
- last = last-1 unless len%pieces >= i
149
- chunks << self[start..last] || []
150
- start = last+1
151
- end
152
- chunks
153
- end
154
-
155
- end
156
-
157
- class String
158
-
159
- def backward_truncate
160
- if length <= 50
161
- spaces = ""
162
- (50-length).times{ spaces << " " }
163
- return self << spaces
164
- else
165
- return "..." << self[self.length-50+3..self.length]
166
- end
167
- end
168
-
169
- def success
170
- WebTranslateIt::Util.can_display_colors? ? "\e[32m#{self}\e[0m" : self
171
- end
172
-
173
- def failure
174
- WebTranslateIt::Util.can_display_colors? ? "\e[31m#{self}\e[0m" : self
175
- end
176
-
177
- def checksumify
178
- WebTranslateIt::Util.can_display_colors? ? "\e[33m#{self[0..6]}\e[0m" : self[0..6]
179
- end
180
-
181
- def titleize
182
- WebTranslateIt::Util.can_display_colors? ? "\e[1m#{self}\e[0m\n\n" : self
183
- end
184
-
185
- def important
186
- WebTranslateIt::Util.can_display_colors? ? "\e[1m#{self}\e[0m" : self
187
- end
188
- end
134
+ end
@@ -0,0 +1,19 @@
1
+ class ArrayUtil
2
+ def self.to_columns(arr)
3
+ " #{StringUtil.backward_truncate(arr[0])} | #{arr[1]} #{arr[2]}"
4
+ end
5
+
6
+ def self.chunk(arr, pieces=2)
7
+ len = arr.length;
8
+ mid = (len/pieces)
9
+ chunks = []
10
+ start = 0
11
+ 1.upto(pieces) do |i|
12
+ last = start+mid
13
+ last = last-1 unless len%pieces >= i
14
+ chunks << arr[start..last] || []
15
+ start = last+1
16
+ end
17
+ chunks
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ class StringUtil
2
+
3
+ def self.backward_truncate(str)
4
+ if str.length <= 50
5
+ spaces = ""
6
+ (50-str.length).times{ spaces << " " }
7
+ return str.dup << spaces
8
+ else
9
+ return "..." << str[str.length-50+3..str.length]
10
+ end
11
+ end
12
+
13
+ def self.success(str)
14
+ WebTranslateIt::Util.can_display_colors? ? "\e[32m#{str}\e[0m" : str
15
+ end
16
+
17
+ def self.failure(str)
18
+ WebTranslateIt::Util.can_display_colors? ? "\e[31m#{str}\e[0m" : str
19
+ end
20
+
21
+ def self.checksumify(str)
22
+ WebTranslateIt::Util.can_display_colors? ? "\e[33m#{str[0..6]}\e[0m" : str[0..6]
23
+ end
24
+
25
+ def self.titleize(str)
26
+ WebTranslateIt::Util.can_display_colors? ? "\e[1m#{str}\e[0m\n\n" : str
27
+ end
28
+
29
+ def self.important(str)
30
+ WebTranslateIt::Util.can_display_colors? ? "\e[1m#{str}\e[0m" : str
31
+ end
32
+ end
File without changes
data/version.yml CHANGED
@@ -2,4 +2,4 @@
2
2
  :major: 1
3
3
  :minor: 8
4
4
  :tiny: 2
5
- :patch: 0
5
+ :patch: 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_translate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2.0
4
+ version: 1.8.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-12 00:00:00.000000000 Z
12
+ date: 2011-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multipart-post
16
- requirement: &70229730325800 !ruby/object:Gem::Requirement
16
+ requirement: &70362462653320 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.1.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70229730325800
24
+ version_requirements: *70362462653320
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: trollop
27
- requirement: &70229730325300 !ruby/object:Gem::Requirement
27
+ requirement: &70362462652660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.16.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70229730325300
35
+ version_requirements: *70362462652660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sinatra
38
- requirement: &70229730324840 !ruby/object:Gem::Requirement
38
+ requirement: &70362462651680 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.2.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70229730324840
46
+ version_requirements: *70362462651680
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70229730324380 !ruby/object:Gem::Requirement
49
+ requirement: &70362462649880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 2.6.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70229730324380
57
+ version_requirements: *70362462649880
58
58
  description:
59
59
  email: edouard@atelierconvivialite.com
60
60
  executables:
@@ -65,7 +65,7 @@ extra_rdoc_files:
65
65
  - readme.md
66
66
  files:
67
67
  - history.md
68
- - licence
68
+ - license
69
69
  - readme.md
70
70
  - version.yml
71
71
  - examples/locale.rb
@@ -77,6 +77,8 @@ files:
77
77
  - lib/web_translate_it/public/screen.css
78
78
  - lib/web_translate_it/server.rb
79
79
  - lib/web_translate_it/translation_file.rb
80
+ - lib/web_translate_it/util/array_util.rb
81
+ - lib/web_translate_it/util/string_util.rb
80
82
  - lib/web_translate_it/util.rb
81
83
  - lib/web_translate_it/views/index.erb
82
84
  - lib/web_translate_it.rb