Module: Wicked::Wizard::Translated

Extended by:
ActiveSupport::Concern
Includes:
Wicked::Wizard
Defined in:
lib/wicked/wizard/translated.rb

Constant Summary

Constants included from Controller::Concerns::Steps

Controller::Concerns::Steps::PROTECTED_STEPS

Instance Method Summary collapse

Methods included from Wicked::Wizard

#index

Methods included from Controller::Concerns::Steps

#current_step?, #future_step?, #jump_to, #next_step, #next_step?, #past_step?, #previous_step, #previous_step?, #skip_step, #step, #steps, #steps=

Methods included from Controller::Concerns::RenderRedirect

#finish_wizard_path, #process_resource!, #redirect_to_finish_wizard, #redirect_to_next, #render_step, #render_wizard

Methods included from Controller::Concerns::Path

#next_wizard_path, #previous_wizard_path, #wicked_action, #wicked_controller, #wizard_path

Instance Method Details

#wizard_translate(step_name) ⇒ Object

takes a canonical wizard value and translates to correct language

es.yml wicked:

first: "uno"

wizard_translate("first") # => :uno

43
44
45
# File 'lib/wicked/wizard/translated.rb', line 43

def wizard_translate(step_name)
  I18n.t("wicked.#{step_name}")
end

#wizard_translationsObject

creates a hash where keys are translated steps, values are the name of the view file

es:
  hello: "hola mundo"
  wicked:
    first: "uno"
    second: "dos"

 steps :first, :second

=> :first, :dos => :second # spanish => :first, :second => :second # english


27
28
29
30
31
32
33
34
# File 'lib/wicked/wizard/translated.rb', line 27

def wizard_translations
  @wizard_translations ||= steps.inject(ActiveSupport::OrderedHash.new) do |hash, step|
    step              = step.to_s.split(".").last
    translation       = wizard_translate(step)
    hash[translation] = step.to_s
    hash
  end
end

#wizard_value(step_name) ⇒ Object

takes an already translated value and converts to a canonical wizard value

es.yml wicked:

first: "uno"

wizard_value("uno") # => :first

55
56
57
# File 'lib/wicked/wizard/translated.rb', line 55

def wizard_value(step_name)
  wizard_translations["#{step_name}"]
end