phrase 0.4.14 → 0.4.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +15 -0
  2. data/lib/ext/hash.rb +1 -1
  3. data/lib/generators/phrase/install_generator.rb +1 -1
  4. data/lib/generators/templates/phrase.rb +4 -4
  5. data/lib/phrase/adapters/fast_gettext.rb +3 -3
  6. data/lib/phrase/api/client.rb +27 -27
  7. data/lib/phrase/api/config.rb +3 -3
  8. data/lib/phrase/api/exceptions.rb +1 -1
  9. data/lib/phrase/api/query_params.rb +2 -2
  10. data/lib/phrase/backend/phrase_service.rb +12 -12
  11. data/lib/phrase/cache.rb +7 -7
  12. data/lib/phrase/config.rb +18 -18
  13. data/lib/phrase/delegate.rb +2 -2
  14. data/lib/phrase/delegate/fast_gettext.rb +1 -1
  15. data/lib/phrase/delegate/i18n.rb +26 -26
  16. data/lib/phrase/formats.rb +15 -13
  17. data/lib/phrase/formats/csv.rb +1 -1
  18. data/lib/phrase/formats/custom.rb +2 -2
  19. data/lib/phrase/formats/gettext.rb +1 -1
  20. data/lib/phrase/formats/ini.rb +1 -1
  21. data/lib/phrase/formats/json.rb +1 -1
  22. data/lib/phrase/formats/node_json.rb +23 -0
  23. data/lib/phrase/formats/php_array.rb +1 -1
  24. data/lib/phrase/formats/plist.rb +1 -1
  25. data/lib/phrase/formats/properties.rb +1 -1
  26. data/lib/phrase/formats/properties_xml.rb +1 -1
  27. data/lib/phrase/formats/qt_phrase_book.rb +1 -1
  28. data/lib/phrase/formats/qt_translation_source.rb +2 -2
  29. data/lib/phrase/formats/resx.rb +1 -1
  30. data/lib/phrase/formats/resx_windowsphone.rb +1 -1
  31. data/lib/phrase/formats/simple_json.rb +2 -2
  32. data/lib/phrase/formats/strings.rb +4 -4
  33. data/lib/phrase/formats/tmx.rb +2 -2
  34. data/lib/phrase/formats/xliff.rb +2 -2
  35. data/lib/phrase/formats/xml.rb +6 -6
  36. data/lib/phrase/formats/yaml.rb +2 -2
  37. data/lib/phrase/formats/yaml_symfony.rb +2 -2
  38. data/lib/phrase/tool.rb +2 -2
  39. data/lib/phrase/tool/commands.rb +1 -1
  40. data/lib/phrase/tool/commands/base.rb +14 -14
  41. data/lib/phrase/tool/commands/init.rb +4 -4
  42. data/lib/phrase/tool/commands/pull.rb +13 -13
  43. data/lib/phrase/tool/commands/show_help.rb +1 -1
  44. data/lib/phrase/tool/commands/show_version.rb +3 -3
  45. data/lib/phrase/tool/commands/tags.rb +1 -1
  46. data/lib/phrase/tool/config.rb +3 -3
  47. data/lib/phrase/tool/encoding_detector.rb +3 -3
  48. data/lib/phrase/tool/locale.rb +8 -8
  49. data/lib/phrase/tool/options.rb +3 -3
  50. data/lib/phrase/tool/options_factory.rb +11 -11
  51. data/lib/phrase/tool/tag_validator.rb +2 -2
  52. data/lib/phrase/version.rb +1 -1
  53. data/lib/phrase/view_helpers.rb +2 -2
  54. metadata +66 -37
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MmNlOGM1Yzc0NmYwYTM0M2ZmMmUyMjUzN2Q3MmMzMWIwNmRlYTg2ZQ==
5
+ data.tar.gz: !binary |-
6
+ OTE5ZDBmMGE4YWZkYWZiMjc4YzIwNDc0YTFlYjg5Y2I0NzZiNjQ1YQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Yzc5ZWJmMDhkOWNjNmIwYWFkNmY2YjdkNDk2YjBlN2EzOTg3MjNkMmIzMDgx
10
+ ODRhMmZiZjQyMjJmYjNhNDgxZGQwNjFlMzIzMzE1ZDJhZDY3MTFjMThmMmQ0
11
+ NmUzMjJlODRjN2E2NTMwZjg0ZTgyOTUxMDNhNTRkZDY0OTQwN2Q=
12
+ data.tar.gz: !binary |-
13
+ NzA5NzkyMDU2YTJkYzMyYTcwYmYwOGIzYTE4ZTNmZTJlM2RiOGYzYmY5Mjcz
14
+ YzZlODI3ZjY0ZTFkYjliNjY5ZWZkOWNmNDIzMmUxYjUyNjc1YTdmNmE1YThj
15
+ ZWIwMmM4YmY4NjgzZDA3ZTY2MDY4YWFkNGE4OTFhMDMyNjljN2Y=
data/lib/ext/hash.rb CHANGED
@@ -1,4 +1,4 @@
1
- class Hash
1
+ class Hash
2
2
  def symbolize_keys!
