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
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm ruby-1.9.2@
|
1
|
+
rvm ruby-1.9.2@localeapp
|
data/bin/localeapp
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
3
3
|
|
4
|
-
require '
|
4
|
+
require 'localeapp'
|
5
5
|
|
6
6
|
# Don't connect to the net if we're running under cucumber for testing
|
7
7
|
# Use FakeWeb to simulate api.localeapp.com
|
@@ -19,7 +19,7 @@ args = ARGV.dup
|
|
19
19
|
command = args.shift.strip rescue nil
|
20
20
|
|
21
21
|
unless %w{help install}.include?(command)
|
22
|
-
unless
|
22
|
+
unless Localeapp.include_config_file
|
23
23
|
puts "Could not load config file"
|
24
24
|
exit
|
25
25
|
end
|
@@ -28,23 +28,23 @@ end
|
|
28
28
|
case command
|
29
29
|
when 'install'
|
30
30
|
key = args.shift.strip rescue nil
|
31
|
-
installer =
|
31
|
+
installer = Localeapp::CLI::Install.new
|
32
32
|
if installer.execute(key)
|
33
33
|
exit 0
|
34
34
|
else
|
35
35
|
exit 1
|
36
36
|
end
|
37
37
|
when 'pull'
|
38
|
-
|
38
|
+
Localeapp::CLI::Pull.new.execute
|
39
39
|
when 'push'
|
40
40
|
file = args.shift.strip rescue nil
|
41
|
-
pusher =
|
41
|
+
pusher = Localeapp::CLI::Push.new
|
42
42
|
pusher.execute(file)
|
43
43
|
when 'update'
|
44
|
-
|
44
|
+
Localeapp::CLI::Update.new.execute
|
45
45
|
when 'daemon'
|
46
46
|
while true do
|
47
|
-
|
47
|
+
Localeapp::CLI::Update.new.execute
|
48
48
|
sleep 5
|
49
49
|
end
|
50
50
|
else
|
@@ -53,8 +53,8 @@ Usage: localeapp COMMAND [ARGS]
|
|
53
53
|
|
54
54
|
Commands:
|
55
55
|
install <api_key> - Creates new configuration files and confirms key works
|
56
|
-
pull - Pulls all translations from
|
57
|
-
push <file> - Pushes a translation file to
|
56
|
+
pull - Pulls all translations from localeapp.com
|
57
|
+
push <file> - Pushes a translation file to localeapp.com
|
58
58
|
update - Gets any changes since the last poll and updates the yml files
|
59
59
|
daemon - Simple daemon that checks every 5 seconds for new translations
|
60
60
|
HELP
|
@@ -9,7 +9,7 @@ Feature: localeapp executable
|
|
9
9
|
|
10
10
|
Commands:
|
11
11
|
install <api_key> - Creates new configuration files and confirms key works
|
12
|
-
pull - Pulls all translations from
|
12
|
+
pull - Pulls all translations from localeapp.com
|
13
13
|
"""
|
14
14
|
|
15
15
|
Scenario: Running install
|
@@ -18,7 +18,7 @@ Feature: localeapp executable
|
|
18
18
|
And I run `localeapp install MYAPIKEY`
|
19
19
|
Then the output should contain:
|
20
20
|
"""
|
21
|
-
|
21
|
+
Localeapp Install
|
22
22
|
|
23
23
|
Checking API key: MYAPIKEY
|
24
24
|
Success!
|
@@ -34,21 +34,21 @@ Feature: localeapp executable
|
|
34
34
|
And I run `localeapp install BADAPIKEY`
|
35
35
|
Then the output should contain:
|
36
36
|
"""
|
37
|
-
|
37
|
+
Localeapp Install
|
38
38
|
|
39
39
|
Checking API key: BADAPIKEY
|
40
40
|
ERROR: Project not found
|
41
41
|
"""
|
42
|
-
And a file named "config/initializers/
|
42
|
+
And a file named "config/initializers/localeapp.rb" should not exist
|
43
43
|
And the exit status should not be 0
|
44
44
|
|
45
45
|
Scenario: Running pull
|
46
46
|
In order to retreive my translations
|
47
47
|
Given I have a translations on localeapp.com for the project with api key "MYAPIKEY"
|
48
|
-
And a file named "config/initializers/
|
48
|
+
And a file named "config/initializers/localeapp.rb" with:
|
49
49
|
"""
|
50
|
-
require '
|
51
|
-
|
50
|
+
require 'localeapp/rails'
|
51
|
+
Localeapp.configure do |config|
|
52
52
|
config.api_key = 'MYAPIKEY'
|
53
53
|
end
|
54
54
|
"""
|
@@ -56,7 +56,7 @@ Feature: localeapp executable
|
|
56
56
|
When I run `localeapp pull`
|
57
57
|
Then the output should contain:
|
58
58
|
"""
|
59
|
-
|
59
|
+
Localeapp Pull
|
60
60
|
|
61
61
|
Fetching translations:
|
62
62
|
Success!
|
@@ -68,10 +68,10 @@ Feature: localeapp executable
|
|
68
68
|
Scenario: Running push
|
69
69
|
In order to send my translations
|
70
70
|
When I have a valid project on localeapp.com with api key "MYAPIKEY"
|
71
|
-
And a file named "config/initializers/
|
71
|
+
And a file named "config/initializers/localeapp.rb" with:
|
72
72
|
"""
|
73
|
-
require '
|
74
|
-
|
73
|
+
require 'localeapp/rails'
|
74
|
+
Localeapp.configure do |config|
|
75
75
|
config.api_key = 'MYAPIKEY'
|
76
76
|
end
|
77
77
|
"""
|
@@ -79,7 +79,7 @@ Feature: localeapp executable
|
|
79
79
|
When I run `localeapp push config/locales/en.yml`
|
80
80
|
Then the output should contain:
|
81
81
|
"""
|
82
|
-
|
82
|
+
Localeapp Push
|
83
83
|
|
84
84
|
Pushing file:
|
85
85
|
Success!
|
@@ -90,14 +90,14 @@ Feature: localeapp executable
|
|
90
90
|
Scenario: Running update
|
91
91
|
In order to receive the translations that have been updated since the last check
|
92
92
|
When I have a valid project on localeapp.com with api key "MYAPIKEY"
|
93
|
-
And a file named "config/initializers/
|
93
|
+
And a file named "config/initializers/localeapp.rb" with:
|
94
94
|
"""
|
95
|
-
require '
|
96
|
-
|
95
|
+
require 'localeapp/rails'
|
96
|
+
Localeapp.configure do |config|
|
97
97
|
config.api_key = 'MYAPIKEY'
|
98
98
|
end
|
99
99
|
"""
|
100
|
-
And a file named "log/
|
100
|
+
And a file named "log/localeapp.yml" with:
|
101
101
|
"""
|
102
102
|
---
|
103
103
|
:updated_at: 120
|
@@ -108,7 +108,7 @@ Feature: localeapp executable
|
|
108
108
|
When I run `localeapp update`
|
109
109
|
Then the output should contain:
|
110
110
|
"""
|
111
|
-
|
111
|
+
Localeapp update: checking for translations since 120
|
112
112
|
Found and updated new translations
|
113
113
|
"""
|
114
114
|
And a file named "config/locales/en.yml" should exist
|
data/features/support/env.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'aruba/cucumber'
|
2
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../../spec/support/
|
3
|
-
World(
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../../spec/support/localeapp_integration_data'))
|
3
|
+
World(LocaleappIntegrationData)
|
4
4
|
|
5
5
|
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
6
6
|
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require '
|
1
|
+
require 'localeapp'
|
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module Localeapp
|
2
2
|
module ApiCall
|
3
3
|
# creates an object to perform the call
|
4
4
|
def api_call(endpoint, options = {})
|
5
|
-
api_caller =
|
5
|
+
api_caller = Localeapp::ApiCaller.new(endpoint, options)
|
6
6
|
api_caller.call(self)
|
7
7
|
end
|
8
8
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module
|
1
|
+
module Localeapp
|
2
2
|
class ApiCaller
|
3
|
-
include ::
|
3
|
+
include ::Localeapp::Routes
|
4
4
|
|
5
5
|
NonHTTPResponse = Struct.new(:code)
|
6
6
|
|
@@ -20,16 +20,16 @@ module LocaleApp
|
|
20
20
|
|
21
21
|
def call(obj)
|
22
22
|
method, url = send("#{endpoint}_endpoint", options[:url_options] || {})
|
23
|
-
|
23
|
+
Localeapp.debug("API CALL: #{method} #{url}")
|
24
24
|
success = false
|
25
25
|
while connection_attempts < max_connection_attempts
|
26
26
|
sleep_if_retrying
|
27
27
|
response = make_call(method, url)
|
28
|
-
|
28
|
+
Localeapp.debug("RESPONSE: #{response.code}")
|
29
29
|
valid_response_codes = (200..207).to_a
|
30
30
|
if valid_response_codes.include?(response.code.to_i)
|
31
31
|
if options[:success]
|
32
|
-
|
32
|
+
Localeapp.debug("CALLING SUCCESS HANDLER: #{options[:success]}")
|
33
33
|
obj.send(options[:success], response)
|
34
34
|
end
|
35
35
|
success = true
|
@@ -46,7 +46,7 @@ module LocaleApp
|
|
46
46
|
def make_call(method, url)
|
47
47
|
begin
|
48
48
|
@connection_attempts += 1
|
49
|
-
|
49
|
+
Localeapp.debug("ATTEMPT #{@connection_attempts}")
|
50
50
|
request_options = options[:request_options] || {}
|
51
51
|
if method == :post
|
52
52
|
RestClient.send(method, url, options[:payload], request_options)
|
@@ -61,7 +61,7 @@ module LocaleApp
|
|
61
61
|
RestClient::GatewayTimeout => error
|
62
62
|
return error.response
|
63
63
|
rescue Errno::ECONNREFUSED => error
|
64
|
-
|
64
|
+
Localeapp.debug("ERROR: Connection Refused")
|
65
65
|
return NonHTTPResponse.new(-1)
|
66
66
|
end
|
67
67
|
end
|
@@ -69,7 +69,7 @@ module LocaleApp
|
|
69
69
|
def sleep_if_retrying
|
70
70
|
if @connection_attempts > 0
|
71
71
|
time = @connection_attempts * 5
|
72
|
-
|
72
|
+
Localeapp.debug("Sleeping for #{time} before retrying")
|
73
73
|
sleep time
|
74
74
|
end
|
75
75
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module Localeapp
|
2
2
|
module CLI
|
3
3
|
class Install
|
4
4
|
def execute(key, output = $stdout)
|
5
|
-
output.puts "
|
5
|
+
output.puts "Localeapp Install"
|
6
6
|
output.puts ""
|
7
7
|
output.puts "Checking API key: #{key}"
|
8
8
|
if key.nil?
|
@@ -13,9 +13,9 @@ module LocaleApp
|
|
13
13
|
if valid_key
|
14
14
|
output.puts "Success!"
|
15
15
|
output.puts "Project: #{project_data['name']}"
|
16
|
-
|
17
|
-
output.puts "Default Locale: #{
|
18
|
-
if I18n.default_locale.to_s !=
|
16
|
+
localeapp_default_code = project_data['default_locale']['code']
|
17
|
+
output.puts "Default Locale: #{localeapp_default_code} (#{project_data['default_locale']['name']})"
|
18
|
+
if I18n.default_locale.to_s != localeapp_default_code
|
19
19
|
output.puts "WARNING: I18n.default_locale is #{I18n.default_locale}, change in config/environment.rb (Rails 2) or config/application.rb (Rails 3)"
|
20
20
|
end
|
21
21
|
config_file_path = "config/initializers/localeapp.rb"
|
@@ -30,11 +30,11 @@ module LocaleApp
|
|
30
30
|
|
31
31
|
private
|
32
32
|
def check_key(key)
|
33
|
-
|
33
|
+
Localeapp::KeyChecker.new.check(key)
|
34
34
|
end
|
35
35
|
|
36
36
|
def write_configuration_file(path)
|
37
|
-
|
37
|
+
Localeapp.configuration.write_initial(path)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
module
|
1
|
+
module Localeapp
|
2
2
|
module CLI
|
3
3
|
class Pull
|
4
|
-
include ::
|
4
|
+
include ::Localeapp::ApiCall
|
5
5
|
|
6
6
|
def initialize(output = $stdout)
|
7
7
|
@output = output
|
8
8
|
end
|
9
9
|
|
10
10
|
def execute
|
11
|
-
@output.puts "
|
11
|
+
@output.puts "Localeapp Pull"
|
12
12
|
@output.puts ""
|
13
13
|
|
14
14
|
@output.puts "Fetching translations:"
|
@@ -21,9 +21,9 @@ module LocaleApp
|
|
21
21
|
def update_backend(response)
|
22
22
|
@output.puts "Success!"
|
23
23
|
@output.puts "Updating backend:"
|
24
|
-
|
24
|
+
Localeapp.updater.update(JSON.parse(response))
|
25
25
|
@output.puts "Success!"
|
26
|
-
|
26
|
+
Localeapp.poller.write_synchronization_data!(Time.now.to_i, Time.now.to_i)
|
27
27
|
end
|
28
28
|
|
29
29
|
def report_failure(response)
|
@@ -1,14 +1,14 @@
|
|
1
|
-
module
|
1
|
+
module Localeapp
|
2
2
|
module CLI
|
3
3
|
class Push
|
4
|
-
include ::
|
4
|
+
include ::Localeapp::ApiCall
|
5
5
|
|
6
6
|
def initialize(output = $stdout)
|
7
7
|
@output = output
|
8
8
|
end
|
9
9
|
|
10
10
|
def execute(file_path = nil)
|
11
|
-
@output.puts "
|
11
|
+
@output.puts "Localeapp Push"
|
12
12
|
@output.puts ""
|
13
13
|
|
14
14
|
@file_path = file_path
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Localeapp
|
2
2
|
module CLI
|
3
3
|
class Update
|
4
4
|
def initialize(output = $stdout)
|
@@ -6,8 +6,8 @@ module LocaleApp
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def execute
|
9
|
-
poller =
|
10
|
-
@output.puts("
|
9
|
+
poller = Localeapp::Poller.new
|
10
|
+
@output.puts("Localeapp update: checking for translations since #{poller.updated_at}")
|
11
11
|
if poller.poll!
|
12
12
|
@output.puts "Found and updated new translations"
|
13
13
|
else
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Localeapp
|
2
2
|
class Configuration
|
3
3
|
|
4
4
|
# The API key for your project, found on the project edit form
|
@@ -32,7 +32,7 @@ module LocaleApp
|
|
32
32
|
# 'test', 'cucumber', 'production')
|
33
33
|
attr_accessor :disabled_polling_environments
|
34
34
|
|
35
|
-
# The logger used by
|
35
|
+
# The logger used by Localeapp
|
36
36
|
attr_accessor :logger
|
37
37
|
|
38
38
|
# The number of seconds to wait before asking the service for new
|
@@ -40,8 +40,8 @@ module LocaleApp
|
|
40
40
|
attr_accessor :poll_interval
|
41
41
|
|
42
42
|
# The complete path to the data file where we store synchronization
|
43
|
-
# information (defaults to ./
|
44
|
-
# this to RAILS_ROOT/log/
|
43
|
+
# information (defaults to ./localeapp.yml) local_app/rails overwrites
|
44
|
+
# this to RAILS_ROOT/log/localeapp.yml
|
45
45
|
attr_accessor :synchronization_data_file
|
46
46
|
|
47
47
|
# The complete path to the directory where translations are stored
|
@@ -54,7 +54,7 @@ module LocaleApp
|
|
54
54
|
@disabled_reloading_environments = %w(test cucumber production)
|
55
55
|
@disabled_polling_environments = %w(test cucumber production)
|
56
56
|
@poll_interval = 0
|
57
|
-
@synchronization_data_file = File.join('log', '
|
57
|
+
@synchronization_data_file = File.join('log', 'localeapp.yml')
|
58
58
|
@translation_data_directory = File.join('config', 'locales')
|
59
59
|
if ENV['DEBUG']
|
60
60
|
require 'logger'
|
@@ -79,9 +79,9 @@ module LocaleApp
|
|
79
79
|
FileUtils.mkdir_p(dir)
|
80
80
|
File.open(path, 'w+') do |file|
|
81
81
|
file.write <<-CONTENT
|
82
|
-
require '
|
82
|
+
require 'localeapp/rails'
|
83
83
|
|
84
|
-
|
84
|
+
Localeapp.configure do |config|
|
85
85
|
config.api_key = '#{@api_key}'
|
86
86
|
config.host = '#{@host}'
|
87
87
|
config.port = #{@port}
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -2,16 +2,16 @@ require 'yaml'
|
|
2
2
|
require 'rest-client'
|
3
3
|
require 'time'
|
4
4
|
|
5
|
-
module
|
5
|
+
module Localeapp
|
6
6
|
class KeyChecker
|
7
|
-
include ::
|
7
|
+
include ::Localeapp::ApiCall
|
8
8
|
|
9
9
|
def check(key)
|
10
|
-
if
|
11
|
-
|
12
|
-
|
10
|
+
if Localeapp.configuration.nil? # no config file yet
|
11
|
+
Localeapp.configuration = Localeapp::Configuration.new
|
12
|
+
Localeapp.configuration.host = ENV['LA_TEST_HOST'] if ENV['LA_TEST_HOST']
|
13
13
|
end
|
14
|
-
|
14
|
+
Localeapp.configuration.api_key = key
|
15
15
|
api_call :project,
|
16
16
|
:success => :handle_success,
|
17
17
|
:failure => :handle_failure,
|
@@ -2,9 +2,9 @@ require 'yaml'
|
|
2
2
|
require 'rest-client'
|
3
3
|
require 'time'
|
4
4
|
|
5
|
-
module
|
5
|
+
module Localeapp
|
6
6
|
class Poller
|
7
|
-
include ::
|
7
|
+
include ::Localeapp::ApiCall
|
8
8
|
|
9
9
|
# when we last asked the service for updates
|
10
10
|
attr_accessor :polled_at
|
@@ -18,21 +18,21 @@ module LocaleApp
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def synchronization_data
|
21
|
-
if File.exists?(
|
22
|
-
YAML.load_file(
|
21
|
+
if File.exists?(Localeapp.configuration.synchronization_data_file)
|
22
|
+
YAML.load_file(Localeapp.configuration.synchronization_data_file)
|
23
23
|
else
|
24
24
|
{}
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def write_synchronization_data!(polled_at, updated_at)
|
29
|
-
File.open(
|
29
|
+
File.open(Localeapp.configuration.synchronization_data_file, 'w+') do |f|
|
30
30
|
f.write({:polled_at => polled_at, :updated_at => updated_at}.to_yaml)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def needs_polling?
|
35
|
-
synchronization_data[:polled_at] < (Time.now.to_i -
|
35
|
+
synchronization_data[:polled_at] < (Time.now.to_i - Localeapp.configuration.poll_interval)
|
36
36
|
end
|
37
37
|
|
38
38
|
def needs_reloading?
|
@@ -50,7 +50,7 @@ module LocaleApp
|
|
50
50
|
|
51
51
|
def handle_success(response)
|
52
52
|
@success = true
|
53
|
-
|
53
|
+
Localeapp.updater.update(JSON.parse(response))
|
54
54
|
write_synchronization_data!(Time.now.to_i, Time.parse(response.headers[:date]).to_i)
|
55
55
|
end
|
56
56
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# This means the exception handler will be called and missing translations get sent to
|
3
3
|
# localeapp. It's ugly but there's no other way to do it :(
|
4
4
|
|
5
|
-
module
|
5
|
+
module Localeapp::TranslationHelperMonkeyPatch
|
6
6
|
# Delegates to I18n#translate but also performs two additional functions. First, it'll catch MissingTranslationData exceptions
|
7
7
|
# and turn them into inline spans that contains the missing key, such that you can see in a view what is missing where.
|
8
8
|
#
|
@@ -33,4 +33,4 @@ module LocaleApp::TranslationHelperMonkeyPatch
|
|
33
33
|
alias :t :translate
|
34
34
|
end
|
35
35
|
|
36
|
-
ActionView::Base.send(:include, ::
|
36
|
+
ActionView::Base.send(:include, ::Localeapp::TranslationHelperMonkeyPatch)
|
@@ -0,0 +1,34 @@
|
|
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
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Localeapp
|
2
2
|
module Rails
|
3
3
|
def self.initialize
|
4
4
|
if defined?(::Rails.logger)
|
@@ -19,25 +19,25 @@ module LocaleApp
|
|
19
19
|
rails_root = RAILS_ROOT
|
20
20
|
end
|
21
21
|
|
22
|
-
ActionController::Base.send(:include,
|
22
|
+
ActionController::Base.send(:include, Localeapp::Rails::Controller)
|
23
23
|
|
24
24
|
if ::Rails::VERSION::MAJOR == 2 && ::Rails::VERSION::MINOR >= 3 # TODO: Check previous rails versions if required
|
25
|
-
require '
|
25
|
+
require 'localeapp/rails/2_3_translation_helper_monkeypatch'
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
Localeapp.configure do |config|
|
29
29
|
config.logger = rails_logger
|
30
30
|
config.environment_name = rails_env
|
31
31
|
config.project_root = rails_root
|
32
|
-
config.synchronization_data_file = File.join([rails_root, 'log', '
|
32
|
+
config.synchronization_data_file = File.join([rails_root, 'log', 'localeapp.yml'])
|
33
33
|
config.translation_data_directory = File.join([rails_root, 'config', 'locales'])
|
34
34
|
end
|
35
35
|
initialize_synchronization_data_file
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.initialize_synchronization_data_file
|
39
|
-
if !File.exists?(
|
40
|
-
File.open(
|
39
|
+
if !File.exists?(Localeapp.configuration.synchronization_data_file)
|
40
|
+
File.open(Localeapp.configuration.synchronization_data_file, 'w') do |f|
|
41
41
|
f.write({:polled_at => Time.now.to_i, :updated_at => Time.now.to_i}.to_yaml)
|
42
42
|
end
|
43
43
|
end
|
@@ -46,8 +46,8 @@ module LocaleApp
|
|
46
46
|
end
|
47
47
|
|
48
48
|
if defined?(Rails)
|
49
|
-
require '
|
50
|
-
require '
|
51
|
-
|
52
|
-
|
49
|
+
require 'localeapp/rails/controller'
|
50
|
+
require 'localeapp/exception_handler'
|
51
|
+
Localeapp::Rails.initialize
|
52
|
+
Localeapp.log('Loaded localeapp/rails')
|
53
53
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Localeapp
|
2
2
|
module Routes
|
3
3
|
VERSION = 'v1'
|
4
4
|
|
@@ -48,15 +48,15 @@ module LocaleApp
|
|
48
48
|
private
|
49
49
|
|
50
50
|
def base_options
|
51
|
-
options = {:host =>
|
52
|
-
if
|
53
|
-
options[:userinfo] = "#{
|
51
|
+
options = {:host => Localeapp.configuration.host, :port => Localeapp.configuration.port}
|
52
|
+
if Localeapp.configuration.http_auth_username
|
53
|
+
options[:userinfo] = "#{Localeapp.configuration.http_auth_username}:#{Localeapp.configuration.http_auth_password}"
|
54
54
|
end
|
55
55
|
options
|
56
56
|
end
|
57
57
|
|
58
58
|
def project_path(format = nil)
|
59
|
-
path = "/#{VERSION}/projects/#{
|
59
|
+
path = "/#{VERSION}/projects/#{Localeapp.configuration.api_key}"
|
60
60
|
path << ".#{format}" if format
|
61
61
|
path
|
62
62
|
end
|