Skip to content

Commit

Permalink
Use I18n module for system messages instead of hard-coded value
Browse files Browse the repository at this point in the history
  • Loading branch information
sh19910711 committed Aug 14, 2015
1 parent ad17a5a commit fb55d48
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/web_console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'active_support/lazy_load_hooks'
require 'active_support/logger'

require 'web_console/locale'
require 'web_console/integration'
require 'web_console/railtie'
require 'web_console/errors'
Expand Down
15 changes: 15 additions & 0 deletions lib/web_console/config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
en:
errors:
unavailable_session: |
Session %{id} is is no longer available in memory.
If you happen to run on a multi-process server (like Unicorn or Puma) the process
this request hit doesn't store %{id} in memory. Consider turning the number of
processes/workers to one (1) or using a different server in development.
unacceptable_request: |
A supported version is expected in the Accept header.
connection_refused: |
Oops! Failed to connect to the Web Console middleware.
Please make sure a rails development server is running.
2 changes: 2 additions & 0 deletions lib/web_console/locale.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'active_support/core_ext/string/access'
I18n.load_path += Dir[ File.expand_path('../config/locales/*.yml', __FILE__) ]
14 changes: 2 additions & 12 deletions lib/web_console/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ module WebConsole
class Middleware
TEMPLATES_PATH = File.expand_path('../templates', __FILE__)

UNAVAILABLE_SESSION_MESSAGE = <<-END.strip_heredoc
Session %{id} is is no longer available in memory.
If you happen to run on a multi-process server (like Unicorn or Puma) the process
this request hit doesn't store %{id} in memory. Consider turning the number of
processes/workers to one (1) or using a different server in development.
END

UNACCEPTABLE_REQUEST_MESSAGE = "A supported version is expected in the Accept header."

cattr_accessor :mount_point
@@mount_point = '/__web_console'

Expand Down Expand Up @@ -115,13 +105,13 @@ def change_stack_trace(id, request)

def respond_with_unavailable_session(id)
json_response(status: 404) do
{ output: format(UNAVAILABLE_SESSION_MESSAGE, id: id)}
{ output: format(I18n.t('errors.unavailable_session'), id: id)}
end
end

def respond_with_unacceptable_request
json_response(status: 406) do
{ error: UNACCEPTABLE_REQUEST_MESSAGE }
{ output: I18n.t('errors.unacceptable_request') }
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/web_console/testing/fake_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'web_console/whitelist'
require 'web_console/request'
require 'web_console/view'
require 'web_console/locale'

module WebConsole
module Testing
Expand Down

0 comments on commit fb55d48

Please sign in to comment.