Module: AdhearsionI18n::CallControllerMethods

Defined in:
lib/adhearsion-i18n/call_controller_methods.rb

Instance Method Summary collapse

Instance Method Details

#localeObject



28
29
30
# File 'lib/adhearsion-i18n/call_controller_methods.rb', line 28

def locale
  call[:locale] || I18n.default_locale
end

#locale=(l) ⇒ Object



32
33
34
# File 'lib/adhearsion-i18n/call_controller_methods.rb', line 32

def locale=(l)
  call[:locale] = l
end

#t(key, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/adhearsion-i18n/call_controller_methods.rb', line 4

def t(key, options = {})
  this_locale = options[:locale] || locale
  options = {default: '', locale: locale}.merge(options)
  prompt = ::I18n.t "#{key}.audio", options
  text   = ::I18n.t "#{key}.text", options

  if prompt.empty? && text.empty?
    # Look for a translation key that doesn't follow the Adhearsion-I18n structure
    text = ::I18n.t key, options
  end

  unless prompt.empty?
    prompt = "#{Adhearsion.config.i18n.audio_path}/#{this_locale}/#{prompt}"
  end

  RubySpeech::SSML.draw language: this_locale do
    if prompt.empty?
      string text
    else
      audio(src: prompt) { string text }
    end
  end
end