Permalink
Browse files

Allow dynamic sidekiq-web locale paths, for localized extensions, fixes

  • Loading branch information...
1 parent abed0c9 commit ea42d5636c837870ac33f9859333114a55ea0ee8 @mperham committed Oct 21, 2013
Showing with 46 additions and 8 deletions.
  1. +3 −4 Changes.md
  2. +17 −0 lib/sidekiq/core_ext.rb
  3. +1 −1 lib/sidekiq/web.rb
  4. +7 −2 lib/sidekiq/web_helpers.rb
  5. +2 −0 test/fixtures/en.yml
  6. +16 −0 test/test_web.rb
  7. +0 −1 web/locales/en.yml
View
@@ -1,10 +1,9 @@
-HEAD
------------
-- Capistrano version 3 support [#1254, phallstrom]
-
2.16.0
-----------
+- Allow sidekiq-web extensions to add locale paths so extensions
+ can be localized. [#1261, ondrejbartas]
+- Capistrano 3 support [#1254, phallstrom]
- Use Ruby's `resolv-replace` to enable pure Ruby DNS lookups.
This ensures that any DNS resolution that takes place in worker
threads won't lock up the entire VM on MRI. [#1258]
View
@@ -53,6 +53,7 @@ def singleton_class?
begin
require 'active_support/core_ext/hash/keys'
+ require 'active_support/core_ext/hash/deep_merge'
rescue LoadError
class Hash
def stringify_keys
@@ -68,6 +69,22 @@ def symbolize_keys
end
self
end if !{}.respond_to?(:symbolize_keys)
+
+ def deep_merge(other_hash, &block)
+ dup.deep_merge!(other_hash, &block)
+ end if !{}.respond_to?(:deep_merge)
+
+ def deep_merge!(other_hash, &block)
+ other_hash.each_pair do |k,v|
+ tv = self[k]
+ if tv.is_a?(Hash) && v.is_a?(Hash)
+ self[k] = tv.deep_merge(v, &block)
+ else
+ self[k] = block && tv ? block.call(k, tv, v) : v
+ end
+ end
+ self
+ end if !{}.respond_to?(:deep_merge!)
end
end
View
@@ -14,7 +14,7 @@ class Web < Sinatra::Base
set :root, File.expand_path(File.dirname(__FILE__) + "/../../web")
set :public_folder, Proc.new { "#{root}/assets" }
set :views, Proc.new { "#{root}/views" }
- set :locales, Proc.new { "#{root}/locales" }
+ set :locales, ["#{root}/locales"]
helpers WebHelpers
@@ -5,8 +5,13 @@ module Sidekiq
module WebHelpers
def strings
@@strings ||= begin
- Dir["#{settings.locales}/*.yml"].inject({}) do |memo, file|
- memo.merge(YAML.load(File.open(file)))
+ # Allow sidekiq-web extensions to add locale paths
+ # so extensions can be localized
+ settings.locales.each_with_object({}) do |path,global|
+ Dir["#{path}/*.yml"].each_with_object(global) do |file,hash|
+ strs = YAML.load(File.open(file))
+ hash.deep_merge!(strs)
+ end
end
end
end
View
@@ -0,0 +1,2 @@
+en:
+ translated_text: 'Changed text from add locals'
View
@@ -282,6 +282,22 @@ def perform(a, b)
assert_equal 200, last_response.status
end
+ Sidekiq::Web.settings.locales << File.join(File.dirname(__FILE__), "fixtures")
+ it 'can show user defined tab with custom locales' do
+ begin
+ Sidekiq::Web.tabs['Custom Tab'] = '/custom'
+ Sidekiq::Web.get('/custom') do
+ t('translated_text')
+ end
+
+ get '/custom'
+ assert_match /Changed text/, last_response.body
+
+ ensure
+ Sidekiq::Web.tabs.delete 'Custom Tab'
+ end
+ end
+
describe 'stats' do
before do
Sidekiq.redis do |conn|
View
@@ -60,5 +60,4 @@ en: # <---- change this to your locale code
OneMonth: 1 month
ThreeMonths: 3 months
SixMonths: 6 months
- Batches: Batches
Failures: Failures

0 comments on commit ea42d56

Please sign in to comment.