Skip to content

Commit b43ca55

Browse files
committed
Restore internationalization functionality in toolbars
1 parent 1a0ba39 commit b43ca55

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

app/helpers/application_helper/button/basic.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def initialize(view_context, view_binding, instance_data, props)
1414

1515
# Return content under key such as :text or :confirm run through gettext or
1616
# evalated in the context of controller variables and helper methods.
17-
def localized(key)
17+
def localized(key, value = nil)
18+
self[key] = value if value
19+
1820
case self[key]
1921
when NilClass then ''
2022
when Proc then instance_eval(&self[key])

app/helpers/application_helper/toolbar_builder.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,12 @@ def apply_common_props(button, input)
107107
:data => input[:data]
108108
)
109109

110-
button[:enabled] = input[:enabled]
111-
button[:title] = input[:title] unless input[:title].blank?
112-
button[:text] = input[:text] unless input[:text].blank?
113-
button[:confirm] = input[:confirm] unless input[:confirm].blank?
110+
button[:enabled] = input[:enabled]
111+
%i(title text confirm).each do |key|
112+
unless input[key].blank?
113+
button[key] = button.localized(key, input[key])
114+
end
115+
end
114116
button[:url_parms] = update_url_parms(safer_eval(input[:url_parms])) unless input[:url_parms].blank?
115117

116118
if input[:popup] # special behavior: button opens window_url in a new window
@@ -125,7 +127,9 @@ def apply_common_props(button, input)
125127
dis_title = build_toolbar_disable_button(button[:child_id] || button[:id])
126128
if dis_title
127129
button[:enabled] = false
128-
button[:title] = dis_title if dis_title.kind_of? String
130+
if dis_title.kind_of? String
131+
button[:title] = button.localized(:title, dis_title)
132+
end
129133
end
130134
button
131135
end

spec/helpers/application_helper/toolbar_builder_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,7 @@ def setup_firefox_with_linux
24762476
}
24772477
@tb_buttons = {}
24782478
@button = {:id => "custom_#{btn_num}"}
2479+
@button = ApplicationHelper::Button::Basic.new(nil, nil, {}, {:id => "custom_#{btn_num}"})
24792480
allow_any_instance_of(Object).to receive(:query_string).and_return("")
24802481
allow_message_expectations_on_nil
24812482
end
@@ -2516,6 +2517,34 @@ def setup_firefox_with_linux
25162517
expect(subject).to have_key(:onwhen)
25172518
end
25182519
end
2520+
2521+
context "internationalization" do
2522+
it "does translation of text title and confirm strings" do
2523+
%i(text title confirm).each do |key|
2524+
@input[key] = 'Configuration' # common button string, translated into Japanese
2525+
end
2526+
FastGettext.locale = 'ja'
2527+
apply_common_props(@button, @input)
2528+
%i(text title confirm).each do |key|
2529+
expect(@button[key]).not_to match('Configuration')
2530+
end
2531+
FastGettext.locale = 'en'
2532+
end
2533+
2534+
it "does delayed translation of text title and confirm strings" do
2535+
%i(text title confirm).each do |key|
2536+
@input[key] = proc do
2537+
_("Add New %{model}") % {:model => 'Model'}
2538+
end
2539+
end
2540+
FastGettext.locale = 'ja'
2541+
apply_common_props(@button, @input)
2542+
%i(text title confirm).each do |key|
2543+
expect(@button[key]).not_to match('Add New Model')
2544+
end
2545+
FastGettext.locale = 'en'
2546+
end
2547+
end
25192548
end
25202549

25212550
describe "#build_toolbar_save_button" do

0 commit comments

Comments
 (0)