3
3
  keys.each do |key|
4
4
  self[(key.to_sym rescue key) || key] = delete(key)
@@ -16,7 +16,7 @@ module Phrase
16
16
  end
17
17
 
18
18
  def init_phrase
19
- # It is probably preferred to just invoke phrase init via #run
19
+ # It is probably preferred to just invoke phrase init via #run
20
20
  # but this version can be mocked so much better via VCR
21
21
  tool = Phrase::Tool.new(["init", "--secret=#{options[:auth_token]}", "--default-locale=#{options[:default_locale]}"])
22
22
  tool.run
@@ -2,17 +2,17 @@ Phrase.configure do |config|
2
2
  # Enable or disable the PhraseApp context editor in general
3
3
  config.enabled = true
4
4
 
5
- # Fetch your project auth token after creating your first project
5
+ # Fetch your project auth token after creating your first project
6
6
  # in the PhraseApp translation center.
7
7
  config.auth_token = "<%= options[:auth_token] %>"
8
8
 
9
- # Configure an array of key names that should not be handled
9
+ # Configure an array of key names that should not be handled
10
10
  # with PhraseApp. This is useful when a key causes problems
11
11
  # (Such as keys that are used by Rails internally)
12
12
  config.ignored_keys = []
13
13
 
14
- # PhraseApp uses decorators to generate a unique identification key
15
- # in context of your document. However, this might result in conflicts
14
+ # PhraseApp uses decorators to generate a unique identification key
15
+ # in context of your document. However, this might result in conflicts
16
16
  # with other libraries (e.g. client-side template engines) that use a similar syntax.
17
17
  # If you encounter this problem, you might want to change the phrase decorator.
18
18
  # More information: https://phraseapp.com/docs/installation/phrase-gem
@@ -9,17 +9,17 @@ module FastGettext
9
9
  end
10
10
  alias_method :__without_phrase, :_
11
11
  alias_method :_, :__with_phrase
12
-
12
+
13
13
  def n__with_phrase(*args)
14
14
  Phrase::Delegate::FastGettext.new(:n_, *args)
15
15
  end
16
16
  alias_method :n__without_phrase, :n_
17
17
  alias_method :n_, :n__with_phrase
18
-
18
+
19
19
  def s__with_phrase(*args)
20
20
  Phrase::Delegate::FastGettext.new(:s_, *args)
21
21
  end
22
22
  alias_method :s__without_phrase, :s_
23
- alias_method :s_, :s__with_phrase
23
+ alias_method :s_, :s__with_phrase
24
24
  end
25
25
  end if defined? FastGettext::Translation
@@ -8,34 +8,34 @@ require 'phrase'
8
8
  require 'phrase/api'
9
9
 
10
10
  class Phrase::Api::Client
11
-
11
+
12
12
  METHOD_GET = :get
13
13
  METHOD_POST = :post
14
14
  METHOD_PUT = :put
15
-
15
+
16
16
  attr_reader :auth_token
17
-
17
+
18
18
  def initialize(auth_token)
19
19
  raise "No auth token specified!" if (auth_token.nil? or auth_token.blank?)
20
20
  @auth_token = auth_token
21
21
  end
22
-
22
+
23
23
  def fetch_locales
24
24
  result = perform_api_request("/locales", :get)
25
- parsed(result).map do |locale|
25
+ parsed(result).map do |locale|
26
26
  {id: locale['id'], name: locale['name'], code: locale['code'], is_default: locale['is_default']}
27
27
  end
28
28
  end
29
-
29
+
30
30
  def fetch_blacklisted_keys
31
31
  result = perform_api_request("/blacklisted_keys", :get)
32
32
  blacklisted_keys = []
33
- parsed(result).map do |blacklisted_key|
33
+ parsed(result).map do |blacklisted_key|
34
34
  blacklisted_keys << blacklisted_key['name']
35
35
  end
36
36
  blacklisted_keys
37
37
  end
