Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions lib/project/button_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@ class App
# 2 - Add the test
# 3 - Add symbol to the README.md list
def self.add_template_actions(uiac, template, &block)
yes = NSLocalizedString("Yes", nil)
no = NSLocalizedString("No", nil)
cancel = NSLocalizedString("Cancel", nil)
ok = NSLocalizedString("OK", nil)
delete = NSLocalizedString("Delete", nil)

case template
when :yes_no
uiac.addAction(rmq.app.make_button("Yes", &block))
uiac.addAction(rmq.app.make_button("No", &block))
uiac.addAction(rmq.app.make_button(yes, &block))
uiac.addAction(rmq.app.make_button(no, &block))
when :yes_no_cancel
uiac.addAction(rmq.app.make_button("Yes", &block))
uiac.addAction(rmq.app.make_button("No", &block))
uiac.addAction(rmq.app.make_button({title: "Cancel", style: :cancel}, &block))
uiac.addAction(rmq.app.make_button(yes, &block))
uiac.addAction(rmq.app.make_button(no, &block))
uiac.addAction(rmq.app.make_button({title: cancel, style: :cancel}, &block))
when :ok_cancel
uiac.addAction(rmq.app.make_button("OK", &block))
uiac.addAction(rmq.app.make_button({title: "Cancel", style: :cancel}, &block))
uiac.addAction(rmq.app.make_button(ok, &block))
uiac.addAction(rmq.app.make_button({title: cancel, style: :cancel}, &block))
when :delete_cancel
uiac.addAction(rmq.app.make_button({title: "Delete", style: :destructive}, &block))
uiac.addAction(rmq.app.make_button({title: "Cancel", style: :cancel}, &block))
uiac.addAction(rmq.app.make_button({title: delete, style: :destructive}, &block))
uiac.addAction(rmq.app.make_button({title: cancel, style: :cancel}, &block))
end
end

end
end
end
6 changes: 3 additions & 3 deletions lib/project/classic_alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def self.alert_view(opts = {})
raise(ArgumentError, "RedAlert requires a message") if opts[:message].nil? || opts[:message].empty?

opts = {
title: "Alert!",
cancel_button: "OK",
title: NSLocalizedString("Alert!", nil),
cancel_button: NSLocalizedString("OK", nil),
other_buttons: [],
delegate: nil,
view_style: UIAlertViewStyleDefault,
Expand All @@ -39,4 +39,4 @@ def self.alert_view(opts = {})
end

end
end
end
4 changes: 2 additions & 2 deletions lib/project/core_alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class << self
def core_alert(opts = {}, &block)

opts = {
title: "Alert!",
title: NSLocalizedString("Alert!", nil),
style: :alert,
actions: [make_button(&block)],
animated: true,
Expand Down Expand Up @@ -41,4 +41,4 @@ def core_alert(opts = {}, &block)
end # close eigenclass

end
end
end
4 changes: 2 additions & 2 deletions lib/project/red_alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def make_button (opts = {}, &block)
opts = {title: opts} if opts.is_a? String

opts = {
title: "OK",
title: NSLocalizedString("OK", nil),
style: :default,
}.merge(opts)

Expand All @@ -45,4 +45,4 @@ def make_button (opts = {}, &block)
end # close eigenclass

end # close App
end
end
6 changes: 6 additions & 0 deletions resources/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"Yes" = "Oui";
"No" = "Pas";
"Cancel" = "Annuler";
"OK" = "OK";
"Delete" = "Effacer";
"Alert!" = "Alerte!";
53 changes: 52 additions & 1 deletion spec/red_alert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,56 @@
end
end

describe "i18n capability" do
class French
class << self
attr_writer :enabled

def enabled?
@enabled || false
end
end
end


class Kernel
def NSLocalizedString(key, comment)
if French.enabled?
path = NSBundle.mainBundle.pathForResource('fr', ofType:"lproj" )
bundle = NSBundle.bundleWithPath(path)
bundle.localizedStringForKey(key, value:comment, table:nil)
else
key
end
end
end

before do
French.enabled = true

@yes_no_cancel_controller = rmq.app.alert(message: 'yes_no_cancel', actions: :yes_no_cancel, show_now: false)
wait TEST_DELAY do
rmq.view_controller.presentViewController(@yes_no_cancel_controller, animated: false, completion: nil)
end
end

after do
French.enabled = false
end

it 'has the correct values for a :yes_no_cancel template' do
# Default title
@yes_no_cancel_controller.rmq(UILabel)[0].get.text.should == "Alerte!"
# Assigned message
@yes_no_cancel_controller.rmq(UILabel)[1].get.text.should == 'yes_no_cancel'

# Check for the buttons
wait TEST_DELAY do
@yes_no_cancel_controller.rmq(text: "Oui").size.should == 1
@yes_no_cancel_controller.rmq(text: "Pas").size.should == 1
@yes_no_cancel_controller.rmq(text: "Annuler").size.should == 1
end
end
end

end
end