phrase 0.0.4 → 0.0.5

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.
Files changed (3) hide show
  1. data/lib/phrase/tool.rb +57 -8
  2. data/phrase.gemspec +1 -1
  3. metadata +2 -2
data/lib/phrase/tool.rb CHANGED
@@ -29,6 +29,7 @@ module PhraseGem
29
29
  end
30
30
 
31
31
  private
32
+
32
33
  def init(config)
33
34
  secret_param = args.find{ |arg| arg =~ /secret=/ }
34
35
  unless secret_param.to_s.match(/secret=.+/)
@@ -40,6 +41,15 @@ module PhraseGem
40
41
  secret = secret_param.split("=", 2).last
41
42
  config.secret = secret
42
43
  puts "Wrote secret to config file .phrase"
44
+
45
+ default_locale_param = args.find{ |arg| arg =~ /default-locale=/ }
46
+ if default_locale_param.to_s.match(/default-locale=.+/)
47
+ locale_name = default_locale_param.split("=", 2).last
48
+ else
49
+ locale_name = "en"
50
+ end
51
+ create_locale(locale_name, config)
52
+ make_locale_default(locale_name, config)
43
53
  end
44
54
 
45
55
  def push(config)
@@ -66,8 +76,8 @@ module PhraseGem
66
76
  puts "No file or directory specified, using #{self.class.rails_default_locale_folder}"
67
77
  else
68
78
  $stderr.puts "Need either a file or directory:"
69
- $stderr.puts " phrase push FILE"
70
- $stderr.puts " phrase push DIRECTORY"
79
+ $stderr.puts "phrase push FILE"
80
+ $stderr.puts "phrase push DIRECTORY"
71
81
  exit(46)
72
82
  end
73
83
  end
@@ -94,7 +104,7 @@ module PhraseGem
94
104
 
95
105
  if is_yaml_file(file)
96
106
  proceed_with_upload = false
97
- $stderr.puts "Error: Could not upload #{file} (extension not supported)"
107
+ $stderr.puts "Notice: Could not upload #{file} (extension not supported - see http://phraseapp.com/help for more information)"
98
108
  end
99
109
 
100
110
  if proceed_with_upload
@@ -144,12 +154,12 @@ module PhraseGem
144
154
  res = http.request(request)
145
155
 
146
156
  if res.code.to_s =~ /200/
147
- puts " OK"
157
+ puts "OK"
148
158
  File.open("phrase/locales/phrase.#{locale}.yml", "w") do |file|
149
159
  file.write(res.body)
150
160
  end
151
161
  else
152
- puts " Failed"
162
+ puts "Failed"
153
163
  print_server_error(res)
154
164
  end
155
165
  end
@@ -161,14 +171,52 @@ module PhraseGem
161
171
  res = http.request(request)
162
172
 
163
173
  if res.code.to_s =~ /200/
164
- puts " Fetched all locales"
174
+ puts "Fetched all locales"
165
175
  return JSON.parse(res.body).map { |locale| locale['name'] }
166
176
  else
167
- puts " Failed"
177
+ puts "Failed"
168
178
  print_server_error(res)
169
179
  exit(47)
170
180
  end
171
181
  end
182
+
183
+ def create_locale(locale_name, config)
184
+ params = {
185
+ 'auth_token' => config.secret,
186
+ 'locale[name]' => locale_name
187
+ }
188
+
189
+ http = http_client(config)
190
+
191
+ request = Net::HTTP::Post.new("#{config.api_path_prefix}/locales")
192
+ request.set_form_data(params)
193
+ res = http.request(request)
194
+
195
+ if res.code.to_s =~ /200/
196
+ puts "Created locale \"#{locale_name}\""
197
+ else
198
+ puts "Notice: Locale \"#{locale_name}\" could not be created (maybe it already exists)"
199
+ end
200
+ end
201
+
202
+ def make_locale_default(locale_name, config)
203
+ params = {
204
+ 'auth_token' => config.secret,
205
+ }
206
+
207
+ http = http_client(config)
208
+
209
+ request = Net::HTTP::Put.new("#{config.api_path_prefix}/locales/#{locale_name}/make_default")
210
+ request.set_form_data(params)
211
+ res = http.request(request)
212
+
213
+ if res.code.to_s =~ /200/
214
+ puts "Locale \"#{locale_name}\" is now the default locale"
215
+ else
216
+ puts "Notice: Locale \"#{locale_name}\" could not be made the default locale"
217
+ print_server_error(res)
218
+ end
219
+ end
172
220
 
173
221
  def print_server_error(res, filename=nil)
174
222
  error_message = server_error_message(res.body)
@@ -186,9 +234,10 @@ module PhraseGem
186
234
  def print_usage
187
235
  $stderr.puts <<USAGE
188
236
  Welcome to phrase!
237
+
189
238
  phrase Prints usage
190
239
 
191
- phrase init --secret=<YOUR SECRET>
240
+ phrase init --secret=<YOUR SECRET> --default-locale=<YOUR DEFAULT LOCALE>
192
241
 
193
242
  phrase push FILE
194
243
  phrase push DIRECTORY
data/phrase.gemspec CHANGED
@@ -4,7 +4,7 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "phrase"
7
- s.version = "0.0.4"
7
+ s.version = "0.0.5"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Dynport GmbH"]
10
10
  s.email = ["info@phraseapp.com"]
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
4
+ version: 0.0.5
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-22 00:00:00.000000000Z
12
+ date: 2012-03-28 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: The best way to manage i18n.
15
15
  email: