phrase 0.0.3 → 0.0.4
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/Gemfile.lock +2 -0
- data/lib/phrase/tool.rb +34 -4
- data/phrase.gemspec +1 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/phrase/tool.rb
CHANGED
@@ -121,14 +121,28 @@ module PhraseGem
|
|
121
121
|
|
122
122
|
def pull(config)
|
123
123
|
locale = args[1]
|
124
|
+
|
125
|
+
locales = []
|
126
|
+
if locale && locale.strip != ''
|
127
|
+
locales = [locale]
|
128
|
+
else
|
129
|
+
locales = fetch_locales(config)
|
130
|
+
end
|
131
|
+
|
132
|
+
locales.each do |locale|
|
133
|
+
fetch_translation_for_locale(config, locale)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def fetch_translation_for_locale(config, locale)
|
124
138
|
print "Downloading phrase.#{locale}.yml..."
|
125
139
|
::FileUtils.mkdir_p("phrase/locales")
|
126
|
-
|
140
|
+
|
127
141
|
http = http_client(config)
|
128
|
-
|
142
|
+
|
129
143
|
request = Net::HTTP::Get.new("#{config.api_path_prefix}/translations/download?auth_token=#{config.secret}&locale=#{locale}")
|
130
144
|
res = http.request(request)
|
131
|
-
|
145
|
+
|
132
146
|
if res.code.to_s =~ /200/
|
133
147
|
puts " OK"
|
134
148
|
File.open("phrase/locales/phrase.#{locale}.yml", "w") do |file|
|
@@ -139,6 +153,22 @@ module PhraseGem
|
|
139
153
|
print_server_error(res)
|
140
154
|
end
|
141
155
|
end
|
156
|
+
|
157
|
+
def fetch_locales(config)
|
158
|
+
http = http_client(config)
|
159
|
+
|
160
|
+
request = Net::HTTP::Get.new("#{config.api_path_prefix}/locales?auth_token=#{config.secret}")
|
161
|
+
res = http.request(request)
|
162
|
+
|
163
|
+
if res.code.to_s =~ /200/
|
164
|
+
puts " Fetched all locales"
|
165
|
+
return JSON.parse(res.body).map { |locale| locale['name'] }
|
166
|
+
else
|
167
|
+
puts " Failed"
|
168
|
+
print_server_error(res)
|
169
|
+
exit(47)
|
170
|
+
end
|
171
|
+
end
|
142
172
|
|
143
173
|
def print_server_error(res, filename=nil)
|
144
174
|
error_message = server_error_message(res.body)
|
@@ -149,7 +179,7 @@ module PhraseGem
|
|
149
179
|
begin
|
150
180
|
JSON.parse(body)["error"]
|
151
181
|
rescue JSON::ParserError
|
152
|
-
"
|
182
|
+
"Unknown error"
|
153
183
|
end
|
154
184
|
end
|
155
185
|
|
data/phrase.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phrase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
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-03-
|
12
|
+
date: 2012-03-22 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: The best way to manage i18n.
|
15
15
|
email:
|