localeapp 0.0.7 → 0.0.8
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/.rvmrc +1 -1
- data/bin/localeapp +9 -9
- data/features/localeapp_binary.feature +17 -17
- data/features/support/env.rb +2 -2
- data/init.rb +1 -1
- data/lib/{locale_app → localeapp}/api_call.rb +2 -2
- data/lib/{locale_app → localeapp}/api_caller.rb +8 -8
- data/lib/{locale_app → localeapp}/cli/install.rb +7 -7
- data/lib/{locale_app → localeapp}/cli/pull.rb +5 -5
- data/lib/{locale_app → localeapp}/cli/push.rb +3 -3
- data/lib/{locale_app → localeapp}/cli/update.rb +3 -3
- data/lib/{locale_app → localeapp}/configuration.rb +7 -7
- data/lib/localeapp/exception_handler.rb +21 -0
- data/lib/{locale_app → localeapp}/key_checker.rb +6 -6
- data/lib/{locale_app → localeapp}/missing_translations.rb +1 -1
- data/lib/{locale_app → localeapp}/poller.rb +7 -7
- data/lib/{locale_app → localeapp}/rails/2_3_translation_helper_monkeypatch.rb +2 -2
- data/lib/localeapp/rails/controller.rb +34 -0
- data/lib/{locale_app → localeapp}/rails/flatten.rb +0 -0
- data/lib/{locale_app → localeapp}/rails.rb +11 -11
- data/lib/{locale_app → localeapp}/routes.rb +5 -5
- data/lib/{locale_app → localeapp}/sender.rb +8 -8
- data/lib/{locale_app/tasks/locale_app.rake → localeapp/tasks/localeapp.rake} +2 -2
- data/lib/{locale_app → localeapp}/updater.rb +2 -2
- data/lib/localeapp/version.rb +3 -0
- data/lib/localeapp.rb +98 -1
- data/localeapp.gemspec +2 -2
- data/run_ci +1 -1
- data/spec/{locale_app → localeapp}/api_call_spec.rb +3 -3
- data/spec/{locale_app → localeapp}/api_caller_spec.rb +4 -4
- data/spec/{locale_app → localeapp}/cli/install_spec.rb +3 -3
- data/spec/{locale_app → localeapp}/cli/pull_spec.rb +9 -9
- data/spec/{locale_app → localeapp}/cli/push_spec.rb +2 -2
- data/spec/localeapp/cli/update_spec.rb +18 -0
- data/spec/{locale_app → localeapp}/configuration_spec.rb +6 -6
- data/spec/{locale_app → localeapp}/exception_handler_spec.rb +6 -6
- data/spec/{locale_app → localeapp}/key_checker_spec.rb +3 -3
- data/spec/{locale_app → localeapp}/missing_translations_spec.rb +5 -5
- data/spec/{locale_app → localeapp}/poller_spec.rb +5 -5
- data/spec/{locale_app → localeapp}/rails/controller_spec.rb +28 -28
- data/spec/{locale_app → localeapp}/routes_spec.rb +2 -2
- data/spec/{locale_app → localeapp}/sender_spec.rb +6 -6
- data/spec/{locale_app → localeapp}/updater_spec.rb +2 -2
- data/spec/spec_helper.rb +7 -7
- data/spec/support/{locale_app_integration_data.rb → localeapp_integration_data.rb} +1 -1
- data/spec/support/{locale_app_synchronization_data.rb → localeapp_synchronization_data.rb} +1 -1
- metadata +57 -58
- data/lib/locale_app/exception_handler.rb +0 -21
- data/lib/locale_app/rails/controller.rb +0 -34
- data/lib/locale_app/version.rb +0 -3
- data/lib/locale_app.rb +0 -98
- data/spec/locale_app/cli/update_spec.rb +0 -18
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Localeapp::Sender, "#post_translation(locale, key, options, value = nil)" do
|
4
4
|
before(:each) do
|
5
5
|
with_configuration(:api_key => "TEST_KEY") do
|
6
|
-
@sender =
|
6
|
+
@sender = Localeapp::Sender.new
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -22,10 +22,10 @@ describe LocaleApp::Sender, "#post_translation(locale, key, options, value = nil
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
25
|
+
describe Localeapp::Sender, "#post_missing_translations" do
|
26
26
|
before(:each) do
|
27
27
|
with_configuration(:api_key => 'TEST_KEY') do
|
28
|
-
@sender =
|
28
|
+
@sender = Localeapp::Sender.new
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -34,7 +34,7 @@ describe LocaleApp::Sender, "#post_missing_translations" do
|
|
34
34
|
{ :key => "test.key", :locale => "en" },
|
35
35
|
{ :key => "test.key2", :locale => "en" }
|
36
36
|
]
|
37
|
-
|
37
|
+
Localeapp.missing_translations.should_receive(:to_send).and_return(missing_to_send)
|
38
38
|
data = { :translations => missing_to_send }
|
39
39
|
# have to stub RestClient here as FakeWeb doesn't support looking at the post body yet
|
40
40
|
RestClient.should_receive(:post).with(@sender.missing_translations_url, data.to_json, :content_type => :json).and_return(double('response', :code => 200))
|
@@ -42,7 +42,7 @@ describe LocaleApp::Sender, "#post_missing_translations" do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "does nothing if there are no missing translations to send" do
|
45
|
-
|
45
|
+
Localeapp.missing_translations.should_receive(:to_send).and_return([])
|
46
46
|
RestClient.should_not_receive(:post)
|
47
47
|
@sender.post_missing_translations
|
48
48
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Localeapp::Updater, ".update(data)" do
|
4
4
|
before(:each) do
|
5
5
|
@yml_dir = Dir.mktmpdir
|
6
6
|
Dir.glob(File.join(File.dirname(__FILE__), '..', 'fixtures', '*.yml')).each { |f| FileUtils.cp f, @yml_dir }
|
7
7
|
with_configuration(:translation_data_directory => @yml_dir) do
|
8
|
-
@updater =
|
8
|
+
@updater = Localeapp::Updater.new
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'i18n'
|
2
|
-
require '
|
2
|
+
require 'localeapp'
|
3
3
|
require 'fakeweb'
|
4
|
-
require 'support/
|
5
|
-
require 'support/
|
4
|
+
require 'support/localeapp_integration_data'
|
5
|
+
require 'support/localeapp_synchronization_data'
|
6
6
|
require 'logger'
|
7
7
|
|
8
8
|
def with_configuration(options = {})
|
9
|
-
|
10
|
-
|
9
|
+
Localeapp.configuration = nil
|
10
|
+
Localeapp.configure do |configuration|
|
11
11
|
options.each do |option, value|
|
12
12
|
configuration.send("#{option}=", value)
|
13
13
|
end
|
@@ -16,8 +16,8 @@ def with_configuration(options = {})
|
|
16
16
|
end
|
17
17
|
|
18
18
|
RSpec.configure do |config|
|
19
|
-
config.include(
|
20
|
-
config.include(
|
19
|
+
config.include(LocaleappIntegrationData)
|
20
|
+
config.include(LocaleappSynchronizationData)
|
21
21
|
config.before(:each) do
|
22
22
|
FakeWeb.allow_net_connect = false
|
23
23
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# This module is the source for all data that simulates what the real app would return.
|
2
2
|
# It's included in the specs and cucumber tests, so if our format changes we
|
3
3
|
# should only have to change here
|
4
|
-
module
|
4
|
+
module LocaleappIntegrationData
|
5
5
|
def valid_project_data
|
6
6
|
{
|
7
7
|
'name' => "Test Project",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localeapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Christopher Dell
|
@@ -196,50 +196,49 @@ files:
|
|
196
196
|
- features/support/env.rb
|
197
197
|
- features/support/hooks.rb
|
198
198
|
- init.rb
|
199
|
-
- lib/locale_app.rb
|
200
|
-
- lib/locale_app/api_call.rb
|
201
|
-
- lib/locale_app/api_caller.rb
|
202
|
-
- lib/locale_app/cli/install.rb
|
203
|
-
- lib/locale_app/cli/pull.rb
|
204
|
-
- lib/locale_app/cli/push.rb
|
205
|
-
- lib/locale_app/cli/update.rb
|
206
|
-
- lib/locale_app/configuration.rb
|
207
|
-
- lib/locale_app/exception_handler.rb
|
208
|
-
- lib/locale_app/key_checker.rb
|
209
|
-
- lib/locale_app/missing_translations.rb
|
210
|
-
- lib/locale_app/poller.rb
|
211
|
-
- lib/locale_app/rails.rb
|
212
|
-
- lib/locale_app/rails/2_3_translation_helper_monkeypatch.rb
|
213
|
-
- lib/locale_app/rails/controller.rb
|
214
|
-
- lib/locale_app/rails/flatten.rb
|
215
|
-
- lib/locale_app/routes.rb
|
216
|
-
- lib/locale_app/sender.rb
|
217
|
-
- lib/locale_app/tasks/locale_app.rake
|
218
|
-
- lib/locale_app/updater.rb
|
219
|
-
- lib/locale_app/version.rb
|
220
199
|
- lib/localeapp.rb
|
200
|
+
- lib/localeapp/api_call.rb
|
201
|
+
- lib/localeapp/api_caller.rb
|
202
|
+
- lib/localeapp/cli/install.rb
|
203
|
+
- lib/localeapp/cli/pull.rb
|
204
|
+
- lib/localeapp/cli/push.rb
|
205
|
+
- lib/localeapp/cli/update.rb
|
206
|
+
- lib/localeapp/configuration.rb
|
207
|
+
- lib/localeapp/exception_handler.rb
|
208
|
+
- lib/localeapp/key_checker.rb
|
209
|
+
- lib/localeapp/missing_translations.rb
|
210
|
+
- lib/localeapp/poller.rb
|
211
|
+
- lib/localeapp/rails.rb
|
212
|
+
- lib/localeapp/rails/2_3_translation_helper_monkeypatch.rb
|
213
|
+
- lib/localeapp/rails/controller.rb
|
214
|
+
- lib/localeapp/rails/flatten.rb
|
215
|
+
- lib/localeapp/routes.rb
|
216
|
+
- lib/localeapp/sender.rb
|
217
|
+
- lib/localeapp/tasks/localeapp.rake
|
218
|
+
- lib/localeapp/updater.rb
|
219
|
+
- lib/localeapp/version.rb
|
221
220
|
- localeapp.gemspec
|
222
221
|
- run_ci
|
223
222
|
- spec/fixtures/en.yml
|
224
223
|
- spec/fixtures/es.yml
|
225
|
-
- spec/
|
226
|
-
- spec/
|
227
|
-
- spec/
|
228
|
-
- spec/
|
229
|
-
- spec/
|
230
|
-
- spec/
|
231
|
-
- spec/
|
232
|
-
- spec/
|
233
|
-
- spec/
|
234
|
-
- spec/
|
235
|
-
- spec/
|
236
|
-
- spec/
|
237
|
-
- spec/
|
238
|
-
- spec/
|
239
|
-
- spec/
|
224
|
+
- spec/localeapp/api_call_spec.rb
|
225
|
+
- spec/localeapp/api_caller_spec.rb
|
226
|
+
- spec/localeapp/cli/install_spec.rb
|
227
|
+
- spec/localeapp/cli/pull_spec.rb
|
228
|
+
- spec/localeapp/cli/push_spec.rb
|
229
|
+
- spec/localeapp/cli/update_spec.rb
|
230
|
+
- spec/localeapp/configuration_spec.rb
|
231
|
+
- spec/localeapp/exception_handler_spec.rb
|
232
|
+
- spec/localeapp/key_checker_spec.rb
|
233
|
+
- spec/localeapp/missing_translations_spec.rb
|
234
|
+
- spec/localeapp/poller_spec.rb
|
235
|
+
- spec/localeapp/rails/controller_spec.rb
|
236
|
+
- spec/localeapp/routes_spec.rb
|
237
|
+
- spec/localeapp/sender_spec.rb
|
238
|
+
- spec/localeapp/updater_spec.rb
|
240
239
|
- spec/spec_helper.rb
|
241
|
-
- spec/support/
|
242
|
-
- spec/support/
|
240
|
+
- spec/support/localeapp_integration_data.rb
|
241
|
+
- spec/support/localeapp_synchronization_data.rb
|
243
242
|
homepage: http://rubygems.org/gems/localeapp
|
244
243
|
licenses: []
|
245
244
|
|
@@ -280,21 +279,21 @@ test_files:
|
|
280
279
|
- features/support/hooks.rb
|
281
280
|
- spec/fixtures/en.yml
|
282
281
|
- spec/fixtures/es.yml
|
283
|
-
- spec/
|
284
|
-
- spec/
|
285
|
-
- spec/
|
286
|
-
- spec/
|
287
|
-
- spec/
|
288
|
-
- spec/
|
289
|
-
- spec/
|
290
|
-
- spec/
|
291
|
-
- spec/
|
292
|
-
- spec/
|
293
|
-
- spec/
|
294
|
-
- spec/
|
295
|
-
- spec/
|
296
|
-
- spec/
|
297
|
-
- spec/
|
282
|
+
- spec/localeapp/api_call_spec.rb
|
283
|
+
- spec/localeapp/api_caller_spec.rb
|
284
|
+
- spec/localeapp/cli/install_spec.rb
|
285
|
+
- spec/localeapp/cli/pull_spec.rb
|
286
|
+
- spec/localeapp/cli/push_spec.rb
|
287
|
+
- spec/localeapp/cli/update_spec.rb
|
288
|
+
- spec/localeapp/configuration_spec.rb
|
289
|
+
- spec/localeapp/exception_handler_spec.rb
|
290
|
+
- spec/localeapp/key_checker_spec.rb
|
291
|
+
- spec/localeapp/missing_translations_spec.rb
|
292
|
+
- spec/localeapp/poller_spec.rb
|
293
|
+
- spec/localeapp/rails/controller_spec.rb
|
294
|
+
- spec/localeapp/routes_spec.rb
|
295
|
+
- spec/localeapp/sender_spec.rb
|
296
|
+
- spec/localeapp/updater_spec.rb
|
298
297
|
- spec/spec_helper.rb
|
299
|
-
- spec/support/
|
300
|
-
- spec/support/
|
298
|
+
- spec/support/localeapp_integration_data.rb
|
299
|
+
- spec/support/localeapp_synchronization_data.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module LocaleApp
|
2
|
-
class ExceptionHandler
|
3
|
-
def self.call(exception, locale, key, options)
|
4
|
-
LocaleApp.log(exception.message)
|
5
|
-
if I18n::MissingTranslationData === exception
|
6
|
-
LocaleApp.log("Detected missing translation for key(s) #{key.inspect}")
|
7
|
-
|
8
|
-
[*key].each do |key|
|
9
|
-
LocaleApp.missing_translations.add(locale, key, options)
|
10
|
-
end
|
11
|
-
|
12
|
-
[locale, key].join(', ')
|
13
|
-
else
|
14
|
-
LocaleApp.log('Raising exception')
|
15
|
-
raise
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
I18n.exception_handler = LocaleApp::ExceptionHandler
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module LocaleApp
|
2
|
-
module Rails
|
3
|
-
module Controller
|
4
|
-
def self.included(base)
|
5
|
-
base.before_filter :handle_translation_updates
|
6
|
-
base.after_filter :send_missing_translations
|
7
|
-
end
|
8
|
-
|
9
|
-
def handle_translation_updates
|
10
|
-
unless ::LocaleApp.configuration.polling_disabled?
|
11
|
-
::LocaleApp.log Time.now.to_i.to_s << '-- Handling translation updates'
|
12
|
-
if ::LocaleApp.poller.needs_polling?
|
13
|
-
::LocaleApp.log Time.now.to_i.to_s << ' - polling'
|
14
|
-
::LocaleApp.poller.poll!
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
unless ::LocaleApp.configuration.reloading_disabled?
|
19
|
-
if ::LocaleApp.poller.needs_reloading?
|
20
|
-
::LocaleApp.log Time.now.to_i.to_s << '- reloading I18n'
|
21
|
-
I18n.reload!
|
22
|
-
::LocaleApp.poller.updated_at = ::LocaleApp.poller.synchronization_data[:updated_at]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def send_missing_translations
|
28
|
-
return if ::LocaleApp.configuration.sending_disabled?
|
29
|
-
|
30
|
-
::LocaleApp.sender.post_missing_translations
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/lib/locale_app/version.rb
DELETED
data/lib/locale_app.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
# AUDIT: Find a better way of doing this
|
2
|
-
begin
|
3
|
-
require 'i18n'
|
4
|
-
rescue LoadError
|
5
|
-
# we're in 2.3 and we need to load rails to get the vendored i18n
|
6
|
-
require 'thread' # for rubygems > 1.6.0 support
|
7
|
-
require 'active_support'
|
8
|
-
end
|
9
|
-
|
10
|
-
begin
|
11
|
-
require 'i18n/core_ext/hash'
|
12
|
-
rescue LoadError
|
13
|
-
# Assume that we're in rails 2.3 and AS supplies deep_merge
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
require 'locale_app/version'
|
18
|
-
require 'locale_app/configuration'
|
19
|
-
require 'locale_app/routes'
|
20
|
-
require 'locale_app/api_call'
|
21
|
-
require 'locale_app/api_caller'
|
22
|
-
require 'locale_app/sender'
|
23
|
-
require 'locale_app/poller'
|
24
|
-
require 'locale_app/updater'
|
25
|
-
require 'locale_app/key_checker'
|
26
|
-
require 'locale_app/missing_translations'
|
27
|
-
|
28
|
-
require 'locale_app/cli/install'
|
29
|
-
require 'locale_app/cli/pull'
|
30
|
-
require 'locale_app/cli/push'
|
31
|
-
require 'locale_app/cli/update'
|
32
|
-
|
33
|
-
# AUDIT: Will this work on ruby 1.9.x
|
34
|
-
$KCODE="UTF8" if RUBY_VERSION < '1.9'
|
35
|
-
|
36
|
-
require 'ya2yaml'
|
37
|
-
|
38
|
-
module LocaleApp
|
39
|
-
API_VERSION = "1"
|
40
|
-
LOG_PREFIX = "** [LocaleApp] "
|
41
|
-
|
42
|
-
class << self
|
43
|
-
# An LocaleApp configuration object.
|
44
|
-
attr_accessor :configuration
|
45
|
-
|
46
|
-
# The sender object is responsible for delivering formatted data to the LocaleApp server.
|
47
|
-
attr_accessor :sender
|
48
|
-
|
49
|
-
# The poller object is responsible for retrieving data for the LocaleApp server
|
50
|
-
attr_accessor :poller
|
51
|
-
|
52
|
-
# The updater object is responsible for merging translations into the i18n backend
|
53
|
-
attr_accessor :updater
|
54
|
-
|
55
|
-
# The missing_translations object is responsible for keeping track of missing translations
|
56
|
-
# that will be sent to the backend
|
57
|
-
attr_reader :missing_translations
|
58
|
-
|
59
|
-
|
60
|
-
# Writes out the given message to the #logger
|
61
|
-
def log(message)
|
62
|
-
logger.info LOG_PREFIX + message if logger
|
63
|
-
end
|
64
|
-
|
65
|
-
def debug(message)
|
66
|
-
logger.debug(LOG_PREFIX + message) if logger
|
67
|
-
end
|
68
|
-
|
69
|
-
# Look for the Rails logger currently defined
|
70
|
-
def logger
|
71
|
-
self.configuration && self.configuration.logger
|
72
|
-
end
|
73
|
-
|
74
|
-
# @example Configuration
|
75
|
-
# LocaleApp.configure do |config|
|
76
|
-
# config.api_key = '1234567890abcdef'
|
77
|
-
# end
|
78
|
-
def configure
|
79
|
-
self.configuration ||= Configuration.new
|
80
|
-
yield(configuration)
|
81
|
-
self.sender = Sender.new
|
82
|
-
self.poller = Poller.new
|
83
|
-
self.updater = Updater.new
|
84
|
-
@missing_translations = MissingTranslations.new
|
85
|
-
end
|
86
|
-
|
87
|
-
# requires the LocaleApp configuration
|
88
|
-
def include_config_file(file_path=nil)
|
89
|
-
file_path ||= File.join(Dir.pwd, 'config', 'initializers', 'locale_app')
|
90
|
-
begin
|
91
|
-
require file_path
|
92
|
-
true
|
93
|
-
rescue
|
94
|
-
false
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'locale_app/cli/update'
|
3
|
-
|
4
|
-
describe LocaleApp::CLI::Update, "#execute" do
|
5
|
-
before do
|
6
|
-
@output = StringIO.new
|
7
|
-
@updater = LocaleApp::CLI::Update.new(@output)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "creates a Poller and calls poll! on it" do
|
11
|
-
with_configuration do
|
12
|
-
poller = LocaleApp::Poller.new
|
13
|
-
poller.should_receive(:poll!)
|
14
|
-
LocaleApp::Poller.should_receive(:new).and_return(poller)
|
15
|
-
@updater.execute
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|