38
-
38
+
39
39
  def translate(key)
40
40
  raise "You must specify a key" if key.nil? or key.blank?
41
41
  keys = {}
@@ -43,14 +43,14 @@ class Phrase::Api::Client
43
43
  keys = extract_structured_object(result["translate"]) if result["translate"]
44
44
  keys
45
45
  end
46
-
46
+
47
47
  def find_keys_by_name(key_names=[])
48
48
  parsed(perform_api_request("/translation_keys", :get, {:key_names => key_names}))
49
49
  end
50
-
50
+
51
51
  def create_locale(name)
52
52
  raise "You must specify a name" if name.nil? or name.blank?
53
-
53
+
54
54
  begin
55
55
  perform_api_request("/locales", :post, {
56
56
  "locale[name]" => name
@@ -60,10 +60,10 @@ class Phrase::Api::Client
60
60
  end
61
61
  true
62
62
  end
63
-
63
+
64
64
  def make_locale_default(name)
65
65
  raise "You must specify a name" if name.nil? or name.blank?
66
-
66
+
67
67
  begin
68
68
  perform_api_request("/locales/#{name}/make_default", :put)
69
69
  rescue Phrase::Api::Exceptions::ServerError => e
@@ -71,11 +71,11 @@ class Phrase::Api::Client
71
71
  end
72
72
  true
73
73
  end
74
-
74
+
75
75
  def download_translations_for_locale(name, format, tag=nil)
76
76
  raise "You must specify a name" if name.nil? or name.blank?
77
77
  raise "You must specify a format" if format.nil? or format.blank?
78
-
78
+
79
79
  begin
80
80
  content = perform_api_request("/translations/download.#{format}", :get, {'locale' => name, 'tag' => tag})
81
81
  return content
@@ -83,7 +83,7 @@ class Phrase::Api::Client
83
83
  raise "Translations #{name} could not be downloaded"
84
84
  end
85
85
  end
86
-
86
+
87
87
  def upload(filename, file_content, tags=[], locale=nil, format=nil, update_translations=false, skip_unverification=false)
88
88
  begin
89
89
  params = {
@@ -106,7 +106,7 @@ class Phrase::Api::Client
106
106
  result = perform_api_request("/tags", :get)
107
107
  parsed(result)
108
108
  end
109
-
109
+
110
110
  private
111
111
  def extract_structured_object(translation)
112
112
  if translation.is_a?(Hash)
@@ -191,13 +191,13 @@ private
191
191
  def should_retry?(request, response)
192
192
  request.method.to_s.downcase == METHOD_GET.to_s && response.code.to_i == 502
193
193
  end
194
-
194
+
195
195
  def get_request(endpoint, params={})
196
196
  params.merge!('auth_token' => @auth_token)
197
197
  request = Net::HTTP::Get.new("#{api_path_for(endpoint)}?#{query_for_params(params)}")
198
198
  request
199
199
  end
200
-
200
+
201
201
  def post_request(endpoint, params={})
202
202
  request = Net::HTTP::Post.new("#{api_path_for(endpoint)}")
203
203
  params.merge!({
@@ -206,7 +206,7 @@ private
206
206
  set_form_data(request, params)
207
207
  request
208
208
  end
209
-
209
+
210
210
  def put_request(endpoint, params={})
211
211
  request = Net::HTTP::Put.new("#{api_path_for(endpoint)}")
212
212
  params.merge!({
@@ -215,11 +215,11 @@ private
215
215
  set_form_data(request, params)
216
216
  request
217
217
  end
218
-
218
+
219
219
  def api_path_for(endpoint)
220
220
  "#{Phrase::Api::Config.api_path_prefix}#{endpoint}"
221
221
  end
222
-
222
+
223
223
  def http_client
224
224
  client = Net::HTTP.new(Phrase::Api::Config.api_host, Phrase::Api::Config.api_port)
225
225
  client.use_ssl = true if Phrase::Api::Config.api_use_ssl?
@@ -227,11 +227,11 @@ private
227
227
  client.ca_file = File.join(File.dirname(__FILE__), "..", "..", "..", "cacert.pem")
228
228
  client
229
229
  end
230
-
230
+
231
231
  # Support for arrays in POST data
232
232
  # http://blog.assimov.net/blog/2010/06/01/postput-arrays-with-ruby-nethttp-set_form_data/
233
233
  def set_form_data(request, params, separator='&')
234
- request.body = params.map do |key, value|
234
+ request.body = params.map do |key, value|
235
235
  if value.instance_of?(Array)
236
236
  value.map {|value_item| "#{escaped(key.to_s)}=#{escaped(value_item.to_s)}"}.join(separator)
237
237
  else
@@ -240,12 +240,12 @@ private
240
240
  end.join(separator)
241
241
  request.content_type = 'application/x-www-form-urlencoded'
242
242
  end
243
-
243
+
244
244
  def parsed(raw_data)
245
245
  JSON.parse(raw_data)
246
246
  end
247
-
248
- def escaped(value)
247
+
248
+ def escaped(value)
249
249
  CGI::escape(value)
250
250
  end
251
251
 
@@ -7,15 +7,15 @@ class Phrase::Api::Config
7
7
  def self.api_port
8
8
  ENV.fetch("PHRASE_API_PORT", "443")
9
9
  end
10
-
10
+
11
11
  def self.api_host
12
12
  ENV.fetch("PHRASE_API_HOST", "phraseapp.com")
13
13
  end
14
-
14
+
15
15
  def self.api_path_prefix
16
16
  "/api/#{Phrase::API_VERSION}"
17
17
  end
18
-
18
+
19
19
  def self.api_use_ssl?
20
20
  ENV.fetch("PHRASE_API_USE_SSL", "1") == "1"
21
21
  end
@@ -6,4 +6,4 @@ require 'phrase/api'
6
6
  module Phrase::Api::Exceptions
7
7
  class Unauthorized < StandardError; end
8
8
  class ServerError < StandardError; end
9
- end
9
+ end
@@ -7,14 +7,14 @@ class Phrase::Api::QueryParams
7
7
  when Hash then value.map { |k,v| encode(v, append_key(key,k)) }.join("&")
8
8
  when nil then ""
9
9
  else
10
- "#{key}=#{CGI.escape(value.to_s)}"
10
+ "#{key}=#{CGI.escape(value.to_s)}"
11
11
  end
12
12
  end
13
13
 
14
14
  def self.append_key(root_key, key)
15
15
  if root_key.nil?
16
16
  key
17
- else
17
+ else
18
18
  "#{root_key}[#{key.to_s}]"
19
19
  end
20
20
  end
@@ -3,13 +3,13 @@
3
3
  require 'phrase/delegate/i18n'
4
4
 
5
5
  class Phrase::Backend::PhraseService
6
-
6
+
7
7
  attr_accessor :api_client, :blacklisted_keys
8
-
8
+
9
9
  def initialize(args = {})
10
10
  self
11
11
  end
12
-
12
+
13
13
  def translate(*args)
14
14
  if to_be_translated_without_phrase?(args)
15
15
  I18n.translate_without_phrase(*args)
@@ -54,15 +54,15 @@ protected
54
54
  end
55
55
  false
56
56
  end
57
-
57
+
58
58
  def blacklisted_keys
59
59
  @blacklisted_keys ||= api_client.fetch_blacklisted_keys
60
60
  end
61
-
61
+
62
62
  def api_client
63
63
  @api_client ||= Phrase::Api::Client.new(Phrase.auth_token)
64
64
  end
65
-
65
+
66
66
  def phrase_delegate_for(args)
67
67
  key = given_key_from_args(args)
68
68
  return nil unless present?(key)
@@ -87,9 +87,9 @@ protected
87
87
  key.gsub!(/^\./, '')
88
88
  key
89
89
  end
90
-
90
+
91
91
  def split_args(args)
92
- options = options_from_args(args)
92
+ options = options_from_args(args)
93
93
  key ||= args.shift
94
94
  locale = options.delete(:locale) || I18n.locale
95
95
  return [locale, key, options[:scope], nil]
@@ -101,7 +101,7 @@ protected
101
101
 
102
102
  def transform_args_based_on_caller(args)
103
103
  translation_caller = identify_caller
104
-
104
+
105
105
  if translation_caller and args.first =~ /^\./
106
106
  options = options_from_args(args)
107
107
 
@@ -122,7 +122,7 @@ protected
122
122
  send(:caller)[0..6].each do |intermediate_caller|
123
123
  translation_caller = calling_template(intermediate_caller) unless translation_caller
124
124
  end
125
-
125
+
126
126
  if present?(translation_caller)
127
127
  find_lookup_scope(translation_caller)
128
128
  else
@@ -136,7 +136,7 @@ protected
136
136
 
137
137
  def blank?(str)
138
138
  raise "blank?(str) can only be given a String or nil" unless str.is_a?(String) or str.nil?
139
- str.nil? or str == ''
139
+ str.nil? or str == ''
140
140
  end
141
141
 
142
142
  def present?(str)
@@ -155,7 +155,7 @@ protected
155
155
 
156
156
  def remove_underscore_form_partial(template_or_partial)
157
157
  if template_or_partial.to_s[0,1] == "_"
158
- template_or_partial.to_s[1..-1]
158
+ template_or_partial.to_s[1..-1]
159
159
  else
160
160
  template_or_partial.to_s
161
161
  end
data/lib/phrase/cache.rb CHANGED
@@ -3,18 +3,18 @@
3
3
  require 'phrase'
4
4
 
5
5
  class Phrase::Cache
6
-
6
+
7
7
  attr_accessor :lifetime
8
-
8
+
9
9
  def initialize(args={})
10
10
  @store = {}
11
11
  @lifetime = args.fetch(:lifetime, Phrase.cache_lifetime)
12
12
  end
13
-
13
+
14
14
  def cached?(cache_key)
15
15
  @store.has_key?(cache_key) && !expired?(cache_key)
16
16
  end
17
-
17
+
18
18
  def get(cache_key)
19
19
  begin
20
20
  @store.fetch(cache_key)[:payload]
@@ -22,13 +22,13 @@ class Phrase::Cache
22
22
  nil
23
23
  end
24
24
  end
25
-
25
+
26
26
  def set(cache_key, value)
27
27
  @store[cache_key] = {timestamp: Time.now, payload: value}
28
28
  end
29
-
29
+
30
30
  private
31
31
  def expired?(cache_key)
32
32
  @store.fetch(cache_key)[:timestamp] < (Time.now - @lifetime)
33
33
  end
34
- end
34
+ end
data/lib/phrase/config.rb CHANGED
@@ -4,7 +4,7 @@ class Phrase::Config
4
4
  def client_version
5
5
  Phrase::CLIENT_VERSION
6
6
  end
7
-
7
+
8
8
  def api_version
9
9
  Phrase::API_VERSION
10
10
  end
@@ -13,73 +13,73 @@ class Phrase::Config
13
13
  @@auth_token = "" if !defined? @@auth_token or @@auth_token.nil?
14
14
  @@auth_token
15
15
  end
16
-
16
+
17
17
  def auth_token=(auth_token)
18
18
  @@auth_token = auth_token
19
19
  end
20
-
20
+
21
21
  def enabled
22
22
  @@enabled = false if !defined? @@enabled or @@enabled.nil?
23
23
  @@enabled
24
24
  end
25
-
25
+
26
26
  def enabled=(enabled)
27
27
  @@enabled = enabled
28
28
  end
29
-
29
+
30
30
  def backend
31
31
  @@backend ||= Phrase::Backend::PhraseService.new
32
32
  end
33
-
33
+
34
34
  def backend=(backend)
35
35
  @@backend = backend
36
36
  end
37
-
37
+
38
38
  def prefix
39
39
  @@prefix ||= "{{__"
40
40
  end
41
-
41
+
42
42
  def prefix=(prefix)
43
43
  @@prefix = prefix
44
44
  end
45
-
45
+
46
46
  def suffix
47
47
  @@suffix ||= "__}}"
48
48
  end
49
-
49
+
50
50
  def suffix=(suffix)
51
51
  @@suffix = suffix
52
52
  end
53
-
53
+
54
54
  def js_host
55
55
  @@js_host ||= 'phraseapp.com'
56
56
  end
57
-
57
+
58
58
  def js_host=(js_host)
59
59
  @@js_host = js_host
60
60
  end
61
-
61
+
62
62
  def js_use_ssl
63
63
  @@js_use_ssl = true if !defined? @@js_use_ssl or @@js_use_ssl.nil?
64
64
  @@js_use_ssl
65
65
  end
66
-
66
+
67
67
  def js_use_ssl=(js_use_ssl)
68
68
  @@js_use_ssl = js_use_ssl
69
69
  end
70
-
70
+
71
71
  def cache_key_segments_initial
72
72
  @@cache_key_segments_initial ||= ["simple_form"]
73
73
  end
74
-
74
+
75
75
  def cache_key_segments_initial=(cache_key_segments_initial=[])
76
76
  @@cache_key_segments_initial = cache_key_segments_initial
77
77
  end
78
-
78
+
79
79
  def cache_lifetime
80
80
  @@cache_lifetime ||= 300
81
81
  end
82
-
82
+
83
83
  def cache_lifetime=(cache_lifetime)
84
84
  @@cache_lifetime = cache_lifetime
85
85
  end