web_translate_it 2.0.1 → 2.0.2
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.
- data/history.md +5 -0
- data/lib/web_translate_it/string.rb +21 -14
- data/lib/web_translate_it/term.rb +20 -14
- data/lib/web_translate_it/term_translation.rb +2 -4
- data/lib/web_translate_it/translation.rb +1 -1
- data/lib/web_translate_it/util.rb +11 -5
- data/readme.md +3 -1
- data/spec/web_translate_it/string_spec.rb +1 -2
- data/version +1 -1
- metadata +3 -4
- data/examples/en.yml +0 -43
data/history.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## Version 2.0.2 / 2012-06-06
|
2
|
+
|
3
|
+
* String, Translation, Term and TermTranslation classes now raise exceptions and display useful error messages. #87
|
4
|
+
* Implemented pagination for `String#find_all` and `Term#find_all`. This should work seemlessly with no API change.
|
5
|
+
|
1
6
|
## Version 2.0.1 / 2012-05-11
|
2
7
|
|
3
8
|
* Fix: Issue with saving labels on a string.
|
@@ -49,8 +49,6 @@ module WebTranslateIt
|
|
49
49
|
# puts strings.inspect #=> An array of WebTranslateIt::String objects
|
50
50
|
#
|
51
51
|
# to find and instantiate an array of String which key is like `product_name_123`.
|
52
|
-
#
|
53
|
-
# TODO: Implement pagination
|
54
52
|
|
55
53
|
def self.find_all(params = {})
|
56
54
|
params.stringify_keys!
|
@@ -62,12 +60,22 @@ module WebTranslateIt
|
|
62
60
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
63
61
|
|
64
62
|
begin
|
65
|
-
response = Util.handle_response(Connection.http_connection.request(request), true)
|
66
63
|
strings = []
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
64
|
+
while(request) do
|
65
|
+
response = Connection.http_connection.request(request)
|
66
|
+
YAML.load(response.body).each do |string_response|
|
67
|
+
string = WebTranslateIt::String.new(string_response)
|
68
|
+
string.new_record = false
|
69
|
+
strings.push(string)
|
70
|
+
end
|
71
|
+
if response["Link"] && response["Link"].include?("rel=\"next\"")
|
72
|
+
url = response["Link"].match(/<(.*)>; rel="next"/)[1]
|
73
|
+
request = Net::HTTP::Get.new(url)
|
74
|
+
request.add_field("X-Client-Name", "web_translate_it")
|
75
|
+
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
76
|
+
else
|
77
|
+
request = nil
|
78
|
+
end
|
71
79
|
end
|
72
80
|
return strings
|
73
81
|
rescue Timeout::Error
|
@@ -96,9 +104,8 @@ module WebTranslateIt
|
|
96
104
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
97
105
|
|
98
106
|
begin
|
99
|
-
response = Connection.http_connection.request(request)
|
100
|
-
|
101
|
-
string = WebTranslateIt::String.new(YAML.load(response.body))
|
107
|
+
response = Util.handle_response(Connection.http_connection.request(request), true, true)
|
108
|
+
string = WebTranslateIt::String.new(YAML.load(response))
|
102
109
|
string.new_record = false
|
103
110
|
return string
|
104
111
|
rescue Timeout::Error
|
@@ -139,7 +146,7 @@ module WebTranslateIt
|
|
139
146
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
140
147
|
|
141
148
|
begin
|
142
|
-
Util.handle_response(Connection.http_connection.request(request), true)
|
149
|
+
Util.handle_response(Connection.http_connection.request(request), true, true)
|
143
150
|
rescue Timeout::Error
|
144
151
|
puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
|
145
152
|
sleep(5)
|
@@ -164,7 +171,7 @@ module WebTranslateIt
|
|
164
171
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
165
172
|
|
166
173
|
begin
|
167
|
-
response = Util.handle_response(Connection.http_connection.request(request), true)
|
174
|
+
response = Util.handle_response(Connection.http_connection.request(request), true, true)
|
168
175
|
hash = YAML.load(response)
|
169
176
|
return nil if hash.empty?
|
170
177
|
translation = WebTranslateIt::Translation.new(hash)
|
@@ -195,7 +202,7 @@ module WebTranslateIt
|
|
195
202
|
end
|
196
203
|
|
197
204
|
begin
|
198
|
-
Util.handle_response(Connection.http_connection.request(request), true)
|
205
|
+
Util.handle_response(Connection.http_connection.request(request), true, true)
|
199
206
|
rescue Timeout::Error
|
200
207
|
puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
|
201
208
|
sleep(5)
|
@@ -214,7 +221,7 @@ module WebTranslateIt
|
|
214
221
|
request.body = self.to_json(true)
|
215
222
|
|
216
223
|
begin
|
217
|
-
response = YAML.load(Util.handle_response(Connection.http_connection.request(request), true))
|
224
|
+
response = YAML.load(Util.handle_response(Connection.http_connection.request(request), true, true))
|
218
225
|
self.id = response["id"]
|
219
226
|
self.new_record = false
|
220
227
|
return true
|
@@ -40,8 +40,6 @@ module WebTranslateIt
|
|
40
40
|
# end
|
41
41
|
#
|
42
42
|
# puts terms.inspect #=> An array of WebTranslateIt::Term objects
|
43
|
-
#
|
44
|
-
# TODO: Implement pagination
|
45
43
|
|
46
44
|
def self.find_all(params = {})
|
47
45
|
params.stringify_keys!
|
@@ -53,15 +51,24 @@ module WebTranslateIt
|
|
53
51
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
54
52
|
|
55
53
|
begin
|
56
|
-
response = Util.handle_response(Connection.http_connection.request(request), true)
|
57
54
|
terms = []
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
while(request) do
|
56
|
+
response = Connection.http_connection.request(request)
|
57
|
+
YAML.load(response).each do |term_response|
|
58
|
+
term = WebTranslateIt::Term.new(term_response)
|
59
|
+
term.new_record = false
|
60
|
+
terms.push(term)
|
61
|
+
end
|
62
|
+
if response["Link"] && response["Link"].include?("rel=\"next\"")
|
63
|
+
url = response["Link"].match(/<(.*)>; rel="next"/)[1]
|
64
|
+
request = Net::HTTP::Get.new(url)
|
65
|
+
request.add_field("X-Client-Name", "web_translate_it")
|
66
|
+
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
67
|
+
else
|
68
|
+
request = nil
|
69
|
+
end
|
62
70
|
end
|
63
71
|
return terms
|
64
|
-
|
65
72
|
rescue Timeout::Error
|
66
73
|
puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
|
67
74
|
sleep(5)
|
@@ -88,8 +95,7 @@ module WebTranslateIt
|
|
88
95
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
89
96
|
|
90
97
|
begin
|
91
|
-
response = Connection.http_connection.request(request)
|
92
|
-
return nil if response.code.to_i == 404
|
98
|
+
response = Util.handle_response(Connection.http_connection.request(request), true, true)
|
93
99
|
term = WebTranslateIt::Term.new(YAML.load(response.body))
|
94
100
|
term.new_record = false
|
95
101
|
return term
|
@@ -131,7 +137,7 @@ module WebTranslateIt
|
|
131
137
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
132
138
|
|
133
139
|
begin
|
134
|
-
Util.handle_response(Connection.http_connection.request(request), true)
|
140
|
+
Util.handle_response(Connection.http_connection.request(request), true, true)
|
135
141
|
rescue Timeout::Error
|
136
142
|
puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
|
137
143
|
sleep(5)
|
@@ -156,7 +162,7 @@ module WebTranslateIt
|
|
156
162
|
request.add_field("X-Client-Version", WebTranslateIt::Util.version)
|
157
163
|
|
158
164
|
begin
|
159
|
-
response = Util.handle_response(Connection.http_connection.request(request), true)
|
165
|
+
response = Util.handle_response(Connection.http_connection.request(request), true, true)
|
160
166
|
array = YAML.load(response)
|
161
167
|
return nil if array.empty?
|
162
168
|
translations = []
|
@@ -189,7 +195,7 @@ module WebTranslateIt
|
|
189
195
|
end
|
190
196
|
|
191
197
|
begin
|
192
|
-
Util.handle_response(Connection.http_connection.request(request), true)
|
198
|
+
Util.handle_response(Connection.http_connection.request(request), true, true)
|
193
199
|
rescue Timeout::Error
|
194
200
|
puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
|
195
201
|
sleep(5)
|
@@ -206,7 +212,7 @@ module WebTranslateIt
|
|
206
212
|
request.body = self.to_json(true)
|
207
213
|
|
208
214
|
begin
|
209
|
-
response = YAML.load(Util.handle_response(Connection.http_connection.request(request), true))
|
215
|
+
response = YAML.load(Util.handle_response(Connection.http_connection.request(request), true, true))
|
210
216
|
self.id = response["id"]
|
211
217
|
self.new_record = false
|
212
218
|
return true
|
@@ -61,8 +61,7 @@ module WebTranslateIt
|
|
61
61
|
request.body = self.to_hash.to_json
|
62
62
|
|
63
63
|
begin
|
64
|
-
response = Util.handle_response(Connection.http_connection.request(request), true)
|
65
|
-
response = YAML.load(response)
|
64
|
+
response = YAML.load(Util.handle_response(Connection.http_connection.request(request), true, true))
|
66
65
|
self.id = response["id"]
|
67
66
|
self.new_record = false
|
68
67
|
return true
|
@@ -83,8 +82,7 @@ module WebTranslateIt
|
|
83
82
|
request.body = self.to_hash.to_json
|
84
83
|
|
85
84
|
begin
|
86
|
-
Util.handle_response(Connection.http_connection.request(request), true)
|
87
|
-
|
85
|
+
Util.handle_response(Connection.http_connection.request(request), true, true)
|
88
86
|
rescue Timeout::Error
|
89
87
|
puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
|
90
88
|
sleep(5)
|
@@ -49,7 +49,7 @@ module WebTranslateIt
|
|
49
49
|
request.body = self.to_hash.to_json
|
50
50
|
|
51
51
|
begin
|
52
|
-
Util.handle_response(Connection.http_connection.request(request), true)
|
52
|
+
Util.handle_response(Connection.http_connection.request(request), true, true)
|
53
53
|
rescue Timeout::Error
|
54
54
|
puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
|
55
55
|
sleep(5)
|
@@ -4,6 +4,8 @@ module WebTranslateIt
|
|
4
4
|
# A few useful functions
|
5
5
|
class Util
|
6
6
|
|
7
|
+
require 'json'
|
8
|
+
|
7
9
|
# Return a string representing the gem version
|
8
10
|
# For example "1.8.3"
|
9
11
|
def self.version
|
@@ -15,15 +17,19 @@ module WebTranslateIt
|
|
15
17
|
((processed*10)/total).to_f.ceil*10
|
16
18
|
end
|
17
19
|
|
18
|
-
def self.handle_response(response, return_response = false)
|
20
|
+
def self.handle_response(response, return_response = false, raise_exception = false)
|
19
21
|
if response.code.to_i >= 400 and response.code.to_i < 500
|
20
|
-
if
|
21
|
-
|
22
|
+
if raise_exception
|
23
|
+
raise "Error: #{JSON.parse(response.body)['error']}"
|
22
24
|
else
|
23
|
-
StringUtil.failure(
|
25
|
+
StringUtil.failure(JSON.parse(response.body)['error'])
|
24
26
|
end
|
25
27
|
elsif response.code.to_i == 500
|
26
|
-
|
28
|
+
if raise_exception
|
29
|
+
raise "Error: Server temporarily unavailable (Error 500)."
|
30
|
+
else
|
31
|
+
StringUtil.failure("Error: Server temporarily unavailable (Error 500).")
|
32
|
+
end
|
27
33
|
else
|
28
34
|
return response.body if return_response
|
29
35
|
return StringUtil.success("OK") if response.code.to_i == 200
|
data/readme.md
CHANGED
@@ -23,7 +23,9 @@ This readme focusses on the most commonly used functionality of this rubygem: th
|
|
23
23
|
|
24
24
|
## Installation
|
25
25
|
|
26
|
-
|
26
|
+
A dependency of wti needs gcc in order to install, so you will need build tools. With Linux, `apt-get install gcc` or `yum install gcc` should do it.
|
27
|
+
|
28
|
+
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/AtelierConvivialite/webtranslateit/wiki/Install-wti-on-Windows).
|
27
29
|
|
28
30
|
gem install web_translate_it
|
29
31
|
|
@@ -93,8 +93,7 @@ describe WebTranslateIt::String do
|
|
93
93
|
string_fetched.should_not be_nil
|
94
94
|
|
95
95
|
string_fetched.delete
|
96
|
-
|
97
|
-
string_fetched.should be_nil
|
96
|
+
lambda { WebTranslateIt::String.find(string.id) }.should raise_error
|
98
97
|
end
|
99
98
|
end
|
100
99
|
end
|
data/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.2
|
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: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multipart-post
|
@@ -104,7 +104,6 @@ files:
|
|
104
104
|
- license
|
105
105
|
- readme.md
|
106
106
|
- version
|
107
|
-
- examples/en.yml
|
108
107
|
- examples/locale.rb
|
109
108
|
- lib/web_translate_it/auto_fetch.rb
|
110
109
|
- lib/web_translate_it/cacert.pem
|
@@ -155,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
154
|
version: '0'
|
156
155
|
requirements: []
|
157
156
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.8.
|
157
|
+
rubygems_version: 1.8.24
|
159
158
|
signing_key:
|
160
159
|
specification_version: 3
|
161
160
|
summary: A CLI to sync locale files with webtranslateit.com.
|
data/examples/en.yml
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
fr:
|
2
|
-
activerecord:
|
3
|
-
errors:
|
4
|
-
templates:
|
5
|
-
header:
|
6
|
-
one: "1 error prohibited this {{model}} from being saved"
|
7
|
-
other: "{{count}} errors prohibited this {{model}} from being saved"
|
8
|
-
body: "there were problems with the following fields:"
|
9
|
-
messages:
|
10
|
-
accepted: "must be accepted"
|
11
|
-
blank: "can't be blank"
|
12
|
-
confirmation: "doesn't match confirmation"
|
13
|
-
empty: "can't be empty"
|
14
|
-
equal_to: "must be equal to {{count}}"
|
15
|
-
even: "must be even"
|
16
|
-
exclusion: "is reserved"
|
17
|
-
greater_than: "must be greater than {{count}}"
|
18
|
-
greater_than_or_equal_to: "must be greater than or equal to {{count}}"
|
19
|
-
inclusion: "is not included in the list"
|
20
|
-
invalid: "is invalid"
|
21
|
-
less_than: "must be less than {{count}}"
|
22
|
-
less_than_or_equal_to: "must be less than or equal to {{count}}"
|
23
|
-
not_a_number: "is not a number"
|
24
|
-
odd: "must be odd"
|
25
|
-
taken: "is already taken"
|
26
|
-
too_long: "is too long (maximum is {{count}} characters)"
|
27
|
-
too_short: "is too short (minimum is {{count}} characters)"
|
28
|
-
wrong_length: "is the wrong length (should be {{count}} characters)"
|
29
|
-
models:
|
30
|
-
invitation:
|
31
|
-
attributes:
|
32
|
-
email:
|
33
|
-
user_already_invited: "This user has already been invited"
|
34
|
-
user_already_member: "This user is already a member"
|
35
|
-
project_file:
|
36
|
-
attributes:
|
37
|
-
file:
|
38
|
-
file_format_not_supported: "Sorry, we currenly support only Gettext .pot/.po, .yml/.yaml and .strings"
|
39
|
-
another_one: dskjdks
|
40
|
-
another_string: "this is another string"
|
41
|
-
hello: "Hello world!!"
|
42
|
-
new_string: hehe
|
43
|
-
test: " & & "
|